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 27 matching lines...) Expand all Loading... |
38 #define BASE_HASH_NAMESPACE base_hash | 38 #define BASE_HASH_NAMESPACE base_hash |
39 | 39 |
40 // This is a hack to disable the gcc 4.4 warning about hash_map and hash_set | 40 // This is a hack to disable the gcc 4.4 warning about hash_map and hash_set |
41 // being deprecated. We can get rid of this when we upgrade to VS2008 and we | 41 // being deprecated. We can get rid of this when we upgrade to VS2008 and we |
42 // can use <tr1/unordered_map> and <tr1/unordered_set>. | 42 // can use <tr1/unordered_map> and <tr1/unordered_set>. |
43 #ifdef __DEPRECATED | 43 #ifdef __DEPRECATED |
44 #define CHROME_OLD__DEPRECATED __DEPRECATED | 44 #define CHROME_OLD__DEPRECATED __DEPRECATED |
45 #undef __DEPRECATED | 45 #undef __DEPRECATED |
46 #endif | 46 #endif |
47 | 47 |
48 #if defined(OS_ANDROID) | 48 #if defined(OS_ANDROID) && defined(USE_STLPORT) |
49 #include <hash_map> | 49 #include <hash_map> |
50 #include <hash_set> | 50 #include <hash_set> |
51 #define BASE_HASH_IMPL_NAMESPACE std | 51 #define BASE_HASH_IMPL_NAMESPACE std |
52 #else | 52 #else |
53 #include <ext/hash_map> | 53 #include <ext/hash_map> |
54 #include <ext/hash_set> | 54 #include <ext/hash_set> |
55 #define BASE_HASH_IMPL_NAMESPACE __gnu_cxx | 55 #define BASE_HASH_IMPL_NAMESPACE __gnu_cxx |
56 #endif | 56 #endif |
57 | 57 |
58 #include <string> | 58 #include <string> |
(...skipping 18 matching lines...) Expand all Loading... |
77 }; | 77 }; |
78 | 78 |
79 template<typename T> | 79 template<typename T> |
80 struct hash<T*> { | 80 struct hash<T*> { |
81 std::size_t operator()(T* value) const { | 81 std::size_t operator()(T* value) const { |
82 return BASE_HASH_IMPL_NAMESPACE::hash<uintptr_t>()( | 82 return BASE_HASH_IMPL_NAMESPACE::hash<uintptr_t>()( |
83 reinterpret_cast<uintptr_t>(value)); | 83 reinterpret_cast<uintptr_t>(value)); |
84 } | 84 } |
85 }; | 85 }; |
86 | 86 |
87 #if !defined(OS_ANDROID) | 87 #if !defined(USE_STLPORT) |
88 // The GNU C++ library provides identity hash functions for many integral types, | 88 // The GNU C++ library provides identity hash functions for many integral types, |
89 // but not for |long long|. This hash function will truncate if |size_t| is | 89 // but not for |long long|. This hash function will truncate if |size_t| is |
90 // narrower than |long long|. This is probably good enough for what we will | 90 // narrower than |long long|. This is probably good enough for what we will |
91 // use it for. | 91 // use it for. |
92 | 92 |
93 #define DEFINE_TRIVIAL_HASH(integral_type) \ | 93 #define DEFINE_TRIVIAL_HASH(integral_type) \ |
94 template<> \ | 94 template<> \ |
95 struct hash<integral_type> { \ | 95 struct hash<integral_type> { \ |
96 std::size_t operator()(integral_type value) const { \ | 96 std::size_t operator()(integral_type value) const { \ |
97 return static_cast<std::size_t>(value); \ | 97 return static_cast<std::size_t>(value); \ |
98 } \ | 98 } \ |
99 } | 99 } |
100 | 100 |
101 DEFINE_TRIVIAL_HASH(long long); | 101 DEFINE_TRIVIAL_HASH(long long); |
102 DEFINE_TRIVIAL_HASH(unsigned long long); | 102 DEFINE_TRIVIAL_HASH(unsigned long long); |
103 | 103 |
104 #undef DEFINE_TRIVIAL_HASH | 104 #undef DEFINE_TRIVIAL_HASH |
105 #endif // !defined(OS_ANDROID) | 105 #endif // !defined(USE_STLPORT) |
106 | 106 |
107 // Implement string hash functions so that strings of various flavors can | 107 // Implement string hash functions so that strings of various flavors can |
108 // be used as keys in STL maps and sets. The hash algorithm comes from the | 108 // be used as keys in STL maps and sets. The hash algorithm comes from the |
109 // GNU C++ library, in <tr1/functional>. It is duplicated here because GCC | 109 // GNU C++ library, in <tr1/functional>. It is duplicated here because GCC |
110 // versions prior to 4.3.2 are unable to compile <tr1/functional> when RTTI | 110 // versions prior to 4.3.2 are unable to compile <tr1/functional> when RTTI |
111 // is disabled, as it is in our build. | 111 // is disabled, as it is in our build. |
112 | 112 |
113 #define DEFINE_STRING_HASH(string_type) \ | 113 #define DEFINE_STRING_HASH(string_type) \ |
114 template<> \ | 114 template<> \ |
115 struct hash<string_type> { \ | 115 struct hash<string_type> { \ |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 return base::HashPair(value.first, value.second); | 319 return base::HashPair(value.first, value.second); |
320 } | 320 } |
321 }; | 321 }; |
322 | 322 |
323 } | 323 } |
324 | 324 |
325 #undef DEFINE_PAIR_HASH_FUNCTION_START | 325 #undef DEFINE_PAIR_HASH_FUNCTION_START |
326 #undef DEFINE_PAIR_HASH_FUNCTION_END | 326 #undef DEFINE_PAIR_HASH_FUNCTION_END |
327 | 327 |
328 #endif // BASE_CONTAINERS_HASH_TABLES_H_ | 328 #endif // BASE_CONTAINERS_HASH_TABLES_H_ |
OLD | NEW |