OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 * | 18 * |
19 */ | 19 */ |
20 | 20 |
21 #ifndef WTF_HashFunctions_h | 21 #ifndef WTF_HashFunctions_h |
22 #define WTF_HashFunctions_h | 22 #define WTF_HashFunctions_h |
23 | 23 |
24 #include "wtf/OwnPtr.h" | |
24 #include "wtf/RefPtr.h" | 25 #include "wtf/RefPtr.h" |
25 #include "wtf/StdLibExtras.h" | 26 #include "wtf/StdLibExtras.h" |
26 #include <stdint.h> | 27 #include <stdint.h> |
27 | 28 |
28 namespace WTF { | 29 namespace WTF { |
29 | 30 |
30 template<size_t size> struct IntTypes; | 31 template<size_t size> struct IntTypes; |
31 template<> struct IntTypes<1> { typedef int8_t SignedType; typedef uint8_t U nsignedType; }; | 32 template<> struct IntTypes<1> { typedef int8_t SignedType; typedef uint8_t U nsignedType; }; |
32 template<> struct IntTypes<2> { typedef int16_t SignedType; typedef uint16_t UnsignedType; }; | 33 template<> struct IntTypes<2> { typedef int16_t SignedType; typedef uint16_t UnsignedType; }; |
33 template<> struct IntTypes<4> { typedef int32_t SignedType; typedef uint32_t UnsignedType; }; | 34 template<> struct IntTypes<4> { typedef int32_t SignedType; typedef uint32_t UnsignedType; }; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 #if COMPILER(MSVC) | 132 #if COMPILER(MSVC) |
132 #pragma warning(pop) | 133 #pragma warning(pop) |
133 #endif | 134 #endif |
134 } | 135 } |
135 static bool equal(T a, T b) { return a == b; } | 136 static bool equal(T a, T b) { return a == b; } |
136 static const bool safeToCompareToEmptyOrDeleted = true; | 137 static const bool safeToCompareToEmptyOrDeleted = true; |
137 }; | 138 }; |
138 template<typename P> struct PtrHash<RefPtr<P> > : PtrHash<P*> { | 139 template<typename P> struct PtrHash<RefPtr<P> > : PtrHash<P*> { |
139 using PtrHash<P*>::hash; | 140 using PtrHash<P*>::hash; |
140 static unsigned hash(const RefPtr<P>& key) { return hash(key.get()); } | 141 static unsigned hash(const RefPtr<P>& key) { return hash(key.get()); } |
142 static unsigned hash(const PassRefPtr<P>& key) { return hash(key.get()); } | |
141 using PtrHash<P*>::equal; | 143 using PtrHash<P*>::equal; |
142 static bool equal(const RefPtr<P>& a, const RefPtr<P>& b) { return a == b; } | 144 static bool equal(const RefPtr<P>& a, const RefPtr<P>& b) { return a == b; } |
143 static bool equal(P* a, const RefPtr<P>& b) { return a == b; } | 145 static bool equal(P* a, const RefPtr<P>& b) { return a == b; } |
144 static bool equal(const RefPtr<P>& a, P* b) { return a == b; } | 146 static bool equal(const RefPtr<P>& a, P* b) { return a == b; } |
147 static bool equal(const RefPtr<P>& a, const PassRefPtr<P>& b) { return a == b; } | |
145 }; | 148 }; |
146 template<typename P> struct PtrHash<RawPtr<P> > : PtrHash<P*> { | 149 template<typename P> struct PtrHash<RawPtr<P> > : PtrHash<P*> { |
147 using PtrHash<P*>::hash; | 150 using PtrHash<P*>::hash; |
148 static unsigned hash(const RawPtr<P>& key) { return hash(key.get()); } | 151 static unsigned hash(const RawPtr<P>& key) { return hash(key.get()); } |
149 using PtrHash<P*>::equal; | 152 using PtrHash<P*>::equal; |
150 static bool equal(const RawPtr<P>& a, const RawPtr<P>& b) { return a == b; } | 153 static bool equal(const RawPtr<P>& a, const RawPtr<P>& b) { return a == b; } |
151 static bool equal(P* a, const RawPtr<P>& b) { return a == b; } | 154 static bool equal(P* a, const RawPtr<P>& b) { return a == b; } |
152 static bool equal(const RawPtr<P>& a, P* b) { return a == b; } | 155 static bool equal(const RawPtr<P>& a, P* b) { return a == b; } |
153 }; | 156 }; |
157 template<typename P> struct PtrHash<OwnPtr<P> > : PtrHash<P*> { | |
158 using PtrHash<P*>::hash; | |
159 static unsigned hash(const OwnPtr<P>& key) { return hash(key.get()); } | |
160 static unsigned hash(const PassOwnPtr<P>& key) { return hash(key.get()); } | |
161 | |
162 static bool equal(const OwnPtr<P>& a, const OwnPtr<P>& b) | |
163 { | |
164 RELEASE_ASSERT(!a || a.get() != b.get()); | |
Erik Corry
2014/04/28 07:53:03
I understand why you have this, but I think RELEAS
Mikhail
2014/04/28 08:00:40
Oh, thanks for the catch! I've put it for debuggin
| |
165 return a.get() == b.get(); | |
166 } | |
167 static bool equal(const OwnPtr<P>& a, P* b) { return a == b; } | |
168 static bool equal(const OwnPtr<P>& a, const PassOwnPtr<P>& b) | |
169 { | |
170 RELEASE_ASSERT(!a || a.get() != b.get()); | |
171 return a.get() == b.get(); | |
172 } | |
173 }; | |
154 | 174 |
155 // default hash function for each type | 175 // default hash function for each type |
156 | 176 |
157 template<typename T> struct DefaultHash; | 177 template<typename T> struct DefaultHash; |
158 | 178 |
159 template<typename T, typename U> struct PairHash { | 179 template<typename T, typename U> struct PairHash { |
160 static unsigned hash(const std::pair<T, U>& p) | 180 static unsigned hash(const std::pair<T, U>& p) |
161 { | 181 { |
162 return pairIntHash(DefaultHash<T>::Hash::hash(p.first), DefaultHash< U>::Hash::hash(p.second)); | 182 return pairIntHash(DefaultHash<T>::Hash::hash(p.first), DefaultHash< U>::Hash::hash(p.second)); |
163 } | 183 } |
(...skipping 27 matching lines...) Expand all Loading... | |
191 #endif | 211 #endif |
192 | 212 |
193 template<> struct DefaultHash<float> { typedef FloatHash<float> Hash; }; | 213 template<> struct DefaultHash<float> { typedef FloatHash<float> Hash; }; |
194 template<> struct DefaultHash<double> { typedef FloatHash<double> Hash; }; | 214 template<> struct DefaultHash<double> { typedef FloatHash<double> Hash; }; |
195 | 215 |
196 // make PtrHash the default hash function for pointer types that don't speci alize | 216 // make PtrHash the default hash function for pointer types that don't speci alize |
197 | 217 |
198 template<typename P> struct DefaultHash<P*> { typedef PtrHash<P*> Hash; }; | 218 template<typename P> struct DefaultHash<P*> { typedef PtrHash<P*> Hash; }; |
199 template<typename P> struct DefaultHash<RefPtr<P> > { typedef PtrHash<RefPtr <P> > Hash; }; | 219 template<typename P> struct DefaultHash<RefPtr<P> > { typedef PtrHash<RefPtr <P> > Hash; }; |
200 template<typename P> struct DefaultHash<RawPtr<P> > { typedef PtrHash<RawPtr <P> > Hash; }; | 220 template<typename P> struct DefaultHash<RawPtr<P> > { typedef PtrHash<RawPtr <P> > Hash; }; |
221 template<typename P> struct DefaultHash<OwnPtr<P> > { typedef PtrHash<OwnPtr <P> > Hash; }; | |
201 | 222 |
202 // make IntPairHash the default hash function for pairs of (at most) 32-bit integers. | 223 // make IntPairHash the default hash function for pairs of (at most) 32-bit integers. |
203 | 224 |
204 template<> struct DefaultHash<std::pair<short, short> > { typedef IntPairHas h<short, short> Hash; }; | 225 template<> struct DefaultHash<std::pair<short, short> > { typedef IntPairHas h<short, short> Hash; }; |
205 template<> struct DefaultHash<std::pair<short, unsigned short> > { typedef I ntPairHash<short, unsigned short> Hash; }; | 226 template<> struct DefaultHash<std::pair<short, unsigned short> > { typedef I ntPairHash<short, unsigned short> Hash; }; |
206 template<> struct DefaultHash<std::pair<short, int> > { typedef IntPairHash< short, int> Hash; }; | 227 template<> struct DefaultHash<std::pair<short, int> > { typedef IntPairHash< short, int> Hash; }; |
207 template<> struct DefaultHash<std::pair<short, unsigned> > { typedef IntPair Hash<short, unsigned> Hash; }; | 228 template<> struct DefaultHash<std::pair<short, unsigned> > { typedef IntPair Hash<short, unsigned> Hash; }; |
208 template<> struct DefaultHash<std::pair<unsigned short, short> > { typedef I ntPairHash<unsigned short, short> Hash; }; | 229 template<> struct DefaultHash<std::pair<unsigned short, short> > { typedef I ntPairHash<unsigned short, short> Hash; }; |
209 template<> struct DefaultHash<std::pair<unsigned short, unsigned short> > { typedef IntPairHash<unsigned short, unsigned short> Hash; }; | 230 template<> struct DefaultHash<std::pair<unsigned short, unsigned short> > { typedef IntPairHash<unsigned short, unsigned short> Hash; }; |
210 template<> struct DefaultHash<std::pair<unsigned short, int> > { typedef Int PairHash<unsigned short, int> Hash; }; | 231 template<> struct DefaultHash<std::pair<unsigned short, int> > { typedef Int PairHash<unsigned short, int> Hash; }; |
(...skipping 11 matching lines...) Expand all Loading... | |
222 | 243 |
223 template<typename T, typename U> struct DefaultHash<std::pair<T, U> > { type def PairHash<T, U> Hash; }; | 244 template<typename T, typename U> struct DefaultHash<std::pair<T, U> > { type def PairHash<T, U> Hash; }; |
224 | 245 |
225 } // namespace WTF | 246 } // namespace WTF |
226 | 247 |
227 using WTF::DefaultHash; | 248 using WTF::DefaultHash; |
228 using WTF::IntHash; | 249 using WTF::IntHash; |
229 using WTF::PtrHash; | 250 using WTF::PtrHash; |
230 | 251 |
231 #endif // WTF_HashFunctions_h | 252 #endif // WTF_HashFunctions_h |
OLD | NEW |