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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/hash_tables.h
===================================================================
--- base/hash_tables.h (revision 21480)
+++ base/hash_tables.h (working copy)
@@ -17,6 +17,8 @@
#include "build/build_config.h"
+#include "base/string16.h"
+
#if defined(COMPILER_MSVC)
#include <hash_map>
#include <hash_set>
@@ -100,6 +102,32 @@
}
};
+#if defined(WCHAR_T_IS_UTF32)
+template<>
+struct hash<string16> {
+ size_t operator()(const string16& s) const {
+ // This comes from GNU libstdc++, but the types have been changed to
+ // make it compile. The lib only defines the hash for string and wstring.
+ std::size_t result = 0;
+ for (string16::const_iterator i = s.begin(); i != s.end(); ++i)
+ result = (result * 131) + *i;
+ return result;
+ }
+};
+
+template<>
+struct hash<const string16> {
+ size_t operator()(const string16& s) const {
+ // This comes from GNU libstdc++, but the types have been changed to
+ // make it compile. The lib only defines the hash for string and wstring.
+ std::size_t result = 0;
+ for (string16::const_iterator i = s.begin(); i != s.end(); ++i)
+ result = (result * 131) + *i;
+ return result;
+ }
+};
+#endif
+
}
#endif
« 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