summaryrefslogtreecommitdiffstats
path: root/base/hash_tables.h
diff options
context:
space:
mode:
authorjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-24 01:20:08 +0000
committerjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-24 01:20:08 +0000
commit4f9b2a7e42fc567073f4999a888b3140bec460bb (patch)
tree9e8f6fce73b21e6c53931b36c68d7b40d8090301 /base/hash_tables.h
parent6e282c938d74f513dc5a92c2d96cfd955ac05d9b (diff)
downloadchromium_src-4f9b2a7e42fc567073f4999a888b3140bec460bb.zip
chromium_src-4f9b2a7e42fc567073f4999a888b3140bec460bb.tar.gz
chromium_src-4f9b2a7e42fc567073f4999a888b3140bec460bb.tar.bz2
I'm apparently the first one who's tried to do hash_map<string16, ...>. Unfortunately, hash_map<> does not know how to hash a string16 when string16 isn't a wstring. I looked in <tr1/functional> and saw that only std::string and std::wstring have hashing functions.
This change adds a hashing function for string16's when they're not the same as a std::wstring. BUG=none TEST=none Review URL: http://codereview.chromium.org/160062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21494 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/hash_tables.h')
-rw-r--r--base/hash_tables.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/base/hash_tables.h b/base/hash_tables.h
index 5e50cfc..3f701f0 100644
--- a/base/hash_tables.h
+++ b/base/hash_tables.h
@@ -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 @@ struct hash<long long> {
}
};
+#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