xref: /freebsd/contrib/llvm-project/libcxx/include/__cxx03/ext/hash_set (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric// -*- C++ -*-
2*700637cbSDimitry Andric//===----------------------------------------------------------------------===//
3*700637cbSDimitry Andric//
4*700637cbSDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*700637cbSDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
6*700637cbSDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*700637cbSDimitry Andric//
8*700637cbSDimitry Andric//===----------------------------------------------------------------------===//
9*700637cbSDimitry Andric
10*700637cbSDimitry Andric#ifndef _LIBCPP___CXX03_HASH_SET
11*700637cbSDimitry Andric#define _LIBCPP___CXX03_HASH_SET
12*700637cbSDimitry Andric
13*700637cbSDimitry Andric/*
14*700637cbSDimitry Andric
15*700637cbSDimitry Andric    hash_set synopsis
16*700637cbSDimitry Andric
17*700637cbSDimitry Andricnamespace __gnu_cxx
18*700637cbSDimitry Andric{
19*700637cbSDimitry Andric
20*700637cbSDimitry Andrictemplate <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
21*700637cbSDimitry Andric          class Alloc = allocator<Value>>
22*700637cbSDimitry Andricclass hash_set
23*700637cbSDimitry Andric{
24*700637cbSDimitry Andricpublic:
25*700637cbSDimitry Andric    // types
26*700637cbSDimitry Andric    typedef Value                                                      key_type;
27*700637cbSDimitry Andric    typedef key_type                                                   value_type;
28*700637cbSDimitry Andric    typedef Hash                                                       hasher;
29*700637cbSDimitry Andric    typedef Pred                                                       key_equal;
30*700637cbSDimitry Andric    typedef Alloc                                                      allocator_type;
31*700637cbSDimitry Andric    typedef value_type&                                                reference;
32*700637cbSDimitry Andric    typedef const value_type&                                          const_reference;
33*700637cbSDimitry Andric    typedef typename allocator_traits<allocator_type>::pointer         pointer;
34*700637cbSDimitry Andric    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
35*700637cbSDimitry Andric    typedef typename allocator_traits<allocator_type>::size_type       size_type;
36*700637cbSDimitry Andric    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
37*700637cbSDimitry Andric
38*700637cbSDimitry Andric    typedef /unspecified/ iterator;
39*700637cbSDimitry Andric    typedef /unspecified/ const_iterator;
40*700637cbSDimitry Andric
41*700637cbSDimitry Andric    explicit hash_set(size_type n = 193, const hasher& hf = hasher(),
42*700637cbSDimitry Andric                           const key_equal& eql = key_equal(),
43*700637cbSDimitry Andric                           const allocator_type& a = allocator_type());
44*700637cbSDimitry Andric    template <class InputIterator>
45*700637cbSDimitry Andric        hash_set(InputIterator f, InputIterator l,
46*700637cbSDimitry Andric                      size_type n = 193, const hasher& hf = hasher(),
47*700637cbSDimitry Andric                      const key_equal& eql = key_equal(),
48*700637cbSDimitry Andric                      const allocator_type& a = allocator_type());
49*700637cbSDimitry Andric    hash_set(const hash_set&);
50*700637cbSDimitry Andric    ~hash_set();
51*700637cbSDimitry Andric    hash_set& operator=(const hash_set&);
52*700637cbSDimitry Andric
53*700637cbSDimitry Andric    allocator_type get_allocator() const;
54*700637cbSDimitry Andric
55*700637cbSDimitry Andric    bool      empty() const;
56*700637cbSDimitry Andric    size_type size() const;
57*700637cbSDimitry Andric    size_type max_size() const;
58*700637cbSDimitry Andric
59*700637cbSDimitry Andric    iterator       begin();
60*700637cbSDimitry Andric    iterator       end();
61*700637cbSDimitry Andric    const_iterator begin()  const;
62*700637cbSDimitry Andric    const_iterator end()    const;
63*700637cbSDimitry Andric
64*700637cbSDimitry Andric    pair<iterator, bool> insert(const value_type& obj);
65*700637cbSDimitry Andric    template <class InputIterator>
66*700637cbSDimitry Andric        void insert(InputIterator first, InputIterator last);
67*700637cbSDimitry Andric
68*700637cbSDimitry Andric    void erase(const_iterator position);
69*700637cbSDimitry Andric    size_type erase(const key_type& k);
70*700637cbSDimitry Andric    void erase(const_iterator first, const_iterator last);
71*700637cbSDimitry Andric    void clear();
72*700637cbSDimitry Andric
73*700637cbSDimitry Andric    void swap(hash_set&);
74*700637cbSDimitry Andric
75*700637cbSDimitry Andric    hasher hash_funct() const;
76*700637cbSDimitry Andric    key_equal key_eq() const;
77*700637cbSDimitry Andric
78*700637cbSDimitry Andric    iterator       find(const key_type& k);
79*700637cbSDimitry Andric    const_iterator find(const key_type& k) const;
80*700637cbSDimitry Andric    size_type count(const key_type& k) const;
81*700637cbSDimitry Andric    pair<iterator, iterator>             equal_range(const key_type& k);
82*700637cbSDimitry Andric    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
83*700637cbSDimitry Andric
84*700637cbSDimitry Andric    size_type bucket_count() const;
85*700637cbSDimitry Andric    size_type max_bucket_count() const;
86*700637cbSDimitry Andric
87*700637cbSDimitry Andric    size_type elems_in_bucket(size_type n) const;
88*700637cbSDimitry Andric
89*700637cbSDimitry Andric    void resize(size_type n);
90*700637cbSDimitry Andric};
91*700637cbSDimitry Andric
92*700637cbSDimitry Andrictemplate <class Value, class Hash, class Pred, class Alloc>
93*700637cbSDimitry Andric    void swap(hash_set<Value, Hash, Pred, Alloc>& x,
94*700637cbSDimitry Andric              hash_set<Value, Hash, Pred, Alloc>& y);
95*700637cbSDimitry Andric
96*700637cbSDimitry Andrictemplate <class Value, class Hash, class Pred, class Alloc>
97*700637cbSDimitry Andric    bool
98*700637cbSDimitry Andric    operator==(const hash_set<Value, Hash, Pred, Alloc>& x,
99*700637cbSDimitry Andric               const hash_set<Value, Hash, Pred, Alloc>& y);
100*700637cbSDimitry Andric
101*700637cbSDimitry Andrictemplate <class Value, class Hash, class Pred, class Alloc>
102*700637cbSDimitry Andric    bool
103*700637cbSDimitry Andric    operator!=(const hash_set<Value, Hash, Pred, Alloc>& x,
104*700637cbSDimitry Andric               const hash_set<Value, Hash, Pred, Alloc>& y);
105*700637cbSDimitry Andric
106*700637cbSDimitry Andrictemplate <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
107*700637cbSDimitry Andric          class Alloc = allocator<Value>>
108*700637cbSDimitry Andricclass hash_multiset
109*700637cbSDimitry Andric{
110*700637cbSDimitry Andricpublic:
111*700637cbSDimitry Andric    // types
112*700637cbSDimitry Andric    typedef Value                                                      key_type;
113*700637cbSDimitry Andric    typedef key_type                                                   value_type;
114*700637cbSDimitry Andric    typedef Hash                                                       hasher;
115*700637cbSDimitry Andric    typedef Pred                                                       key_equal;
116*700637cbSDimitry Andric    typedef Alloc                                                      allocator_type;
117*700637cbSDimitry Andric    typedef value_type&                                                reference;
118*700637cbSDimitry Andric    typedef const value_type&                                          const_reference;
119*700637cbSDimitry Andric    typedef typename allocator_traits<allocator_type>::pointer         pointer;
120*700637cbSDimitry Andric    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
121*700637cbSDimitry Andric    typedef typename allocator_traits<allocator_type>::size_type       size_type;
122*700637cbSDimitry Andric    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
123*700637cbSDimitry Andric
124*700637cbSDimitry Andric    typedef /unspecified/ iterator;
125*700637cbSDimitry Andric    typedef /unspecified/ const_iterator;
126*700637cbSDimitry Andric
127*700637cbSDimitry Andric    explicit hash_multiset(size_type n = 193, const hasher& hf = hasher(),
128*700637cbSDimitry Andric                           const key_equal& eql = key_equal(),
129*700637cbSDimitry Andric                           const allocator_type& a = allocator_type());
130*700637cbSDimitry Andric    template <class InputIterator>
131*700637cbSDimitry Andric        hash_multiset(InputIterator f, InputIterator l,
132*700637cbSDimitry Andric                      size_type n = 193, const hasher& hf = hasher(),
133*700637cbSDimitry Andric                      const key_equal& eql = key_equal(),
134*700637cbSDimitry Andric                      const allocator_type& a = allocator_type());
135*700637cbSDimitry Andric    hash_multiset(const hash_multiset&);
136*700637cbSDimitry Andric    ~hash_multiset();
137*700637cbSDimitry Andric    hash_multiset& operator=(const hash_multiset&);
138*700637cbSDimitry Andric
139*700637cbSDimitry Andric    allocator_type get_allocator() const;
140*700637cbSDimitry Andric
141*700637cbSDimitry Andric    bool      empty() const;
142*700637cbSDimitry Andric    size_type size() const;
143*700637cbSDimitry Andric    size_type max_size() const;
144*700637cbSDimitry Andric
145*700637cbSDimitry Andric    iterator       begin();
146*700637cbSDimitry Andric    iterator       end();
147*700637cbSDimitry Andric    const_iterator begin()  const;
148*700637cbSDimitry Andric    const_iterator end()    const;
149*700637cbSDimitry Andric
150*700637cbSDimitry Andric    iterator insert(const value_type& obj);
151*700637cbSDimitry Andric    template <class InputIterator>
152*700637cbSDimitry Andric        void insert(InputIterator first, InputIterator last);
153*700637cbSDimitry Andric
154*700637cbSDimitry Andric    void erase(const_iterator position);
155*700637cbSDimitry Andric    size_type erase(const key_type& k);
156*700637cbSDimitry Andric    void erase(const_iterator first, const_iterator last);
157*700637cbSDimitry Andric    void clear();
158*700637cbSDimitry Andric
159*700637cbSDimitry Andric    void swap(hash_multiset&);
160*700637cbSDimitry Andric
161*700637cbSDimitry Andric    hasher hash_funct() const;
162*700637cbSDimitry Andric    key_equal key_eq() const;
163*700637cbSDimitry Andric
164*700637cbSDimitry Andric    iterator       find(const key_type& k);
165*700637cbSDimitry Andric    const_iterator find(const key_type& k) const;
166*700637cbSDimitry Andric    size_type count(const key_type& k) const;
167*700637cbSDimitry Andric    pair<iterator, iterator>             equal_range(const key_type& k);
168*700637cbSDimitry Andric    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
169*700637cbSDimitry Andric
170*700637cbSDimitry Andric    size_type bucket_count() const;
171*700637cbSDimitry Andric    size_type max_bucket_count() const;
172*700637cbSDimitry Andric
173*700637cbSDimitry Andric    size_type elems_in_bucket(size_type n) const;
174*700637cbSDimitry Andric
175*700637cbSDimitry Andric    void resize(size_type n);
176*700637cbSDimitry Andric};
177*700637cbSDimitry Andric
178*700637cbSDimitry Andrictemplate <class Value, class Hash, class Pred, class Alloc>
179*700637cbSDimitry Andric    void swap(hash_multiset<Value, Hash, Pred, Alloc>& x,
180*700637cbSDimitry Andric              hash_multiset<Value, Hash, Pred, Alloc>& y);
181*700637cbSDimitry Andric
182*700637cbSDimitry Andrictemplate <class Value, class Hash, class Pred, class Alloc>
183*700637cbSDimitry Andric    bool
184*700637cbSDimitry Andric    operator==(const hash_multiset<Value, Hash, Pred, Alloc>& x,
185*700637cbSDimitry Andric               const hash_multiset<Value, Hash, Pred, Alloc>& y);
186*700637cbSDimitry Andric
187*700637cbSDimitry Andrictemplate <class Value, class Hash, class Pred, class Alloc>
188*700637cbSDimitry Andric    bool
189*700637cbSDimitry Andric    operator!=(const hash_multiset<Value, Hash, Pred, Alloc>& x,
190*700637cbSDimitry Andric               const hash_multiset<Value, Hash, Pred, Alloc>& y);
191*700637cbSDimitry Andric}  // __gnu_cxx
192*700637cbSDimitry Andric
193*700637cbSDimitry Andric*/
194*700637cbSDimitry Andric
195*700637cbSDimitry Andric#include <__cxx03/__config>
196*700637cbSDimitry Andric#include <__cxx03/__hash_table>
197*700637cbSDimitry Andric#include <__cxx03/algorithm>
198*700637cbSDimitry Andric#include <__cxx03/ext/__hash>
199*700637cbSDimitry Andric#include <__cxx03/functional>
200*700637cbSDimitry Andric
201*700637cbSDimitry Andric#if defined(__DEPRECATED) && __DEPRECATED
202*700637cbSDimitry Andric#  if defined(_LIBCPP_WARNING)
203*700637cbSDimitry Andric_LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set>")
204*700637cbSDimitry Andric#  else
205*700637cbSDimitry Andric#    warning Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set>
206*700637cbSDimitry Andric#  endif
207*700637cbSDimitry Andric#endif
208*700637cbSDimitry Andric
209*700637cbSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
210*700637cbSDimitry Andric#  pragma GCC system_header
211*700637cbSDimitry Andric#endif
212*700637cbSDimitry Andric
213*700637cbSDimitry Andricnamespace __gnu_cxx {
214*700637cbSDimitry Andric
215*700637cbSDimitry Andrictemplate <class _Value,
216*700637cbSDimitry Andric          class _Hash  = hash<_Value>,
217*700637cbSDimitry Andric          class _Pred  = std::equal_to<_Value>,
218*700637cbSDimitry Andric          class _Alloc = std::allocator<_Value> >
219*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS hash_set {
220*700637cbSDimitry Andricpublic:
221*700637cbSDimitry Andric  // types
222*700637cbSDimitry Andric  typedef _Value key_type;
223*700637cbSDimitry Andric  typedef key_type value_type;
224*700637cbSDimitry Andric  typedef _Hash hasher;
225*700637cbSDimitry Andric  typedef _Pred key_equal;
226*700637cbSDimitry Andric  typedef _Alloc allocator_type;
227*700637cbSDimitry Andric  typedef value_type& reference;
228*700637cbSDimitry Andric  typedef const value_type& const_reference;
229*700637cbSDimitry Andric
230*700637cbSDimitry Andricprivate:
231*700637cbSDimitry Andric  typedef std::__hash_table<value_type, hasher, key_equal, allocator_type> __table;
232*700637cbSDimitry Andric
233*700637cbSDimitry Andric  __table __table_;
234*700637cbSDimitry Andric
235*700637cbSDimitry Andricpublic:
236*700637cbSDimitry Andric  typedef typename __table::pointer pointer;
237*700637cbSDimitry Andric  typedef typename __table::const_pointer const_pointer;
238*700637cbSDimitry Andric  typedef typename __table::size_type size_type;
239*700637cbSDimitry Andric  typedef typename __table::difference_type difference_type;
240*700637cbSDimitry Andric
241*700637cbSDimitry Andric  typedef typename __table::const_iterator iterator;
242*700637cbSDimitry Andric  typedef typename __table::const_iterator const_iterator;
243*700637cbSDimitry Andric
244*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI hash_set() {}
245*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit hash_set(
246*700637cbSDimitry Andric      size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
247*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI hash_set(size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a);
248*700637cbSDimitry Andric  template <class _InputIterator>
249*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI hash_set(_InputIterator __first, _InputIterator __last);
250*700637cbSDimitry Andric  template <class _InputIterator>
251*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI
252*700637cbSDimitry Andric  hash_set(_InputIterator __first,
253*700637cbSDimitry Andric           _InputIterator __last,
254*700637cbSDimitry Andric           size_type __n,
255*700637cbSDimitry Andric           const hasher& __hf     = hasher(),
256*700637cbSDimitry Andric           const key_equal& __eql = key_equal());
257*700637cbSDimitry Andric  template <class _InputIterator>
258*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI
259*700637cbSDimitry Andric  hash_set(_InputIterator __first,
260*700637cbSDimitry Andric           _InputIterator __last,
261*700637cbSDimitry Andric           size_type __n,
262*700637cbSDimitry Andric           const hasher& __hf,
263*700637cbSDimitry Andric           const key_equal& __eql,
264*700637cbSDimitry Andric           const allocator_type& __a);
265*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI hash_set(const hash_set& __u);
266*700637cbSDimitry Andric
267*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const { return allocator_type(__table_.__node_alloc()); }
268*700637cbSDimitry Andric
269*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool empty() const { return __table_.size() == 0; }
270*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type size() const { return __table_.size(); }
271*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type max_size() const { return __table_.max_size(); }
272*700637cbSDimitry Andric
273*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator begin() { return __table_.begin(); }
274*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator end() { return __table_.end(); }
275*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return __table_.begin(); }
276*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
277*700637cbSDimitry Andric
278*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI std::pair<iterator, bool> insert(const value_type& __x) {
279*700637cbSDimitry Andric    return __table_.__insert_unique(__x);
280*700637cbSDimitry Andric  }
281*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x).first; }
282*700637cbSDimitry Andric  template <class _InputIterator>
283*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
284*700637cbSDimitry Andric
285*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void erase(const_iterator __p) { __table_.erase(__p); }
286*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __table_.__erase_unique(__k); }
287*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void erase(const_iterator __first, const_iterator __last) { __table_.erase(__first, __last); }
288*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void clear() { __table_.clear(); }
289*700637cbSDimitry Andric
290*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(hash_set& __u) { __table_.swap(__u.__table_); }
291*700637cbSDimitry Andric
292*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI hasher hash_funct() const { return __table_.hash_function(); }
293*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI key_equal key_eq() const { return __table_.key_eq(); }
294*700637cbSDimitry Andric
295*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __table_.find(__k); }
296*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __table_.find(__k); }
297*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __table_.__count_unique(__k); }
298*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI std::pair<iterator, iterator> equal_range(const key_type& __k) {
299*700637cbSDimitry Andric    return __table_.__equal_range_unique(__k);
300*700637cbSDimitry Andric  }
301*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
302*700637cbSDimitry Andric    return __table_.__equal_range_unique(__k);
303*700637cbSDimitry Andric  }
304*700637cbSDimitry Andric
305*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type bucket_count() const { return __table_.bucket_count(); }
306*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type max_bucket_count() const { return __table_.max_bucket_count(); }
307*700637cbSDimitry Andric
308*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type elems_in_bucket(size_type __n) const { return __table_.bucket_size(__n); }
309*700637cbSDimitry Andric
310*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void resize(size_type __n) { __table_.__rehash_unique(__n); }
311*700637cbSDimitry Andric};
312*700637cbSDimitry Andric
313*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
314*700637cbSDimitry Andrichash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n, const hasher& __hf, const key_equal& __eql)
315*700637cbSDimitry Andric    : __table_(__hf, __eql) {
316*700637cbSDimitry Andric  __table_.__rehash_unique(__n);
317*700637cbSDimitry Andric}
318*700637cbSDimitry Andric
319*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
320*700637cbSDimitry Andrichash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
321*700637cbSDimitry Andric    size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
322*700637cbSDimitry Andric    : __table_(__hf, __eql, __a) {
323*700637cbSDimitry Andric  __table_.__rehash_unique(__n);
324*700637cbSDimitry Andric}
325*700637cbSDimitry Andric
326*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
327*700637cbSDimitry Andrictemplate <class _InputIterator>
328*700637cbSDimitry Andrichash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(_InputIterator __first, _InputIterator __last) {
329*700637cbSDimitry Andric  insert(__first, __last);
330*700637cbSDimitry Andric}
331*700637cbSDimitry Andric
332*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
333*700637cbSDimitry Andrictemplate <class _InputIterator>
334*700637cbSDimitry Andrichash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
335*700637cbSDimitry Andric    _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const key_equal& __eql)
336*700637cbSDimitry Andric    : __table_(__hf, __eql) {
337*700637cbSDimitry Andric  __table_.__rehash_unique(__n);
338*700637cbSDimitry Andric  insert(__first, __last);
339*700637cbSDimitry Andric}
340*700637cbSDimitry Andric
341*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
342*700637cbSDimitry Andrictemplate <class _InputIterator>
343*700637cbSDimitry Andrichash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
344*700637cbSDimitry Andric    _InputIterator __first,
345*700637cbSDimitry Andric    _InputIterator __last,
346*700637cbSDimitry Andric    size_type __n,
347*700637cbSDimitry Andric    const hasher& __hf,
348*700637cbSDimitry Andric    const key_equal& __eql,
349*700637cbSDimitry Andric    const allocator_type& __a)
350*700637cbSDimitry Andric    : __table_(__hf, __eql, __a) {
351*700637cbSDimitry Andric  __table_.__rehash_unique(__n);
352*700637cbSDimitry Andric  insert(__first, __last);
353*700637cbSDimitry Andric}
354*700637cbSDimitry Andric
355*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
356*700637cbSDimitry Andrichash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(const hash_set& __u) : __table_(__u.__table_) {
357*700637cbSDimitry Andric  __table_.__rehash_unique(__u.bucket_count());
358*700637cbSDimitry Andric  insert(__u.begin(), __u.end());
359*700637cbSDimitry Andric}
360*700637cbSDimitry Andric
361*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
362*700637cbSDimitry Andrictemplate <class _InputIterator>
363*700637cbSDimitry Andricinline void hash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
364*700637cbSDimitry Andric  for (; __first != __last; ++__first)
365*700637cbSDimitry Andric    __table_.__insert_unique(*__first);
366*700637cbSDimitry Andric}
367*700637cbSDimitry Andric
368*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
369*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void
370*700637cbSDimitry Andricswap(hash_set<_Value, _Hash, _Pred, _Alloc>& __x, hash_set<_Value, _Hash, _Pred, _Alloc>& __y) {
371*700637cbSDimitry Andric  __x.swap(__y);
372*700637cbSDimitry Andric}
373*700637cbSDimitry Andric
374*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
375*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool
376*700637cbSDimitry Andricoperator==(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, const hash_set<_Value, _Hash, _Pred, _Alloc>& __y) {
377*700637cbSDimitry Andric  if (__x.size() != __y.size())
378*700637cbSDimitry Andric    return false;
379*700637cbSDimitry Andric  typedef typename hash_set<_Value, _Hash, _Pred, _Alloc>::const_iterator const_iterator;
380*700637cbSDimitry Andric  for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); __i != __ex; ++__i) {
381*700637cbSDimitry Andric    const_iterator __j = __y.find(*__i);
382*700637cbSDimitry Andric    if (__j == __ey || !(*__i == *__j))
383*700637cbSDimitry Andric      return false;
384*700637cbSDimitry Andric  }
385*700637cbSDimitry Andric  return true;
386*700637cbSDimitry Andric}
387*700637cbSDimitry Andric
388*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
389*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
390*700637cbSDimitry Andricoperator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, const hash_set<_Value, _Hash, _Pred, _Alloc>& __y) {
391*700637cbSDimitry Andric  return !(__x == __y);
392*700637cbSDimitry Andric}
393*700637cbSDimitry Andric
394*700637cbSDimitry Andrictemplate <class _Value,
395*700637cbSDimitry Andric          class _Hash  = hash<_Value>,
396*700637cbSDimitry Andric          class _Pred  = std::equal_to<_Value>,
397*700637cbSDimitry Andric          class _Alloc = std::allocator<_Value> >
398*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS hash_multiset {
399*700637cbSDimitry Andricpublic:
400*700637cbSDimitry Andric  // types
401*700637cbSDimitry Andric  typedef _Value key_type;
402*700637cbSDimitry Andric  typedef key_type value_type;
403*700637cbSDimitry Andric  typedef _Hash hasher;
404*700637cbSDimitry Andric  typedef _Pred key_equal;
405*700637cbSDimitry Andric  typedef _Alloc allocator_type;
406*700637cbSDimitry Andric  typedef value_type& reference;
407*700637cbSDimitry Andric  typedef const value_type& const_reference;
408*700637cbSDimitry Andric
409*700637cbSDimitry Andricprivate:
410*700637cbSDimitry Andric  typedef std::__hash_table<value_type, hasher, key_equal, allocator_type> __table;
411*700637cbSDimitry Andric
412*700637cbSDimitry Andric  __table __table_;
413*700637cbSDimitry Andric
414*700637cbSDimitry Andricpublic:
415*700637cbSDimitry Andric  typedef typename __table::pointer pointer;
416*700637cbSDimitry Andric  typedef typename __table::const_pointer const_pointer;
417*700637cbSDimitry Andric  typedef typename __table::size_type size_type;
418*700637cbSDimitry Andric  typedef typename __table::difference_type difference_type;
419*700637cbSDimitry Andric
420*700637cbSDimitry Andric  typedef typename __table::const_iterator iterator;
421*700637cbSDimitry Andric  typedef typename __table::const_iterator const_iterator;
422*700637cbSDimitry Andric
423*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI hash_multiset() {}
424*700637cbSDimitry Andric  explicit _LIBCPP_HIDE_FROM_ABI
425*700637cbSDimitry Andric  hash_multiset(size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
426*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI
427*700637cbSDimitry Andric  hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a);
428*700637cbSDimitry Andric  template <class _InputIterator>
429*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI hash_multiset(_InputIterator __first, _InputIterator __last);
430*700637cbSDimitry Andric  template <class _InputIterator>
431*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI
432*700637cbSDimitry Andric  hash_multiset(_InputIterator __first,
433*700637cbSDimitry Andric                _InputIterator __last,
434*700637cbSDimitry Andric                size_type __n,
435*700637cbSDimitry Andric                const hasher& __hf     = hasher(),
436*700637cbSDimitry Andric                const key_equal& __eql = key_equal());
437*700637cbSDimitry Andric  template <class _InputIterator>
438*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI hash_multiset(
439*700637cbSDimitry Andric      _InputIterator __first,
440*700637cbSDimitry Andric      _InputIterator __last,
441*700637cbSDimitry Andric      size_type __n,
442*700637cbSDimitry Andric      const hasher& __hf,
443*700637cbSDimitry Andric      const key_equal& __eql,
444*700637cbSDimitry Andric      const allocator_type& __a);
445*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI hash_multiset(const hash_multiset& __u);
446*700637cbSDimitry Andric
447*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const { return allocator_type(__table_.__node_alloc()); }
448*700637cbSDimitry Andric
449*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool empty() const { return __table_.size() == 0; }
450*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type size() const { return __table_.size(); }
451*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type max_size() const { return __table_.max_size(); }
452*700637cbSDimitry Andric
453*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator begin() { return __table_.begin(); }
454*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator end() { return __table_.end(); }
455*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return __table_.begin(); }
456*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
457*700637cbSDimitry Andric
458*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__insert_multi(__x); }
459*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x); }
460*700637cbSDimitry Andric  template <class _InputIterator>
461*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
462*700637cbSDimitry Andric
463*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void erase(const_iterator __p) { __table_.erase(__p); }
464*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __table_.__erase_multi(__k); }
465*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void erase(const_iterator __first, const_iterator __last) { __table_.erase(__first, __last); }
466*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void clear() { __table_.clear(); }
467*700637cbSDimitry Andric
468*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(hash_multiset& __u) { __table_.swap(__u.__table_); }
469*700637cbSDimitry Andric
470*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI hasher hash_funct() const { return __table_.hash_function(); }
471*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI key_equal key_eq() const { return __table_.key_eq(); }
472*700637cbSDimitry Andric
473*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __table_.find(__k); }
474*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __table_.find(__k); }
475*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __table_.__count_multi(__k); }
476*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI std::pair<iterator, iterator> equal_range(const key_type& __k) {
477*700637cbSDimitry Andric    return __table_.__equal_range_multi(__k);
478*700637cbSDimitry Andric  }
479*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
480*700637cbSDimitry Andric    return __table_.__equal_range_multi(__k);
481*700637cbSDimitry Andric  }
482*700637cbSDimitry Andric
483*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type bucket_count() const { return __table_.bucket_count(); }
484*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type max_bucket_count() const { return __table_.max_bucket_count(); }
485*700637cbSDimitry Andric
486*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type elems_in_bucket(size_type __n) const { return __table_.bucket_size(__n); }
487*700637cbSDimitry Andric
488*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void resize(size_type __n) { __table_.__rehash_multi(__n); }
489*700637cbSDimitry Andric};
490*700637cbSDimitry Andric
491*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
492*700637cbSDimitry Andrichash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql)
493*700637cbSDimitry Andric    : __table_(__hf, __eql) {
494*700637cbSDimitry Andric  __table_.__rehash_multi(__n);
495*700637cbSDimitry Andric}
496*700637cbSDimitry Andric
497*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
498*700637cbSDimitry Andrichash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
499*700637cbSDimitry Andric    size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
500*700637cbSDimitry Andric    : __table_(__hf, __eql, __a) {
501*700637cbSDimitry Andric  __table_.__rehash_multi(__n);
502*700637cbSDimitry Andric}
503*700637cbSDimitry Andric
504*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
505*700637cbSDimitry Andrictemplate <class _InputIterator>
506*700637cbSDimitry Andrichash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(_InputIterator __first, _InputIterator __last) {
507*700637cbSDimitry Andric  insert(__first, __last);
508*700637cbSDimitry Andric}
509*700637cbSDimitry Andric
510*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
511*700637cbSDimitry Andrictemplate <class _InputIterator>
512*700637cbSDimitry Andrichash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
513*700637cbSDimitry Andric    _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const key_equal& __eql)
514*700637cbSDimitry Andric    : __table_(__hf, __eql) {
515*700637cbSDimitry Andric  __table_.__rehash_multi(__n);
516*700637cbSDimitry Andric  insert(__first, __last);
517*700637cbSDimitry Andric}
518*700637cbSDimitry Andric
519*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
520*700637cbSDimitry Andrictemplate <class _InputIterator>
521*700637cbSDimitry Andrichash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
522*700637cbSDimitry Andric    _InputIterator __first,
523*700637cbSDimitry Andric    _InputIterator __last,
524*700637cbSDimitry Andric    size_type __n,
525*700637cbSDimitry Andric    const hasher& __hf,
526*700637cbSDimitry Andric    const key_equal& __eql,
527*700637cbSDimitry Andric    const allocator_type& __a)
528*700637cbSDimitry Andric    : __table_(__hf, __eql, __a) {
529*700637cbSDimitry Andric  __table_.__rehash_multi(__n);
530*700637cbSDimitry Andric  insert(__first, __last);
531*700637cbSDimitry Andric}
532*700637cbSDimitry Andric
533*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
534*700637cbSDimitry Andrichash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(const hash_multiset& __u) : __table_(__u.__table_) {
535*700637cbSDimitry Andric  __table_.__rehash_multi(__u.bucket_count());
536*700637cbSDimitry Andric  insert(__u.begin(), __u.end());
537*700637cbSDimitry Andric}
538*700637cbSDimitry Andric
539*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
540*700637cbSDimitry Andrictemplate <class _InputIterator>
541*700637cbSDimitry Andricinline void hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
542*700637cbSDimitry Andric  for (; __first != __last; ++__first)
543*700637cbSDimitry Andric    __table_.__insert_multi(*__first);
544*700637cbSDimitry Andric}
545*700637cbSDimitry Andric
546*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
547*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void
548*700637cbSDimitry Andricswap(hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) {
549*700637cbSDimitry Andric  __x.swap(__y);
550*700637cbSDimitry Andric}
551*700637cbSDimitry Andric
552*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
553*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator==(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
554*700637cbSDimitry Andric                                      const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) {
555*700637cbSDimitry Andric  if (__x.size() != __y.size())
556*700637cbSDimitry Andric    return false;
557*700637cbSDimitry Andric  typedef typename hash_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator const_iterator;
558*700637cbSDimitry Andric  typedef std::pair<const_iterator, const_iterator> _EqRng;
559*700637cbSDimitry Andric  for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) {
560*700637cbSDimitry Andric    _EqRng __xeq = __x.equal_range(*__i);
561*700637cbSDimitry Andric    _EqRng __yeq = __y.equal_range(*__i);
562*700637cbSDimitry Andric    if (std::distance(__xeq.first, __xeq.second) != std::distance(__yeq.first, __yeq.second) ||
563*700637cbSDimitry Andric        !std::is_permutation(__xeq.first, __xeq.second, __yeq.first))
564*700637cbSDimitry Andric      return false;
565*700637cbSDimitry Andric    __i = __xeq.second;
566*700637cbSDimitry Andric  }
567*700637cbSDimitry Andric  return true;
568*700637cbSDimitry Andric}
569*700637cbSDimitry Andric
570*700637cbSDimitry Andrictemplate <class _Value, class _Hash, class _Pred, class _Alloc>
571*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator!=(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
572*700637cbSDimitry Andric                                             const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) {
573*700637cbSDimitry Andric  return !(__x == __y);
574*700637cbSDimitry Andric}
575*700637cbSDimitry Andric
576*700637cbSDimitry Andric} // namespace __gnu_cxx
577*700637cbSDimitry Andric
578*700637cbSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
579*700637cbSDimitry Andric#  include <__cxx03/iterator>
580*700637cbSDimitry Andric#  include <__cxx03/type_traits>
581*700637cbSDimitry Andric#endif
582*700637cbSDimitry Andric
583*700637cbSDimitry Andric#endif // _LIBCPP___CXX03_HASH_SET
584