blob: 21ce3be8a18c0f511b101db455ad4810a36f46d4 [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>
206
Howard Hinnant1dba4452011-07-24 23:59:50 +0000207#if __DEPRECATED
Howard Hinnant3e519522010-05-11 19:42:16 +0000208#warning Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>
Howard Hinnant1dba4452011-07-24 23:59:50 +0000209#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000210
211#pragma GCC system_header
212
213namespace __gnu_cxx {
214
215using namespace std;
216
217template <class _Tp, class _Hash, bool = is_empty<_Hash>::value>
218class __hash_map_hasher
219 : private _Hash
220{
221public:
Howard Hinnantfb100022010-09-21 21:28:23 +0000222 _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : _Hash() {}
223 _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : _Hash(__h) {}
224 _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return *this;}
225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000226 size_t operator()(const _Tp& __x) const
227 {return static_cast<const _Hash&>(*this)(__x.first);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000228 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000229 size_t operator()(const typename _Tp::first_type& __x) const
230 {return static_cast<const _Hash&>(*this)(__x);}
231};
232
233template <class _Tp, class _Hash>
234class __hash_map_hasher<_Tp, _Hash, false>
235{
236 _Hash __hash_;
237public:
Howard Hinnantfb100022010-09-21 21:28:23 +0000238 _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : __hash_() {}
239 _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : __hash_(__h) {}
240 _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return __hash_;}
241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000242 size_t operator()(const _Tp& __x) const
243 {return __hash_(__x.first);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000245 size_t operator()(const typename _Tp::first_type& __x) const
246 {return __hash_(__x);}
247};
248
249template <class _Tp, class _Pred, bool = is_empty<_Pred>::value>
250class __hash_map_equal
251 : private _Pred
252{
253public:
Howard Hinnantfb100022010-09-21 21:28:23 +0000254 _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : _Pred() {}
255 _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : _Pred(__p) {}
256 _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return *this;}
257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000258 bool operator()(const _Tp& __x, const _Tp& __y) const
259 {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000261 bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
262 {return static_cast<const _Pred&>(*this)(__x, __y.first);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000264 bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
265 {return static_cast<const _Pred&>(*this)(__x.first, __y);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb3371f62010-08-22 00:02:43 +0000267 bool operator()(const typename _Tp::first_type& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +0000268 const typename _Tp::first_type& __y) const
269 {return static_cast<const _Pred&>(*this)(__x, __y);}
270};
271
272template <class _Tp, class _Pred>
273class __hash_map_equal<_Tp, _Pred, false>
274{
275 _Pred __pred_;
276public:
Howard Hinnantfb100022010-09-21 21:28:23 +0000277 _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : __pred_() {}
278 _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : __pred_(__p) {}
279 _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return __pred_;}
280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000281 bool operator()(const _Tp& __x, const _Tp& __y) const
282 {return __pred_(__x.first, __y.first);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000284 bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
285 {return __pred_(__x, __y.first);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000287 bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
288 {return __pred_(__x.first, __y);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000290 bool operator()(const typename _Tp::first_type& __x,
291 const typename _Tp::first_type& __y) const
292 {return __pred_(__x, __y);}
293};
294
295template <class _Alloc>
296class __hash_map_node_destructor
297{
298 typedef _Alloc allocator_type;
299 typedef allocator_traits<allocator_type> __alloc_traits;
300 typedef typename __alloc_traits::value_type::value_type value_type;
301public:
302 typedef typename __alloc_traits::pointer pointer;
303private:
304 typedef typename value_type::first_type first_type;
305 typedef typename value_type::second_type second_type;
306
307 allocator_type& __na_;
308
309 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
310
311public:
312 bool __first_constructed;
313 bool __second_constructed;
314
Howard Hinnantfb100022010-09-21 21:28:23 +0000315 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000316 explicit __hash_map_node_destructor(allocator_type& __na)
317 : __na_(__na),
318 __first_constructed(false),
319 __second_constructed(false)
320 {}
321
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000322#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantfb100022010-09-21 21:28:23 +0000323 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000324 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
325 : __na_(__x.__na_),
326 __first_constructed(__x.__value_constructed),
327 __second_constructed(__x.__value_constructed)
328 {
329 __x.__value_constructed = false;
330 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000331#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantfb100022010-09-21 21:28:23 +0000332 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000333 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
334 : __na_(__x.__na_),
335 __first_constructed(__x.__value_constructed),
336 __second_constructed(__x.__value_constructed)
337 {
338 const_cast<bool&>(__x.__value_constructed) = false;
339 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000340#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000341
Howard Hinnantfb100022010-09-21 21:28:23 +0000342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000343 void operator()(pointer __p)
344 {
345 if (__second_constructed)
Howard Hinnantce48a112011-06-30 21:18:19 +0000346 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second));
Howard Hinnant3e519522010-05-11 19:42:16 +0000347 if (__first_constructed)
Howard Hinnantce48a112011-06-30 21:18:19 +0000348 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first));
Howard Hinnant3e519522010-05-11 19:42:16 +0000349 if (__p)
350 __alloc_traits::deallocate(__na_, __p, 1);
351 }
352};
353
354template <class _HashIterator>
Howard Hinnantfb100022010-09-21 21:28:23 +0000355class _LIBCPP_VISIBLE __hash_map_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000356{
357 _HashIterator __i_;
358
359 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits;
360 typedef const typename _HashIterator::value_type::first_type key_type;
361 typedef typename _HashIterator::value_type::second_type mapped_type;
362public:
363 typedef forward_iterator_tag iterator_category;
364 typedef pair<key_type, mapped_type> value_type;
365 typedef typename _HashIterator::difference_type difference_type;
366 typedef value_type& reference;
367 typedef typename __pointer_traits::template
368#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
369 rebind<value_type>
370#else
371 rebind<value_type>::other
372#endif
373 pointer;
374
Howard Hinnantfb100022010-09-21 21:28:23 +0000375 _LIBCPP_INLINE_VISIBILITY __hash_map_iterator() {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000376
Howard Hinnantfb100022010-09-21 21:28:23 +0000377 _LIBCPP_INLINE_VISIBILITY __hash_map_iterator(_HashIterator __i) : __i_(__i) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000378
Howard Hinnantfb100022010-09-21 21:28:23 +0000379 _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *operator->();}
380 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return (pointer)__i_.operator->();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000381
Howard Hinnantfb100022010-09-21 21:28:23 +0000382 _LIBCPP_INLINE_VISIBILITY __hash_map_iterator& operator++() {++__i_; return *this;}
383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000384 __hash_map_iterator operator++(int)
385 {
386 __hash_map_iterator __t(*this);
387 ++(*this);
388 return __t;
389 }
390
Howard Hinnantfb100022010-09-21 21:28:23 +0000391 friend _LIBCPP_INLINE_VISIBILITY
392 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000393 {return __x.__i_ == __y.__i_;}
Howard Hinnantfb100022010-09-21 21:28:23 +0000394 friend _LIBCPP_INLINE_VISIBILITY
395 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000396 {return __x.__i_ != __y.__i_;}
397
Howard Hinnantfb100022010-09-21 21:28:23 +0000398 template <class, class, class, class, class> friend class _LIBCPP_VISIBLE hash_map;
399 template <class, class, class, class, class> friend class _LIBCPP_VISIBLE hash_multimap;
400 template <class> friend class _LIBCPP_VISIBLE __hash_const_iterator;
401 template <class> friend class _LIBCPP_VISIBLE __hash_const_local_iterator;
402 template <class> friend class _LIBCPP_VISIBLE __hash_map_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000403};
404
405template <class _HashIterator>
Howard Hinnantfb100022010-09-21 21:28:23 +0000406class _LIBCPP_VISIBLE __hash_map_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000407{
408 _HashIterator __i_;
409
410 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits;
411 typedef const typename _HashIterator::value_type::first_type key_type;
412 typedef typename _HashIterator::value_type::second_type mapped_type;
413public:
414 typedef forward_iterator_tag iterator_category;
415 typedef pair<key_type, mapped_type> value_type;
416 typedef typename _HashIterator::difference_type difference_type;
417 typedef const value_type& reference;
418 typedef typename __pointer_traits::template
419#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
420 rebind<value_type>
421#else
422 rebind<value_type>::other
423#endif
424 pointer;
425
Howard Hinnantfb100022010-09-21 21:28:23 +0000426 _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator() {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000427
Howard Hinnantfb100022010-09-21 21:28:23 +0000428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000429 __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {}
Howard Hinnantfb100022010-09-21 21:28:23 +0000430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000431 __hash_map_const_iterator(
432 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
433 : __i_(__i.__i_) {}
434
Howard Hinnantfb100022010-09-21 21:28:23 +0000435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000436 reference operator*() const {return *operator->();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000437 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000438 pointer operator->() const {return (pointer)__i_.operator->();}
439
Howard Hinnantfb100022010-09-21 21:28:23 +0000440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000441 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnantfb100022010-09-21 21:28:23 +0000442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000443 __hash_map_const_iterator operator++(int)
444 {
445 __hash_map_const_iterator __t(*this);
446 ++(*this);
447 return __t;
448 }
449
Howard Hinnantfb100022010-09-21 21:28:23 +0000450 friend _LIBCPP_INLINE_VISIBILITY
451 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000452 {return __x.__i_ == __y.__i_;}
Howard Hinnantfb100022010-09-21 21:28:23 +0000453 friend _LIBCPP_INLINE_VISIBILITY
454 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000455 {return __x.__i_ != __y.__i_;}
456
Howard Hinnantfb100022010-09-21 21:28:23 +0000457 template <class, class, class, class, class> friend class _LIBCPP_VISIBLE hash_map;
458 template <class, class, class, class, class> friend class _LIBCPP_VISIBLE hash_multimap;
459 template <class> friend class _LIBCPP_VISIBLE __hash_const_iterator;
460 template <class> friend class _LIBCPP_VISIBLE __hash_const_local_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000461};
462
463template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
464 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnantfb100022010-09-21 21:28:23 +0000465class _LIBCPP_VISIBLE hash_map
Howard Hinnant3e519522010-05-11 19:42:16 +0000466{
467public:
468 // types
469 typedef _Key key_type;
470 typedef _Tp mapped_type;
Alexis Huntfe473ae2011-07-29 23:31:53 +0000471 typedef _Tp data_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000472 typedef _Hash hasher;
473 typedef _Pred key_equal;
474 typedef _Alloc allocator_type;
475 typedef pair<const key_type, mapped_type> value_type;
476 typedef value_type& reference;
477 typedef const value_type& const_reference;
478
479private:
480 typedef pair<key_type, mapped_type> __value_type;
481 typedef __hash_map_hasher<__value_type, hasher> __hasher;
482 typedef __hash_map_equal<__value_type, key_equal> __key_equal;
483 typedef typename allocator_traits<allocator_type>::template
484#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
485 rebind_alloc<__value_type>
486#else
487 rebind_alloc<__value_type>::other
488#endif
489 __allocator_type;
490
491 typedef __hash_table<__value_type, __hasher,
492 __key_equal, __allocator_type> __table;
493
494 __table __table_;
495
496 typedef typename __table::__node_pointer __node_pointer;
497 typedef typename __table::__node_const_pointer __node_const_pointer;
498 typedef typename __table::__node_traits __node_traits;
499 typedef typename __table::__node_allocator __node_allocator;
500 typedef typename __table::__node __node;
501 typedef __hash_map_node_destructor<__node_allocator> _D;
502 typedef unique_ptr<__node, _D> __node_holder;
503 typedef allocator_traits<allocator_type> __alloc_traits;
504public:
505 typedef typename __alloc_traits::pointer pointer;
506 typedef typename __alloc_traits::const_pointer const_pointer;
507 typedef typename __alloc_traits::size_type size_type;
508 typedef typename __alloc_traits::difference_type difference_type;
509
510 typedef __hash_map_iterator<typename __table::iterator> iterator;
511 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
512
Howard Hinnantfb100022010-09-21 21:28:23 +0000513 _LIBCPP_INLINE_VISIBILITY hash_map() {__table_.rehash(193);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000514 explicit hash_map(size_type __n, const hasher& __hf = hasher(),
515 const key_equal& __eql = key_equal());
516 hash_map(size_type __n, const hasher& __hf,
517 const key_equal& __eql,
518 const allocator_type& __a);
519 template <class _InputIterator>
520 hash_map(_InputIterator __first, _InputIterator __last);
521 template <class _InputIterator>
522 hash_map(_InputIterator __first, _InputIterator __last,
523 size_type __n, const hasher& __hf = hasher(),
524 const key_equal& __eql = key_equal());
525 template <class _InputIterator>
526 hash_map(_InputIterator __first, _InputIterator __last,
527 size_type __n, const hasher& __hf,
528 const key_equal& __eql,
529 const allocator_type& __a);
530 hash_map(const hash_map& __u);
531
Howard Hinnantfb100022010-09-21 21:28:23 +0000532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000533 allocator_type get_allocator() const
534 {return allocator_type(__table_.__node_alloc());}
535
Howard Hinnantfb100022010-09-21 21:28:23 +0000536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000537 bool empty() const {return __table_.size() == 0;}
Howard Hinnantfb100022010-09-21 21:28:23 +0000538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000539 size_type size() const {return __table_.size();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000541 size_type max_size() const {return __table_.max_size();}
542
Howard Hinnantfb100022010-09-21 21:28:23 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000544 iterator begin() {return __table_.begin();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000546 iterator end() {return __table_.end();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000548 const_iterator begin() const {return __table_.begin();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000550 const_iterator end() const {return __table_.end();}
551
Howard Hinnantfb100022010-09-21 21:28:23 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000553 pair<iterator, bool> insert(const value_type& __x)
554 {return __table_.__insert_unique(__x);}
Alexis Huntfe473ae2011-07-29 23:31:53 +0000555 _LIBCPP_INLINE_VISIBILITY
556 iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000557 template <class _InputIterator>
558 void insert(_InputIterator __first, _InputIterator __last);
559
Howard Hinnantfb100022010-09-21 21:28:23 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000561 void erase(const_iterator __p) {__table_.erase(__p.__i_);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000563 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000565 void erase(const_iterator __first, const_iterator __last)
566 {__table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000568 void clear() {__table_.clear();}
569
Howard Hinnantfb100022010-09-21 21:28:23 +0000570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000571 void swap(hash_map& __u) {__table_.swap(__u.__table_);}
572
Howard Hinnantfb100022010-09-21 21:28:23 +0000573 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000574 hasher hash_funct() const
575 {return __table_.hash_function().hash_function();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000577 key_equal key_eq() const
578 {return __table_.key_eq().key_eq();}
579
Howard Hinnantfb100022010-09-21 21:28:23 +0000580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000581 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000583 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000585 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000587 pair<iterator, iterator> equal_range(const key_type& __k)
588 {return __table_.__equal_range_unique(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000590 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
591 {return __table_.__equal_range_unique(__k);}
592
593 mapped_type& operator[](const key_type& __k);
594
Howard Hinnantfb100022010-09-21 21:28:23 +0000595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000596 size_type bucket_count() const {return __table_.bucket_count();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000598 size_type max_bucket_count() const {return __table_.max_bucket_count();}
599
Howard Hinnantfb100022010-09-21 21:28:23 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000601 size_type elems_in_bucket(size_type __n) const
602 {return __table_.bucket_size(__n);}
603
Howard Hinnantfb100022010-09-21 21:28:23 +0000604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000605 void resize(size_type __n) {__table_.rehash(__n);}
606
607private:
608 __node_holder __construct_node(const key_type& __k);
609};
610
611template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
612hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
613 size_type __n, const hasher& __hf, const key_equal& __eql)
614 : __table_(__hf, __eql)
615{
616 __table_.rehash(__n);
617}
618
619template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
620hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
621 size_type __n, const hasher& __hf, const key_equal& __eql,
622 const allocator_type& __a)
623 : __table_(__hf, __eql, __a)
624{
625 __table_.rehash(__n);
626}
627
628template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
629template <class _InputIterator>
630hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
631 _InputIterator __first, _InputIterator __last)
632{
633 __table_.rehash(193);
634 insert(__first, __last);
635}
636
637template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
638template <class _InputIterator>
639hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
640 _InputIterator __first, _InputIterator __last, size_type __n,
641 const hasher& __hf, const key_equal& __eql)
642 : __table_(__hf, __eql)
643{
644 __table_.rehash(__n);
645 insert(__first, __last);
646}
647
648template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
649template <class _InputIterator>
650hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
651 _InputIterator __first, _InputIterator __last, size_type __n,
652 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
653 : __table_(__hf, __eql, __a)
654{
655 __table_.rehash(__n);
656 insert(__first, __last);
657}
658
659template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
660hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
661 const hash_map& __u)
662 : __table_(__u.__table_)
663{
664 __table_.rehash(__u.bucket_count());
665 insert(__u.begin(), __u.end());
666}
667
668template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
669typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
670hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k)
671{
672 __node_allocator& __na = __table_.__node_alloc();
673 __node_holder __h(__node_traits::allocate(__na, 1), _D(__na));
Howard Hinnantce48a112011-06-30 21:18:19 +0000674 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k);
Howard Hinnant3e519522010-05-11 19:42:16 +0000675 __h.get_deleter().__first_constructed = true;
Howard Hinnantce48a112011-06-30 21:18:19 +0000676 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
Howard Hinnant3e519522010-05-11 19:42:16 +0000677 __h.get_deleter().__second_constructed = true;
Howard Hinnantce48a112011-06-30 21:18:19 +0000678 return _VSTD::move(__h);
Howard Hinnant3e519522010-05-11 19:42:16 +0000679}
680
681template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
682template <class _InputIterator>
Howard Hinnantfb100022010-09-21 21:28:23 +0000683inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000684void
685hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
686 _InputIterator __last)
687{
688 for (; __first != __last; ++__first)
689 __table_.__insert_unique(*__first);
690}
691
692template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
693_Tp&
694hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
695{
696 iterator __i = find(__k);
697 if (__i != end())
698 return __i->second;
699 __node_holder __h = __construct_node(__k);
700 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
701 __h.release();
702 return __r.first->second;
703}
704
705template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantfb100022010-09-21 21:28:23 +0000706inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000707void
708swap(hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
709 hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
710{
711 __x.swap(__y);
712}
713
714template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
715bool
716operator==(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
717 const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
718{
719 if (__x.size() != __y.size())
720 return false;
721 typedef typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
722 const_iterator;
723 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
724 __i != __ex; ++__i)
725 {
726 const_iterator __j = __y.find(__i->first);
727 if (__j == __ey || !(*__i == *__j))
728 return false;
729 }
730 return true;
731}
732
733template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantfb100022010-09-21 21:28:23 +0000734inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000735bool
736operator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
737 const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
738{
739 return !(__x == __y);
740}
741
742template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
743 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnantfb100022010-09-21 21:28:23 +0000744class _LIBCPP_VISIBLE hash_multimap
Howard Hinnant3e519522010-05-11 19:42:16 +0000745{
746public:
747 // types
748 typedef _Key key_type;
749 typedef _Tp mapped_type;
Alexis Huntfe473ae2011-07-29 23:31:53 +0000750 typedef _Tp data_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000751 typedef _Hash hasher;
752 typedef _Pred key_equal;
753 typedef _Alloc allocator_type;
754 typedef pair<const key_type, mapped_type> value_type;
755 typedef value_type& reference;
756 typedef const value_type& const_reference;
757
758private:
759 typedef pair<key_type, mapped_type> __value_type;
760 typedef __hash_map_hasher<__value_type, hasher> __hasher;
761 typedef __hash_map_equal<__value_type, key_equal> __key_equal;
762 typedef typename allocator_traits<allocator_type>::template
763#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
764 rebind_alloc<__value_type>
765#else
766 rebind_alloc<__value_type>::other
767#endif
768 __allocator_type;
769
770 typedef __hash_table<__value_type, __hasher,
771 __key_equal, __allocator_type> __table;
772
773 __table __table_;
774
775 typedef typename __table::__node_traits __node_traits;
776 typedef typename __table::__node_allocator __node_allocator;
777 typedef typename __table::__node __node;
778 typedef __hash_map_node_destructor<__node_allocator> _D;
779 typedef unique_ptr<__node, _D> __node_holder;
780 typedef allocator_traits<allocator_type> __alloc_traits;
781public:
782 typedef typename __alloc_traits::pointer pointer;
783 typedef typename __alloc_traits::const_pointer const_pointer;
784 typedef typename __alloc_traits::size_type size_type;
785 typedef typename __alloc_traits::difference_type difference_type;
786
787 typedef __hash_map_iterator<typename __table::iterator> iterator;
788 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
789
Howard Hinnantfb100022010-09-21 21:28:23 +0000790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000791 hash_multimap() {__table_.rehash(193);}
792 explicit hash_multimap(size_type __n, const hasher& __hf = hasher(),
793 const key_equal& __eql = key_equal());
794 hash_multimap(size_type __n, const hasher& __hf,
795 const key_equal& __eql,
796 const allocator_type& __a);
797 template <class _InputIterator>
798 hash_multimap(_InputIterator __first, _InputIterator __last);
799 template <class _InputIterator>
800 hash_multimap(_InputIterator __first, _InputIterator __last,
801 size_type __n, const hasher& __hf = hasher(),
802 const key_equal& __eql = key_equal());
803 template <class _InputIterator>
804 hash_multimap(_InputIterator __first, _InputIterator __last,
805 size_type __n, const hasher& __hf,
806 const key_equal& __eql,
807 const allocator_type& __a);
808 hash_multimap(const hash_multimap& __u);
809
Howard Hinnantfb100022010-09-21 21:28:23 +0000810 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000811 allocator_type get_allocator() const
812 {return allocator_type(__table_.__node_alloc());}
813
Howard Hinnantfb100022010-09-21 21:28:23 +0000814 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000815 bool empty() const {return __table_.size() == 0;}
Howard Hinnantfb100022010-09-21 21:28:23 +0000816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000817 size_type size() const {return __table_.size();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000819 size_type max_size() const {return __table_.max_size();}
820
Howard Hinnantfb100022010-09-21 21:28:23 +0000821 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000822 iterator begin() {return __table_.begin();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000824 iterator end() {return __table_.end();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000826 const_iterator begin() const {return __table_.begin();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000828 const_iterator end() const {return __table_.end();}
829
Howard Hinnantfb100022010-09-21 21:28:23 +0000830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000831 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Alexis Huntfe473ae2011-07-29 23:31:53 +0000832 _LIBCPP_INLINE_VISIBILITY
833 iterator insert(const_iterator, const value_type& __x) {return insert(__x);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000834 template <class _InputIterator>
835 void insert(_InputIterator __first, _InputIterator __last);
836
Howard Hinnantfb100022010-09-21 21:28:23 +0000837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000838 void erase(const_iterator __p) {__table_.erase(__p.__i_);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000840 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000842 void erase(const_iterator __first, const_iterator __last)
843 {__table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000845 void clear() {__table_.clear();}
846
Howard Hinnantfb100022010-09-21 21:28:23 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000848 void swap(hash_multimap& __u) {__table_.swap(__u.__table_);}
849
Howard Hinnantfb100022010-09-21 21:28:23 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000851 hasher hash_funct() const
852 {return __table_.hash_function().hash_function();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000854 key_equal key_eq() const
855 {return __table_.key_eq().key_eq();}
856
Howard Hinnantfb100022010-09-21 21:28:23 +0000857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000858 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000860 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000862 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000864 pair<iterator, iterator> equal_range(const key_type& __k)
865 {return __table_.__equal_range_multi(__k);}
Howard Hinnantfb100022010-09-21 21:28:23 +0000866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000867 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
868 {return __table_.__equal_range_multi(__k);}
869
Howard Hinnantfb100022010-09-21 21:28:23 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000871 size_type bucket_count() const {return __table_.bucket_count();}
Howard Hinnantfb100022010-09-21 21:28:23 +0000872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000873 size_type max_bucket_count() const {return __table_.max_bucket_count();}
874
Howard Hinnantfb100022010-09-21 21:28:23 +0000875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000876 size_type elems_in_bucket(size_type __n) const
877 {return __table_.bucket_size(__n);}
878
Howard Hinnantfb100022010-09-21 21:28:23 +0000879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000880 void resize(size_type __n) {__table_.rehash(__n);}
881};
882
883template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
884hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
885 size_type __n, const hasher& __hf, const key_equal& __eql)
886 : __table_(__hf, __eql)
887{
888 __table_.rehash(__n);
889}
890
891template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
892hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
893 size_type __n, const hasher& __hf, const key_equal& __eql,
894 const allocator_type& __a)
895 : __table_(__hf, __eql, __a)
896{
897 __table_.rehash(__n);
898}
899
900template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
901template <class _InputIterator>
902hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
903 _InputIterator __first, _InputIterator __last)
904{
905 __table_.rehash(193);
906 insert(__first, __last);
907}
908
909template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
910template <class _InputIterator>
911hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
912 _InputIterator __first, _InputIterator __last, size_type __n,
913 const hasher& __hf, const key_equal& __eql)
914 : __table_(__hf, __eql)
915{
916 __table_.rehash(__n);
917 insert(__first, __last);
918}
919
920template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
921template <class _InputIterator>
922hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
923 _InputIterator __first, _InputIterator __last, size_type __n,
924 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
925 : __table_(__hf, __eql, __a)
926{
927 __table_.rehash(__n);
928 insert(__first, __last);
929}
930
931template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
932hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
933 const hash_multimap& __u)
934 : __table_(__u.__table_)
935{
936 __table_.rehash(__u.bucket_count());
937 insert(__u.begin(), __u.end());
938}
939
940template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
941template <class _InputIterator>
Howard Hinnantfb100022010-09-21 21:28:23 +0000942inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000943void
944hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
945 _InputIterator __last)
946{
947 for (; __first != __last; ++__first)
948 __table_.__insert_multi(*__first);
949}
950
951template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantfb100022010-09-21 21:28:23 +0000952inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000953void
954swap(hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
955 hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
956{
957 __x.swap(__y);
958}
959
960template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
961bool
962operator==(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
963 const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
964{
965 if (__x.size() != __y.size())
966 return false;
967 typedef typename hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
968 const_iterator;
969 typedef pair<const_iterator, const_iterator> _EqRng;
970 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
971 {
972 _EqRng __xeq = __x.equal_range(__i->first);
973 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnantce48a112011-06-30 21:18:19 +0000974 if (_VSTD::distance(__xeq.first, __xeq.second) !=
975 _VSTD::distance(__yeq.first, __yeq.second) ||
976 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnant3e519522010-05-11 19:42:16 +0000977 return false;
978 __i = __xeq.second;
979 }
980 return true;
981}
982
983template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantfb100022010-09-21 21:28:23 +0000984inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000985bool
986operator!=(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
987 const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
988{
989 return !(__x == __y);
990}
991
992} // __gnu_cxx
993
994#endif // _LIBCPP_HASH_MAP