xref: /openbsd/gnu/llvm/libcxx/include/ext/hash_set (revision 4bdff4be)
146035553Spatrick// -*- C++ -*-
2*4bdff4beSrobert//===----------------------------------------------------------------------===//
346035553Spatrick//
446035553Spatrick// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
546035553Spatrick// See https://llvm.org/LICENSE.txt for license information.
646035553Spatrick// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
746035553Spatrick//
846035553Spatrick//===----------------------------------------------------------------------===//
946035553Spatrick
1046035553Spatrick#ifndef _LIBCPP_HASH_SET
1146035553Spatrick#define _LIBCPP_HASH_SET
1246035553Spatrick
1346035553Spatrick/*
1446035553Spatrick
1546035553Spatrick    hash_set synopsis
1646035553Spatrick
1746035553Spatricknamespace __gnu_cxx
1846035553Spatrick{
1946035553Spatrick
2046035553Spatricktemplate <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
2146035553Spatrick          class Alloc = allocator<Value>>
2246035553Spatrickclass hash_set
2346035553Spatrick{
2446035553Spatrickpublic:
2546035553Spatrick    // types
2646035553Spatrick    typedef Value                                                      key_type;
2746035553Spatrick    typedef key_type                                                   value_type;
2846035553Spatrick    typedef Hash                                                       hasher;
2946035553Spatrick    typedef Pred                                                       key_equal;
3046035553Spatrick    typedef Alloc                                                      allocator_type;
3146035553Spatrick    typedef value_type&                                                reference;
3246035553Spatrick    typedef const value_type&                                          const_reference;
3346035553Spatrick    typedef typename allocator_traits<allocator_type>::pointer         pointer;
3446035553Spatrick    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
3546035553Spatrick    typedef typename allocator_traits<allocator_type>::size_type       size_type;
3646035553Spatrick    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
3746035553Spatrick
3846035553Spatrick    typedef /unspecified/ iterator;
3946035553Spatrick    typedef /unspecified/ const_iterator;
4046035553Spatrick
4146035553Spatrick    explicit hash_set(size_type n = 193, const hasher& hf = hasher(),
4246035553Spatrick                           const key_equal& eql = key_equal(),
4346035553Spatrick                           const allocator_type& a = allocator_type());
4446035553Spatrick    template <class InputIterator>
4546035553Spatrick        hash_set(InputIterator f, InputIterator l,
4646035553Spatrick                      size_type n = 193, const hasher& hf = hasher(),
4746035553Spatrick                      const key_equal& eql = key_equal(),
4846035553Spatrick                      const allocator_type& a = allocator_type());
4946035553Spatrick    hash_set(const hash_set&);
5046035553Spatrick    ~hash_set();
5146035553Spatrick    hash_set& operator=(const hash_set&);
5246035553Spatrick
5346035553Spatrick    allocator_type get_allocator() const;
5446035553Spatrick
5546035553Spatrick    bool      empty() const;
5646035553Spatrick    size_type size() const;
5746035553Spatrick    size_type max_size() const;
5846035553Spatrick
5946035553Spatrick    iterator       begin();
6046035553Spatrick    iterator       end();
6146035553Spatrick    const_iterator begin()  const;
6246035553Spatrick    const_iterator end()    const;
6346035553Spatrick
6446035553Spatrick    pair<iterator, bool> insert(const value_type& obj);
6546035553Spatrick    template <class InputIterator>
6646035553Spatrick        void insert(InputIterator first, InputIterator last);
6746035553Spatrick
6846035553Spatrick    void erase(const_iterator position);
6946035553Spatrick    size_type erase(const key_type& k);
7046035553Spatrick    void erase(const_iterator first, const_iterator last);
7146035553Spatrick    void clear();
7246035553Spatrick
7346035553Spatrick    void swap(hash_set&);
7446035553Spatrick
7546035553Spatrick    hasher hash_funct() const;
7646035553Spatrick    key_equal key_eq() const;
7746035553Spatrick
7846035553Spatrick    iterator       find(const key_type& k);
7946035553Spatrick    const_iterator find(const key_type& k) const;
8046035553Spatrick    size_type count(const key_type& k) const;
8146035553Spatrick    pair<iterator, iterator>             equal_range(const key_type& k);
8246035553Spatrick    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
8346035553Spatrick
8446035553Spatrick    size_type bucket_count() const;
8546035553Spatrick    size_type max_bucket_count() const;
8646035553Spatrick
8746035553Spatrick    size_type elems_in_bucket(size_type n) const;
8846035553Spatrick
8946035553Spatrick    void resize(size_type n);
9046035553Spatrick};
9146035553Spatrick
9246035553Spatricktemplate <class Value, class Hash, class Pred, class Alloc>
9346035553Spatrick    void swap(hash_set<Value, Hash, Pred, Alloc>& x,
9446035553Spatrick              hash_set<Value, Hash, Pred, Alloc>& y);
9546035553Spatrick
9646035553Spatricktemplate <class Value, class Hash, class Pred, class Alloc>
9746035553Spatrick    bool
9846035553Spatrick    operator==(const hash_set<Value, Hash, Pred, Alloc>& x,
9946035553Spatrick               const hash_set<Value, Hash, Pred, Alloc>& y);
10046035553Spatrick
10146035553Spatricktemplate <class Value, class Hash, class Pred, class Alloc>
10246035553Spatrick    bool
10346035553Spatrick    operator!=(const hash_set<Value, Hash, Pred, Alloc>& x,
10446035553Spatrick               const hash_set<Value, Hash, Pred, Alloc>& y);
10546035553Spatrick
10646035553Spatricktemplate <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
10746035553Spatrick          class Alloc = allocator<Value>>
10846035553Spatrickclass hash_multiset
10946035553Spatrick{
11046035553Spatrickpublic:
11146035553Spatrick    // types
11246035553Spatrick    typedef Value                                                      key_type;
11346035553Spatrick    typedef key_type                                                   value_type;
11446035553Spatrick    typedef Hash                                                       hasher;
11546035553Spatrick    typedef Pred                                                       key_equal;
11646035553Spatrick    typedef Alloc                                                      allocator_type;
11746035553Spatrick    typedef value_type&                                                reference;
11846035553Spatrick    typedef const value_type&                                          const_reference;
11946035553Spatrick    typedef typename allocator_traits<allocator_type>::pointer         pointer;
12046035553Spatrick    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
12146035553Spatrick    typedef typename allocator_traits<allocator_type>::size_type       size_type;
12246035553Spatrick    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
12346035553Spatrick
12446035553Spatrick    typedef /unspecified/ iterator;
12546035553Spatrick    typedef /unspecified/ const_iterator;
12646035553Spatrick
12746035553Spatrick    explicit hash_multiset(size_type n = 193, const hasher& hf = hasher(),
12846035553Spatrick                           const key_equal& eql = key_equal(),
12946035553Spatrick                           const allocator_type& a = allocator_type());
13046035553Spatrick    template <class InputIterator>
13146035553Spatrick        hash_multiset(InputIterator f, InputIterator l,
13246035553Spatrick                      size_type n = 193, const hasher& hf = hasher(),
13346035553Spatrick                      const key_equal& eql = key_equal(),
13446035553Spatrick                      const allocator_type& a = allocator_type());
13546035553Spatrick    hash_multiset(const hash_multiset&);
13646035553Spatrick    ~hash_multiset();
13746035553Spatrick    hash_multiset& operator=(const hash_multiset&);
13846035553Spatrick
13946035553Spatrick    allocator_type get_allocator() const;
14046035553Spatrick
14146035553Spatrick    bool      empty() const;
14246035553Spatrick    size_type size() const;
14346035553Spatrick    size_type max_size() const;
14446035553Spatrick
14546035553Spatrick    iterator       begin();
14646035553Spatrick    iterator       end();
14746035553Spatrick    const_iterator begin()  const;
14846035553Spatrick    const_iterator end()    const;
14946035553Spatrick
15046035553Spatrick    iterator insert(const value_type& obj);
15146035553Spatrick    template <class InputIterator>
15246035553Spatrick        void insert(InputIterator first, InputIterator last);
15346035553Spatrick
15446035553Spatrick    void erase(const_iterator position);
15546035553Spatrick    size_type erase(const key_type& k);
15646035553Spatrick    void erase(const_iterator first, const_iterator last);
15746035553Spatrick    void clear();
15846035553Spatrick
15946035553Spatrick    void swap(hash_multiset&);
16046035553Spatrick
16146035553Spatrick    hasher hash_funct() const;
16246035553Spatrick    key_equal key_eq() const;
16346035553Spatrick
16446035553Spatrick    iterator       find(const key_type& k);
16546035553Spatrick    const_iterator find(const key_type& k) const;
16646035553Spatrick    size_type count(const key_type& k) const;
16746035553Spatrick    pair<iterator, iterator>             equal_range(const key_type& k);
16846035553Spatrick    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
16946035553Spatrick
17046035553Spatrick    size_type bucket_count() const;
17146035553Spatrick    size_type max_bucket_count() const;
17246035553Spatrick
17346035553Spatrick    size_type elems_in_bucket(size_type n) const;
17446035553Spatrick
17546035553Spatrick    void resize(size_type n);
17646035553Spatrick};
17746035553Spatrick
17846035553Spatricktemplate <class Value, class Hash, class Pred, class Alloc>
17946035553Spatrick    void swap(hash_multiset<Value, Hash, Pred, Alloc>& x,
18046035553Spatrick              hash_multiset<Value, Hash, Pred, Alloc>& y);
18146035553Spatrick
18246035553Spatricktemplate <class Value, class Hash, class Pred, class Alloc>
18346035553Spatrick    bool
18446035553Spatrick    operator==(const hash_multiset<Value, Hash, Pred, Alloc>& x,
18546035553Spatrick               const hash_multiset<Value, Hash, Pred, Alloc>& y);
18646035553Spatrick
18746035553Spatricktemplate <class Value, class Hash, class Pred, class Alloc>
18846035553Spatrick    bool
18946035553Spatrick    operator!=(const hash_multiset<Value, Hash, Pred, Alloc>& x,
19046035553Spatrick               const hash_multiset<Value, Hash, Pred, Alloc>& y);
19146035553Spatrick}  // __gnu_cxx
19246035553Spatrick
19346035553Spatrick*/
19446035553Spatrick
195*4bdff4beSrobert#include <__assert> // all public C++ headers provide the assertion handler
19646035553Spatrick#include <__config>
19746035553Spatrick#include <__hash_table>
198*4bdff4beSrobert#include <algorithm>
19946035553Spatrick#include <ext/__hash>
200*4bdff4beSrobert#include <functional>
20146035553Spatrick
20276d0caaeSpatrick#if defined(__DEPRECATED) && __DEPRECATED
20346035553Spatrick#if defined(_LIBCPP_WARNING)
20446035553Spatrick    _LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set>")
20546035553Spatrick#else
20646035553Spatrick#   warning Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set>
20746035553Spatrick#endif
20846035553Spatrick#endif
20946035553Spatrick
210*4bdff4beSrobert#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
211*4bdff4beSrobert#  pragma GCC system_header
212*4bdff4beSrobert#endif
213*4bdff4beSrobert
21446035553Spatricknamespace __gnu_cxx {
21546035553Spatrick
21646035553Spatrick
21746035553Spatricktemplate <class _Value, class _Hash = hash<_Value>, class _Pred = std::equal_to<_Value>,
21846035553Spatrick          class _Alloc = std::allocator<_Value> >
21946035553Spatrickclass _LIBCPP_TEMPLATE_VIS hash_set
22046035553Spatrick{
22146035553Spatrickpublic:
22246035553Spatrick    // types
22346035553Spatrick    typedef _Value                                                     key_type;
22446035553Spatrick    typedef key_type                                                   value_type;
22546035553Spatrick    typedef _Hash                                                      hasher;
22646035553Spatrick    typedef _Pred                                                      key_equal;
22746035553Spatrick    typedef _Alloc                                                     allocator_type;
22846035553Spatrick    typedef value_type&                                                reference;
22946035553Spatrick    typedef const value_type&                                          const_reference;
23046035553Spatrick
23146035553Spatrickprivate:
23246035553Spatrick    typedef std::__hash_table<value_type, hasher, key_equal, allocator_type> __table;
23346035553Spatrick
23446035553Spatrick    __table __table_;
23546035553Spatrick
23646035553Spatrickpublic:
23746035553Spatrick    typedef typename __table::pointer         pointer;
23846035553Spatrick    typedef typename __table::const_pointer   const_pointer;
23946035553Spatrick    typedef typename __table::size_type       size_type;
24046035553Spatrick    typedef typename __table::difference_type difference_type;
24146035553Spatrick
24246035553Spatrick    typedef typename __table::const_iterator       iterator;
24346035553Spatrick    typedef typename __table::const_iterator       const_iterator;
24446035553Spatrick
24546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
24646035553Spatrick    hash_set() { }
24746035553Spatrick    explicit hash_set(size_type __n, const hasher& __hf = hasher(),
24846035553Spatrick                           const key_equal& __eql = key_equal());
24946035553Spatrick    hash_set(size_type __n, const hasher& __hf, const key_equal& __eql,
25046035553Spatrick                  const allocator_type& __a);
25146035553Spatrick    template <class _InputIterator>
25246035553Spatrick        hash_set(_InputIterator __first, _InputIterator __last);
25346035553Spatrick    template <class _InputIterator>
25446035553Spatrick        hash_set(_InputIterator __first, _InputIterator __last,
25546035553Spatrick                      size_type __n, const hasher& __hf = hasher(),
25646035553Spatrick                      const key_equal& __eql = key_equal());
25746035553Spatrick    template <class _InputIterator>
25846035553Spatrick        hash_set(_InputIterator __first, _InputIterator __last,
25946035553Spatrick                      size_type __n, const hasher& __hf, const key_equal& __eql,
26046035553Spatrick                      const allocator_type& __a);
26146035553Spatrick    hash_set(const hash_set& __u);
26246035553Spatrick
26346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
26446035553Spatrick    allocator_type get_allocator() const
26546035553Spatrick        {return allocator_type(__table_.__node_alloc());}
26646035553Spatrick
26746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
26846035553Spatrick    bool      empty() const {return __table_.size() == 0;}
26946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
27046035553Spatrick    size_type size() const  {return __table_.size();}
27146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
27246035553Spatrick    size_type max_size() const {return __table_.max_size();}
27346035553Spatrick
27446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
27546035553Spatrick    iterator       begin()        {return __table_.begin();}
27646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
27746035553Spatrick    iterator       end()          {return __table_.end();}
27846035553Spatrick    _LIBCPP_INLINE_VISIBILITY
27946035553Spatrick    const_iterator begin()  const {return __table_.begin();}
28046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
28146035553Spatrick    const_iterator end()    const {return __table_.end();}
28246035553Spatrick
28346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
28446035553Spatrick    std::pair<iterator, bool> insert(const value_type& __x)
28546035553Spatrick        {return __table_.__insert_unique(__x);}
28646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
28746035553Spatrick    iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;}
28846035553Spatrick    template <class _InputIterator>
28946035553Spatrick        _LIBCPP_INLINE_VISIBILITY
29046035553Spatrick        void insert(_InputIterator __first, _InputIterator __last);
29146035553Spatrick
29246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
29346035553Spatrick    void erase(const_iterator __p) {__table_.erase(__p);}
29446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
29546035553Spatrick    size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
29646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
29746035553Spatrick    void erase(const_iterator __first, const_iterator __last)
29846035553Spatrick        {__table_.erase(__first, __last);}
29946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
30046035553Spatrick    void clear() {__table_.clear();}
30146035553Spatrick
30246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
30346035553Spatrick    void swap(hash_set& __u) {__table_.swap(__u.__table_);}
30446035553Spatrick
30546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
30646035553Spatrick    hasher hash_funct() const {return __table_.hash_function();}
30746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
30846035553Spatrick    key_equal key_eq() const {return __table_.key_eq();}
30946035553Spatrick
31046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
31146035553Spatrick    iterator       find(const key_type& __k)       {return __table_.find(__k);}
31246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
31346035553Spatrick    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
31446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
31546035553Spatrick    size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
31646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
31746035553Spatrick    std::pair<iterator, iterator>             equal_range(const key_type& __k)
31846035553Spatrick        {return __table_.__equal_range_unique(__k);}
31946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
32046035553Spatrick    std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
32146035553Spatrick        {return __table_.__equal_range_unique(__k);}
32246035553Spatrick
32346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
32446035553Spatrick    size_type bucket_count() const {return __table_.bucket_count();}
32546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
32646035553Spatrick    size_type max_bucket_count() const {return __table_.max_bucket_count();}
32746035553Spatrick
32846035553Spatrick    _LIBCPP_INLINE_VISIBILITY
32946035553Spatrick    size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);}
33046035553Spatrick
33146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
332*4bdff4beSrobert    void resize(size_type __n) {__table_.__rehash_unique(__n);}
33346035553Spatrick};
33446035553Spatrick
33546035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
33646035553Spatrickhash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n,
33746035553Spatrick        const hasher& __hf, const key_equal& __eql)
33846035553Spatrick    : __table_(__hf, __eql)
33946035553Spatrick{
340*4bdff4beSrobert    __table_.__rehash_unique(__n);
34146035553Spatrick}
34246035553Spatrick
34346035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
34446035553Spatrickhash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n,
34546035553Spatrick        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
34646035553Spatrick    : __table_(__hf, __eql, __a)
34746035553Spatrick{
348*4bdff4beSrobert    __table_.__rehash_unique(__n);
34946035553Spatrick}
35046035553Spatrick
35146035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
35246035553Spatricktemplate <class _InputIterator>
35346035553Spatrickhash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
35446035553Spatrick        _InputIterator __first, _InputIterator __last)
35546035553Spatrick{
35646035553Spatrick    insert(__first, __last);
35746035553Spatrick}
35846035553Spatrick
35946035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
36046035553Spatricktemplate <class _InputIterator>
36146035553Spatrickhash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
36246035553Spatrick        _InputIterator __first, _InputIterator __last, size_type __n,
36346035553Spatrick        const hasher& __hf, const key_equal& __eql)
36446035553Spatrick    : __table_(__hf, __eql)
36546035553Spatrick{
366*4bdff4beSrobert    __table_.__rehash_unique(__n);
36746035553Spatrick    insert(__first, __last);
36846035553Spatrick}
36946035553Spatrick
37046035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
37146035553Spatricktemplate <class _InputIterator>
37246035553Spatrickhash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
37346035553Spatrick        _InputIterator __first, _InputIterator __last, size_type __n,
37446035553Spatrick        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
37546035553Spatrick    : __table_(__hf, __eql, __a)
37646035553Spatrick{
377*4bdff4beSrobert    __table_.__rehash_unique(__n);
37846035553Spatrick    insert(__first, __last);
37946035553Spatrick}
38046035553Spatrick
38146035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
38246035553Spatrickhash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(
38346035553Spatrick        const hash_set& __u)
38446035553Spatrick    : __table_(__u.__table_)
38546035553Spatrick{
386*4bdff4beSrobert    __table_.__rehash_unique(__u.bucket_count());
38746035553Spatrick    insert(__u.begin(), __u.end());
38846035553Spatrick}
38946035553Spatrick
39046035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
39146035553Spatricktemplate <class _InputIterator>
39246035553Spatrickinline
39346035553Spatrickvoid
39446035553Spatrickhash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
39546035553Spatrick                                                    _InputIterator __last)
39646035553Spatrick{
39746035553Spatrick    for (; __first != __last; ++__first)
39846035553Spatrick        __table_.__insert_unique(*__first);
39946035553Spatrick}
40046035553Spatrick
40146035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
40246035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
40346035553Spatrickvoid
40446035553Spatrickswap(hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
40546035553Spatrick     hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
40646035553Spatrick{
40746035553Spatrick    __x.swap(__y);
40846035553Spatrick}
40946035553Spatrick
41046035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
411*4bdff4beSrobert_LIBCPP_HIDE_FROM_ABI bool
41246035553Spatrickoperator==(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
41346035553Spatrick           const hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
41446035553Spatrick{
41546035553Spatrick    if (__x.size() != __y.size())
41646035553Spatrick        return false;
41746035553Spatrick    typedef typename hash_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
41846035553Spatrick                                                                 const_iterator;
41946035553Spatrick    for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
42046035553Spatrick            __i != __ex; ++__i)
42146035553Spatrick    {
42246035553Spatrick        const_iterator __j = __y.find(*__i);
42346035553Spatrick        if (__j == __ey || !(*__i == *__j))
42446035553Spatrick            return false;
42546035553Spatrick    }
42646035553Spatrick    return true;
42746035553Spatrick}
42846035553Spatrick
42946035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
43046035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
43146035553Spatrickbool
43246035553Spatrickoperator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x,
43346035553Spatrick           const hash_set<_Value, _Hash, _Pred, _Alloc>& __y)
43446035553Spatrick{
43546035553Spatrick    return !(__x == __y);
43646035553Spatrick}
43746035553Spatrick
43846035553Spatricktemplate <class _Value, class _Hash = hash<_Value>, class _Pred = std::equal_to<_Value>,
43946035553Spatrick          class _Alloc = std::allocator<_Value> >
44046035553Spatrickclass _LIBCPP_TEMPLATE_VIS hash_multiset
44146035553Spatrick{
44246035553Spatrickpublic:
44346035553Spatrick    // types
44446035553Spatrick    typedef _Value                                                     key_type;
44546035553Spatrick    typedef key_type                                                   value_type;
44646035553Spatrick    typedef _Hash                                                      hasher;
44746035553Spatrick    typedef _Pred                                                      key_equal;
44846035553Spatrick    typedef _Alloc                                                     allocator_type;
44946035553Spatrick    typedef value_type&                                                reference;
45046035553Spatrick    typedef const value_type&                                          const_reference;
45146035553Spatrick
45246035553Spatrickprivate:
45346035553Spatrick    typedef std::__hash_table<value_type, hasher, key_equal, allocator_type> __table;
45446035553Spatrick
45546035553Spatrick    __table __table_;
45646035553Spatrick
45746035553Spatrickpublic:
45846035553Spatrick    typedef typename __table::pointer         pointer;
45946035553Spatrick    typedef typename __table::const_pointer   const_pointer;
46046035553Spatrick    typedef typename __table::size_type       size_type;
46146035553Spatrick    typedef typename __table::difference_type difference_type;
46246035553Spatrick
46346035553Spatrick    typedef typename __table::const_iterator       iterator;
46446035553Spatrick    typedef typename __table::const_iterator       const_iterator;
46546035553Spatrick
46646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
46746035553Spatrick    hash_multiset() { }
46846035553Spatrick    explicit hash_multiset(size_type __n, const hasher& __hf = hasher(),
46946035553Spatrick                                const key_equal& __eql = key_equal());
47046035553Spatrick    hash_multiset(size_type __n, const hasher& __hf,
47146035553Spatrick                       const key_equal& __eql, const allocator_type& __a);
47246035553Spatrick    template <class _InputIterator>
47346035553Spatrick        hash_multiset(_InputIterator __first, _InputIterator __last);
47446035553Spatrick    template <class _InputIterator>
47546035553Spatrick        hash_multiset(_InputIterator __first, _InputIterator __last,
47646035553Spatrick                      size_type __n, const hasher& __hf = hasher(),
47746035553Spatrick                      const key_equal& __eql = key_equal());
47846035553Spatrick    template <class _InputIterator>
47946035553Spatrick        hash_multiset(_InputIterator __first, _InputIterator __last,
48046035553Spatrick                      size_type __n , const hasher& __hf,
48146035553Spatrick                      const key_equal& __eql, const allocator_type& __a);
48246035553Spatrick    hash_multiset(const hash_multiset& __u);
48346035553Spatrick
48446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
48546035553Spatrick    allocator_type get_allocator() const
48646035553Spatrick        {return allocator_type(__table_.__node_alloc());}
48746035553Spatrick
48846035553Spatrick    _LIBCPP_INLINE_VISIBILITY
48946035553Spatrick    bool      empty() const {return __table_.size() == 0;}
49046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
49146035553Spatrick    size_type size() const  {return __table_.size();}
49246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
49346035553Spatrick    size_type max_size() const {return __table_.max_size();}
49446035553Spatrick
49546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
49646035553Spatrick    iterator       begin()        {return __table_.begin();}
49746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
49846035553Spatrick    iterator       end()          {return __table_.end();}
49946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
50046035553Spatrick    const_iterator begin()  const {return __table_.begin();}
50146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
50246035553Spatrick    const_iterator end()    const {return __table_.end();}
50346035553Spatrick
50446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
50546035553Spatrick    iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
50646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
50746035553Spatrick    iterator insert(const_iterator, const value_type& __x) {return insert(__x);}
50846035553Spatrick    template <class _InputIterator>
50946035553Spatrick        _LIBCPP_INLINE_VISIBILITY
51046035553Spatrick        void insert(_InputIterator __first, _InputIterator __last);
51146035553Spatrick
51246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
51346035553Spatrick    void erase(const_iterator __p) {__table_.erase(__p);}
51446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
51546035553Spatrick    size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
51646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
51746035553Spatrick    void erase(const_iterator __first, const_iterator __last)
51846035553Spatrick        {__table_.erase(__first, __last);}
51946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
52046035553Spatrick    void clear() {__table_.clear();}
52146035553Spatrick
52246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
52346035553Spatrick    void swap(hash_multiset& __u) {__table_.swap(__u.__table_);}
52446035553Spatrick
52546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
52646035553Spatrick    hasher hash_funct() const {return __table_.hash_function();}
52746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
52846035553Spatrick    key_equal key_eq() const {return __table_.key_eq();}
52946035553Spatrick
53046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
53146035553Spatrick    iterator       find(const key_type& __k)       {return __table_.find(__k);}
53246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
53346035553Spatrick    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
53446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
53546035553Spatrick    size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
53646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
53746035553Spatrick    std::pair<iterator, iterator>             equal_range(const key_type& __k)
53846035553Spatrick        {return __table_.__equal_range_multi(__k);}
53946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
54046035553Spatrick    std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
54146035553Spatrick        {return __table_.__equal_range_multi(__k);}
54246035553Spatrick
54346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
54446035553Spatrick    size_type bucket_count() const {return __table_.bucket_count();}
54546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
54646035553Spatrick    size_type max_bucket_count() const {return __table_.max_bucket_count();}
54746035553Spatrick
54846035553Spatrick    _LIBCPP_INLINE_VISIBILITY
54946035553Spatrick    size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);}
55046035553Spatrick
55146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
552*4bdff4beSrobert    void resize(size_type __n) {__table_.__rehash_multi(__n);}
55346035553Spatrick};
55446035553Spatrick
55546035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
55646035553Spatrickhash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
55746035553Spatrick        size_type __n, const hasher& __hf, const key_equal& __eql)
55846035553Spatrick    : __table_(__hf, __eql)
55946035553Spatrick{
560*4bdff4beSrobert    __table_.__rehash_multi(__n);
56146035553Spatrick}
56246035553Spatrick
56346035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
56446035553Spatrickhash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
56546035553Spatrick        size_type __n, const hasher& __hf, const key_equal& __eql,
56646035553Spatrick        const allocator_type& __a)
56746035553Spatrick    : __table_(__hf, __eql, __a)
56846035553Spatrick{
569*4bdff4beSrobert    __table_.__rehash_multi(__n);
57046035553Spatrick}
57146035553Spatrick
57246035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
57346035553Spatricktemplate <class _InputIterator>
57446035553Spatrickhash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
57546035553Spatrick        _InputIterator __first, _InputIterator __last)
57646035553Spatrick{
57746035553Spatrick    insert(__first, __last);
57846035553Spatrick}
57946035553Spatrick
58046035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
58146035553Spatricktemplate <class _InputIterator>
58246035553Spatrickhash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
58346035553Spatrick        _InputIterator __first, _InputIterator __last, size_type __n,
58446035553Spatrick        const hasher& __hf, const key_equal& __eql)
58546035553Spatrick    : __table_(__hf, __eql)
58646035553Spatrick{
587*4bdff4beSrobert    __table_.__rehash_multi(__n);
58846035553Spatrick    insert(__first, __last);
58946035553Spatrick}
59046035553Spatrick
59146035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
59246035553Spatricktemplate <class _InputIterator>
59346035553Spatrickhash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
59446035553Spatrick        _InputIterator __first, _InputIterator __last, size_type __n,
59546035553Spatrick        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
59646035553Spatrick    : __table_(__hf, __eql, __a)
59746035553Spatrick{
598*4bdff4beSrobert    __table_.__rehash_multi(__n);
59946035553Spatrick    insert(__first, __last);
60046035553Spatrick}
60146035553Spatrick
60246035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
60346035553Spatrickhash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset(
60446035553Spatrick        const hash_multiset& __u)
60546035553Spatrick    : __table_(__u.__table_)
60646035553Spatrick{
607*4bdff4beSrobert    __table_.__rehash_multi(__u.bucket_count());
60846035553Spatrick    insert(__u.begin(), __u.end());
60946035553Spatrick}
61046035553Spatrick
61146035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
61246035553Spatricktemplate <class _InputIterator>
61346035553Spatrickinline
61446035553Spatrickvoid
61546035553Spatrickhash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
61646035553Spatrick                                                    _InputIterator __last)
61746035553Spatrick{
61846035553Spatrick    for (; __first != __last; ++__first)
61946035553Spatrick        __table_.__insert_multi(*__first);
62046035553Spatrick}
62146035553Spatrick
62246035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
62346035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
62446035553Spatrickvoid
62546035553Spatrickswap(hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
62646035553Spatrick     hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
62746035553Spatrick{
62846035553Spatrick    __x.swap(__y);
62946035553Spatrick}
63046035553Spatrick
63146035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
632*4bdff4beSrobert_LIBCPP_HIDE_FROM_ABI bool
63346035553Spatrickoperator==(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
63446035553Spatrick           const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
63546035553Spatrick{
63646035553Spatrick    if (__x.size() != __y.size())
63746035553Spatrick        return false;
63846035553Spatrick    typedef typename hash_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
63946035553Spatrick                                                                 const_iterator;
64046035553Spatrick    typedef std::pair<const_iterator, const_iterator> _EqRng;
64146035553Spatrick    for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
64246035553Spatrick    {
64346035553Spatrick        _EqRng __xeq = __x.equal_range(*__i);
64446035553Spatrick        _EqRng __yeq = __y.equal_range(*__i);
64546035553Spatrick        if (_VSTD::distance(__xeq.first, __xeq.second) !=
64646035553Spatrick            _VSTD::distance(__yeq.first, __yeq.second) ||
64746035553Spatrick                  !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
64846035553Spatrick            return false;
64946035553Spatrick        __i = __xeq.second;
65046035553Spatrick    }
65146035553Spatrick    return true;
65246035553Spatrick}
65346035553Spatrick
65446035553Spatricktemplate <class _Value, class _Hash, class _Pred, class _Alloc>
65546035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
65646035553Spatrickbool
65746035553Spatrickoperator!=(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
65846035553Spatrick           const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
65946035553Spatrick{
66046035553Spatrick    return !(__x == __y);
66146035553Spatrick}
66246035553Spatrick
663*4bdff4beSrobert} // namespace __gnu_cxx
664*4bdff4beSrobert
665*4bdff4beSrobert#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
666*4bdff4beSrobert#  include <concepts>
667*4bdff4beSrobert#  include <iterator>
668*4bdff4beSrobert#endif
66946035553Spatrick
67046035553Spatrick#endif // _LIBCPP_HASH_SET
671