|
@@ -108,8 +108,13 @@
|
|
# define GOOGLE_PROTOBUF_HAS_CXX11_HASH
|
|
# define GOOGLE_PROTOBUF_HAS_CXX11_HASH
|
|
# define GOOGLE_PROTOBUF_HASH_COMPARE std::hash_compare
|
|
# define GOOGLE_PROTOBUF_HASH_COMPARE std::hash_compare
|
|
# elif _MSC_VER >= 1500 // Since Visual Studio 2008
|
|
# elif _MSC_VER >= 1500 // Since Visual Studio 2008
|
|
-# undef GOOGLE_PROTOBUF_HAVE_HASH_MAP
|
|
|
|
-# undef GOOGLE_PROTOBUF_HAVE_HASH_SET
|
|
|
|
|
|
+# define GOOGLE_PROTOBUF_HASH_NAMESPACE stdext
|
|
|
|
+# include <hash_map>
|
|
|
|
+# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map
|
|
|
|
+# include <hash_set>
|
|
|
|
+# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set
|
|
|
|
+# define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare
|
|
|
|
+# define GOOGLE_PROTOBUF_CONTAINERS_NEED_HASH_COMPARE
|
|
# elif _MSC_VER >= 1310
|
|
# elif _MSC_VER >= 1310
|
|
# define GOOGLE_PROTOBUF_HASH_NAMESPACE stdext
|
|
# define GOOGLE_PROTOBUF_HASH_NAMESPACE stdext
|
|
# include <hash_map>
|
|
# include <hash_map>
|
|
@@ -247,6 +252,52 @@ template <>
|
|
struct hash<const char*>
|
|
struct hash<const char*>
|
|
: public GOOGLE_PROTOBUF_HASH_COMPARE<const char*, CstringLess> {};
|
|
: public GOOGLE_PROTOBUF_HASH_COMPARE<const char*, CstringLess> {};
|
|
|
|
|
|
|
|
+#ifdef GOOGLE_PROTOBUF_CONTAINERS_NEED_HASH_COMPARE
|
|
|
|
+
|
|
|
|
+template <typename Key, typename HashFcn, typename EqualKey>
|
|
|
|
+struct InternalHashCompare : public GOOGLE_PROTOBUF_HASH_COMPARE<Key> {
|
|
|
|
+ InternalHashCompare() {}
|
|
|
|
+ InternalHashCompare(HashFcn hashfcn, EqualKey equalkey)
|
|
|
|
+ : hashfcn_(hashfcn), equalkey_(equalkey) {}
|
|
|
|
+ size_t operator()(const Key& key) const { return hashfcn_(key); }
|
|
|
|
+ bool operator()(const Key& key1, const Key& key2) const {
|
|
|
|
+ return !equalkey_(key1, key2);
|
|
|
|
+ }
|
|
|
|
+ HashFcn hashfcn_;
|
|
|
|
+ EqualKey equalkey_;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+template <typename Key, typename Data,
|
|
|
|
+ typename HashFcn = hash<Key>,
|
|
|
|
+ typename EqualKey = std::equal_to<Key>,
|
|
|
|
+ typename Alloc = std::allocator< std::pair<const Key, Data> > >
|
|
|
|
+class hash_map
|
|
|
|
+ : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS<
|
|
|
|
+ Key, Data, InternalHashCompare<Key, HashFcn, EqualKey>, Alloc> {
|
|
|
|
+ typedef GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS<
|
|
|
|
+ Key, Data, InternalHashCompare<Key, HashFcn, EqualKey>, Alloc> BaseClass;
|
|
|
|
+
|
|
|
|
+ public:
|
|
|
|
+ hash_map(int a = 0, const HashFcn& b = HashFcn(),
|
|
|
|
+ const EqualKey& c = EqualKey(), const Alloc& d = Alloc())
|
|
|
|
+ : BaseClass(InternalHashCompare<Key, HashFcn, EqualKey>(b, c), d) {}
|
|
|
|
+
|
|
|
|
+ HashFcn hash_function() const { return HashFcn(); }
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+template <typename Key, typename HashFcn = hash<Key>,
|
|
|
|
+ typename EqualKey = std::equal_to<Key> >
|
|
|
|
+class hash_set
|
|
|
|
+ : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_SET_CLASS<
|
|
|
|
+ Key, InternalHashCompare<Key, HashFcn, EqualKey> > {
|
|
|
|
+ public:
|
|
|
|
+ hash_set(int = 0) {}
|
|
|
|
+
|
|
|
|
+ HashFcn hash_function() const { return HashFcn(); }
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+#else // GOOGLE_PROTOBUF_CONTAINERS_NEED_HASH_COMPARE
|
|
|
|
+
|
|
template <typename Key, typename Data,
|
|
template <typename Key, typename Data,
|
|
typename HashFcn = hash<Key>,
|
|
typename HashFcn = hash<Key>,
|
|
typename EqualKey = std::equal_to<Key>,
|
|
typename EqualKey = std::equal_to<Key>,
|
|
@@ -275,8 +326,9 @@ class hash_set
|
|
|
|
|
|
HashFcn hash_function() const { return HashFcn(); }
|
|
HashFcn hash_function() const { return HashFcn(); }
|
|
};
|
|
};
|
|
|
|
+#endif // GOOGLE_PROTOBUF_CONTAINERS_NEED_HASH_COMPARE
|
|
|
|
|
|
-#else
|
|
|
|
|
|
+#else // defined(_MSC_VER) && !defined(_STLPORT_VERSION)
|
|
|
|
|
|
template <typename Key>
|
|
template <typename Key>
|
|
struct hash : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash<Key> {
|
|
struct hash : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash<Key> {
|