5 #ifndef BALL_DATATYPE_HASHMAP_H
6 #define BALL_DATATYPE_HASHMAP_H
12 #ifndef BALL_COMMON_HASH_H
16 #ifndef BALL_DATATYPE_TRIPLE_H
20 #ifndef BALL_DATATYPE_QUADRUPLE_H
27 #ifdef BALL_HAS_UNORDERED_MAP
29 #if defined(BALL_HAS_STD_UNORDERED_MAP)
30 # include <unordered_map>
31 #elif defined(BALL_HAS_TR1_UNORDERED_MAP)
32 # include <tr1/unordered_map>
33 #elif defined(BALL_HAS_BOOST_UNORDERED_MAP)
34 # include <boost/unordered_map.hpp>
37 #elif defined(BALL_HAS_HASH_MAP)
38 #if defined(BALL_EXT_INCLUDE_PREFIX)
39 # include <ext/hash_map>
40 # include <ext/hash_fun.h>
43 # include <hash_fun.h>
49 #if defined(BALL_HAS_UNORDERED_MAP) && !defined(BALL_HAS_BOOST_UNORDERED_MAP)
51 #ifdef BALL_EXTEND_HASH_IN_STD_NS
54 #endif // BALL_EXTEND_HASH_IN_STD_NS
56 #ifdef BALL_HAS_TR1_UNORDERED_MAP
59 #endif // BALL_HAS_TR1_UNORDERED_MAP
63 void hash_combine_ala_boost(
size_t & seed, T
const & v)
66 seed ^=
h(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
69 template<
class A,
class B>
70 struct hash<pair<A, B> > :
public std::unary_function<pair<A,B>, size_t>
73 operator()(pair<A, B> p)
const
76 hash_combine_ala_boost(seed, p.first);
77 hash_combine_ala_boost(seed, p.second);
83 template <
class A,
class B,
class C>
84 struct hash< ::
BALL::Triple<A, B, C> > :
public std::unary_function< ::BALL::Triple<A, B, C>, size_t>
90 hash_combine_ala_boost(seed, t.
first);
91 hash_combine_ala_boost(seed, t.
second);
92 hash_combine_ala_boost(seed, t.
third);
98 template <
class A,
class B,
class C,
class D>
99 struct hash< ::
BALL::Quadruple<A, B, C, D> > :
public std::unary_function< const ::BALL::Quadruple<A, B, C, D>, size_t>
105 hash_combine_ala_boost(seed, q.
first);
106 hash_combine_ala_boost(seed, q.
second);
107 hash_combine_ala_boost(seed, q.
third);
108 hash_combine_ala_boost(seed, q.
fourth);
114 #ifndef BALL_COMPILER_MSVC
116 struct hash<const ::
BALL::String&> :
public std::unary_function<const ::BALL::String &, size_t>
119 operator()(const ::BALL::String& s)
const
121 hash<const string&>
h;
128 struct hash< ::
BALL::String > :
public std::unary_function< ::BALL::String, size_t >
137 #ifdef BALL_HAS_TR1_UNORDERED_MAP
139 #endif // BALL_HAS_TR1_UNORDERED_MAP
141 #ifdef BALL_EXTEND_HASH_IN_STD_NS
143 #endif // BALL_EXTEND_HASH_IN_STD_NS
145 #endif // if defined(BALL_HAS_UNORDERED_MAP) && !defined(BALL_HAS_BOOST_UNORDERED_MAP)
147 #ifdef BALL_HAS_HASH_MAP
148 namespace BALL_MAP_NAMESPACE
153 size_t operator()(
const T* x)
const {
return (
size_t)x; }
157 struct hash<BALL::String>
159 size_t operator () (
const BALL::String& s)
const {
return __stl_hash_string(s.c_str());}
162 #ifdef BALL_NEEDS_LONGSIZE_HASH
170 #endif // BALL_HAS_HASH_MAP
179 template <
class Key,
class T>
181 :
public BALL_MAP_NAME
211 inline bool has(
const Key& key)
const
213 return Base::find(key)!=Base::end();
229 Size size()
const {
return BALL_MAP_NAME::size(); }
236 template <
class Key,
class T>
240 if (it == Base::end())
251 template <
class Key,
class T>
255 if (size() != rhs.
size())
264 for (; it != BALL_MAP_NAME::end(); ++it)
266 if (!rhs.
has(it->first))
return false;
271 template <
class Key,
class T>
274 return BALL_MAP_NAME::operator[] (key);
279 #endif // BALL_DATATYPE_HASHMAP_H