blob: d8fc1e6c03c0ca07ed685699096a5316e791330e [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;
Marshall Clow1f508012015-04-07 05:21:38 +0000496 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __value_type>::type __allocator_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000497
498 typedef __hash_table<__value_type, __hasher,
499 __key_equal, __allocator_type> __table;
500
501 __table __table_;
502
503 typedef typename __table::__node_pointer __node_pointer;
504 typedef typename __table::__node_const_pointer __node_const_pointer;
505 typedef typename __table::__node_traits __node_traits;
506 typedef typename __table::__node_allocator __node_allocator;
507 typedef typename __table::__node __node;
Howard Hinnantc003db12011-11-29 18:15:50 +0000508 typedef __hash_map_node_destructor<__node_allocator> _Dp;
509 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +0000510 typedef allocator_traits<allocator_type> __alloc_traits;
511public:
512 typedef typename __alloc_traits::pointer pointer;
513 typedef typename __alloc_traits::const_pointer const_pointer;
514 typedef typename __alloc_traits::size_type size_type;
515 typedef typename __alloc_traits::difference_type difference_type;
516
517 typedef __hash_map_iterator<typename __table::iterator> iterator;
518 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
519
Howard Hinnantfb100022010-09-21 21:28:23 +0000520 _LIBCPP_INLINE_VISIBILITY hash_map() {__table_.rehash(193);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000521 explicit hash_map(size_type __n, const hasher& __hf = hasher(),
522 const key_equal& __eql = key_equal());
523 hash_map(size_type __n, const hasher& __hf,
524 const key_equal& __eql,
525 const allocator_type& __a);
526 template <class _InputIterator>
527 hash_map(_InputIterator __first, _InputIterator __last);
528 template <class _InputIterator>
529 hash_map(_InputIterator __first, _InputIterator __last,
530 size_type __n, const hasher& __hf = hasher(),
531 const key_equal& __eql = key_equal());
532 template <class _InputIterator>
533 hash_map(_InputIterator __first, _InputIterator __last,
534 size_type __n, const hasher& __hf,
535 const key_equal& __eql,
536 const allocator_type& __a);
537 hash_map(const hash_map& __u);
538
Howard Hinnantfb100022010-09-21 21:28:23 +0000539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000540 allocator_type get_allocator() const
541 {return allocator_type(__table_.__node_alloc());}
542
Howard Hinnantfb100022010-09-21 21:28:23 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000544 bool empty() const {return __table_.size() == 0;}
Howard Hinnantfb100022010-09-21 21:28:23 +0000545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000546 size_type size() const {return __table_.size();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000548 size_type max_size() const {return __table_.max_size();}
549
Howard Hinnantfb100022010-09-21 21:28:23 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000551 iterator begin() {return __table_.begin();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000553 iterator end() {return __table_.end();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000555 const_iterator begin() const {return __table_.begin();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000557 const_iterator end() const {return __table_.end();}
558
Howard Hinnantfb100022010-09-21 21:28:23 +0000559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000560 pair<iterator, bool> insert(const value_type& __x)
561 {return __table_.__insert_unique(__x);}
Alexis Huntfe473ae2011-07-29 23:31:53 +0000562 _LIBCPP_INLINE_VISIBILITY
563 iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000564 template <class _InputIterator>
565 void insert(_InputIterator __first, _InputIterator __last);
566
Howard Hinnantfb100022010-09-21 21:28:23 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000568 void erase(const_iterator __p) {__table_.erase(__p.__i_);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000570 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000572 void erase(const_iterator __first, const_iterator __last)
573 {__table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000574 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000575 void clear() {__table_.clear();}
576
Howard Hinnantfb100022010-09-21 21:28:23 +0000577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000578 void swap(hash_map& __u) {__table_.swap(__u.__table_);}
579
Howard Hinnantfb100022010-09-21 21:28:23 +0000580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000581 hasher hash_funct() const
582 {return __table_.hash_function().hash_function();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000584 key_equal key_eq() const
585 {return __table_.key_eq().key_eq();}
586
Howard Hinnantfb100022010-09-21 21:28:23 +0000587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000588 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000590 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000592 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000594 pair<iterator, iterator> equal_range(const key_type& __k)
595 {return __table_.__equal_range_unique(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000597 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
598 {return __table_.__equal_range_unique(__k);}
599
600 mapped_type& operator[](const key_type& __k);
601
Howard Hinnantfb100022010-09-21 21:28:23 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000603 size_type bucket_count() const {return __table_.bucket_count();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000605 size_type max_bucket_count() const {return __table_.max_bucket_count();}
606
Howard Hinnantfb100022010-09-21 21:28:23 +0000607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000608 size_type elems_in_bucket(size_type __n) const
609 {return __table_.bucket_size(__n);}
610
Howard Hinnantfb100022010-09-21 21:28:23 +0000611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000612 void resize(size_type __n) {__table_.rehash(__n);}
613
614private:
615 __node_holder __construct_node(const key_type& __k);
616};
617
618template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
619hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
620 size_type __n, const hasher& __hf, const key_equal& __eql)
621 : __table_(__hf, __eql)
622{
623 __table_.rehash(__n);
624}
625
626template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
627hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
628 size_type __n, const hasher& __hf, const key_equal& __eql,
629 const allocator_type& __a)
630 : __table_(__hf, __eql, __a)
631{
632 __table_.rehash(__n);
633}
634
635template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
636template <class _InputIterator>
637hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
638 _InputIterator __first, _InputIterator __last)
639{
640 __table_.rehash(193);
641 insert(__first, __last);
642}
643
644template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
645template <class _InputIterator>
646hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
647 _InputIterator __first, _InputIterator __last, size_type __n,
648 const hasher& __hf, const key_equal& __eql)
649 : __table_(__hf, __eql)
650{
651 __table_.rehash(__n);
652 insert(__first, __last);
653}
654
655template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
656template <class _InputIterator>
657hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
658 _InputIterator __first, _InputIterator __last, size_type __n,
659 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
660 : __table_(__hf, __eql, __a)
661{
662 __table_.rehash(__n);
663 insert(__first, __last);
664}
665
666template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
667hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
668 const hash_map& __u)
669 : __table_(__u.__table_)
670{
671 __table_.rehash(__u.bucket_count());
672 insert(__u.begin(), __u.end());
673}
674
675template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
676typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
677hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k)
678{
679 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +0000680 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantce48a112011-06-30 21:18:19 +0000681 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k);
Howard Hinnant3e519522010-05-11 19:42:16 +0000682 __h.get_deleter().__first_constructed = true;
Howard Hinnantce48a112011-06-30 21:18:19 +0000683 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
Howard Hinnant3e519522010-05-11 19:42:16 +0000684 __h.get_deleter().__second_constructed = true;
Howard Hinnant179b1f82013-08-22 18:29:50 +0000685 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnant3e519522010-05-11 19:42:16 +0000686}
687
688template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
689template <class _InputIterator>
Howard Hinnantfb100022010-09-21 21:28:23 +0000690inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000691void
692hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
693 _InputIterator __last)
694{
695 for (; __first != __last; ++__first)
696 __table_.__insert_unique(*__first);
697}
698
699template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
700_Tp&
701hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
702{
703 iterator __i = find(__k);
704 if (__i != end())
705 return __i->second;
706 __node_holder __h = __construct_node(__k);
707 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
708 __h.release();
709 return __r.first->second;
710}
711
712template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantfb100022010-09-21 21:28:23 +0000713inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000714void
715swap(hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
716 hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
717{
718 __x.swap(__y);
719}
720
721template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
722bool
723operator==(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
724 const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
725{
726 if (__x.size() != __y.size())
727 return false;
728 typedef typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
729 const_iterator;
730 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
731 __i != __ex; ++__i)
732 {
733 const_iterator __j = __y.find(__i->first);
734 if (__j == __ey || !(*__i == *__j))
735 return false;
736 }
737 return true;
738}
739
740template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantfb100022010-09-21 21:28:23 +0000741inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000742bool
743operator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
744 const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
745{
746 return !(__x == __y);
747}
748
749template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
750 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnantf0544c22013-08-12 18:38:34 +0000751class _LIBCPP_TYPE_VIS_ONLY hash_multimap
Howard Hinnant3e519522010-05-11 19:42:16 +0000752{
753public:
754 // types
755 typedef _Key key_type;
756 typedef _Tp mapped_type;
Alexis Huntfe473ae2011-07-29 23:31:53 +0000757 typedef _Tp data_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000758 typedef _Hash hasher;
759 typedef _Pred key_equal;
760 typedef _Alloc allocator_type;
761 typedef pair<const key_type, mapped_type> value_type;
762 typedef value_type& reference;
763 typedef const value_type& const_reference;
764
765private:
766 typedef pair<key_type, mapped_type> __value_type;
767 typedef __hash_map_hasher<__value_type, hasher> __hasher;
768 typedef __hash_map_equal<__value_type, key_equal> __key_equal;
Marshall Clow1f508012015-04-07 05:21:38 +0000769 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __value_type>::type __allocator_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000770
771 typedef __hash_table<__value_type, __hasher,
772 __key_equal, __allocator_type> __table;
773
774 __table __table_;
775
776 typedef typename __table::__node_traits __node_traits;
777 typedef typename __table::__node_allocator __node_allocator;
778 typedef typename __table::__node __node;
Howard Hinnantc003db12011-11-29 18:15:50 +0000779 typedef __hash_map_node_destructor<__node_allocator> _Dp;
780 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +0000781 typedef allocator_traits<allocator_type> __alloc_traits;
782public:
783 typedef typename __alloc_traits::pointer pointer;
784 typedef typename __alloc_traits::const_pointer const_pointer;
785 typedef typename __alloc_traits::size_type size_type;
786 typedef typename __alloc_traits::difference_type difference_type;
787
788 typedef __hash_map_iterator<typename __table::iterator> iterator;
789 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
790
Howard Hinnantfb100022010-09-21 21:28:23 +0000791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000792 hash_multimap() {__table_.rehash(193);}
793 explicit hash_multimap(size_type __n, const hasher& __hf = hasher(),
794 const key_equal& __eql = key_equal());
795 hash_multimap(size_type __n, const hasher& __hf,
796 const key_equal& __eql,
797 const allocator_type& __a);
798 template <class _InputIterator>
799 hash_multimap(_InputIterator __first, _InputIterator __last);
800 template <class _InputIterator>
801 hash_multimap(_InputIterator __first, _InputIterator __last,
802 size_type __n, const hasher& __hf = hasher(),
803 const key_equal& __eql = key_equal());
804 template <class _InputIterator>
805 hash_multimap(_InputIterator __first, _InputIterator __last,
806 size_type __n, const hasher& __hf,
807 const key_equal& __eql,
808 const allocator_type& __a);
809 hash_multimap(const hash_multimap& __u);
810
Howard Hinnantfb100022010-09-21 21:28:23 +0000811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000812 allocator_type get_allocator() const
813 {return allocator_type(__table_.__node_alloc());}
814
Howard Hinnantfb100022010-09-21 21:28:23 +0000815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000816 bool empty() const {return __table_.size() == 0;}
Howard Hinnantfb100022010-09-21 21:28:23 +0000817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000818 size_type size() const {return __table_.size();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000820 size_type max_size() const {return __table_.max_size();}
821
Howard Hinnantfb100022010-09-21 21:28:23 +0000822 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000823 iterator begin() {return __table_.begin();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000825 iterator end() {return __table_.end();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000827 const_iterator begin() const {return __table_.begin();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000829 const_iterator end() const {return __table_.end();}
830
Howard Hinnantfb100022010-09-21 21:28:23 +0000831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000832 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Alexis Huntfe473ae2011-07-29 23:31:53 +0000833 _LIBCPP_INLINE_VISIBILITY
834 iterator insert(const_iterator, const value_type& __x) {return insert(__x);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000835 template <class _InputIterator>
836 void insert(_InputIterator __first, _InputIterator __last);
837
Howard Hinnantfb100022010-09-21 21:28:23 +0000838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000839 void erase(const_iterator __p) {__table_.erase(__p.__i_);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000841 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000843 void erase(const_iterator __first, const_iterator __last)
844 {__table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000845 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000846 void clear() {__table_.clear();}
847
Howard Hinnantfb100022010-09-21 21:28:23 +0000848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000849 void swap(hash_multimap& __u) {__table_.swap(__u.__table_);}
850
Howard Hinnantfb100022010-09-21 21:28:23 +0000851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000852 hasher hash_funct() const
853 {return __table_.hash_function().hash_function();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000855 key_equal key_eq() const
856 {return __table_.key_eq().key_eq();}
857
Howard Hinnantfb100022010-09-21 21:28:23 +0000858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000859 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000861 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000863 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000865 pair<iterator, iterator> equal_range(const key_type& __k)
866 {return __table_.__equal_range_multi(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000868 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
869 {return __table_.__equal_range_multi(__k);}
870
Howard Hinnantfb100022010-09-21 21:28:23 +0000871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000872 size_type bucket_count() const {return __table_.bucket_count();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000874 size_type max_bucket_count() const {return __table_.max_bucket_count();}
875
Howard Hinnantfb100022010-09-21 21:28:23 +0000876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000877 size_type elems_in_bucket(size_type __n) const
878 {return __table_.bucket_size(__n);}
879
Howard Hinnantfb100022010-09-21 21:28:23 +0000880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000881 void resize(size_type __n) {__table_.rehash(__n);}
882};
883
884template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
885hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
886 size_type __n, const hasher& __hf, const key_equal& __eql)
887 : __table_(__hf, __eql)
888{
889 __table_.rehash(__n);
890}
891
892template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
893hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
894 size_type __n, const hasher& __hf, const key_equal& __eql,
895 const allocator_type& __a)
896 : __table_(__hf, __eql, __a)
897{
898 __table_.rehash(__n);
899}
900
901template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
902template <class _InputIterator>
903hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
904 _InputIterator __first, _InputIterator __last)
905{
906 __table_.rehash(193);
907 insert(__first, __last);
908}
909
910template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
911template <class _InputIterator>
912hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
913 _InputIterator __first, _InputIterator __last, size_type __n,
914 const hasher& __hf, const key_equal& __eql)
915 : __table_(__hf, __eql)
916{
917 __table_.rehash(__n);
918 insert(__first, __last);
919}
920
921template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
922template <class _InputIterator>
923hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
924 _InputIterator __first, _InputIterator __last, size_type __n,
925 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
926 : __table_(__hf, __eql, __a)
927{
928 __table_.rehash(__n);
929 insert(__first, __last);
930}
931
932template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
933hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
934 const hash_multimap& __u)
935 : __table_(__u.__table_)
936{
937 __table_.rehash(__u.bucket_count());
938 insert(__u.begin(), __u.end());
939}
940
941template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
942template <class _InputIterator>
Howard Hinnantfb100022010-09-21 21:28:23 +0000943inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000944void
945hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
946 _InputIterator __last)
947{
948 for (; __first != __last; ++__first)
949 __table_.__insert_multi(*__first);
950}
951
952template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantfb100022010-09-21 21:28:23 +0000953inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000954void
955swap(hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
956 hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
957{
958 __x.swap(__y);
959}
960
961template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
962bool
963operator==(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
964 const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
965{
966 if (__x.size() != __y.size())
967 return false;
968 typedef typename hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
969 const_iterator;
970 typedef pair<const_iterator, const_iterator> _EqRng;
971 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
972 {
973 _EqRng __xeq = __x.equal_range(__i->first);
974 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnantce48a112011-06-30 21:18:19 +0000975 if (_VSTD::distance(__xeq.first, __xeq.second) !=
976 _VSTD::distance(__yeq.first, __yeq.second) ||
977 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnant3e519522010-05-11 19:42:16 +0000978 return false;
979 __i = __xeq.second;
980 }
981 return true;
982}
983
984template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantfb100022010-09-21 21:28:23 +0000985inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000986bool
987operator!=(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
988 const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
989{
990 return !(__x == __y);
991}
992
993} // __gnu_cxx
994
995#endif // _LIBCPP_HASH_MAP