5 #ifndef BALL_DATATYPE_HASHMAP_H
6 #define BALL_DATATYPE_HASHMAP_H
8 #ifndef BALL_COMMON_EXCEPTION_H
12 #ifndef BALL_DATATYPE_STRING_H
16 #ifndef BALL_DATATYPE_TRIPLE_H
20 #ifndef BALL_DATATYPE_QUADRUPLE_H
24 #include <boost/unordered_map.hpp>
25 #include <boost/functional/hash.hpp>
30 struct hash<BALL::String>
32 size_t operator () (
const BALL::String& s)
const {
return boost::hash<std::string>()(s); }
35 template <
typename T1,
typename T2,
typename T3>
36 struct hash<BALL::Triple<T1, T2, T3> >
41 boost::hash_combine(hash, s.
first);
42 boost::hash_combine(hash, s.
second);
43 boost::hash_combine(hash, s.
third);
49 template <
typename T1,
typename T2,
typename T3,
typename T4>
50 struct hash<BALL::Quadruple<T1, T2, T3, T4> >
55 boost::hash_combine(hash, s.
first);
56 boost::hash_combine(hash, s.
second);
57 boost::hash_combine(hash, s.
third);
58 boost::hash_combine(hash, s.
fourth);
72 template <
class Key,
class T>
73 class HashMap :
public boost::unordered_map<Key, T>
93 typedef boost::unordered_map<Key, T>
Base;
102 inline bool has(
const Key& key)
const
104 return Base::find(key) != Base::end();
129 template <
class Key,
class T>
133 if (it == Base::end())
143 template <
class Key,
class T>
147 if (Base::size() != rhs.
size())
156 for (; it != Base::end(); ++it)
158 if (!rhs.
has(it->first))
return false;
164 template <
class Key,
class T>
167 return Base::operator[] (key);
172 #endif // BALL_DATATYPE_HASHMAP_H
GeneralException()
Default constructor.
Base::const_iterator ConstIterator
bool operator==(const HashMap< Key, T > &rhs) const
Equality operator. Check whether two two hashmaps contain the same elements. O(n) runtime...
IllegalKey(const char *file, int line)
const T & operator[](const Key &key) const
Return a constant reference to the element whose key is key.
boost::unordered_map< Key, T > Base
Base::value_type * PointerType
bool has(const Key &key) const
Test whether the map contains the given key.
HashMap illegal key exception.
Base::value_type ValueType
HashMap class based on the STL map (containing serveral convenience functions)