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