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