blob: e20fd41e6fd081fcc6a3f9e270e9d81826f39815 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------- hash_set ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-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 Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_HASH_SET
12#define _LIBCPP_HASH_SET
13
14/*
15
16 hash_set synopsis
17
18namespace __gnu_cxx
19{
20
21template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
22 class Alloc = allocator<Value>>
23class hash_set
24{
25public:
26 // types
27 typedef Value key_type;
28 typedef key_type value_type;
29 typedef Hash hasher;
30 typedef Pred key_equal;
31 typedef Alloc allocator_type;
32 typedef value_type& reference;
33 typedef const value_type& const_reference;
34 typedef typename allocator_traits<allocator_type>::pointer pointer;
35 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
36 typedef typename allocator_traits<allocator_type>::size_type size_type;
37 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
38
39 typedef /unspecified/ iterator;
40 typedef /unspecified/ const_iterator;
41
42 explicit hash_set(size_type n = 193, const hasher& hf = hasher(),
43 const key_equal& eql = key_equal(),
44 const allocator_type& a = allocator_type());
45 template <class InputIterator>
46 hash_set(InputIterator f, InputIterator l,
47 size_type n = 193, const hasher& hf = hasher(),
48 const key_equal& eql = key_equal(),
49 const allocator_type& a = allocator_type());
50 hash_set(const hash_set&);
51 ~hash_set();
52 hash_set& operator=(const hash_set&);
53
54 allocator_type get_allocator() const;
55
56 bool empty() const;
57 size_type size() const;
58 size_type max_size() const;
59
60 iterator begin();
61 iterator end();
62 const_iterator begin() const;
63 const_iterator end() const;
64
65 pair<iterator, bool> insert(const value_type& obj);
66 template <class InputIterator>
67 void insert(InputIterator first, InputIterator last);
68
69 void erase(const_iterator position);
70 size_type erase(const key_type& k);
71 void erase(const_iterator first, const_iterator last);
72 void clear();
73
74 void swap(hash_set&);
75
76 hasher hash_funct() const;
77 key_equal key_eq() const;
78
79 iterator find(const key_type& k);
80 const_iterator find(const key_type& k) const;
81 size_type count(const key_type& k) const;
82 pair<iterator, iterator> equal_range(const key_type& k);
83 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
84
85 size_type bucket_count() const;
86 size_type max_bucket_count() const;
87
88 size_type elems_in_bucket(size_type n) const;
89
90 void resize(size_type n);
91};
92
93template <class Value, class Hash, class Pred, class Alloc>
94 void swap(hash_set<Value, Hash, Pred, Alloc>& x,
95 hash_set<Value, Hash, Pred, Alloc>& y);
96
97template <class Value, class Hash, class Pred, class Alloc>
98 bool
99 operator==(const hash_set<Value, Hash, Pred, Alloc>& x,
100 const hash_set<Value, Hash, Pred, Alloc>& y);
101
102template <class Value, class Hash, class Pred, class Alloc>
103 bool
104 operator!=(const hash_set<Value, Hash, Pred, Alloc>& x,
105 const hash_set<Value, Hash, Pred, Alloc>& y);
106
107template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
108 class Alloc = allocator<Value>>
109class hash_multiset
110{
111public:
112 // types
113 typedef Value key_type;
114 typedef key_type value_type;
115 typedef Hash hasher;
116 typedef Pred key_equal;
117 typedef Alloc allocator_type;
118 typedef value_type& reference;
119 typedef const value_type& const_reference;
120 typedef typename allocator_traits<allocator_type>::pointer pointer;
121 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
122 typedef typename allocator_traits<allocator_type>::size_type size_type;
123 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
124
125 typedef /unspecified/ iterator;
126 typedef /unspecified/ const_iterator;
127
128 explicit hash_multiset(size_type n = 193, const hasher& hf = hasher(),
129 const key_equal& eql = key_equal(),
130 const allocator_type& a = allocator_type());
131 template <class InputIterator>
132 hash_multiset(InputIterator f, InputIterator l,
133 size_type n = 193, const hasher& hf = hasher(),
134 const key_equal& eql = key_equal(),
135 const allocator_type& a = allocator_type());
136 hash_multiset(const hash_multiset&);
137 ~hash_multiset();
138 hash_multiset& operator=(const hash_multiset&);
139
140 allocator_type get_allocator() const;
141
142 bool empty() const;
143 size_type size() const;
144 size_type max_size() const;
145
146 iterator begin();
147 iterator end();
148 const_iterator begin() const;
149 const_iterator end() const;
150
151 iterator insert(const value_type& obj);
152 template <class InputIterator>
153 void insert(InputIterator first, InputIterator last);
154
155 void erase(const_iterator position);
156 size_type erase(const key_type& k);
157 void erase(const_iterator first, const_iterator last);
158 void clear();
159
160 void swap(hash_multiset&);
161
162 hasher hash_funct() const;
163 key_equal key_eq() const;
164
165 iterator find(const key_type& k);
166 const_iterator find(const key_type& k) const;
167 size_type count(const key_type& k) const;
168 pair<iterator, iterator> equal_range(const key_type& k);
169 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
170
171 size_type bucket_count() const;
172 size_type max_bucket_count() const;
173
174 size_type elems_in_bucket(size_type n) const;
175
176 void resize(size_type n);
177};
178
179template <class Value, class Hash, class Pred, class Alloc>
180 void swap(hash_multiset<Value, Hash, Pred, Alloc>& x,
181 hash_multiset<Value, Hash, Pred, Alloc>& y);
182
183template <class Value, class Hash, class Pred, class Alloc>
184 bool
185 operator==(const hash_multiset<Value, Hash, Pred, Alloc>& x,
186 const hash_multiset<Value, Hash, Pred, Alloc>& y);
187
188template <class Value, class Hash, class Pred, class Alloc>
189 bool
190 operator!=(const hash_multiset<Value, Hash, Pred, Alloc>& x,
191 const hash_multiset<Value, Hash, Pred, Alloc>& y);
192} // __gnu_cxx
193
194*/
195
196#include <__config>
197#include <__hash_table>
198#include <functional>
199
Howard Hinnant4f598032011-07-24 23:59:50 +0000200#if __DEPRECATED
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000201#warning Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>
Howard Hinnant4f598032011-07-24 23:59:50 +0000202#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000203
204namespace __gnu_cxx {
205
206using namespace std;
207
208template <class _Value, class _Hash = std::hash<_Value>, class _Pred = equal_to<_Value>,
209 class _Alloc = allocator<_Value> >
Howard Hinnant422a53f2010-09-21 21:28:23 +0000210class _LIBCPP_VISIBLE hash_set
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000211{
212public:
213 // types
214 typedef _Value key_type;
215 typedef key_type value_type;
216 typedef _Hash hasher;
217 typedef _Pred key_equal;
218 typedef _Alloc allocator_type;
219 typedef value_type& reference;
220 typedef const value_type& const_reference;
221
222private:
223 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
224
225 __table __table_;
226
227public:
228 typedef typename __table::pointer pointer;
229 typedef typename __table::const_pointer const_pointer;
230 typedef typename __table::size_type size_type;
231 typedef typename __table::difference_type difference_type;
232
233 typedef typename __table::const_iterator iterator;
234 typedef typename __table::const_iterator const_iterator;
235
Howard Hinnant422a53f2010-09-21 21:28:23 +0000236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000237 hash_set() {__table_.rehash(193);}
238 explicit hash_set(size_type __n, const hasher& __hf = hasher(),
239 const key_equal& __eql = key_equal());
240 hash_set(size_type __n, const hasher& __hf, const key_equal& __eql,
241 const allocator_type& __a);
242 template <class _InputIterator>
243 hash_set(_InputIterator __first, _InputIterator __last);
244 template <class _InputIterator>
245 hash_set(_InputIterator __first, _InputIterator __last,
246 size_type __n, const hasher& __hf = hasher(),
247 const key_equal& __eql = key_equal());
248 template <class _InputIterator>
249 hash_set(_InputIterator __first, _InputIterator __last,
250 size_type __n, const hasher& __hf, const key_equal& __eql,
251 const allocator_type& __a);
252 hash_set(const hash_set& __u);
253
Howard Hinnant422a53f2010-09-21 21:28:23 +0000254 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255 allocator_type get_allocator() const
256 {return allocator_type(__table_.__node_alloc());}
257
Howard Hinnant422a53f2010-09-21 21:28:23 +0000258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000259 bool empty() const {return __table_.size() == 0;}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000261 size_type size() const {return __table_.size();}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000263 size_type max_size() const {return __table_.max_size();}
264
Howard Hinnant422a53f2010-09-21 21:28:23 +0000265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000266 iterator begin() {return __table_.begin();}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000267 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268 iterator end() {return __table_.end();}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270 const_iterator begin() const {return __table_.begin();}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000271 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272 const_iterator end() const {return __table_.end();}
273
Howard Hinnant422a53f2010-09-21 21:28:23 +0000274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000275 pair<iterator, bool> insert(const value_type& __x)
276 {return __table_.__insert_unique(__x);}
277 template <class _InputIterator>
278 void insert(_InputIterator __first, _InputIterator __last);
279
Howard Hinnant422a53f2010-09-21 21:28:23 +0000280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000281 void erase(const_iterator __p) {__table_.erase(__p);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000283 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000285 void erase(const_iterator __first, const_iterator __last)
286 {__table_.erase(__first, __last);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000288 void clear() {__table_.clear();}
289
Howard Hinnant422a53f2010-09-21 21:28:23 +0000290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000291 void swap(hash_set& __u) {__table_.swap(__u.__table_);}
292
Howard Hinnant422a53f2010-09-21 21:28:23 +0000293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000294 hasher hash_funct() const {return __table_.hash_function();}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296 key_equal key_eq() const {return __table_.key_eq();}
297
Howard Hinnant422a53f2010-09-21 21:28:23 +0000298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000299 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000301 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000303 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305 pair<iterator, iterator> equal_range(const key_type& __k)
306 {return __table_.__equal_range_unique(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000307 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000308 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
309 {return __table_.__equal_range_unique(__k);}
310
Howard Hinnant422a53f2010-09-21 21:28:23 +0000311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312 size_type bucket_count() const {return __table_.bucket_count();}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000314 size_type max_bucket_count() const {return __table_.max_bucket_count();}
315
Howard Hinnant422a53f2010-09-21 21:28:23 +0000316 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000317 size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);}
318
Howard Hinnant422a53f2010-09-21 21:28:23 +0000319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000320 void resize(size_type __n) {__table_.rehash(__n);}
321};
322
323template <class _Value, class _Hash, class _Pred, class _Alloc>
324hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n,
325 const hasher& __hf, const key_equal& __eql)
326 : __table_(__hf, __eql)
327{
328 __table_.rehash(__n);
329}
330
331template <class _Value, class _Hash, class _Pred, class _Alloc>
332hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n,
333 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
334 : __table_(__hf, __eql, __a)
335{
336 __table_.rehash(__n);
337}
338
339template <class _Value, class _Hash, class _Pred, class _Alloc>
340template <class _InputIterator>
341hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
342 _InputIterator __first, _InputIterator __last)
343{
344 __table_.rehash(193);
345 insert(__first, __last);
346}
347
348template <class _Value, class _Hash, class _Pred, class _Alloc>
349template <class _InputIterator>
350hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
351 _InputIterator __first, _InputIterator __last, size_type __n,
352 const hasher& __hf, const key_equal& __eql)
353 : __table_(__hf, __eql)
354{
355 __table_.rehash(__n);
356 insert(__first, __last);
357}
358
359template <class _Value, class _Hash, class _Pred, class _Alloc>
360template <class _InputIterator>
361hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
362 _InputIterator __first, _InputIterator __last, size_type __n,
363 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
364 : __table_(__hf, __eql, __a)
365{
366 __table_.rehash(__n);
367 insert(__first, __last);
368}
369
370template <class _Value, class _Hash, class _Pred, class _Alloc>
371hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
372 const hash_set& __u)
373 : __table_(__u.__table_)
374{
375 __table_.rehash(__u.bucket_count());
376 insert(__u.begin(), __u.end());
377}
378
379template <class _Value, class _Hash, class _Pred, class _Alloc>
380template <class _InputIterator>
Howard Hinnant422a53f2010-09-21 21:28:23 +0000381inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382void
383hash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
384 _InputIterator __last)
385{
386 for (; __first != __last; ++__first)
387 __table_.__insert_unique(*__first);
388}
389
390template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnant422a53f2010-09-21 21:28:23 +0000391inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392void
393swap(hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
394 hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
395{
396 __x.swap(__y);
397}
398
399template <class _Value, class _Hash, class _Pred, class _Alloc>
400bool
401operator==(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
402 const hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
403{
404 if (__x.size() != __y.size())
405 return false;
406 typedef typename hash_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
407 const_iterator;
408 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
409 __i != __ex; ++__i)
410 {
411 const_iterator __j = __y.find(*__i);
412 if (__j == __ey || !(*__i == *__j))
413 return false;
414 }
415 return true;
416}
417
418template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnant422a53f2010-09-21 21:28:23 +0000419inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420bool
421operator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
422 const hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
423{
424 return !(__x == __y);
425}
426
427template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
428 class _Alloc = allocator<_Value> >
Howard Hinnant422a53f2010-09-21 21:28:23 +0000429class _LIBCPP_VISIBLE hash_multiset
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430{
431public:
432 // types
433 typedef _Value key_type;
434 typedef key_type value_type;
435 typedef _Hash hasher;
436 typedef _Pred key_equal;
437 typedef _Alloc allocator_type;
438 typedef value_type& reference;
439 typedef const value_type& const_reference;
440
441private:
442 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
443
444 __table __table_;
445
446public:
447 typedef typename __table::pointer pointer;
448 typedef typename __table::const_pointer const_pointer;
449 typedef typename __table::size_type size_type;
450 typedef typename __table::difference_type difference_type;
451
452 typedef typename __table::const_iterator iterator;
453 typedef typename __table::const_iterator const_iterator;
454
Howard Hinnant422a53f2010-09-21 21:28:23 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000456 hash_multiset() {__table_.rehash(193);}
457 explicit hash_multiset(size_type __n, const hasher& __hf = hasher(),
458 const key_equal& __eql = key_equal());
459 hash_multiset(size_type __n, const hasher& __hf,
460 const key_equal& __eql, const allocator_type& __a);
461 template <class _InputIterator>
462 hash_multiset(_InputIterator __first, _InputIterator __last);
463 template <class _InputIterator>
464 hash_multiset(_InputIterator __first, _InputIterator __last,
465 size_type __n, const hasher& __hf = hasher(),
466 const key_equal& __eql = key_equal());
467 template <class _InputIterator>
468 hash_multiset(_InputIterator __first, _InputIterator __last,
469 size_type __n , const hasher& __hf,
470 const key_equal& __eql, const allocator_type& __a);
471 hash_multiset(const hash_multiset& __u);
472
Howard Hinnant422a53f2010-09-21 21:28:23 +0000473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474 allocator_type get_allocator() const
475 {return allocator_type(__table_.__node_alloc());}
476
Howard Hinnant422a53f2010-09-21 21:28:23 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000478 bool empty() const {return __table_.size() == 0;}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000480 size_type size() const {return __table_.size();}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482 size_type max_size() const {return __table_.max_size();}
483
Howard Hinnant422a53f2010-09-21 21:28:23 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000485 iterator begin() {return __table_.begin();}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000487 iterator end() {return __table_.end();}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489 const_iterator begin() const {return __table_.begin();}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491 const_iterator end() const {return __table_.end();}
492
Howard Hinnant422a53f2010-09-21 21:28:23 +0000493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000494 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
495 template <class _InputIterator>
496 void insert(_InputIterator __first, _InputIterator __last);
497
Howard Hinnant422a53f2010-09-21 21:28:23 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499 void erase(const_iterator __p) {__table_.erase(__p);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000503 void erase(const_iterator __first, const_iterator __last)
504 {__table_.erase(__first, __last);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506 void clear() {__table_.clear();}
507
Howard Hinnant422a53f2010-09-21 21:28:23 +0000508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509 void swap(hash_multiset& __u) {__table_.swap(__u.__table_);}
510
Howard Hinnant422a53f2010-09-21 21:28:23 +0000511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000512 hasher hash_funct() const {return __table_.hash_function();}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514 key_equal key_eq() const {return __table_.key_eq();}
515
Howard Hinnant422a53f2010-09-21 21:28:23 +0000516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523 pair<iterator, iterator> equal_range(const key_type& __k)
524 {return __table_.__equal_range_multi(__k);}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
527 {return __table_.__equal_range_multi(__k);}
528
Howard Hinnant422a53f2010-09-21 21:28:23 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530 size_type bucket_count() const {return __table_.bucket_count();}
Howard Hinnant422a53f2010-09-21 21:28:23 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532 size_type max_bucket_count() const {return __table_.max_bucket_count();}
533
Howard Hinnant422a53f2010-09-21 21:28:23 +0000534 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000535 size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);}
536
Howard Hinnant422a53f2010-09-21 21:28:23 +0000537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538 void resize(size_type __n) {__table_.rehash(__n);}
539};
540
541template <class _Value, class _Hash, class _Pred, class _Alloc>
542hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
543 size_type __n, const hasher& __hf, const key_equal& __eql)
544 : __table_(__hf, __eql)
545{
546 __table_.rehash(__n);
547}
548
549template <class _Value, class _Hash, class _Pred, class _Alloc>
550hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
551 size_type __n, const hasher& __hf, const key_equal& __eql,
552 const allocator_type& __a)
553 : __table_(__hf, __eql, __a)
554{
555 __table_.rehash(__n);
556}
557
558template <class _Value, class _Hash, class _Pred, class _Alloc>
559template <class _InputIterator>
560hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
561 _InputIterator __first, _InputIterator __last)
562{
563 __table_.rehash(193);
564 insert(__first, __last);
565}
566
567template <class _Value, class _Hash, class _Pred, class _Alloc>
568template <class _InputIterator>
569hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
570 _InputIterator __first, _InputIterator __last, size_type __n,
571 const hasher& __hf, const key_equal& __eql)
572 : __table_(__hf, __eql)
573{
574 __table_.rehash(__n);
575 insert(__first, __last);
576}
577
578template <class _Value, class _Hash, class _Pred, class _Alloc>
579template <class _InputIterator>
580hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
581 _InputIterator __first, _InputIterator __last, size_type __n,
582 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
583 : __table_(__hf, __eql, __a)
584{
585 __table_.rehash(__n);
586 insert(__first, __last);
587}
588
589template <class _Value, class _Hash, class _Pred, class _Alloc>
590hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
591 const hash_multiset& __u)
592 : __table_(__u.__table_)
593{
594 __table_.rehash(__u.bucket_count());
595 insert(__u.begin(), __u.end());
596}
597
598template <class _Value, class _Hash, class _Pred, class _Alloc>
599template <class _InputIterator>
Howard Hinnant422a53f2010-09-21 21:28:23 +0000600inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601void
602hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
603 _InputIterator __last)
604{
605 for (; __first != __last; ++__first)
606 __table_.__insert_multi(*__first);
607}
608
609template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnant422a53f2010-09-21 21:28:23 +0000610inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000611void
612swap(hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
613 hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
614{
615 __x.swap(__y);
616}
617
618template <class _Value, class _Hash, class _Pred, class _Alloc>
619bool
620operator==(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
621 const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
622{
623 if (__x.size() != __y.size())
624 return false;
625 typedef typename hash_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
626 const_iterator;
627 typedef pair<const_iterator, const_iterator> _EqRng;
628 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
629 {
630 _EqRng __xeq = __x.equal_range(*__i);
631 _EqRng __yeq = __y.equal_range(*__i);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000632 if (_VSTD::distance(__xeq.first, __xeq.second) !=
633 _VSTD::distance(__yeq.first, __yeq.second) ||
634 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000635 return false;
636 __i = __xeq.second;
637 }
638 return true;
639}
640
641template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnant422a53f2010-09-21 21:28:23 +0000642inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643bool
644operator!=(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
645 const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
646{
647 return !(__x == __y);
648}
649
650} // __gnu_cxx
651
652#endif // _LIBCPP_HASH_SET