From ee7e9420e3f76a9f6b68ac2581c48404783db07d Mon Sep 17 00:00:00 2001 From: "kenton@google.com" Date: Mon, 21 Dec 2009 18:58:23 +0000 Subject: Use unordered_map when available. Changes to stl_hash.m4 provided by Oleg Smolsky. --- src/google/protobuf/stubs/hash.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/google/protobuf/stubs/hash.h') 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 #endif +#include + namespace google { namespace protobuf { @@ -145,21 +147,30 @@ struct hash { } }; +// 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 : public HASH_NAMESPACE::hash { +struct hash { + inline size_t operator()(const char* str) const { + size_t result = 0; + for (; *str != '\0'; str++) { + result = 5 * result + *str; + } + return result; + } }; template , typename EqualKey = std::equal_to > -class hash_map : public HASH_NAMESPACE::hash_map< +class hash_map : public HASH_NAMESPACE::HASH_MAP_CLASS< Key, Data, HashFcn, EqualKey> { }; template , typename EqualKey = std::equal_to > -class hash_set : public HASH_NAMESPACE::hash_set< +class hash_set : public HASH_NAMESPACE::HASH_SET_CLASS< Key, HashFcn, EqualKey> { }; -- cgit v1.2.3