15 #ifndef GU_UNORDERED_HPP
16 #define GU_UNORDERED_HPP
18 #if defined(HAVE_BOOST_UNORDERED_MAP_HPP)
19 #include <boost/unordered_map.hpp>
20 #include <boost/unordered_set.hpp>
21 #elif defined(HAVE_UNORDERED_MAP)
22 #include <unordered_map>
23 #include <unordered_set>
24 #elif defined(HAVE_TR1_UNORDERED_MAP)
25 #include <tr1/unordered_map>
26 #include <tr1/unordered_set>
28 #error "no unordered map available"
31 #include "gu_throw.hpp"
39 #if defined(HAVE_BOOST_UNORDERED_MAP_HPP)
40 typedef boost::hash<K> Type;
41 #elif defined(HAVE_UNORDERED_MAP)
42 typedef std::hash<K> Type;
43 #elif defined(HAVE_TR1_UNORDERED_MAP)
44 typedef std::tr1::hash<K> Type;
46 size_t operator()(
const K& k)
const
54 size_t HashValue(
const K& key)
59 template <
typename K,
typename H = UnorderedHash<K>,
60 class P = std::equal_to<K>,
61 class A = std::allocator<K> >
64 #if defined(HAVE_BOOST_UNORDERED_MAP_HPP)
65 typedef boost::unordered_set<K, H, P, A> type;
66 #elif defined(HAVE_UNORDERED_MAP)
67 typedef std::unordered_set<K, H, P, A> type;
68 #elif defined(HAVE_TR1_UNORDERED_MAP)
69 typedef std::tr1::unordered_set<K, H, P, A> type;
73 typedef typename type::value_type value_type;
74 typedef typename type::iterator iterator;
75 typedef typename type::const_iterator const_iterator;
80 iterator begin() {
return impl_.begin(); }
81 const_iterator begin()
const {
return impl_.begin(); }
82 iterator end() {
return impl_.end(); }
83 const_iterator end()
const {
return impl_.end(); }
84 std::pair<iterator, bool> insert(
const value_type& k)
85 {
return impl_.insert(k); }
86 iterator insert_unique(
const value_type& k)
88 std::pair<iterator, bool> ret(insert(k));
89 if (ret.second ==
false) gu_throw_fatal <<
"insert unique failed";
92 iterator find(
const K& key) {
return impl_.find(key); }
93 const_iterator find(
const K& key)
const {
return impl_.find(key); }
94 iterator erase(iterator i) {
return impl_.erase(i); }
95 size_t size()
const {
return impl_.size(); }
96 bool empty()
const {
return impl_.empty(); }
97 void clear() { impl_.clear(); }
98 void rehash(
size_t n) { impl_.rehash(n); }
99 #if defined(HAVE_UNORDERED_MAP)
100 void reserve(
size_t n) { impl_.reserve(n); }
105 template <
typename K,
typename V,
typename H = UnorderedHash<K>,
106 class P = std::equal_to<K>,
107 class A = std::allocator<std::pair<const K, V> > >
110 #if defined(HAVE_BOOST_UNORDERED_MAP_HPP)
111 typedef boost::unordered_map<K, V, H, P, A> type;
112 #elif defined(HAVE_UNORDERED_MAP)
113 typedef std::unordered_map<K, V, H, P, A> type;
114 #elif defined(HAVE_TR1_UNORDERED_MAP)
115 typedef std::tr1::unordered_map<K, V, H, P, A> type;
119 typedef typename type::value_type value_type;
120 typedef typename type::iterator iterator;
121 typedef typename type::const_iterator const_iterator;
125 iterator begin() {
return impl_.begin(); }
126 const_iterator begin()
const {
return impl_.begin(); }
127 iterator end() {
return impl_.end(); }
128 const_iterator end()
const {
return impl_.end(); }
129 std::pair<iterator, bool> insert(
const std::pair<K, V>& kv)
130 {
return impl_.insert(kv); }
131 iterator insert_unique(
const std::pair<K, V>& kv)
133 std::pair<iterator, bool> ret(insert(kv));
134 if (ret.second ==
false) gu_throw_fatal <<
"insert unique failed";
137 iterator find(
const K& key) {
return impl_.find(key); }
138 const_iterator find(
const K& key)
const {
return impl_.find(key); }
139 iterator erase(iterator i) {
return impl_.erase(i); }
140 size_t size()
const {
return impl_.size(); }
141 bool empty()
const {
return impl_.empty(); }
142 void clear() { impl_.clear(); }
143 void rehash(
size_t n) { impl_.rehash(n); }
146 template <
typename K,
typename V,
typename H = UnorderedHash<K> >
149 #if defined(HAVE_BOOST_UNORDERED_MAP_HPP)
150 typedef boost::unordered_multimap<K, V> type;
151 #elif defined(HAVE_UNORDERED_MAP)
152 typedef std::unordered_multimap<K, V> type;
153 #elif defined(HAVE_TR1_UNORDERED_MAP)
154 typedef std::tr1::unordered_multimap<K, V> type;
158 typedef typename type::value_type value_type;
159 typedef typename type::iterator iterator;
160 typedef typename type::const_iterator const_iterator;
163 void clear() { impl_.clear(); }
165 iterator begin() {
return impl_.begin(); }
166 const_iterator begin()
const {
return impl_.begin(); }
167 iterator end() {
return impl_.end(); }
168 const_iterator end()
const {
return impl_.end(); }
169 iterator insert(
const std::pair<K, V>& kv)
170 {
return impl_.insert(kv); }
171 iterator find(
const K& key) {
return impl_.find(key); }
172 const_iterator find(
const K& key)
const {
return impl_.find(key); }
173 std::pair<iterator, iterator>
174 equal_range(
const K& key) {
return impl_.equal_range(key); }
175 std::pair<const_iterator, const_iterator>
176 equal_range(
const K& key)
const
177 {
return impl_.equal_range(key); }
178 void erase(iterator i) { impl_.erase(i); }
179 size_t size()
const {
return impl_.size(); }
180 bool empty()
const {
return impl_.empty(); }
184 #endif // GU_UNORDERED_HPP
Definition: gu_unordered.hpp:62
Definition: gu_unordered.hpp:147
Definition: gu_unordered.hpp:108
Definition: gu_unordered.hpp:36