diff options
author | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2009-12-21 18:58:23 +0000 |
---|---|---|
committer | kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2009-12-21 18:58:23 +0000 |
commit | ee7e9420e3f76a9f6b68ac2581c48404783db07d (patch) | |
tree | a64e43ad45aa0e511227374ec2fc93a7ab0899bd /src | |
parent | 8ee1474044c0618be2f53539ee7cc68560002b60 (diff) | |
download | protobuf-ee7e9420e3f76a9f6b68ac2581c48404783db07d.tar.gz protobuf-ee7e9420e3f76a9f6b68ac2581c48404783db07d.tar.bz2 protobuf-ee7e9420e3f76a9f6b68ac2581c48404783db07d.zip |
Use unordered_map when available. Changes to stl_hash.m4 provided by Oleg Smolsky.
Diffstat (limited to 'src')
-rw-r--r-- | src/google/protobuf/stubs/hash.h | 17 |
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> { }; |