Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: base/hash_tables.h

Issue 160062: Hashing string16s. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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:
11 // base::hash_map<int> my_map; 11 // base::hash_map<int> my_map;
12 // base::hash_set<int> my_set; 12 // base::hash_set<int> my_set;
13 // 13 //
14 14
15 #ifndef BASE_HASH_TABLES_H__ 15 #ifndef BASE_HASH_TABLES_H__
16 #define BASE_HASH_TABLES_H__ 16 #define BASE_HASH_TABLES_H__
17 17
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 19
20 #include "base/string16.h"
21
20 #if defined(COMPILER_MSVC) 22 #if defined(COMPILER_MSVC)
21 #include <hash_map> 23 #include <hash_map>
22 #include <hash_set> 24 #include <hash_set>
23 namespace base { 25 namespace base {
24 using stdext::hash_map; 26 using stdext::hash_map;
25 using stdext::hash_set; 27 using stdext::hash_set;
26 } 28 }
27 #elif defined(COMPILER_GCC) 29 #elif defined(COMPILER_GCC)
28 // This is a hack to disable the gcc 4.4 warning about hash_map and hash_set 30 // This is a hack to disable the gcc 4.4 warning about hash_map and hash_set
29 // being deprecated. We can get rid of this when we upgrade to VS2008 and we 31 // being deprecated. We can get rid of this when we upgrade to VS2008 and we
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 95 }
94 }; 96 };
95 97
96 template<> 98 template<>
97 struct hash<long long> { 99 struct hash<long long> {
98 size_t operator()(long long i) const { 100 size_t operator()(long long i) const {
99 return std::tr1::hash<long>()((long) i); 101 return std::tr1::hash<long>()((long) i);
100 } 102 }
101 }; 103 };
102 104
105 #if defined(WCHAR_T_IS_UTF32)
106 template<>
107 struct hash<string16> {
108 size_t operator()(const string16& s) const {
109 // This comes from GNU libstdc++, but the types have been changed to
110 // make it compile. The lib only defines the hash for string and wstring.
111 std::size_t result = 0;
112 for (string16::const_iterator i = s.begin(); i != s.end(); ++i)
113 result = (result * 131) + *i;
114 return result;
115 }
116 };
117
118 template<>
119 struct hash<const string16> {
120 size_t operator()(const string16& s) const {
121 // This comes from GNU libstdc++, but the types have been changed to
122 // make it compile. The lib only defines the hash for string and wstring.
123 std::size_t result = 0;
124 for (string16::const_iterator i = s.begin(); i != s.end(); ++i)
125 result = (result * 131) + *i;
126 return result;
127 }
128 };
129 #endif
130
103 } 131 }
104 132
105 #endif 133 #endif
106 134
107 #endif // BASE_HASH_TABLES_H__ 135 #endif // BASE_HASH_TABLES_H__
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698