blob: d8fc1e6c03c0ca07ed685699096a5316e791330e [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===-------------------------- hash_map ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:168//
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>
Sean Huntaffd9e52011-07-29 23:31:56206#include <ext/__hash>
Howard Hinnantbc8d3f92010-05-11 19:42:16207
Howard Hinnant4f598032011-07-24 23:59:50208#if __DEPRECATED
Howard Hinnantf7555062013-10-04 21:14:44209#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 Hinnant4f598032011-07-24 23:59:50214#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16215
216#pragma GCC system_header
217
218namespace __gnu_cxx {
219
220using namespace std;
221
Howard Hinnantd4cf2152011-12-11 20:31:33222template <class _Tp, class _Hash, bool = is_empty<_Hash>::value
223#if __has_feature(is_final)
224 && !__is_final(_Hash)
225#endif
226 >
Howard Hinnantbc8d3f92010-05-11 19:42:16227class __hash_map_hasher
228 : private _Hash
229{
230public:
Howard Hinnant422a53f2010-09-21 21:28:23231 _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 Hinnantbc8d3f92010-05-11 19:42:16235 size_t operator()(const _Tp& __x) const
236 {return static_cast<const _Hash&>(*this)(__x.first);}
Howard Hinnant422a53f2010-09-21 21:28:23237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16238 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 Hinnant422a53f2010-09-21 21:28:23247 _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 Hinnantbc8d3f92010-05-11 19:42:16251 size_t operator()(const _Tp& __x) const
252 {return __hash_(__x.first);}
Howard Hinnant422a53f2010-09-21 21:28:23253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16254 size_t operator()(const typename _Tp::first_type& __x) const
255 {return __hash_(__x);}
256};
257
Howard Hinnantd4cf2152011-12-11 20:31:33258template <class _Tp, class _Pred, bool = is_empty<_Pred>::value
259#if __has_feature(is_final)
260 && !__is_final(_Pred)
261#endif
262 >
Howard Hinnantbc8d3f92010-05-11 19:42:16263class __hash_map_equal
264 : private _Pred
265{
266public:
Howard Hinnant422a53f2010-09-21 21:28:23267 _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 Hinnantbc8d3f92010-05-11 19:42:16271 bool operator()(const _Tp& __x, const _Tp& __y) const
272 {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
Howard Hinnant422a53f2010-09-21 21:28:23273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16274 bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
275 {return static_cast<const _Pred&>(*this)(__x, __y.first);}
Howard Hinnant422a53f2010-09-21 21:28:23276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16277 bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
278 {return static_cast<const _Pred&>(*this)(__x.first, __y);}
Howard Hinnant422a53f2010-09-21 21:28:23279 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43280 bool operator()(const typename _Tp::first_type& __x,
Howard Hinnantbc8d3f92010-05-11 19:42:16281 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 Hinnant422a53f2010-09-21 21:28:23290 _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 Hinnantbc8d3f92010-05-11 19:42:16294 bool operator()(const _Tp& __x, const _Tp& __y) const
295 {return __pred_(__x.first, __y.first);}
Howard Hinnant422a53f2010-09-21 21:28:23296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16297 bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
298 {return __pred_(__x, __y.first);}
Howard Hinnant422a53f2010-09-21 21:28:23299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16300 bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
301 {return __pred_(__x.first, __y);}
Howard Hinnant422a53f2010-09-21 21:28:23302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16303 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 Hinnant422a53f2010-09-21 21:28:23328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16329 explicit __hash_map_node_destructor(allocator_type& __na)
330 : __na_(__na),
331 __first_constructed(false),
332 __second_constructed(false)
333 {}
334
Howard Hinnant73d21a42010-09-04 23:28:19335#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant422a53f2010-09-21 21:28:23336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16337 __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 Hinnant73d21a42010-09-04 23:28:19344#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant422a53f2010-09-21 21:28:23345 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16346 __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 Hinnant73d21a42010-09-04 23:28:19353#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16354
Howard Hinnant422a53f2010-09-21 21:28:23355 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16356 void operator()(pointer __p)
357 {
358 if (__second_constructed)
Howard Hinnant0949eed2011-06-30 21:18:19359 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16360 if (__first_constructed)
Howard Hinnant0949eed2011-06-30 21:18:19361 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16362 if (__p)
363 __alloc_traits::deallocate(__na_, __p, 1);
364 }
365};
366
367template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34368class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16369{
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 Hinnant422a53f2010-09-21 21:28:23388 _LIBCPP_INLINE_VISIBILITY __hash_map_iterator() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16389
Howard Hinnant422a53f2010-09-21 21:28:23390 _LIBCPP_INLINE_VISIBILITY __hash_map_iterator(_HashIterator __i) : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16391
Howard Hinnant422a53f2010-09-21 21:28:23392 _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *operator->();}
393 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return (pointer)__i_.operator->();}
Howard Hinnantbc8d3f92010-05-11 19:42:16394
Howard Hinnant422a53f2010-09-21 21:28:23395 _LIBCPP_INLINE_VISIBILITY __hash_map_iterator& operator++() {++__i_; return *this;}
396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16397 __hash_map_iterator operator++(int)
398 {
399 __hash_map_iterator __t(*this);
400 ++(*this);
401 return __t;
402 }
403
Howard Hinnant422a53f2010-09-21 21:28:23404 friend _LIBCPP_INLINE_VISIBILITY
405 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16406 {return __x.__i_ == __y.__i_;}
Howard Hinnant422a53f2010-09-21 21:28:23407 friend _LIBCPP_INLINE_VISIBILITY
408 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16409 {return __x.__i_ != __y.__i_;}
410
Howard Hinnant0f678bd2013-08-12 18:38:34411 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 Hinnantbc8d3f92010-05-11 19:42:16416};
417
418template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34419class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16420{
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 Collingbournebe8a99a2014-03-03 19:50:01433 rebind<const value_type>
Howard Hinnantbc8d3f92010-05-11 19:42:16434#else
Peter Collingbournebe8a99a2014-03-03 19:50:01435 rebind<const value_type>::other
Howard Hinnantbc8d3f92010-05-11 19:42:16436#endif
437 pointer;
438
Howard Hinnant422a53f2010-09-21 21:28:23439 _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16440
Howard Hinnant422a53f2010-09-21 21:28:23441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16442 __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {}
Howard Hinnant422a53f2010-09-21 21:28:23443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16444 __hash_map_const_iterator(
445 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
446 : __i_(__i.__i_) {}
447
Howard Hinnant422a53f2010-09-21 21:28:23448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16449 reference operator*() const {return *operator->();}
Howard Hinnant422a53f2010-09-21 21:28:23450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16451 pointer operator->() const {return (pointer)__i_.operator->();}
452
Howard Hinnant422a53f2010-09-21 21:28:23453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16454 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant422a53f2010-09-21 21:28:23455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16456 __hash_map_const_iterator operator++(int)
457 {
458 __hash_map_const_iterator __t(*this);
459 ++(*this);
460 return __t;
461 }
462
Howard Hinnant422a53f2010-09-21 21:28:23463 friend _LIBCPP_INLINE_VISIBILITY
464 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16465 {return __x.__i_ == __y.__i_;}
Howard Hinnant422a53f2010-09-21 21:28:23466 friend _LIBCPP_INLINE_VISIBILITY
467 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16468 {return __x.__i_ != __y.__i_;}
469
Howard Hinnant0f678bd2013-08-12 18:38:34470 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 Hinnantbc8d3f92010-05-11 19:42:16474};
475
476template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
477 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34478class _LIBCPP_TYPE_VIS_ONLY hash_map
Howard Hinnantbc8d3f92010-05-11 19:42:16479{
480public:
481 // types
482 typedef _Key key_type;
483 typedef _Tp mapped_type;
Sean Hunte36a1962011-07-29 23:31:53484 typedef _Tp data_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16485 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 Clow66302c62015-04-07 05:21:38496 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16497
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 Hinnant99968442011-11-29 18:15:50508 typedef __hash_map_node_destructor<__node_allocator> _Dp;
509 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16510 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 Hinnant422a53f2010-09-21 21:28:23520 _LIBCPP_INLINE_VISIBILITY hash_map() {__table_.rehash(193);}
Howard Hinnantbc8d3f92010-05-11 19:42:16521 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 Hinnant422a53f2010-09-21 21:28:23539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16540 allocator_type get_allocator() const
541 {return allocator_type(__table_.__node_alloc());}
542
Howard Hinnant422a53f2010-09-21 21:28:23543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16544 bool empty() const {return __table_.size() == 0;}
Howard Hinnant422a53f2010-09-21 21:28:23545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16546 size_type size() const {return __table_.size();}
Howard Hinnant422a53f2010-09-21 21:28:23547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16548 size_type max_size() const {return __table_.max_size();}
549
Howard Hinnant422a53f2010-09-21 21:28:23550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16551 iterator begin() {return __table_.begin();}
Howard Hinnant422a53f2010-09-21 21:28:23552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16553 iterator end() {return __table_.end();}
Howard Hinnant422a53f2010-09-21 21:28:23554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16555 const_iterator begin() const {return __table_.begin();}
Howard Hinnant422a53f2010-09-21 21:28:23556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16557 const_iterator end() const {return __table_.end();}
558
Howard Hinnant422a53f2010-09-21 21:28:23559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16560 pair<iterator, bool> insert(const value_type& __x)
561 {return __table_.__insert_unique(__x);}
Sean Hunte36a1962011-07-29 23:31:53562 _LIBCPP_INLINE_VISIBILITY
563 iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;}
Howard Hinnantbc8d3f92010-05-11 19:42:16564 template <class _InputIterator>
565 void insert(_InputIterator __first, _InputIterator __last);
566
Howard Hinnant422a53f2010-09-21 21:28:23567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16568 void erase(const_iterator __p) {__table_.erase(__p.__i_);}
Howard Hinnant422a53f2010-09-21 21:28:23569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16570 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16572 void erase(const_iterator __first, const_iterator __last)
573 {__table_.erase(__first.__i_, __last.__i_);}
Howard Hinnant422a53f2010-09-21 21:28:23574 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16575 void clear() {__table_.clear();}
576
Howard Hinnant422a53f2010-09-21 21:28:23577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16578 void swap(hash_map& __u) {__table_.swap(__u.__table_);}
579
Howard Hinnant422a53f2010-09-21 21:28:23580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16581 hasher hash_funct() const
582 {return __table_.hash_function().hash_function();}
Howard Hinnant422a53f2010-09-21 21:28:23583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16584 key_equal key_eq() const
585 {return __table_.key_eq().key_eq();}
586
Howard Hinnant422a53f2010-09-21 21:28:23587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16588 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16590 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16592 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16594 pair<iterator, iterator> equal_range(const key_type& __k)
595 {return __table_.__equal_range_unique(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16597 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 Hinnant422a53f2010-09-21 21:28:23602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16603 size_type bucket_count() const {return __table_.bucket_count();}
Howard Hinnant422a53f2010-09-21 21:28:23604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16605 size_type max_bucket_count() const {return __table_.max_bucket_count();}
606
Howard Hinnant422a53f2010-09-21 21:28:23607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16608 size_type elems_in_bucket(size_type __n) const
609 {return __table_.bucket_size(__n);}
610
Howard Hinnant422a53f2010-09-21 21:28:23611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16612 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 Hinnant99968442011-11-29 18:15:50680 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19681 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16682 __h.get_deleter().__first_constructed = true;
Howard Hinnant0949eed2011-06-30 21:18:19683 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16684 __h.get_deleter().__second_constructed = true;
Howard Hinnant9a894d92013-08-22 18:29:50685 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16686}
687
688template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
689template <class _InputIterator>
Howard Hinnant422a53f2010-09-21 21:28:23690inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16691void
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 Hinnant422a53f2010-09-21 21:28:23713inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16714void
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 Hinnant422a53f2010-09-21 21:28:23741inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16742bool
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 Hinnant0f678bd2013-08-12 18:38:34751class _LIBCPP_TYPE_VIS_ONLY hash_multimap
Howard Hinnantbc8d3f92010-05-11 19:42:16752{
753public:
754 // types
755 typedef _Key key_type;
756 typedef _Tp mapped_type;
Sean Hunte36a1962011-07-29 23:31:53757 typedef _Tp data_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16758 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 Clow66302c62015-04-07 05:21:38769 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16770
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 Hinnant99968442011-11-29 18:15:50779 typedef __hash_map_node_destructor<__node_allocator> _Dp;
780 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16781 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 Hinnant422a53f2010-09-21 21:28:23791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16792 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 Hinnant422a53f2010-09-21 21:28:23811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16812 allocator_type get_allocator() const
813 {return allocator_type(__table_.__node_alloc());}
814
Howard Hinnant422a53f2010-09-21 21:28:23815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16816 bool empty() const {return __table_.size() == 0;}
Howard Hinnant422a53f2010-09-21 21:28:23817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16818 size_type size() const {return __table_.size();}
Howard Hinnant422a53f2010-09-21 21:28:23819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16820 size_type max_size() const {return __table_.max_size();}
821
Howard Hinnant422a53f2010-09-21 21:28:23822 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16823 iterator begin() {return __table_.begin();}
Howard Hinnant422a53f2010-09-21 21:28:23824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16825 iterator end() {return __table_.end();}
Howard Hinnant422a53f2010-09-21 21:28:23826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16827 const_iterator begin() const {return __table_.begin();}
Howard Hinnant422a53f2010-09-21 21:28:23828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16829 const_iterator end() const {return __table_.end();}
830
Howard Hinnant422a53f2010-09-21 21:28:23831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16832 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Sean Hunte36a1962011-07-29 23:31:53833 _LIBCPP_INLINE_VISIBILITY
834 iterator insert(const_iterator, const value_type& __x) {return insert(__x);}
Howard Hinnantbc8d3f92010-05-11 19:42:16835 template <class _InputIterator>
836 void insert(_InputIterator __first, _InputIterator __last);
837
Howard Hinnant422a53f2010-09-21 21:28:23838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16839 void erase(const_iterator __p) {__table_.erase(__p.__i_);}
Howard Hinnant422a53f2010-09-21 21:28:23840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16841 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16843 void erase(const_iterator __first, const_iterator __last)
844 {__table_.erase(__first.__i_, __last.__i_);}
Howard Hinnant422a53f2010-09-21 21:28:23845 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16846 void clear() {__table_.clear();}
847
Howard Hinnant422a53f2010-09-21 21:28:23848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16849 void swap(hash_multimap& __u) {__table_.swap(__u.__table_);}
850
Howard Hinnant422a53f2010-09-21 21:28:23851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16852 hasher hash_funct() const
853 {return __table_.hash_function().hash_function();}
Howard Hinnant422a53f2010-09-21 21:28:23854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16855 key_equal key_eq() const
856 {return __table_.key_eq().key_eq();}
857
Howard Hinnant422a53f2010-09-21 21:28:23858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16859 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16861 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16863 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16865 pair<iterator, iterator> equal_range(const key_type& __k)
866 {return __table_.__equal_range_multi(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16868 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
869 {return __table_.__equal_range_multi(__k);}
870
Howard Hinnant422a53f2010-09-21 21:28:23871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16872 size_type bucket_count() const {return __table_.bucket_count();}
Howard Hinnant422a53f2010-09-21 21:28:23873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16874 size_type max_bucket_count() const {return __table_.max_bucket_count();}
875
Howard Hinnant422a53f2010-09-21 21:28:23876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16877 size_type elems_in_bucket(size_type __n) const
878 {return __table_.bucket_size(__n);}
879
Howard Hinnant422a53f2010-09-21 21:28:23880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16881 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 Hinnant422a53f2010-09-21 21:28:23943inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16944void
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 Hinnant422a53f2010-09-21 21:28:23953inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16954void
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 Hinnant0949eed2011-06-30 21:18:19975 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 Hinnantbc8d3f92010-05-11 19:42:16978 return false;
979 __i = __xeq.second;
980 }
981 return true;
982}
983
984template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant422a53f2010-09-21 21:28:23985inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16986bool
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