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 return a.get() == b.get(); |
| 165 } |
| 166 static bool equal(const OwnPtr<P>& a, P* b) { return a == b; } |
| 167 static bool equal(const OwnPtr<P>& a, const PassOwnPtr<P>& b) |
| 168 { |
| 169 return a.get() == b.get(); |
| 170 } |
| 171 }; |
154 | 172 |
155 // default hash function for each type | 173 // default hash function for each type |
156 | 174 |
157 template<typename T> struct DefaultHash; | 175 template<typename T> struct DefaultHash; |
158 | 176 |
159 template<typename T, typename U> struct PairHash { | 177 template<typename T, typename U> struct PairHash { |
160 static unsigned hash(const std::pair<T, U>& p) | 178 static unsigned hash(const std::pair<T, U>& p) |
161 { | 179 { |
162 return pairIntHash(DefaultHash<T>::Hash::hash(p.first), DefaultHash<
U>::Hash::hash(p.second)); | 180 return pairIntHash(DefaultHash<T>::Hash::hash(p.first), DefaultHash<
U>::Hash::hash(p.second)); |
163 } | 181 } |
(...skipping 27 matching lines...) Expand all Loading... |
191 #endif | 209 #endif |
192 | 210 |
193 template<> struct DefaultHash<float> { typedef FloatHash<float> Hash; }; | 211 template<> struct DefaultHash<float> { typedef FloatHash<float> Hash; }; |
194 template<> struct DefaultHash<double> { typedef FloatHash<double> Hash; }; | 212 template<> struct DefaultHash<double> { typedef FloatHash<double> Hash; }; |
195 | 213 |
196 // make PtrHash the default hash function for pointer types that don't speci
alize | 214 // make PtrHash the default hash function for pointer types that don't speci
alize |
197 | 215 |
198 template<typename P> struct DefaultHash<P*> { typedef PtrHash<P*> Hash; }; | 216 template<typename P> struct DefaultHash<P*> { typedef PtrHash<P*> Hash; }; |
199 template<typename P> struct DefaultHash<RefPtr<P> > { typedef PtrHash<RefPtr
<P> > Hash; }; | 217 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; }; | 218 template<typename P> struct DefaultHash<RawPtr<P> > { typedef PtrHash<RawPtr
<P> > Hash; }; |
| 219 template<typename P> struct DefaultHash<OwnPtr<P> > { typedef PtrHash<OwnPtr
<P> > Hash; }; |
201 | 220 |
202 // make IntPairHash the default hash function for pairs of (at most) 32-bit
integers. | 221 // make IntPairHash the default hash function for pairs of (at most) 32-bit
integers. |
203 | 222 |
204 template<> struct DefaultHash<std::pair<short, short> > { typedef IntPairHas
h<short, short> Hash; }; | 223 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; }; | 224 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; }; | 225 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; }; | 226 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; }; | 227 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; }; | 228 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; }; | 229 template<> struct DefaultHash<std::pair<unsigned short, int> > { typedef Int
PairHash<unsigned short, int> Hash; }; |
(...skipping 11 matching lines...) Expand all Loading... |
222 | 241 |
223 template<typename T, typename U> struct DefaultHash<std::pair<T, U> > { type
def PairHash<T, U> Hash; }; | 242 template<typename T, typename U> struct DefaultHash<std::pair<T, U> > { type
def PairHash<T, U> Hash; }; |
224 | 243 |
225 } // namespace WTF | 244 } // namespace WTF |
226 | 245 |
227 using WTF::DefaultHash; | 246 using WTF::DefaultHash; |
228 using WTF::IntHash; | 247 using WTF::IntHash; |
229 using WTF::PtrHash; | 248 using WTF::PtrHash; |
230 | 249 |
231 #endif // WTF_HashFunctions_h | 250 #endif // WTF_HashFunctions_h |
OLD | NEW |