Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 | 5 |
| 6 // | 6 // |
| 7 // Deal with the differences between Microsoft and GNU implemenations | 7 // Deal with the differences between Microsoft and GNU implemenations |
| 8 // of hash_map. Allows all platforms to use |base::hash_map| and | 8 // of hash_map. Allows all platforms to use |base::hash_map| and |
| 9 // |base::hash_set|. | 9 // |base::hash_set|. |
| 10 // eg: | 10 // eg: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 return static_cast<std::size_t>(value); \ | 78 return static_cast<std::size_t>(value); \ |
| 79 } \ | 79 } \ |
| 80 } | 80 } |
| 81 | 81 |
| 82 DEFINE_TRIVIAL_HASH(long long); | 82 DEFINE_TRIVIAL_HASH(long long); |
| 83 DEFINE_TRIVIAL_HASH(unsigned long long); | 83 DEFINE_TRIVIAL_HASH(unsigned long long); |
| 84 | 84 |
| 85 #undef DEFINE_TRIVIAL_HASH | 85 #undef DEFINE_TRIVIAL_HASH |
| 86 #endif // !defined(OS_ANDROID) | 86 #endif // !defined(OS_ANDROID) |
| 87 | 87 |
| 88 // To align with C++11's std::hash and MSVC's pre-standard stdext::hash_value, | |
| 89 // provide a default hash function for raw pointers. Note: const char * is still | |
| 90 // specialized to hash as a C string. This is consistent with the currently used | |
| 91 // stdext::hash_value, but not C++11. | |
| 92 template<typename T> | |
| 93 struct hash<T*> { | |
| 94 std::size_t operator()(T* value) const { | |
| 95 BASE_HASH_NAMESPACE::hash<uintptr_t> h; | |
|
viettrungluu
2014/10/08 17:19:44
You're already inside BASE_HASH_NAMESPACE.
davidben
2014/10/08 18:04:01
Done.
| |
| 96 return h(reinterpret_cast<uintptr_t>(value)); | |
|
viettrungluu
2014/10/08 17:19:45
So you should be able to do |return hash<uintptr_t
davidben
2014/10/08 18:04:01
Done, except the cast is still needed.
| |
| 97 } | |
| 98 }; | |
| 99 | |
| 88 // Implement string hash functions so that strings of various flavors can | 100 // Implement string hash functions so that strings of various flavors can |
| 89 // be used as keys in STL maps and sets. The hash algorithm comes from the | 101 // be used as keys in STL maps and sets. The hash algorithm comes from the |
| 90 // GNU C++ library, in <tr1/functional>. It is duplicated here because GCC | 102 // GNU C++ library, in <tr1/functional>. It is duplicated here because GCC |
| 91 // versions prior to 4.3.2 are unable to compile <tr1/functional> when RTTI | 103 // versions prior to 4.3.2 are unable to compile <tr1/functional> when RTTI |
| 92 // is disabled, as it is in our build. | 104 // is disabled, as it is in our build. |
| 93 | 105 |
| 94 #define DEFINE_STRING_HASH(string_type) \ | 106 #define DEFINE_STRING_HASH(string_type) \ |
| 95 template<> \ | 107 template<> \ |
| 96 struct hash<string_type> { \ | 108 struct hash<string_type> { \ |
| 97 std::size_t operator()(const string_type& s) const { \ | 109 std::size_t operator()(const string_type& s) const { \ |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 #else | 267 #else |
| 256 #error define hash<std::pair<Type1, Type2> > for your compiler | 268 #error define hash<std::pair<Type1, Type2> > for your compiler |
| 257 #endif // COMPILER | 269 #endif // COMPILER |
| 258 | 270 |
| 259 } | 271 } |
| 260 | 272 |
| 261 #undef DEFINE_PAIR_HASH_FUNCTION_START | 273 #undef DEFINE_PAIR_HASH_FUNCTION_START |
| 262 #undef DEFINE_PAIR_HASH_FUNCTION_END | 274 #undef DEFINE_PAIR_HASH_FUNCTION_END |
| 263 | 275 |
| 264 #endif // BASE_CONTAINERS_HASH_TABLES_H_ | 276 #endif // BASE_CONTAINERS_HASH_TABLES_H_ |
| OLD | NEW |