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" | |
25 #include "wtf/RefPtr.h" | 24 #include "wtf/RefPtr.h" |
26 #include "wtf/StdLibExtras.h" | 25 #include "wtf/StdLibExtras.h" |
27 #include <memory> | 26 #include <memory> |
28 #include <stdint.h> | 27 #include <stdint.h> |
29 #include <type_traits> | 28 #include <type_traits> |
30 | 29 |
31 namespace WTF { | 30 namespace WTF { |
32 | 31 |
33 template <size_t size> struct IntTypes; | 32 template <size_t size> struct IntTypes; |
34 template <> struct IntTypes<1> { typedef int8_t SignedType; typedef uint8_t Unsi
gnedType; }; | 33 template <> struct IntTypes<1> { typedef int8_t SignedType; typedef uint8_t Unsi
gnedType; }; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 static unsigned hash(const RefPtr<T>& key) { return hash(key.get()); } | 147 static unsigned hash(const RefPtr<T>& key) { return hash(key.get()); } |
149 static unsigned hash(const PassRefPtr<T>& key) { return hash(key.get()); } | 148 static unsigned hash(const PassRefPtr<T>& key) { return hash(key.get()); } |
150 using PtrHash<T>::equal; | 149 using PtrHash<T>::equal; |
151 static bool equal(const RefPtr<T>& a, const RefPtr<T>& b) { return a == b; } | 150 static bool equal(const RefPtr<T>& a, const RefPtr<T>& b) { return a == b; } |
152 static bool equal(T* a, const RefPtr<T>& b) { return a == b; } | 151 static bool equal(T* a, const RefPtr<T>& b) { return a == b; } |
153 static bool equal(const RefPtr<T>& a, T* b) { return a == b; } | 152 static bool equal(const RefPtr<T>& a, T* b) { return a == b; } |
154 static bool equal(const RefPtr<T>& a, const PassRefPtr<T>& b) { return a ==
b; } | 153 static bool equal(const RefPtr<T>& a, const PassRefPtr<T>& b) { return a ==
b; } |
155 }; | 154 }; |
156 | 155 |
157 template <typename T> | 156 template <typename T> |
158 struct OwnPtrHash : PtrHash<T> { | |
159 using PtrHash<T>::hash; | |
160 static unsigned hash(const OwnPtr<T>& key) { return hash(key.get()); } | |
161 | |
162 static bool equal(const OwnPtr<T>& a, const OwnPtr<T>& b) | |
163 { | |
164 return a.get() == b.get(); | |
165 } | |
166 static bool equal(const OwnPtr<T>& a, T* b) { return a == b; } | |
167 }; | |
168 | |
169 template <typename T> | |
170 struct UniquePtrHash : PtrHash<T> { | 157 struct UniquePtrHash : PtrHash<T> { |
171 using PtrHash<T>::hash; | 158 using PtrHash<T>::hash; |
172 static unsigned hash(const std::unique_ptr<T>& key) { return hash(key.get())
; } | 159 static unsigned hash(const std::unique_ptr<T>& key) { return hash(key.get())
; } |
173 static bool equal(const std::unique_ptr<T>& a, const std::unique_ptr<T>& b)
{ return a == b; } | 160 static bool equal(const std::unique_ptr<T>& a, const std::unique_ptr<T>& b)
{ return a == b; } |
174 static bool equal(const std::unique_ptr<T>& a, const T* b) { return a.get()
== b; } | 161 static bool equal(const std::unique_ptr<T>& a, const T* b) { return a.get()
== b; } |
175 static bool equal(const T* a, const std::unique_ptr<T>& b) { return a == b.g
et(); } | 162 static bool equal(const T* a, const std::unique_ptr<T>& b) { return a == b.g
et(); } |
176 }; | 163 }; |
177 | 164 |
178 // Default hash function for each type. | 165 // Default hash function for each type. |
179 template <typename T> | 166 template <typename T> |
(...skipping 28 matching lines...) Expand all Loading... |
208 // Specializations for pointer types. | 195 // Specializations for pointer types. |
209 template <typename T> | 196 template <typename T> |
210 struct DefaultHash<T*> { | 197 struct DefaultHash<T*> { |
211 using Hash = PtrHash<T>; | 198 using Hash = PtrHash<T>; |
212 }; | 199 }; |
213 template <typename T> | 200 template <typename T> |
214 struct DefaultHash<RefPtr<T>> { | 201 struct DefaultHash<RefPtr<T>> { |
215 using Hash = RefPtrHash<T>; | 202 using Hash = RefPtrHash<T>; |
216 }; | 203 }; |
217 template <typename T> | 204 template <typename T> |
218 struct DefaultHash<OwnPtr<T>> { | |
219 using Hash = OwnPtrHash<T>; | |
220 }; | |
221 template <typename T> | |
222 struct DefaultHash<std::unique_ptr<T>> { | 205 struct DefaultHash<std::unique_ptr<T>> { |
223 using Hash = UniquePtrHash<T>; | 206 using Hash = UniquePtrHash<T>; |
224 }; | 207 }; |
225 | 208 |
226 // Specializations for pairs. | 209 // Specializations for pairs. |
227 | 210 |
228 // Generic case (T or U is non-integral): | 211 // Generic case (T or U is non-integral): |
229 template <typename T, typename U, bool areBothIntegral> | 212 template <typename T, typename U, bool areBothIntegral> |
230 struct PairHashImpl { | 213 struct PairHashImpl { |
231 static unsigned hash(const std::pair<T, U>& p) | 214 static unsigned hash(const std::pair<T, U>& p) |
(...skipping 28 matching lines...) Expand all Loading... |
260 using Hash = PairHash<T, U>; | 243 using Hash = PairHash<T, U>; |
261 }; | 244 }; |
262 | 245 |
263 } // namespace WTF | 246 } // namespace WTF |
264 | 247 |
265 using WTF::DefaultHash; | 248 using WTF::DefaultHash; |
266 using WTF::IntHash; | 249 using WTF::IntHash; |
267 using WTF::PtrHash; | 250 using WTF::PtrHash; |
268 | 251 |
269 #endif // WTF_HashFunctions_h | 252 #endif // WTF_HashFunctions_h |
OLD | NEW |