aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/stubs/hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/stubs/hash.h')
-rw-r--r--src/google/protobuf/stubs/hash.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h
index a828a9c6..07798bcd 100644
--- a/src/google/protobuf/stubs/hash.h
+++ b/src/google/protobuf/stubs/hash.h
@@ -48,6 +48,8 @@
#include <set>
#endif
+#include <ext/hash_map>
+
namespace google {
namespace protobuf {
@@ -145,21 +147,30 @@ struct hash<const Key*> {
}
};
+// Unlike the old SGI version, the TR1 "hash" does not special-case char*. So,
+// we go ahead and provide our own implementation.
template <>
-struct hash<const char*> : public HASH_NAMESPACE::hash<const char*> {
+struct hash<const char*> {
+ inline size_t operator()(const char* str) const {
+ size_t result = 0;
+ for (; *str != '\0'; str++) {
+ result = 5 * result + *str;
+ }
+ return result;
+ }
};
template <typename Key, typename Data,
typename HashFcn = hash<Key>,
typename EqualKey = std::equal_to<Key> >
-class hash_map : public HASH_NAMESPACE::hash_map<
+class hash_map : public HASH_NAMESPACE::HASH_MAP_CLASS<
Key, Data, HashFcn, EqualKey> {
};
template <typename Key,
typename HashFcn = hash<Key>,
typename EqualKey = std::equal_to<Key> >
-class hash_set : public HASH_NAMESPACE::hash_set<
+class hash_set : public HASH_NAMESPACE::HASH_SET_CLASS<
Key, HashFcn, EqualKey> {
};