blob: 36cd595e0343b25ef3574ad429dd2d339d379180 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- hash_map ----------------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00005//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_HASH_MAP
12#define _LIBCPP_HASH_MAP
13
14/*
15
16 hash_map synopsis
17
18namespace __gnu_cxx
19{
20
21template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
22 class Alloc = allocator<pair<const Key, T>>>
23class hash_map
24{
25public:
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
96template <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
100template <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
105template <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
110template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
111 class Alloc = allocator<pair<const Key, T>>>
112class hash_multimap
113{
114public:
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
184template <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
188template <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
193template <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 Hunt8d2ed562011-07-29 23:31:56 +0000206#include <ext/__hash>
Howard Hinnant3e519522010-05-11 19:42:16 +0000207
Howard Hinnant1dba4452011-07-24 23:59:50 +0000208#if __DEPRECATED
Howard Hinnant80b84d42013-10-04 21:14:44 +0000209#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 Hinnant1dba4452011-07-24 23:59:50 +0000214#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000215
216#pragma GCC system_header
217
218namespace __gnu_cxx {
219
220using namespace std;
221
Howard Hinnant42b8bb52011-12-11 20:31:33 +0000222template <class _Tp, class _Hash, bool = is_empty<_Hash>::value
223#if __has_feature(is_final)
224 && !__is_final(_Hash)
225#endif
226 >
Howard Hinnant3e519522010-05-11 19:42:16 +0000227class __hash_map_hasher
228 : private _Hash
229{
230public:
Howard Hinnantfb100022010-09-21 21:28:23 +0000231 _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 Hinnant3e519522010-05-11 19:42:16 +0000235 size_t operator()(const _Tp& __x) const
236 {return static_cast<const _Hash&>(*this)(__x.first);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000238 size_t operator()(const typename _Tp::first_type& __x) const
239 {return static_cast<const _Hash&>(*this)(__x);}
240};
241
242template <class _Tp, class _Hash>
243class __hash_map_hasher<_Tp, _Hash, false>
244{
245 _Hash __hash_;
246public:
Howard Hinnantfb100022010-09-21 21:28:23 +0000247 _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 Hinnant3e519522010-05-11 19:42:16 +0000251 size_t operator()(const _Tp& __x) const
252 {return __hash_(__x.first);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000254 size_t operator()(const typename _Tp::first_type& __x) const
255 {return __hash_(__x);}
256};
257
Howard Hinnant42b8bb52011-12-11 20:31:33 +0000258template <class _Tp, class _Pred, bool = is_empty<_Pred>::value
259#if __has_feature(is_final)
260 && !__is_final(_Pred)
261#endif
262 >
Howard Hinnant3e519522010-05-11 19:42:16 +0000263class __hash_map_equal
264 : private _Pred
265{
266public:
Howard Hinnantfb100022010-09-21 21:28:23 +0000267 _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 Hinnant3e519522010-05-11 19:42:16 +0000271 bool operator()(const _Tp& __x, const _Tp& __y) const
272 {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000274 bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
275 {return static_cast<const _Pred&>(*this)(__x, __y.first);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000277 bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
278 {return static_cast<const _Pred&>(*this)(__x.first, __y);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000279 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb3371f62010-08-22 00:02:43 +0000280 bool operator()(const typename _Tp::first_type& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +0000281 const typename _Tp::first_type& __y) const
282 {return static_cast<const _Pred&>(*this)(__x, __y);}
283};
284
285template <class _Tp, class _Pred>
286class __hash_map_equal<_Tp, _Pred, false>
287{
288 _Pred __pred_;
289public:
Howard Hinnantfb100022010-09-21 21:28:23 +0000290 _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 Hinnant3e519522010-05-11 19:42:16 +0000294 bool operator()(const _Tp& __x, const _Tp& __y) const
295 {return __pred_(__x.first, __y.first);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000297 bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
298 {return __pred_(__x, __y.first);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000300 bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
301 {return __pred_(__x.first, __y);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000303 bool operator()(const typename _Tp::first_type& __x,
304 const typename _Tp::first_type& __y) const
305 {return __pred_(__x, __y);}
306};
307
308template <class _Alloc>
309class __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;
314public:
315 typedef typename __alloc_traits::pointer pointer;
316private:
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
324public:
325 bool __first_constructed;
326 bool __second_constructed;
327
Howard Hinnantfb100022010-09-21 21:28:23 +0000328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000329 explicit __hash_map_node_destructor(allocator_type& __na)
330 : __na_(__na),
331 __first_constructed(false),
332 __second_constructed(false)
333 {}
334
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000335#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantfb100022010-09-21 21:28:23 +0000336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000337 __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 Hinnant7609c9b2010-09-04 23:28:19 +0000344#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantfb100022010-09-21 21:28:23 +0000345 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000346 __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 Hinnant7609c9b2010-09-04 23:28:19 +0000353#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000354
Howard Hinnantfb100022010-09-21 21:28:23 +0000355 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000356 void operator()(pointer __p)
357 {
358 if (__second_constructed)
Howard Hinnantce48a112011-06-30 21:18:19 +0000359 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second));
Howard Hinnant3e519522010-05-11 19:42:16 +0000360 if (__first_constructed)
Howard Hinnantce48a112011-06-30 21:18:19 +0000361 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first));
Howard Hinnant3e519522010-05-11 19:42:16 +0000362 if (__p)
363 __alloc_traits::deallocate(__na_, __p, 1);
364 }
365};
366
367template <class _HashIterator>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000368class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000369{
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;
375public:
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 Hinnantfb100022010-09-21 21:28:23 +0000388 _LIBCPP_INLINE_VISIBILITY __hash_map_iterator() {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000389
Howard Hinnantfb100022010-09-21 21:28:23 +0000390 _LIBCPP_INLINE_VISIBILITY __hash_map_iterator(_HashIterator __i) : __i_(__i) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000391
Howard Hinnantfb100022010-09-21 21:28:23 +0000392 _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *operator->();}
393 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return (pointer)__i_.operator->();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000394
Howard Hinnantfb100022010-09-21 21:28:23 +0000395 _LIBCPP_INLINE_VISIBILITY __hash_map_iterator& operator++() {++__i_; return *this;}
396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000397 __hash_map_iterator operator++(int)
398 {
399 __hash_map_iterator __t(*this);
400 ++(*this);
401 return __t;
402 }
403
Howard Hinnantfb100022010-09-21 21:28:23 +0000404 friend _LIBCPP_INLINE_VISIBILITY
405 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000406 {return __x.__i_ == __y.__i_;}
Howard Hinnantfb100022010-09-21 21:28:23 +0000407 friend _LIBCPP_INLINE_VISIBILITY
408 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000409 {return __x.__i_ != __y.__i_;}
410
Howard Hinnantf0544c22013-08-12 18:38:34 +0000411 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 Hinnant3e519522010-05-11 19:42:16 +0000416};
417
418template <class _HashIterator>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000419class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000420{
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;
426public:
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 Collingbourne99aadbd2014-03-03 19:50:01 +0000433 rebind<const value_type>
Howard Hinnant3e519522010-05-11 19:42:16 +0000434#else
Peter Collingbourne99aadbd2014-03-03 19:50:01 +0000435 rebind<const value_type>::other
Howard Hinnant3e519522010-05-11 19:42:16 +0000436#endif
437 pointer;
438
Howard Hinnantfb100022010-09-21 21:28:23 +0000439 _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator() {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000440
Howard Hinnantfb100022010-09-21 21:28:23 +0000441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000442 __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {}
Howard Hinnantfb100022010-09-21 21:28:23 +0000443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000444 __hash_map_const_iterator(
445 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
446 : __i_(__i.__i_) {}
447
Howard Hinnantfb100022010-09-21 21:28:23 +0000448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000449 reference operator*() const {return *operator->();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000451 pointer operator->() const {return (pointer)__i_.operator->();}
452
Howard Hinnantfb100022010-09-21 21:28:23 +0000453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000454 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnantfb100022010-09-21 21:28:23 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000456 __hash_map_const_iterator operator++(int)
457 {
458 __hash_map_const_iterator __t(*this);
459 ++(*this);
460 return __t;
461 }
462
Howard Hinnantfb100022010-09-21 21:28:23 +0000463 friend _LIBCPP_INLINE_VISIBILITY
464 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000465 {return __x.__i_ == __y.__i_;}
Howard Hinnantfb100022010-09-21 21:28:23 +0000466 friend _LIBCPP_INLINE_VISIBILITY
467 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000468 {return __x.__i_ != __y.__i_;}
469
Howard Hinnantf0544c22013-08-12 18:38:34 +0000470 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 Hinnant3e519522010-05-11 19:42:16 +0000474};
475
476template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
477 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnantf0544c22013-08-12 18:38:34 +0000478class _LIBCPP_TYPE_VIS_ONLY hash_map
Howard Hinnant3e519522010-05-11 19:42:16 +0000479{
480public:
481 // types
482 typedef _Key key_type;
483 typedef _Tp mapped_type;
Alexis Huntfe473ae2011-07-29 23:31:53 +0000484 typedef _Tp data_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000485 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
492private:
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 Hinnantc003db12011-11-29 18:15:50 +0000514 typedef __hash_map_node_destructor<__node_allocator> _Dp;
515 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +0000516 typedef allocator_traits<allocator_type> __alloc_traits;
517public:
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 Hinnantfb100022010-09-21 21:28:23 +0000526 _LIBCPP_INLINE_VISIBILITY hash_map() {__table_.rehash(193);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000527 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 Hinnantfb100022010-09-21 21:28:23 +0000545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000546 allocator_type get_allocator() const
547 {return allocator_type(__table_.__node_alloc());}
548
Howard Hinnantfb100022010-09-21 21:28:23 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000550 bool empty() const {return __table_.size() == 0;}
Howard Hinnantfb100022010-09-21 21:28:23 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000552 size_type size() const {return __table_.size();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000554 size_type max_size() const {return __table_.max_size();}
555
Howard Hinnantfb100022010-09-21 21:28:23 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000557 iterator begin() {return __table_.begin();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000559 iterator end() {return __table_.end();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000561 const_iterator begin() const {return __table_.begin();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000563 const_iterator end() const {return __table_.end();}
564
Howard Hinnantfb100022010-09-21 21:28:23 +0000565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000566 pair<iterator, bool> insert(const value_type& __x)
567 {return __table_.__insert_unique(__x);}
Alexis Huntfe473ae2011-07-29 23:31:53 +0000568 _LIBCPP_INLINE_VISIBILITY
569 iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000570 template <class _InputIterator>
571 void insert(_InputIterator __first, _InputIterator __last);
572
Howard Hinnantfb100022010-09-21 21:28:23 +0000573 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000574 void erase(const_iterator __p) {__table_.erase(__p.__i_);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000576 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000578 void erase(const_iterator __first, const_iterator __last)
579 {__table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000581 void clear() {__table_.clear();}
582
Howard Hinnantfb100022010-09-21 21:28:23 +0000583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000584 void swap(hash_map& __u) {__table_.swap(__u.__table_);}
585
Howard Hinnantfb100022010-09-21 21:28:23 +0000586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000587 hasher hash_funct() const
588 {return __table_.hash_function().hash_function();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000590 key_equal key_eq() const
591 {return __table_.key_eq().key_eq();}
592
Howard Hinnantfb100022010-09-21 21:28:23 +0000593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000594 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000596 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000598 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000600 pair<iterator, iterator> equal_range(const key_type& __k)
601 {return __table_.__equal_range_unique(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000603 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 Hinnantfb100022010-09-21 21:28:23 +0000608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000609 size_type bucket_count() const {return __table_.bucket_count();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000611 size_type max_bucket_count() const {return __table_.max_bucket_count();}
612
Howard Hinnantfb100022010-09-21 21:28:23 +0000613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000614 size_type elems_in_bucket(size_type __n) const
615 {return __table_.bucket_size(__n);}
616
Howard Hinnantfb100022010-09-21 21:28:23 +0000617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000618 void resize(size_type __n) {__table_.rehash(__n);}
619
620private:
621 __node_holder __construct_node(const key_type& __k);
622};
623
624template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
625hash_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
632template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
633hash_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
641template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
642template <class _InputIterator>
643hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
644 _InputIterator __first, _InputIterator __last)
645{
646 __table_.rehash(193);
647 insert(__first, __last);
648}
649
650template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
651template <class _InputIterator>
652hash_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
661template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
662template <class _InputIterator>
663hash_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
672template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
673hash_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
681template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
682typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
683hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k)
684{
685 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +0000686 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantce48a112011-06-30 21:18:19 +0000687 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k);
Howard Hinnant3e519522010-05-11 19:42:16 +0000688 __h.get_deleter().__first_constructed = true;
Howard Hinnantce48a112011-06-30 21:18:19 +0000689 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
Howard Hinnant3e519522010-05-11 19:42:16 +0000690 __h.get_deleter().__second_constructed = true;
Howard Hinnant179b1f82013-08-22 18:29:50 +0000691 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnant3e519522010-05-11 19:42:16 +0000692}
693
694template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
695template <class _InputIterator>
Howard Hinnantfb100022010-09-21 21:28:23 +0000696inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000697void
698hash_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
705template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
706_Tp&
707hash_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
718template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantfb100022010-09-21 21:28:23 +0000719inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000720void
721swap(hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
722 hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
723{
724 __x.swap(__y);
725}
726
727template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
728bool
729operator==(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
746template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantfb100022010-09-21 21:28:23 +0000747inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000748bool
749operator!=(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
755template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
756 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnantf0544c22013-08-12 18:38:34 +0000757class _LIBCPP_TYPE_VIS_ONLY hash_multimap
Howard Hinnant3e519522010-05-11 19:42:16 +0000758{
759public:
760 // types
761 typedef _Key key_type;
762 typedef _Tp mapped_type;
Alexis Huntfe473ae2011-07-29 23:31:53 +0000763 typedef _Tp data_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000764 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
771private:
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 Hinnantc003db12011-11-29 18:15:50 +0000791 typedef __hash_map_node_destructor<__node_allocator> _Dp;
792 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +0000793 typedef allocator_traits<allocator_type> __alloc_traits;
794public:
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 Hinnantfb100022010-09-21 21:28:23 +0000803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000804 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 Hinnantfb100022010-09-21 21:28:23 +0000823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000824 allocator_type get_allocator() const
825 {return allocator_type(__table_.__node_alloc());}
826
Howard Hinnantfb100022010-09-21 21:28:23 +0000827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000828 bool empty() const {return __table_.size() == 0;}
Howard Hinnantfb100022010-09-21 21:28:23 +0000829 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000830 size_type size() const {return __table_.size();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000832 size_type max_size() const {return __table_.max_size();}
833
Howard Hinnantfb100022010-09-21 21:28:23 +0000834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000835 iterator begin() {return __table_.begin();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000837 iterator end() {return __table_.end();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000839 const_iterator begin() const {return __table_.begin();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000841 const_iterator end() const {return __table_.end();}
842
Howard Hinnantfb100022010-09-21 21:28:23 +0000843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000844 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Alexis Huntfe473ae2011-07-29 23:31:53 +0000845 _LIBCPP_INLINE_VISIBILITY
846 iterator insert(const_iterator, const value_type& __x) {return insert(__x);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000847 template <class _InputIterator>
848 void insert(_InputIterator __first, _InputIterator __last);
849
Howard Hinnantfb100022010-09-21 21:28:23 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000851 void erase(const_iterator __p) {__table_.erase(__p.__i_);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000853 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000855 void erase(const_iterator __first, const_iterator __last)
856 {__table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000858 void clear() {__table_.clear();}
859
Howard Hinnantfb100022010-09-21 21:28:23 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000861 void swap(hash_multimap& __u) {__table_.swap(__u.__table_);}
862
Howard Hinnantfb100022010-09-21 21:28:23 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000864 hasher hash_funct() const
865 {return __table_.hash_function().hash_function();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000867 key_equal key_eq() const
868 {return __table_.key_eq().key_eq();}
869
Howard Hinnantfb100022010-09-21 21:28:23 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000871 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000873 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000875 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000877 pair<iterator, iterator> equal_range(const key_type& __k)
878 {return __table_.__equal_range_multi(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000880 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
881 {return __table_.__equal_range_multi(__k);}
882
Howard Hinnantfb100022010-09-21 21:28:23 +0000883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000884 size_type bucket_count() const {return __table_.bucket_count();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000886 size_type max_bucket_count() const {return __table_.max_bucket_count();}
887
Howard Hinnantfb100022010-09-21 21:28:23 +0000888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000889 size_type elems_in_bucket(size_type __n) const
890 {return __table_.bucket_size(__n);}
891
Howard Hinnantfb100022010-09-21 21:28:23 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000893 void resize(size_type __n) {__table_.rehash(__n);}
894};
895
896template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
897hash_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
904template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
905hash_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
913template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
914template <class _InputIterator>
915hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
916 _InputIterator __first, _InputIterator __last)
917{
918 __table_.rehash(193);
919 insert(__first, __last);
920}
921
922template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
923template <class _InputIterator>
924hash_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
933template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
934template <class _InputIterator>
935hash_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
944template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
945hash_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
953template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
954template <class _InputIterator>
Howard Hinnantfb100022010-09-21 21:28:23 +0000955inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000956void
957hash_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
964template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantfb100022010-09-21 21:28:23 +0000965inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000966void
967swap(hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
968 hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
969{
970 __x.swap(__y);
971}
972
973template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
974bool
975operator==(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 Hinnantce48a112011-06-30 21:18:19 +0000987 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 Hinnant3e519522010-05-11 19:42:16 +0000990 return false;
991 __i = __xeq.second;
992 }
993 return true;
994}
995
996template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantfb100022010-09-21 21:28:23 +0000997inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000998bool
999operator!=(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