Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===-------------------------- hash_map ----------------------------------===// |
| 3 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_HASH_MAP |
| 12 | #define _LIBCPP_HASH_MAP |
| 13 | |
| 14 | /* |
| 15 | |
| 16 | hash_map synopsis |
| 17 | |
| 18 | namespace __gnu_cxx |
| 19 | { |
| 20 | |
| 21 | template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 22 | class Alloc = allocator<pair<const Key, T>>> |
| 23 | class hash_map |
| 24 | { |
| 25 | public: |
| 26 | // types |
| 27 | typedef Key key_type; |
| 28 | typedef T mapped_type; |
| 29 | typedef Hash hasher; |
| 30 | typedef Pred key_equal; |
| 31 | typedef Alloc allocator_type; |
| 32 | typedef pair<const key_type, mapped_type> value_type; |
| 33 | typedef value_type& reference; |
| 34 | typedef const value_type& const_reference; |
| 35 | typedef typename allocator_traits<allocator_type>::pointer pointer; |
| 36 | typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; |
| 37 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 38 | typedef typename allocator_traits<allocator_type>::difference_type difference_type; |
| 39 | |
| 40 | typedef /unspecified/ iterator; |
| 41 | typedef /unspecified/ const_iterator; |
| 42 | |
| 43 | explicit hash_map(size_type n = 193, const hasher& hf = hasher(), |
| 44 | const key_equal& eql = key_equal(), |
| 45 | const allocator_type& a = allocator_type()); |
| 46 | template <class InputIterator> |
| 47 | hash_map(InputIterator f, InputIterator l, |
| 48 | size_type n = 193, const hasher& hf = hasher(), |
| 49 | const key_equal& eql = key_equal(), |
| 50 | const allocator_type& a = allocator_type()); |
| 51 | hash_map(const hash_map&); |
| 52 | ~hash_map(); |
| 53 | hash_map& operator=(const hash_map&); |
| 54 | |
| 55 | allocator_type get_allocator() const; |
| 56 | |
| 57 | bool empty() const; |
| 58 | size_type size() const; |
| 59 | size_type max_size() const; |
| 60 | |
| 61 | iterator begin(); |
| 62 | iterator end(); |
| 63 | const_iterator begin() const; |
| 64 | const_iterator end() const; |
| 65 | |
| 66 | pair<iterator, bool> insert(const value_type& obj); |
| 67 | template <class InputIterator> |
| 68 | void insert(InputIterator first, InputIterator last); |
| 69 | |
| 70 | void erase(const_iterator position); |
| 71 | size_type erase(const key_type& k); |
| 72 | void erase(const_iterator first, const_iterator last); |
| 73 | void clear(); |
| 74 | |
| 75 | void swap(hash_map&); |
| 76 | |
| 77 | hasher hash_funct() const; |
| 78 | key_equal key_eq() const; |
| 79 | |
| 80 | iterator find(const key_type& k); |
| 81 | const_iterator find(const key_type& k) const; |
| 82 | size_type count(const key_type& k) const; |
| 83 | pair<iterator, iterator> equal_range(const key_type& k); |
| 84 | pair<const_iterator, const_iterator> equal_range(const key_type& k) const; |
| 85 | |
| 86 | mapped_type& operator[](const key_type& k); |
| 87 | |
| 88 | size_type bucket_count() const; |
| 89 | size_type max_bucket_count() const; |
| 90 | |
| 91 | size_type elems_in_bucket(size_type n) const; |
| 92 | |
| 93 | void resize(size_type n); |
| 94 | }; |
| 95 | |
| 96 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 97 | void swap(hash_map<Key, T, Hash, Pred, Alloc>& x, |
| 98 | hash_map<Key, T, Hash, Pred, Alloc>& y); |
| 99 | |
| 100 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 101 | bool |
| 102 | operator==(const hash_map<Key, T, Hash, Pred, Alloc>& x, |
| 103 | const hash_map<Key, T, Hash, Pred, Alloc>& y); |
| 104 | |
| 105 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 106 | bool |
| 107 | operator!=(const hash_map<Key, T, Hash, Pred, Alloc>& x, |
| 108 | const hash_map<Key, T, Hash, Pred, Alloc>& y); |
| 109 | |
| 110 | template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 111 | class Alloc = allocator<pair<const Key, T>>> |
| 112 | class hash_multimap |
| 113 | { |
| 114 | public: |
| 115 | // types |
| 116 | typedef Key key_type; |
| 117 | typedef T mapped_type; |
| 118 | typedef Hash hasher; |
| 119 | typedef Pred key_equal; |
| 120 | typedef Alloc allocator_type; |
| 121 | typedef pair<const key_type, mapped_type> value_type; |
| 122 | typedef value_type& reference; |
| 123 | typedef const value_type& const_reference; |
| 124 | typedef typename allocator_traits<allocator_type>::pointer pointer; |
| 125 | typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; |
| 126 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 127 | typedef typename allocator_traits<allocator_type>::difference_type difference_type; |
| 128 | |
| 129 | typedef /unspecified/ iterator; |
| 130 | typedef /unspecified/ const_iterator; |
| 131 | |
| 132 | explicit hash_multimap(size_type n = 193, const hasher& hf = hasher(), |
| 133 | const key_equal& eql = key_equal(), |
| 134 | const allocator_type& a = allocator_type()); |
| 135 | template <class InputIterator> |
| 136 | hash_multimap(InputIterator f, InputIterator l, |
| 137 | size_type n = 193, const hasher& hf = hasher(), |
| 138 | const key_equal& eql = key_equal(), |
| 139 | const allocator_type& a = allocator_type()); |
| 140 | explicit hash_multimap(const allocator_type&); |
| 141 | hash_multimap(const hash_multimap&); |
| 142 | ~hash_multimap(); |
| 143 | hash_multimap& operator=(const hash_multimap&); |
| 144 | |
| 145 | allocator_type get_allocator() const; |
| 146 | |
| 147 | bool empty() const; |
| 148 | size_type size() const; |
| 149 | size_type max_size() const; |
| 150 | |
| 151 | iterator begin(); |
| 152 | iterator end(); |
| 153 | const_iterator begin() const; |
| 154 | const_iterator end() const; |
| 155 | |
| 156 | iterator insert(const value_type& obj); |
| 157 | template <class InputIterator> |
| 158 | void insert(InputIterator first, InputIterator last); |
| 159 | |
| 160 | void erase(const_iterator position); |
| 161 | size_type erase(const key_type& k); |
| 162 | void erase(const_iterator first, const_iterator last); |
| 163 | void clear(); |
| 164 | |
| 165 | void swap(hash_multimap&); |
| 166 | |
| 167 | hasher hash_funct() const; |
| 168 | key_equal key_eq() const; |
| 169 | |
| 170 | iterator find(const key_type& k); |
| 171 | const_iterator find(const key_type& k) const; |
| 172 | size_type count(const key_type& k) const; |
| 173 | pair<iterator, iterator> equal_range(const key_type& k); |
| 174 | pair<const_iterator, const_iterator> equal_range(const key_type& k) const; |
| 175 | |
| 176 | size_type bucket_count() const; |
| 177 | size_type max_bucket_count() const; |
| 178 | |
| 179 | size_type elems_in_bucket(size_type n) const; |
| 180 | |
| 181 | void resize(size_type n); |
| 182 | }; |
| 183 | |
| 184 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 185 | void swap(hash_multimap<Key, T, Hash, Pred, Alloc>& x, |
| 186 | hash_multimap<Key, T, Hash, Pred, Alloc>& y); |
| 187 | |
| 188 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 189 | bool |
| 190 | operator==(const hash_multimap<Key, T, Hash, Pred, Alloc>& x, |
| 191 | const hash_multimap<Key, T, Hash, Pred, Alloc>& y); |
| 192 | |
| 193 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 194 | bool |
| 195 | operator!=(const hash_multimap<Key, T, Hash, Pred, Alloc>& x, |
| 196 | const hash_multimap<Key, T, Hash, Pred, Alloc>& y); |
| 197 | |
| 198 | } // __gnu_cxx |
| 199 | |
| 200 | */ |
| 201 | |
| 202 | #include <__config> |
| 203 | #include <__hash_table> |
| 204 | #include <functional> |
| 205 | #include <stdexcept> |
Alexis Hunt | 8d2ed56 | 2011-07-29 23:31:56 +0000 | [diff] [blame] | 206 | #include <ext/__hash> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 207 | |
Howard Hinnant | 1dba445 | 2011-07-24 23:59:50 +0000 | [diff] [blame] | 208 | #if __DEPRECATED |
Howard Hinnant | 80b84d4 | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 209 | #if defined(_MSC_VER) && ! defined(__clang__) |
| 210 | _LIBCPP_WARNING("Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>") |
| 211 | #else |
| 212 | # warning Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map> |
| 213 | #endif |
Howard Hinnant | 1dba445 | 2011-07-24 23:59:50 +0000 | [diff] [blame] | 214 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 215 | |
| 216 | #pragma GCC system_header |
| 217 | |
| 218 | namespace __gnu_cxx { |
| 219 | |
| 220 | using namespace std; |
| 221 | |
Howard Hinnant | 42b8bb5 | 2011-12-11 20:31:33 +0000 | [diff] [blame] | 222 | template <class _Tp, class _Hash, bool = is_empty<_Hash>::value |
| 223 | #if __has_feature(is_final) |
| 224 | && !__is_final(_Hash) |
| 225 | #endif |
| 226 | > |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 227 | class __hash_map_hasher |
| 228 | : private _Hash |
| 229 | { |
| 230 | public: |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 231 | _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : _Hash() {} |
| 232 | _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : _Hash(__h) {} |
| 233 | _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return *this;} |
| 234 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 235 | size_t operator()(const _Tp& __x) const |
| 236 | {return static_cast<const _Hash&>(*this)(__x.first);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 237 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 238 | size_t operator()(const typename _Tp::first_type& __x) const |
| 239 | {return static_cast<const _Hash&>(*this)(__x);} |
| 240 | }; |
| 241 | |
| 242 | template <class _Tp, class _Hash> |
| 243 | class __hash_map_hasher<_Tp, _Hash, false> |
| 244 | { |
| 245 | _Hash __hash_; |
| 246 | public: |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 247 | _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : __hash_() {} |
| 248 | _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : __hash_(__h) {} |
| 249 | _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return __hash_;} |
| 250 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 251 | size_t operator()(const _Tp& __x) const |
| 252 | {return __hash_(__x.first);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 253 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 254 | size_t operator()(const typename _Tp::first_type& __x) const |
| 255 | {return __hash_(__x);} |
| 256 | }; |
| 257 | |
Howard Hinnant | 42b8bb5 | 2011-12-11 20:31:33 +0000 | [diff] [blame] | 258 | template <class _Tp, class _Pred, bool = is_empty<_Pred>::value |
| 259 | #if __has_feature(is_final) |
| 260 | && !__is_final(_Pred) |
| 261 | #endif |
| 262 | > |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | class __hash_map_equal |
| 264 | : private _Pred |
| 265 | { |
| 266 | public: |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 267 | _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : _Pred() {} |
| 268 | _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : _Pred(__p) {} |
| 269 | _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return *this;} |
| 270 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 271 | bool operator()(const _Tp& __x, const _Tp& __y) const |
| 272 | {return static_cast<const _Pred&>(*this)(__x.first, __y.first);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 273 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 274 | bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const |
| 275 | {return static_cast<const _Pred&>(*this)(__x, __y.first);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 276 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 277 | bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const |
| 278 | {return static_cast<const _Pred&>(*this)(__x.first, __y);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 279 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 280 | bool operator()(const typename _Tp::first_type& __x, |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 281 | const typename _Tp::first_type& __y) const |
| 282 | {return static_cast<const _Pred&>(*this)(__x, __y);} |
| 283 | }; |
| 284 | |
| 285 | template <class _Tp, class _Pred> |
| 286 | class __hash_map_equal<_Tp, _Pred, false> |
| 287 | { |
| 288 | _Pred __pred_; |
| 289 | public: |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 290 | _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : __pred_() {} |
| 291 | _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : __pred_(__p) {} |
| 292 | _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return __pred_;} |
| 293 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 294 | bool operator()(const _Tp& __x, const _Tp& __y) const |
| 295 | {return __pred_(__x.first, __y.first);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 296 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 297 | bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const |
| 298 | {return __pred_(__x, __y.first);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 299 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 300 | bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const |
| 301 | {return __pred_(__x.first, __y);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 302 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 303 | bool operator()(const typename _Tp::first_type& __x, |
| 304 | const typename _Tp::first_type& __y) const |
| 305 | {return __pred_(__x, __y);} |
| 306 | }; |
| 307 | |
| 308 | template <class _Alloc> |
| 309 | class __hash_map_node_destructor |
| 310 | { |
| 311 | typedef _Alloc allocator_type; |
| 312 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 313 | typedef typename __alloc_traits::value_type::value_type value_type; |
| 314 | public: |
| 315 | typedef typename __alloc_traits::pointer pointer; |
| 316 | private: |
| 317 | typedef typename value_type::first_type first_type; |
| 318 | typedef typename value_type::second_type second_type; |
| 319 | |
| 320 | allocator_type& __na_; |
| 321 | |
| 322 | __hash_map_node_destructor& operator=(const __hash_map_node_destructor&); |
| 323 | |
| 324 | public: |
| 325 | bool __first_constructed; |
| 326 | bool __second_constructed; |
| 327 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 328 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 329 | explicit __hash_map_node_destructor(allocator_type& __na) |
| 330 | : __na_(__na), |
| 331 | __first_constructed(false), |
| 332 | __second_constructed(false) |
| 333 | {} |
| 334 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 335 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 336 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 337 | __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) |
| 338 | : __na_(__x.__na_), |
| 339 | __first_constructed(__x.__value_constructed), |
| 340 | __second_constructed(__x.__value_constructed) |
| 341 | { |
| 342 | __x.__value_constructed = false; |
| 343 | } |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 344 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 345 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 346 | __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x) |
| 347 | : __na_(__x.__na_), |
| 348 | __first_constructed(__x.__value_constructed), |
| 349 | __second_constructed(__x.__value_constructed) |
| 350 | { |
| 351 | const_cast<bool&>(__x.__value_constructed) = false; |
| 352 | } |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 353 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 354 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 355 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 356 | void operator()(pointer __p) |
| 357 | { |
| 358 | if (__second_constructed) |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 359 | __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 360 | if (__first_constructed) |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 361 | __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 362 | if (__p) |
| 363 | __alloc_traits::deallocate(__na_, __p, 1); |
| 364 | } |
| 365 | }; |
| 366 | |
| 367 | template <class _HashIterator> |
Howard Hinnant | f0544c2 | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 368 | class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 369 | { |
| 370 | _HashIterator __i_; |
| 371 | |
| 372 | typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits; |
| 373 | typedef const typename _HashIterator::value_type::first_type key_type; |
| 374 | typedef typename _HashIterator::value_type::second_type mapped_type; |
| 375 | public: |
| 376 | typedef forward_iterator_tag iterator_category; |
| 377 | typedef pair<key_type, mapped_type> value_type; |
| 378 | typedef typename _HashIterator::difference_type difference_type; |
| 379 | typedef value_type& reference; |
| 380 | typedef typename __pointer_traits::template |
| 381 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 382 | rebind<value_type> |
| 383 | #else |
| 384 | rebind<value_type>::other |
| 385 | #endif |
| 386 | pointer; |
| 387 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 388 | _LIBCPP_INLINE_VISIBILITY __hash_map_iterator() {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 389 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 390 | _LIBCPP_INLINE_VISIBILITY __hash_map_iterator(_HashIterator __i) : __i_(__i) {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 391 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 392 | _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *operator->();} |
| 393 | _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return (pointer)__i_.operator->();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 395 | _LIBCPP_INLINE_VISIBILITY __hash_map_iterator& operator++() {++__i_; return *this;} |
| 396 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 397 | __hash_map_iterator operator++(int) |
| 398 | { |
| 399 | __hash_map_iterator __t(*this); |
| 400 | ++(*this); |
| 401 | return __t; |
| 402 | } |
| 403 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 404 | friend _LIBCPP_INLINE_VISIBILITY |
| 405 | bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 406 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 407 | friend _LIBCPP_INLINE_VISIBILITY |
| 408 | bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 409 | {return __x.__i_ != __y.__i_;} |
| 410 | |
Howard Hinnant | f0544c2 | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 411 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY hash_map; |
| 412 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY hash_multimap; |
| 413 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; |
| 414 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator; |
| 415 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 416 | }; |
| 417 | |
| 418 | template <class _HashIterator> |
Howard Hinnant | f0544c2 | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 419 | class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 420 | { |
| 421 | _HashIterator __i_; |
| 422 | |
| 423 | typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits; |
| 424 | typedef const typename _HashIterator::value_type::first_type key_type; |
| 425 | typedef typename _HashIterator::value_type::second_type mapped_type; |
| 426 | public: |
| 427 | typedef forward_iterator_tag iterator_category; |
| 428 | typedef pair<key_type, mapped_type> value_type; |
| 429 | typedef typename _HashIterator::difference_type difference_type; |
| 430 | typedef const value_type& reference; |
| 431 | typedef typename __pointer_traits::template |
| 432 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Peter Collingbourne | 99aadbd | 2014-03-03 19:50:01 +0000 | [diff] [blame] | 433 | rebind<const value_type> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 434 | #else |
Peter Collingbourne | 99aadbd | 2014-03-03 19:50:01 +0000 | [diff] [blame] | 435 | rebind<const value_type>::other |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 436 | #endif |
| 437 | pointer; |
| 438 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 439 | _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator() {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 440 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 441 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 442 | __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 443 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 444 | __hash_map_const_iterator( |
| 445 | __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i) |
| 446 | : __i_(__i.__i_) {} |
| 447 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 448 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 449 | reference operator*() const {return *operator->();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 450 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 451 | pointer operator->() const {return (pointer)__i_.operator->();} |
| 452 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 453 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 454 | __hash_map_const_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 455 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 456 | __hash_map_const_iterator operator++(int) |
| 457 | { |
| 458 | __hash_map_const_iterator __t(*this); |
| 459 | ++(*this); |
| 460 | return __t; |
| 461 | } |
| 462 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 463 | friend _LIBCPP_INLINE_VISIBILITY |
| 464 | bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 465 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 466 | friend _LIBCPP_INLINE_VISIBILITY |
| 467 | bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 468 | {return __x.__i_ != __y.__i_;} |
| 469 | |
Howard Hinnant | f0544c2 | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 470 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY hash_map; |
| 471 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY hash_multimap; |
| 472 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; |
| 473 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 474 | }; |
| 475 | |
| 476 | template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, |
| 477 | class _Alloc = allocator<pair<const _Key, _Tp> > > |
Howard Hinnant | f0544c2 | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 478 | class _LIBCPP_TYPE_VIS_ONLY hash_map |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 479 | { |
| 480 | public: |
| 481 | // types |
| 482 | typedef _Key key_type; |
| 483 | typedef _Tp mapped_type; |
Alexis Hunt | fe473ae | 2011-07-29 23:31:53 +0000 | [diff] [blame] | 484 | typedef _Tp data_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 485 | typedef _Hash hasher; |
| 486 | typedef _Pred key_equal; |
| 487 | typedef _Alloc allocator_type; |
| 488 | typedef pair<const key_type, mapped_type> value_type; |
| 489 | typedef value_type& reference; |
| 490 | typedef const value_type& const_reference; |
| 491 | |
| 492 | private: |
| 493 | typedef pair<key_type, mapped_type> __value_type; |
| 494 | typedef __hash_map_hasher<__value_type, hasher> __hasher; |
| 495 | typedef __hash_map_equal<__value_type, key_equal> __key_equal; |
| 496 | typedef typename allocator_traits<allocator_type>::template |
| 497 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 498 | rebind_alloc<__value_type> |
| 499 | #else |
| 500 | rebind_alloc<__value_type>::other |
| 501 | #endif |
| 502 | __allocator_type; |
| 503 | |
| 504 | typedef __hash_table<__value_type, __hasher, |
| 505 | __key_equal, __allocator_type> __table; |
| 506 | |
| 507 | __table __table_; |
| 508 | |
| 509 | typedef typename __table::__node_pointer __node_pointer; |
| 510 | typedef typename __table::__node_const_pointer __node_const_pointer; |
| 511 | typedef typename __table::__node_traits __node_traits; |
| 512 | typedef typename __table::__node_allocator __node_allocator; |
| 513 | typedef typename __table::__node __node; |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 514 | typedef __hash_map_node_destructor<__node_allocator> _Dp; |
| 515 | typedef unique_ptr<__node, _Dp> __node_holder; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 516 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 517 | public: |
| 518 | typedef typename __alloc_traits::pointer pointer; |
| 519 | typedef typename __alloc_traits::const_pointer const_pointer; |
| 520 | typedef typename __alloc_traits::size_type size_type; |
| 521 | typedef typename __alloc_traits::difference_type difference_type; |
| 522 | |
| 523 | typedef __hash_map_iterator<typename __table::iterator> iterator; |
| 524 | typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; |
| 525 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 526 | _LIBCPP_INLINE_VISIBILITY hash_map() {__table_.rehash(193);} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 527 | explicit hash_map(size_type __n, const hasher& __hf = hasher(), |
| 528 | const key_equal& __eql = key_equal()); |
| 529 | hash_map(size_type __n, const hasher& __hf, |
| 530 | const key_equal& __eql, |
| 531 | const allocator_type& __a); |
| 532 | template <class _InputIterator> |
| 533 | hash_map(_InputIterator __first, _InputIterator __last); |
| 534 | template <class _InputIterator> |
| 535 | hash_map(_InputIterator __first, _InputIterator __last, |
| 536 | size_type __n, const hasher& __hf = hasher(), |
| 537 | const key_equal& __eql = key_equal()); |
| 538 | template <class _InputIterator> |
| 539 | hash_map(_InputIterator __first, _InputIterator __last, |
| 540 | size_type __n, const hasher& __hf, |
| 541 | const key_equal& __eql, |
| 542 | const allocator_type& __a); |
| 543 | hash_map(const hash_map& __u); |
| 544 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 545 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 546 | allocator_type get_allocator() const |
| 547 | {return allocator_type(__table_.__node_alloc());} |
| 548 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 549 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 550 | bool empty() const {return __table_.size() == 0;} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 551 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 552 | size_type size() const {return __table_.size();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 553 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 554 | size_type max_size() const {return __table_.max_size();} |
| 555 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 556 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | iterator begin() {return __table_.begin();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 558 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 559 | iterator end() {return __table_.end();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 560 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 561 | const_iterator begin() const {return __table_.begin();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 562 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 563 | const_iterator end() const {return __table_.end();} |
| 564 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 565 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 566 | pair<iterator, bool> insert(const value_type& __x) |
| 567 | {return __table_.__insert_unique(__x);} |
Alexis Hunt | fe473ae | 2011-07-29 23:31:53 +0000 | [diff] [blame] | 568 | _LIBCPP_INLINE_VISIBILITY |
| 569 | iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 570 | template <class _InputIterator> |
| 571 | void insert(_InputIterator __first, _InputIterator __last); |
| 572 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 573 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 574 | void erase(const_iterator __p) {__table_.erase(__p.__i_);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 575 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 576 | size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 577 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 578 | void erase(const_iterator __first, const_iterator __last) |
| 579 | {__table_.erase(__first.__i_, __last.__i_);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 580 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 581 | void clear() {__table_.clear();} |
| 582 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 583 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 584 | void swap(hash_map& __u) {__table_.swap(__u.__table_);} |
| 585 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 586 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 587 | hasher hash_funct() const |
| 588 | {return __table_.hash_function().hash_function();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 589 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 590 | key_equal key_eq() const |
| 591 | {return __table_.key_eq().key_eq();} |
| 592 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 593 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 594 | iterator find(const key_type& __k) {return __table_.find(__k);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 595 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 596 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 597 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 598 | size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 599 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 600 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 601 | {return __table_.__equal_range_unique(__k);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 602 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 603 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 604 | {return __table_.__equal_range_unique(__k);} |
| 605 | |
| 606 | mapped_type& operator[](const key_type& __k); |
| 607 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 608 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 609 | size_type bucket_count() const {return __table_.bucket_count();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 610 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 611 | size_type max_bucket_count() const {return __table_.max_bucket_count();} |
| 612 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 613 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 614 | size_type elems_in_bucket(size_type __n) const |
| 615 | {return __table_.bucket_size(__n);} |
| 616 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 617 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 618 | void resize(size_type __n) {__table_.rehash(__n);} |
| 619 | |
| 620 | private: |
| 621 | __node_holder __construct_node(const key_type& __k); |
| 622 | }; |
| 623 | |
| 624 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 625 | hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( |
| 626 | size_type __n, const hasher& __hf, const key_equal& __eql) |
| 627 | : __table_(__hf, __eql) |
| 628 | { |
| 629 | __table_.rehash(__n); |
| 630 | } |
| 631 | |
| 632 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 633 | hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( |
| 634 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 635 | const allocator_type& __a) |
| 636 | : __table_(__hf, __eql, __a) |
| 637 | { |
| 638 | __table_.rehash(__n); |
| 639 | } |
| 640 | |
| 641 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 642 | template <class _InputIterator> |
| 643 | hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( |
| 644 | _InputIterator __first, _InputIterator __last) |
| 645 | { |
| 646 | __table_.rehash(193); |
| 647 | insert(__first, __last); |
| 648 | } |
| 649 | |
| 650 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 651 | template <class _InputIterator> |
| 652 | hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( |
| 653 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 654 | const hasher& __hf, const key_equal& __eql) |
| 655 | : __table_(__hf, __eql) |
| 656 | { |
| 657 | __table_.rehash(__n); |
| 658 | insert(__first, __last); |
| 659 | } |
| 660 | |
| 661 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 662 | template <class _InputIterator> |
| 663 | hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( |
| 664 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 665 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 666 | : __table_(__hf, __eql, __a) |
| 667 | { |
| 668 | __table_.rehash(__n); |
| 669 | insert(__first, __last); |
| 670 | } |
| 671 | |
| 672 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 673 | hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( |
| 674 | const hash_map& __u) |
| 675 | : __table_(__u.__table_) |
| 676 | { |
| 677 | __table_.rehash(__u.bucket_count()); |
| 678 | insert(__u.begin(), __u.end()); |
| 679 | } |
| 680 | |
| 681 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 682 | typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
| 683 | hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k) |
| 684 | { |
| 685 | __node_allocator& __na = __table_.__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 686 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 687 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 688 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 689 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 690 | __h.get_deleter().__second_constructed = true; |
Howard Hinnant | 179b1f8 | 2013-08-22 18:29:50 +0000 | [diff] [blame] | 691 | return _VSTD::move(__h); // explicitly moved for C++03 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 695 | template <class _InputIterator> |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 696 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 697 | void |
| 698 | hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 699 | _InputIterator __last) |
| 700 | { |
| 701 | for (; __first != __last; ++__first) |
| 702 | __table_.__insert_unique(*__first); |
| 703 | } |
| 704 | |
| 705 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 706 | _Tp& |
| 707 | hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) |
| 708 | { |
| 709 | iterator __i = find(__k); |
| 710 | if (__i != end()) |
| 711 | return __i->second; |
| 712 | __node_holder __h = __construct_node(__k); |
| 713 | pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); |
| 714 | __h.release(); |
| 715 | return __r.first->second; |
| 716 | } |
| 717 | |
| 718 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 719 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 720 | void |
| 721 | swap(hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 722 | hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 723 | { |
| 724 | __x.swap(__y); |
| 725 | } |
| 726 | |
| 727 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 728 | bool |
| 729 | operator==(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 730 | const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 731 | { |
| 732 | if (__x.size() != __y.size()) |
| 733 | return false; |
| 734 | typedef typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator |
| 735 | const_iterator; |
| 736 | for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); |
| 737 | __i != __ex; ++__i) |
| 738 | { |
| 739 | const_iterator __j = __y.find(__i->first); |
| 740 | if (__j == __ey || !(*__i == *__j)) |
| 741 | return false; |
| 742 | } |
| 743 | return true; |
| 744 | } |
| 745 | |
| 746 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 747 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 748 | bool |
| 749 | operator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 750 | const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 751 | { |
| 752 | return !(__x == __y); |
| 753 | } |
| 754 | |
| 755 | template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, |
| 756 | class _Alloc = allocator<pair<const _Key, _Tp> > > |
Howard Hinnant | f0544c2 | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 757 | class _LIBCPP_TYPE_VIS_ONLY hash_multimap |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 758 | { |
| 759 | public: |
| 760 | // types |
| 761 | typedef _Key key_type; |
| 762 | typedef _Tp mapped_type; |
Alexis Hunt | fe473ae | 2011-07-29 23:31:53 +0000 | [diff] [blame] | 763 | typedef _Tp data_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 764 | typedef _Hash hasher; |
| 765 | typedef _Pred key_equal; |
| 766 | typedef _Alloc allocator_type; |
| 767 | typedef pair<const key_type, mapped_type> value_type; |
| 768 | typedef value_type& reference; |
| 769 | typedef const value_type& const_reference; |
| 770 | |
| 771 | private: |
| 772 | typedef pair<key_type, mapped_type> __value_type; |
| 773 | typedef __hash_map_hasher<__value_type, hasher> __hasher; |
| 774 | typedef __hash_map_equal<__value_type, key_equal> __key_equal; |
| 775 | typedef typename allocator_traits<allocator_type>::template |
| 776 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 777 | rebind_alloc<__value_type> |
| 778 | #else |
| 779 | rebind_alloc<__value_type>::other |
| 780 | #endif |
| 781 | __allocator_type; |
| 782 | |
| 783 | typedef __hash_table<__value_type, __hasher, |
| 784 | __key_equal, __allocator_type> __table; |
| 785 | |
| 786 | __table __table_; |
| 787 | |
| 788 | typedef typename __table::__node_traits __node_traits; |
| 789 | typedef typename __table::__node_allocator __node_allocator; |
| 790 | typedef typename __table::__node __node; |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 791 | typedef __hash_map_node_destructor<__node_allocator> _Dp; |
| 792 | typedef unique_ptr<__node, _Dp> __node_holder; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 793 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 794 | public: |
| 795 | typedef typename __alloc_traits::pointer pointer; |
| 796 | typedef typename __alloc_traits::const_pointer const_pointer; |
| 797 | typedef typename __alloc_traits::size_type size_type; |
| 798 | typedef typename __alloc_traits::difference_type difference_type; |
| 799 | |
| 800 | typedef __hash_map_iterator<typename __table::iterator> iterator; |
| 801 | typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; |
| 802 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 803 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 804 | hash_multimap() {__table_.rehash(193);} |
| 805 | explicit hash_multimap(size_type __n, const hasher& __hf = hasher(), |
| 806 | const key_equal& __eql = key_equal()); |
| 807 | hash_multimap(size_type __n, const hasher& __hf, |
| 808 | const key_equal& __eql, |
| 809 | const allocator_type& __a); |
| 810 | template <class _InputIterator> |
| 811 | hash_multimap(_InputIterator __first, _InputIterator __last); |
| 812 | template <class _InputIterator> |
| 813 | hash_multimap(_InputIterator __first, _InputIterator __last, |
| 814 | size_type __n, const hasher& __hf = hasher(), |
| 815 | const key_equal& __eql = key_equal()); |
| 816 | template <class _InputIterator> |
| 817 | hash_multimap(_InputIterator __first, _InputIterator __last, |
| 818 | size_type __n, const hasher& __hf, |
| 819 | const key_equal& __eql, |
| 820 | const allocator_type& __a); |
| 821 | hash_multimap(const hash_multimap& __u); |
| 822 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 823 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 824 | allocator_type get_allocator() const |
| 825 | {return allocator_type(__table_.__node_alloc());} |
| 826 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 827 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 828 | bool empty() const {return __table_.size() == 0;} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 829 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 830 | size_type size() const {return __table_.size();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 831 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 832 | size_type max_size() const {return __table_.max_size();} |
| 833 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 834 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 835 | iterator begin() {return __table_.begin();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 836 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 837 | iterator end() {return __table_.end();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 838 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 839 | const_iterator begin() const {return __table_.begin();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 840 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 841 | const_iterator end() const {return __table_.end();} |
| 842 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 843 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 844 | iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} |
Alexis Hunt | fe473ae | 2011-07-29 23:31:53 +0000 | [diff] [blame] | 845 | _LIBCPP_INLINE_VISIBILITY |
| 846 | iterator insert(const_iterator, const value_type& __x) {return insert(__x);} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 847 | template <class _InputIterator> |
| 848 | void insert(_InputIterator __first, _InputIterator __last); |
| 849 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 850 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 851 | void erase(const_iterator __p) {__table_.erase(__p.__i_);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 852 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 853 | size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 854 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 855 | void erase(const_iterator __first, const_iterator __last) |
| 856 | {__table_.erase(__first.__i_, __last.__i_);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 857 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 858 | void clear() {__table_.clear();} |
| 859 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 860 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 861 | void swap(hash_multimap& __u) {__table_.swap(__u.__table_);} |
| 862 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 863 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 864 | hasher hash_funct() const |
| 865 | {return __table_.hash_function().hash_function();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 866 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 867 | key_equal key_eq() const |
| 868 | {return __table_.key_eq().key_eq();} |
| 869 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 870 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 871 | iterator find(const key_type& __k) {return __table_.find(__k);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 872 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 873 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 874 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 875 | size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 876 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 877 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 878 | {return __table_.__equal_range_multi(__k);} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 879 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 880 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 881 | {return __table_.__equal_range_multi(__k);} |
| 882 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 883 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 884 | size_type bucket_count() const {return __table_.bucket_count();} |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 885 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 886 | size_type max_bucket_count() const {return __table_.max_bucket_count();} |
| 887 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 888 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 889 | size_type elems_in_bucket(size_type __n) const |
| 890 | {return __table_.bucket_size(__n);} |
| 891 | |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 892 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 893 | void resize(size_type __n) {__table_.rehash(__n);} |
| 894 | }; |
| 895 | |
| 896 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 897 | hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( |
| 898 | size_type __n, const hasher& __hf, const key_equal& __eql) |
| 899 | : __table_(__hf, __eql) |
| 900 | { |
| 901 | __table_.rehash(__n); |
| 902 | } |
| 903 | |
| 904 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 905 | hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( |
| 906 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 907 | const allocator_type& __a) |
| 908 | : __table_(__hf, __eql, __a) |
| 909 | { |
| 910 | __table_.rehash(__n); |
| 911 | } |
| 912 | |
| 913 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 914 | template <class _InputIterator> |
| 915 | hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( |
| 916 | _InputIterator __first, _InputIterator __last) |
| 917 | { |
| 918 | __table_.rehash(193); |
| 919 | insert(__first, __last); |
| 920 | } |
| 921 | |
| 922 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 923 | template <class _InputIterator> |
| 924 | hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( |
| 925 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 926 | const hasher& __hf, const key_equal& __eql) |
| 927 | : __table_(__hf, __eql) |
| 928 | { |
| 929 | __table_.rehash(__n); |
| 930 | insert(__first, __last); |
| 931 | } |
| 932 | |
| 933 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 934 | template <class _InputIterator> |
| 935 | hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( |
| 936 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 937 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 938 | : __table_(__hf, __eql, __a) |
| 939 | { |
| 940 | __table_.rehash(__n); |
| 941 | insert(__first, __last); |
| 942 | } |
| 943 | |
| 944 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 945 | hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( |
| 946 | const hash_multimap& __u) |
| 947 | : __table_(__u.__table_) |
| 948 | { |
| 949 | __table_.rehash(__u.bucket_count()); |
| 950 | insert(__u.begin(), __u.end()); |
| 951 | } |
| 952 | |
| 953 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 954 | template <class _InputIterator> |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 955 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 956 | void |
| 957 | hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 958 | _InputIterator __last) |
| 959 | { |
| 960 | for (; __first != __last; ++__first) |
| 961 | __table_.__insert_multi(*__first); |
| 962 | } |
| 963 | |
| 964 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 965 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 966 | void |
| 967 | swap(hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 968 | hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 969 | { |
| 970 | __x.swap(__y); |
| 971 | } |
| 972 | |
| 973 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 974 | bool |
| 975 | operator==(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 976 | const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 977 | { |
| 978 | if (__x.size() != __y.size()) |
| 979 | return false; |
| 980 | typedef typename hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator |
| 981 | const_iterator; |
| 982 | typedef pair<const_iterator, const_iterator> _EqRng; |
| 983 | for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) |
| 984 | { |
| 985 | _EqRng __xeq = __x.equal_range(__i->first); |
| 986 | _EqRng __yeq = __y.equal_range(__i->first); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 987 | if (_VSTD::distance(__xeq.first, __xeq.second) != |
| 988 | _VSTD::distance(__yeq.first, __yeq.second) || |
| 989 | !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 990 | return false; |
| 991 | __i = __xeq.second; |
| 992 | } |
| 993 | return true; |
| 994 | } |
| 995 | |
| 996 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | fb10002 | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 997 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 998 | bool |
| 999 | operator!=(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1000 | const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 1001 | { |
| 1002 | return !(__x == __y); |
| 1003 | } |
| 1004 | |
| 1005 | } // __gnu_cxx |
| 1006 | |
| 1007 | #endif // _LIBCPP_HASH_MAP |