Home | History | Annotate | Line # | Download | only in ext
      1  1.1  joerg // -*- C++ -*-
      2  1.1  joerg //===-------------------------- hash_map ----------------------------------===//
      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_MAP
     11  1.1  joerg #define _LIBCPP_HASH_MAP
     12  1.1  joerg 
     13  1.1  joerg /*
     14  1.1  joerg 
     15  1.1  joerg     hash_map 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 Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
     21  1.1  joerg           class Alloc = allocator<pair<const Key, T>>>
     22  1.1  joerg class hash_map
     23  1.1  joerg {
     24  1.1  joerg public:
     25  1.1  joerg     // types
     26  1.1  joerg     typedef Key                                                        key_type;
     27  1.1  joerg     typedef T                                                          mapped_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 pair<const key_type, mapped_type>                          value_type;
     32  1.1  joerg     typedef value_type&                                                reference;
     33  1.1  joerg     typedef const value_type&                                          const_reference;
     34  1.1  joerg     typedef typename allocator_traits<allocator_type>::pointer         pointer;
     35  1.1  joerg     typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
     36  1.1  joerg     typedef typename allocator_traits<allocator_type>::size_type       size_type;
     37  1.1  joerg     typedef typename allocator_traits<allocator_type>::difference_type difference_type;
     38  1.1  joerg 
     39  1.1  joerg     typedef /unspecified/ iterator;
     40  1.1  joerg     typedef /unspecified/ const_iterator;
     41  1.1  joerg 
     42  1.1  joerg     hash_map();
     43  1.1  joerg     explicit hash_map(size_type n, const hasher& hf = hasher(),
     44  1.1  joerg                            const key_equal& eql = key_equal(),
     45  1.1  joerg                            const allocator_type& a = allocator_type());
     46  1.1  joerg     template <class InputIterator>
     47  1.1  joerg     hash_map(InputIterator f, InputIterator l);
     48  1.1  joerg     template <class InputIterator>
     49  1.1  joerg     hash_map(InputIterator f, InputIterator l,
     50  1.1  joerg                 size_type n, const hasher& hf = hasher(),
     51  1.1  joerg                 const key_equal& eql = key_equal(),
     52  1.1  joerg                 const allocator_type& a = allocator_type());
     53  1.1  joerg     hash_map(const hash_map&);
     54  1.1  joerg     ~hash_map();
     55  1.1  joerg     hash_map& operator=(const hash_map&);
     56  1.1  joerg 
     57  1.1  joerg     allocator_type get_allocator() const;
     58  1.1  joerg 
     59  1.1  joerg     bool      empty() const;
     60  1.1  joerg     size_type size() const;
     61  1.1  joerg     size_type max_size() const;
     62  1.1  joerg 
     63  1.1  joerg     iterator       begin();
     64  1.1  joerg     iterator       end();
     65  1.1  joerg     const_iterator begin()  const;
     66  1.1  joerg     const_iterator end()    const;
     67  1.1  joerg 
     68  1.1  joerg     pair<iterator, bool> insert(const value_type& obj);
     69  1.1  joerg     template <class InputIterator>
     70  1.1  joerg         void insert(InputIterator first, InputIterator last);
     71  1.1  joerg 
     72  1.1  joerg     void erase(const_iterator position);
     73  1.1  joerg     size_type erase(const key_type& k);
     74  1.1  joerg     void erase(const_iterator first, const_iterator last);
     75  1.1  joerg     void clear();
     76  1.1  joerg 
     77  1.1  joerg     void swap(hash_map&);
     78  1.1  joerg 
     79  1.1  joerg     hasher hash_funct() const;
     80  1.1  joerg     key_equal key_eq() const;
     81  1.1  joerg 
     82  1.1  joerg     iterator       find(const key_type& k);
     83  1.1  joerg     const_iterator find(const key_type& k) const;
     84  1.1  joerg     size_type count(const key_type& k) const;
     85  1.1  joerg     pair<iterator, iterator>             equal_range(const key_type& k);
     86  1.1  joerg     pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
     87  1.1  joerg 
     88  1.1  joerg     mapped_type& operator[](const key_type& k);
     89  1.1  joerg 
     90  1.1  joerg     size_type bucket_count() const;
     91  1.1  joerg     size_type max_bucket_count() const;
     92  1.1  joerg 
     93  1.1  joerg     size_type elems_in_bucket(size_type n) const;
     94  1.1  joerg 
     95  1.1  joerg     void resize(size_type n);
     96  1.1  joerg };
     97  1.1  joerg 
     98  1.1  joerg template <class Key, class T, class Hash, class Pred, class Alloc>
     99  1.1  joerg     void swap(hash_map<Key, T, Hash, Pred, Alloc>& x,
    100  1.1  joerg               hash_map<Key, T, Hash, Pred, Alloc>& y);
    101  1.1  joerg 
    102  1.1  joerg template <class Key, class T, class Hash, class Pred, class Alloc>
    103  1.1  joerg     bool
    104  1.1  joerg     operator==(const hash_map<Key, T, Hash, Pred, Alloc>& x,
    105  1.1  joerg                const hash_map<Key, T, Hash, Pred, Alloc>& y);
    106  1.1  joerg 
    107  1.1  joerg template <class Key, class T, class Hash, class Pred, class Alloc>
    108  1.1  joerg     bool
    109  1.1  joerg     operator!=(const hash_map<Key, T, Hash, Pred, Alloc>& x,
    110  1.1  joerg                const hash_map<Key, T, Hash, Pred, Alloc>& y);
    111  1.1  joerg 
    112  1.1  joerg template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
    113  1.1  joerg           class Alloc = allocator<pair<const Key, T>>>
    114  1.1  joerg class hash_multimap
    115  1.1  joerg {
    116  1.1  joerg public:
    117  1.1  joerg     // types
    118  1.1  joerg     typedef Key                                                        key_type;
    119  1.1  joerg     typedef T                                                          mapped_type;
    120  1.1  joerg     typedef Hash                                                       hasher;
    121  1.1  joerg     typedef Pred                                                       key_equal;
    122  1.1  joerg     typedef Alloc                                                      allocator_type;
    123  1.1  joerg     typedef pair<const key_type, mapped_type>                          value_type;
    124  1.1  joerg     typedef value_type&                                                reference;
    125  1.1  joerg     typedef const value_type&                                          const_reference;
    126  1.1  joerg     typedef typename allocator_traits<allocator_type>::pointer         pointer;
    127  1.1  joerg     typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
    128  1.1  joerg     typedef typename allocator_traits<allocator_type>::size_type       size_type;
    129  1.1  joerg     typedef typename allocator_traits<allocator_type>::difference_type difference_type;
    130  1.1  joerg 
    131  1.1  joerg     typedef /unspecified/ iterator;
    132  1.1  joerg     typedef /unspecified/ const_iterator;
    133  1.1  joerg 
    134  1.1  joerg     explicit hash_multimap(size_type n = 193, const hasher& hf = hasher(),
    135  1.1  joerg                            const key_equal& eql = key_equal(),
    136  1.1  joerg                            const allocator_type& a = allocator_type());
    137  1.1  joerg     template <class InputIterator>
    138  1.1  joerg         hash_multimap(InputIterator f, InputIterator l,
    139  1.1  joerg                       size_type n = 193, const hasher& hf = hasher(),
    140  1.1  joerg                       const key_equal& eql = key_equal(),
    141  1.1  joerg                       const allocator_type& a = allocator_type());
    142  1.1  joerg     explicit hash_multimap(const allocator_type&);
    143  1.1  joerg     hash_multimap(const hash_multimap&);
    144  1.1  joerg     ~hash_multimap();
    145  1.1  joerg     hash_multimap& operator=(const hash_multimap&);
    146  1.1  joerg 
    147  1.1  joerg     allocator_type get_allocator() const;
    148  1.1  joerg 
    149  1.1  joerg     bool      empty() const;
    150  1.1  joerg     size_type size() const;
    151  1.1  joerg     size_type max_size() const;
    152  1.1  joerg 
    153  1.1  joerg     iterator       begin();
    154  1.1  joerg     iterator       end();
    155  1.1  joerg     const_iterator begin()  const;
    156  1.1  joerg     const_iterator end()    const;
    157  1.1  joerg 
    158  1.1  joerg     iterator insert(const value_type& obj);
    159  1.1  joerg     template <class InputIterator>
    160  1.1  joerg         void insert(InputIterator first, InputIterator last);
    161  1.1  joerg 
    162  1.1  joerg     void erase(const_iterator position);
    163  1.1  joerg     size_type erase(const key_type& k);
    164  1.1  joerg     void erase(const_iterator first, const_iterator last);
    165  1.1  joerg     void clear();
    166  1.1  joerg 
    167  1.1  joerg     void swap(hash_multimap&);
    168  1.1  joerg 
    169  1.1  joerg     hasher hash_funct() const;
    170  1.1  joerg     key_equal key_eq() const;
    171  1.1  joerg 
    172  1.1  joerg     iterator       find(const key_type& k);
    173  1.1  joerg     const_iterator find(const key_type& k) const;
    174  1.1  joerg     size_type count(const key_type& k) const;
    175  1.1  joerg     pair<iterator, iterator>             equal_range(const key_type& k);
    176  1.1  joerg     pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
    177  1.1  joerg 
    178  1.1  joerg     size_type bucket_count() const;
    179  1.1  joerg     size_type max_bucket_count() const;
    180  1.1  joerg 
    181  1.1  joerg     size_type elems_in_bucket(size_type n) const;
    182  1.1  joerg 
    183  1.1  joerg     void resize(size_type n);
    184  1.1  joerg };
    185  1.1  joerg 
    186  1.1  joerg template <class Key, class T, class Hash, class Pred, class Alloc>
    187  1.1  joerg     void swap(hash_multimap<Key, T, Hash, Pred, Alloc>& x,
    188  1.1  joerg               hash_multimap<Key, T, Hash, Pred, Alloc>& y);
    189  1.1  joerg 
    190  1.1  joerg template <class Key, class T, class Hash, class Pred, class Alloc>
    191  1.1  joerg     bool
    192  1.1  joerg     operator==(const hash_multimap<Key, T, Hash, Pred, Alloc>& x,
    193  1.1  joerg                const hash_multimap<Key, T, Hash, Pred, Alloc>& y);
    194  1.1  joerg 
    195  1.1  joerg template <class Key, class T, class Hash, class Pred, class Alloc>
    196  1.1  joerg     bool
    197  1.1  joerg     operator!=(const hash_multimap<Key, T, Hash, Pred, Alloc>& x,
    198  1.1  joerg                const hash_multimap<Key, T, Hash, Pred, Alloc>& y);
    199  1.1  joerg 
    200  1.1  joerg }  // __gnu_cxx
    201  1.1  joerg 
    202  1.1  joerg */
    203  1.1  joerg 
    204  1.1  joerg #include <__config>
    205  1.1  joerg #include <__hash_table>
    206  1.1  joerg #include <functional>
    207  1.1  joerg #include <stdexcept>
    208  1.1  joerg #include <type_traits>
    209  1.1  joerg #include <ext/__hash>
    210  1.1  joerg 
    211  1.1  joerg #if defined(__DEPRECATED) && __DEPRECATED
    212  1.1  joerg #if defined(_LIBCPP_WARNING)
    213  1.1  joerg     _LIBCPP_WARNING("Use of the header <ext/hash_map> is deprecated.  Migrate to <unordered_map>")
    214  1.1  joerg #else
    215  1.1  joerg #   warning Use of the header <ext/hash_map> is deprecated.  Migrate to <unordered_map>
    216  1.1  joerg #endif
    217  1.1  joerg #endif
    218  1.1  joerg 
    219  1.1  joerg #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
    220  1.1  joerg #pragma GCC system_header
    221  1.1  joerg #endif
    222  1.1  joerg 
    223  1.1  joerg namespace __gnu_cxx {
    224  1.1  joerg 
    225  1.1  joerg template <class _Tp, class _Hash,
    226  1.1  joerg           bool = std::is_empty<_Hash>::value && !std::__libcpp_is_final<_Hash>::value
    227  1.1  joerg         >
    228  1.1  joerg class __hash_map_hasher
    229  1.1  joerg     : private _Hash
    230  1.1  joerg {
    231  1.1  joerg public:
    232  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : _Hash() {}
    233  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : _Hash(__h) {}
    234  1.1  joerg     _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return *this;}
    235  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    236  1.1  joerg     size_t operator()(const _Tp& __x) const
    237  1.1  joerg         {return static_cast<const _Hash&>(*this)(__x.first);}
    238  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    239  1.1  joerg     size_t operator()(const typename _Tp::first_type& __x) const
    240  1.1  joerg         {return static_cast<const _Hash&>(*this)(__x);}
    241  1.1  joerg };
    242  1.1  joerg 
    243  1.1  joerg template <class _Tp, class _Hash>
    244  1.1  joerg class __hash_map_hasher<_Tp, _Hash, false>
    245  1.1  joerg {
    246  1.1  joerg     _Hash __hash_;
    247  1.1  joerg public:
    248  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : __hash_() {}
    249  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : __hash_(__h) {}
    250  1.1  joerg     _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return __hash_;}
    251  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    252  1.1  joerg     size_t operator()(const _Tp& __x) const
    253  1.1  joerg         {return __hash_(__x.first);}
    254  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    255  1.1  joerg     size_t operator()(const typename _Tp::first_type& __x) const
    256  1.1  joerg         {return __hash_(__x);}
    257  1.1  joerg };
    258  1.1  joerg 
    259  1.1  joerg template <class _Tp, class _Pred,
    260  1.1  joerg           bool = std::is_empty<_Pred>::value && !std::__libcpp_is_final<_Pred>::value
    261  1.1  joerg          >
    262  1.1  joerg class __hash_map_equal
    263  1.1  joerg     : private _Pred
    264  1.1  joerg {
    265  1.1  joerg public:
    266  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : _Pred() {}
    267  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : _Pred(__p) {}
    268  1.1  joerg     _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return *this;}
    269  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    270  1.1  joerg     bool operator()(const _Tp& __x, const _Tp& __y) const
    271  1.1  joerg         {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
    272  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    273  1.1  joerg     bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
    274  1.1  joerg         {return static_cast<const _Pred&>(*this)(__x, __y.first);}
    275  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    276  1.1  joerg     bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
    277  1.1  joerg         {return static_cast<const _Pred&>(*this)(__x.first, __y);}
    278  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    279  1.1  joerg     bool operator()(const typename _Tp::first_type& __x,
    280  1.1  joerg                     const typename _Tp::first_type& __y) const
    281  1.1  joerg         {return static_cast<const _Pred&>(*this)(__x, __y);}
    282  1.1  joerg };
    283  1.1  joerg 
    284  1.1  joerg template <class _Tp, class _Pred>
    285  1.1  joerg class __hash_map_equal<_Tp, _Pred, false>
    286  1.1  joerg {
    287  1.1  joerg     _Pred __pred_;
    288  1.1  joerg public:
    289  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : __pred_() {}
    290  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : __pred_(__p) {}
    291  1.1  joerg     _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return __pred_;}
    292  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    293  1.1  joerg     bool operator()(const _Tp& __x, const _Tp& __y) const
    294  1.1  joerg         {return __pred_(__x.first, __y.first);}
    295  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    296  1.1  joerg     bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
    297  1.1  joerg         {return __pred_(__x, __y.first);}
    298  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    299  1.1  joerg     bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
    300  1.1  joerg         {return __pred_(__x.first, __y);}
    301  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    302  1.1  joerg     bool operator()(const typename _Tp::first_type& __x,
    303  1.1  joerg                     const typename _Tp::first_type& __y) const
    304  1.1  joerg         {return __pred_(__x, __y);}
    305  1.1  joerg };
    306  1.1  joerg 
    307  1.1  joerg template <class _Alloc>
    308  1.1  joerg class __hash_map_node_destructor
    309  1.1  joerg {
    310  1.1  joerg     typedef _Alloc                              allocator_type;
    311  1.1  joerg     typedef std::allocator_traits<allocator_type>    __alloc_traits;
    312  1.1  joerg     typedef typename __alloc_traits::value_type::__node_value_type value_type;
    313  1.1  joerg public:
    314  1.1  joerg     typedef typename __alloc_traits::pointer    pointer;
    315  1.1  joerg private:
    316  1.1  joerg     typedef typename value_type::first_type     first_type;
    317  1.1  joerg     typedef typename value_type::second_type    second_type;
    318  1.1  joerg 
    319  1.1  joerg     allocator_type& __na_;
    320  1.1  joerg 
    321  1.1  joerg public:
    322  1.1  joerg     bool __first_constructed;
    323  1.1  joerg     bool __second_constructed;
    324  1.1  joerg 
    325  1.1  joerg     __hash_map_node_destructor(__hash_map_node_destructor const&) = default;
    326  1.1  joerg     __hash_map_node_destructor& operator=(const __hash_map_node_destructor&) = delete;
    327  1.1  joerg 
    328  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    329  1.1  joerg     explicit __hash_map_node_destructor(allocator_type& __na)
    330  1.1  joerg         : __na_(__na),
    331  1.1  joerg           __first_constructed(false),
    332  1.1  joerg           __second_constructed(false)
    333  1.1  joerg         {}
    334  1.1  joerg 
    335  1.1  joerg #ifndef _LIBCPP_CXX03_LANG
    336  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    337  1.1  joerg     __hash_map_node_destructor(std::__hash_node_destructor<allocator_type>&& __x)
    338  1.1  joerg         : __na_(__x.__na_),
    339  1.1  joerg           __first_constructed(__x.__value_constructed),
    340  1.1  joerg           __second_constructed(__x.__value_constructed)
    341  1.1  joerg         {
    342  1.1  joerg             __x.__value_constructed = false;
    343  1.1  joerg         }
    344  1.1  joerg #else  // _LIBCPP_CXX03_LANG
    345  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    346  1.1  joerg     __hash_map_node_destructor(const std::__hash_node_destructor<allocator_type>& __x)
    347  1.1  joerg         : __na_(__x.__na_),
    348  1.1  joerg           __first_constructed(__x.__value_constructed),
    349  1.1  joerg           __second_constructed(__x.__value_constructed)
    350  1.1  joerg         {
    351  1.1  joerg             const_cast<bool&>(__x.__value_constructed) = false;
    352  1.1  joerg         }
    353  1.1  joerg #endif // _LIBCPP_CXX03_LANG
    354  1.1  joerg 
    355  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    356  1.1  joerg     void operator()(pointer __p)
    357  1.1  joerg     {
    358  1.1  joerg         if (__second_constructed)
    359  1.1  joerg             __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second));
    360  1.1  joerg         if (__first_constructed)
    361  1.1  joerg             __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first));
    362  1.1  joerg         if (__p)
    363  1.1  joerg             __alloc_traits::deallocate(__na_, __p, 1);
    364  1.1  joerg     }
    365  1.1  joerg };
    366  1.1  joerg 
    367  1.1  joerg template <class _HashIterator>
    368  1.1  joerg class _LIBCPP_TEMPLATE_VIS __hash_map_iterator
    369  1.1  joerg {
    370  1.1  joerg     _HashIterator __i_;
    371  1.1  joerg 
    372  1.1  joerg     typedef const typename _HashIterator::value_type::first_type key_type;
    373  1.1  joerg     typedef typename _HashIterator::value_type::second_type      mapped_type;
    374  1.1  joerg public:
    375  1.1  joerg     typedef std::forward_iterator_tag                            iterator_category;
    376  1.1  joerg     typedef std::pair<key_type, mapped_type>                     value_type;
    377  1.1  joerg     typedef typename _HashIterator::difference_type              difference_type;
    378  1.1  joerg     typedef value_type&                                          reference;
    379  1.1  joerg     typedef typename std::__rebind_pointer<typename _HashIterator::pointer, value_type>::type
    380  1.1  joerg         pointer;
    381  1.1  joerg 
    382  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __hash_map_iterator() {}
    383  1.1  joerg 
    384  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __hash_map_iterator(_HashIterator __i) : __i_(__i) {}
    385  1.1  joerg 
    386  1.1  joerg     _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *operator->();}
    387  1.1  joerg     _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return (pointer)__i_.operator->();}
    388  1.1  joerg 
    389  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __hash_map_iterator& operator++() {++__i_; return *this;}
    390  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    391  1.1  joerg     __hash_map_iterator operator++(int)
    392  1.1  joerg     {
    393  1.1  joerg         __hash_map_iterator __t(*this);
    394  1.1  joerg         ++(*this);
    395  1.1  joerg         return __t;
    396  1.1  joerg     }
    397  1.1  joerg 
    398  1.1  joerg     friend _LIBCPP_INLINE_VISIBILITY
    399  1.1  joerg     bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
    400  1.1  joerg         {return __x.__i_ == __y.__i_;}
    401  1.1  joerg     friend _LIBCPP_INLINE_VISIBILITY
    402  1.1  joerg     bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
    403  1.1  joerg         {return __x.__i_ != __y.__i_;}
    404  1.1  joerg 
    405  1.1  joerg     template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_map;
    406  1.1  joerg     template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_multimap;
    407  1.1  joerg     template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
    408  1.1  joerg     template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
    409  1.1  joerg     template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
    410  1.1  joerg };
    411  1.1  joerg 
    412  1.1  joerg template <class _HashIterator>
    413  1.1  joerg class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator
    414  1.1  joerg {
    415  1.1  joerg     _HashIterator __i_;
    416  1.1  joerg 
    417  1.1  joerg     typedef const typename _HashIterator::value_type::first_type key_type;
    418  1.1  joerg     typedef typename _HashIterator::value_type::second_type      mapped_type;
    419  1.1  joerg public:
    420  1.1  joerg     typedef std::forward_iterator_tag                            iterator_category;
    421  1.1  joerg     typedef std::pair<key_type, mapped_type>                     value_type;
    422  1.1  joerg     typedef typename _HashIterator::difference_type              difference_type;
    423  1.1  joerg     typedef const value_type&                                    reference;
    424  1.1  joerg     typedef typename std::__rebind_pointer<typename _HashIterator::pointer, const value_type>::type
    425  1.1  joerg         pointer;
    426  1.1  joerg 
    427  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator() {}
    428  1.1  joerg 
    429  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    430  1.1  joerg     __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {}
    431  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    432  1.1  joerg     __hash_map_const_iterator(
    433  1.1  joerg             __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
    434  1.1  joerg                 : __i_(__i.__i_) {}
    435  1.1  joerg 
    436  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    437  1.1  joerg     reference operator*() const {return *operator->();}
    438  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    439  1.1  joerg     pointer operator->() const {return (pointer)__i_.operator->();}
    440  1.1  joerg 
    441  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    442  1.1  joerg     __hash_map_const_iterator& operator++() {++__i_; return *this;}
    443  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    444  1.1  joerg     __hash_map_const_iterator operator++(int)
    445  1.1  joerg     {
    446  1.1  joerg         __hash_map_const_iterator __t(*this);
    447  1.1  joerg         ++(*this);
    448  1.1  joerg         return __t;
    449  1.1  joerg     }
    450  1.1  joerg 
    451  1.1  joerg     friend _LIBCPP_INLINE_VISIBILITY
    452  1.1  joerg     bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
    453  1.1  joerg         {return __x.__i_ == __y.__i_;}
    454  1.1  joerg     friend _LIBCPP_INLINE_VISIBILITY
    455  1.1  joerg     bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
    456  1.1  joerg         {return __x.__i_ != __y.__i_;}
    457  1.1  joerg 
    458  1.1  joerg     template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_map;
    459  1.1  joerg     template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_multimap;
    460  1.1  joerg     template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
    461  1.1  joerg     template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
    462  1.1  joerg };
    463  1.1  joerg 
    464  1.1  joerg template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = std::equal_to<_Key>,
    465  1.1  joerg           class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
    466  1.1  joerg class _LIBCPP_TEMPLATE_VIS hash_map
    467  1.1  joerg {
    468  1.1  joerg public:
    469  1.1  joerg     // types
    470  1.1  joerg     typedef _Key                                           key_type;
    471  1.1  joerg     typedef _Tp                                            mapped_type;
    472  1.1  joerg     typedef _Tp                                            data_type;
    473  1.1  joerg     typedef _Hash                                          hasher;
    474  1.1  joerg     typedef _Pred                                          key_equal;
    475  1.1  joerg     typedef _Alloc                                         allocator_type;
    476  1.1  joerg     typedef std::pair<const key_type, mapped_type>         value_type;
    477  1.1  joerg     typedef value_type&                                    reference;
    478  1.1  joerg     typedef const value_type&                              const_reference;
    479  1.1  joerg 
    480  1.1  joerg private:
    481  1.1  joerg     typedef std::pair<key_type, mapped_type>                    __value_type;
    482  1.1  joerg     typedef __hash_map_hasher<__value_type, hasher>   __hasher;
    483  1.1  joerg     typedef __hash_map_equal<__value_type, key_equal> __key_equal;
    484  1.1  joerg     typedef typename std::__rebind_alloc_helper<
    485  1.1  joerg         std::allocator_traits<allocator_type>, __value_type>::type __allocator_type;
    486  1.1  joerg 
    487  1.1  joerg     typedef std::__hash_table<__value_type, __hasher,
    488  1.1  joerg                          __key_equal,  __allocator_type>   __table;
    489  1.1  joerg 
    490  1.1  joerg     __table __table_;
    491  1.1  joerg 
    492  1.1  joerg     typedef typename __table::__node_pointer               __node_pointer;
    493  1.1  joerg     typedef typename __table::__node_const_pointer         __node_const_pointer;
    494  1.1  joerg     typedef typename __table::__node_traits                __node_traits;
    495  1.1  joerg     typedef typename __table::__node_allocator             __node_allocator;
    496  1.1  joerg     typedef typename __table::__node                       __node;
    497  1.1  joerg     typedef __hash_map_node_destructor<__node_allocator>   _Dp;
    498  1.1  joerg     typedef std::unique_ptr<__node, _Dp>                   __node_holder;
    499  1.1  joerg     typedef std::allocator_traits<allocator_type>          __alloc_traits;
    500  1.1  joerg public:
    501  1.1  joerg     typedef typename __alloc_traits::pointer         pointer;
    502  1.1  joerg     typedef typename __alloc_traits::const_pointer   const_pointer;
    503  1.1  joerg     typedef typename __alloc_traits::size_type       size_type;
    504  1.1  joerg     typedef typename __alloc_traits::difference_type difference_type;
    505  1.1  joerg 
    506  1.1  joerg     typedef __hash_map_iterator<typename __table::iterator>       iterator;
    507  1.1  joerg     typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
    508  1.1  joerg 
    509  1.1  joerg     _LIBCPP_INLINE_VISIBILITY hash_map() { }
    510  1.1  joerg     explicit hash_map(size_type __n, const hasher& __hf = hasher(),
    511  1.1  joerg                            const key_equal& __eql = key_equal());
    512  1.1  joerg     hash_map(size_type __n, const hasher& __hf,
    513  1.1  joerg                   const key_equal& __eql,
    514  1.1  joerg                   const allocator_type& __a);
    515  1.1  joerg     template <class _InputIterator>
    516  1.1  joerg         hash_map(_InputIterator __first, _InputIterator __last);
    517  1.1  joerg     template <class _InputIterator>
    518  1.1  joerg         hash_map(_InputIterator __first, _InputIterator __last,
    519  1.1  joerg                       size_type __n, const hasher& __hf = hasher(),
    520  1.1  joerg                       const key_equal& __eql = key_equal());
    521  1.1  joerg     template <class _InputIterator>
    522  1.1  joerg         hash_map(_InputIterator __first, _InputIterator __last,
    523  1.1  joerg                       size_type __n, const hasher& __hf,
    524  1.1  joerg                       const key_equal& __eql,
    525  1.1  joerg                       const allocator_type& __a);
    526  1.1  joerg     hash_map(const hash_map& __u);
    527  1.1  joerg 
    528  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    529  1.1  joerg     allocator_type get_allocator() const
    530  1.1  joerg         {return allocator_type(__table_.__node_alloc());}
    531  1.1  joerg 
    532  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    533  1.1  joerg     bool      empty() const {return __table_.size() == 0;}
    534  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    535  1.1  joerg     size_type size() const  {return __table_.size();}
    536  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    537  1.1  joerg     size_type max_size() const {return __table_.max_size();}
    538  1.1  joerg 
    539  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    540  1.1  joerg     iterator       begin()        {return __table_.begin();}
    541  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    542  1.1  joerg     iterator       end()          {return __table_.end();}
    543  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    544  1.1  joerg     const_iterator begin()  const {return __table_.begin();}
    545  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    546  1.1  joerg     const_iterator end()    const {return __table_.end();}
    547  1.1  joerg 
    548  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    549  1.1  joerg     std::pair<iterator, bool> insert(const value_type& __x)
    550  1.1  joerg         {return __table_.__insert_unique(__x);}
    551  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    552  1.1  joerg     iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;}
    553  1.1  joerg     template <class _InputIterator>
    554  1.1  joerg         _LIBCPP_INLINE_VISIBILITY
    555  1.1  joerg         void insert(_InputIterator __first, _InputIterator __last);
    556  1.1  joerg 
    557  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    558  1.1  joerg     void erase(const_iterator __p) {__table_.erase(__p.__i_);}
    559  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    560  1.1  joerg     size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
    561  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    562  1.1  joerg     void erase(const_iterator __first, const_iterator __last)
    563  1.1  joerg         {__table_.erase(__first.__i_, __last.__i_);}
    564  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    565  1.1  joerg     void clear() {__table_.clear();}
    566  1.1  joerg 
    567  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    568  1.1  joerg     void swap(hash_map& __u) {__table_.swap(__u.__table_);}
    569  1.1  joerg 
    570  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    571  1.1  joerg     hasher hash_funct() const
    572  1.1  joerg         {return __table_.hash_function().hash_function();}
    573  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    574  1.1  joerg     key_equal key_eq() const
    575  1.1  joerg         {return __table_.key_eq().key_eq();}
    576  1.1  joerg 
    577  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    578  1.1  joerg     iterator       find(const key_type& __k)       {return __table_.find(__k);}
    579  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    580  1.1  joerg     const_iterator find(const key_type& __k) const {return __table_.find(__k);}
    581  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    582  1.1  joerg     size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
    583  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    584  1.1  joerg     std::pair<iterator, iterator>             equal_range(const key_type& __k)
    585  1.1  joerg         {return __table_.__equal_range_unique(__k);}
    586  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    587  1.1  joerg     std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
    588  1.1  joerg         {return __table_.__equal_range_unique(__k);}
    589  1.1  joerg 
    590  1.1  joerg     mapped_type& operator[](const key_type& __k);
    591  1.1  joerg 
    592  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    593  1.1  joerg     size_type bucket_count() const {return __table_.bucket_count();}
    594  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    595  1.1  joerg     size_type max_bucket_count() const {return __table_.max_bucket_count();}
    596  1.1  joerg 
    597  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    598  1.1  joerg     size_type elems_in_bucket(size_type __n) const
    599  1.1  joerg         {return __table_.bucket_size(__n);}
    600  1.1  joerg 
    601  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    602  1.1  joerg     void resize(size_type __n) {__table_.rehash(__n);}
    603  1.1  joerg 
    604  1.1  joerg private:
    605  1.1  joerg     __node_holder __construct_node(const key_type& __k);
    606  1.1  joerg };
    607  1.1  joerg 
    608  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    609  1.1  joerg hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
    610  1.1  joerg         size_type __n, const hasher& __hf, const key_equal& __eql)
    611  1.1  joerg     : __table_(__hf, __eql)
    612  1.1  joerg {
    613  1.1  joerg     __table_.rehash(__n);
    614  1.1  joerg }
    615  1.1  joerg 
    616  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    617  1.1  joerg hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
    618  1.1  joerg         size_type __n, const hasher& __hf, const key_equal& __eql,
    619  1.1  joerg         const allocator_type& __a)
    620  1.1  joerg     : __table_(__hf, __eql, __a)
    621  1.1  joerg {
    622  1.1  joerg     __table_.rehash(__n);
    623  1.1  joerg }
    624  1.1  joerg 
    625  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    626  1.1  joerg template <class _InputIterator>
    627  1.1  joerg hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
    628  1.1  joerg         _InputIterator __first, _InputIterator __last)
    629  1.1  joerg {
    630  1.1  joerg     insert(__first, __last);
    631  1.1  joerg }
    632  1.1  joerg 
    633  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    634  1.1  joerg template <class _InputIterator>
    635  1.1  joerg hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
    636  1.1  joerg         _InputIterator __first, _InputIterator __last, size_type __n,
    637  1.1  joerg         const hasher& __hf, const key_equal& __eql)
    638  1.1  joerg     : __table_(__hf, __eql)
    639  1.1  joerg {
    640  1.1  joerg     __table_.rehash(__n);
    641  1.1  joerg     insert(__first, __last);
    642  1.1  joerg }
    643  1.1  joerg 
    644  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    645  1.1  joerg template <class _InputIterator>
    646  1.1  joerg hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
    647  1.1  joerg         _InputIterator __first, _InputIterator __last, size_type __n,
    648  1.1  joerg         const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
    649  1.1  joerg     : __table_(__hf, __eql, __a)
    650  1.1  joerg {
    651  1.1  joerg     __table_.rehash(__n);
    652  1.1  joerg     insert(__first, __last);
    653  1.1  joerg }
    654  1.1  joerg 
    655  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    656  1.1  joerg hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map(
    657  1.1  joerg         const hash_map& __u)
    658  1.1  joerg     : __table_(__u.__table_)
    659  1.1  joerg {
    660  1.1  joerg     __table_.rehash(__u.bucket_count());
    661  1.1  joerg     insert(__u.begin(), __u.end());
    662  1.1  joerg }
    663  1.1  joerg 
    664  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    665  1.1  joerg typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
    666  1.1  joerg hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k)
    667  1.1  joerg {
    668  1.1  joerg     __node_allocator& __na = __table_.__node_alloc();
    669  1.1  joerg     __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
    670  1.1  joerg     __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k);
    671  1.1  joerg     __h.get_deleter().__first_constructed = true;
    672  1.1  joerg     __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
    673  1.1  joerg     __h.get_deleter().__second_constructed = true;
    674  1.1  joerg     return __h;
    675  1.1  joerg }
    676  1.1  joerg 
    677  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    678  1.1  joerg template <class _InputIterator>
    679  1.1  joerg inline
    680  1.1  joerg void
    681  1.1  joerg hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
    682  1.1  joerg                                                        _InputIterator __last)
    683  1.1  joerg {
    684  1.1  joerg     for (; __first != __last; ++__first)
    685  1.1  joerg         __table_.__insert_unique(*__first);
    686  1.1  joerg }
    687  1.1  joerg 
    688  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    689  1.1  joerg _Tp&
    690  1.1  joerg hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
    691  1.1  joerg {
    692  1.1  joerg     iterator __i = find(__k);
    693  1.1  joerg     if (__i != end())
    694  1.1  joerg         return __i->second;
    695  1.1  joerg     __node_holder __h = __construct_node(__k);
    696  1.1  joerg     std::pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
    697  1.1  joerg     __h.release();
    698  1.1  joerg     return __r.first->second;
    699  1.1  joerg }
    700  1.1  joerg 
    701  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    702  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY
    703  1.1  joerg void
    704  1.1  joerg swap(hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
    705  1.1  joerg      hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
    706  1.1  joerg {
    707  1.1  joerg     __x.swap(__y);
    708  1.1  joerg }
    709  1.1  joerg 
    710  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    711  1.1  joerg bool
    712  1.1  joerg operator==(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
    713  1.1  joerg            const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
    714  1.1  joerg {
    715  1.1  joerg     if (__x.size() != __y.size())
    716  1.1  joerg         return false;
    717  1.1  joerg     typedef typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
    718  1.1  joerg                                                                  const_iterator;
    719  1.1  joerg     for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
    720  1.1  joerg             __i != __ex; ++__i)
    721  1.1  joerg     {
    722  1.1  joerg         const_iterator __j = __y.find(__i->first);
    723  1.1  joerg         if (__j == __ey || !(*__i == *__j))
    724  1.1  joerg             return false;
    725  1.1  joerg     }
    726  1.1  joerg     return true;
    727  1.1  joerg }
    728  1.1  joerg 
    729  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    730  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY
    731  1.1  joerg bool
    732  1.1  joerg operator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
    733  1.1  joerg            const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
    734  1.1  joerg {
    735  1.1  joerg     return !(__x == __y);
    736  1.1  joerg }
    737  1.1  joerg 
    738  1.1  joerg template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = std::equal_to<_Key>,
    739  1.1  joerg           class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
    740  1.1  joerg class _LIBCPP_TEMPLATE_VIS hash_multimap
    741  1.1  joerg {
    742  1.1  joerg public:
    743  1.1  joerg     // types
    744  1.1  joerg     typedef _Key                                           key_type;
    745  1.1  joerg     typedef _Tp                                            mapped_type;
    746  1.1  joerg     typedef _Tp                                            data_type;
    747  1.1  joerg     typedef _Hash                                          hasher;
    748  1.1  joerg     typedef _Pred                                          key_equal;
    749  1.1  joerg     typedef _Alloc                                         allocator_type;
    750  1.1  joerg     typedef std::pair<const key_type, mapped_type>         value_type;
    751  1.1  joerg     typedef value_type&                                    reference;
    752  1.1  joerg     typedef const value_type&                              const_reference;
    753  1.1  joerg 
    754  1.1  joerg private:
    755  1.1  joerg     typedef std::pair<key_type, mapped_type>               __value_type;
    756  1.1  joerg     typedef __hash_map_hasher<__value_type, hasher>   __hasher;
    757  1.1  joerg     typedef __hash_map_equal<__value_type, key_equal> __key_equal;
    758  1.1  joerg     typedef typename std::__rebind_alloc_helper<std::allocator_traits<allocator_type>, __value_type>::type __allocator_type;
    759  1.1  joerg 
    760  1.1  joerg     typedef std::__hash_table<__value_type, __hasher,
    761  1.1  joerg                          __key_equal,  __allocator_type>   __table;
    762  1.1  joerg 
    763  1.1  joerg     __table __table_;
    764  1.1  joerg 
    765  1.1  joerg     typedef typename __table::__node_traits                __node_traits;
    766  1.1  joerg     typedef typename __table::__node_allocator             __node_allocator;
    767  1.1  joerg     typedef typename __table::__node                       __node;
    768  1.1  joerg     typedef __hash_map_node_destructor<__node_allocator>   _Dp;
    769  1.1  joerg     typedef std::unique_ptr<__node, _Dp>                         __node_holder;
    770  1.1  joerg     typedef std::allocator_traits<allocator_type>               __alloc_traits;
    771  1.1  joerg public:
    772  1.1  joerg     typedef typename __alloc_traits::pointer         pointer;
    773  1.1  joerg     typedef typename __alloc_traits::const_pointer   const_pointer;
    774  1.1  joerg     typedef typename __alloc_traits::size_type       size_type;
    775  1.1  joerg     typedef typename __alloc_traits::difference_type difference_type;
    776  1.1  joerg 
    777  1.1  joerg     typedef __hash_map_iterator<typename __table::iterator>       iterator;
    778  1.1  joerg     typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
    779  1.1  joerg 
    780  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    781  1.1  joerg     hash_multimap() { }
    782  1.1  joerg     explicit hash_multimap(size_type __n, const hasher& __hf = hasher(),
    783  1.1  joerg                                 const key_equal& __eql = key_equal());
    784  1.1  joerg     hash_multimap(size_type __n, const hasher& __hf,
    785  1.1  joerg                                 const key_equal& __eql,
    786  1.1  joerg                                 const allocator_type& __a);
    787  1.1  joerg     template <class _InputIterator>
    788  1.1  joerg         hash_multimap(_InputIterator __first, _InputIterator __last);
    789  1.1  joerg     template <class _InputIterator>
    790  1.1  joerg         hash_multimap(_InputIterator __first, _InputIterator __last,
    791  1.1  joerg                       size_type __n, const hasher& __hf = hasher(),
    792  1.1  joerg                       const key_equal& __eql = key_equal());
    793  1.1  joerg     template <class _InputIterator>
    794  1.1  joerg         hash_multimap(_InputIterator __first, _InputIterator __last,
    795  1.1  joerg                       size_type __n, const hasher& __hf,
    796  1.1  joerg                       const key_equal& __eql,
    797  1.1  joerg                       const allocator_type& __a);
    798  1.1  joerg     hash_multimap(const hash_multimap& __u);
    799  1.1  joerg 
    800  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    801  1.1  joerg     allocator_type get_allocator() const
    802  1.1  joerg         {return allocator_type(__table_.__node_alloc());}
    803  1.1  joerg 
    804  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    805  1.1  joerg     bool      empty() const {return __table_.size() == 0;}
    806  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    807  1.1  joerg     size_type size() const  {return __table_.size();}
    808  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    809  1.1  joerg     size_type max_size() const {return __table_.max_size();}
    810  1.1  joerg 
    811  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    812  1.1  joerg     iterator       begin()        {return __table_.begin();}
    813  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    814  1.1  joerg     iterator       end()          {return __table_.end();}
    815  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    816  1.1  joerg     const_iterator begin()  const {return __table_.begin();}
    817  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    818  1.1  joerg     const_iterator end()    const {return __table_.end();}
    819  1.1  joerg 
    820  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    821  1.1  joerg     iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
    822  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    823  1.1  joerg     iterator insert(const_iterator, const value_type& __x) {return insert(__x);}
    824  1.1  joerg     template <class _InputIterator>
    825  1.1  joerg         _LIBCPP_INLINE_VISIBILITY
    826  1.1  joerg         void insert(_InputIterator __first, _InputIterator __last);
    827  1.1  joerg 
    828  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    829  1.1  joerg     void erase(const_iterator __p) {__table_.erase(__p.__i_);}
    830  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    831  1.1  joerg     size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
    832  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    833  1.1  joerg     void erase(const_iterator __first, const_iterator __last)
    834  1.1  joerg         {__table_.erase(__first.__i_, __last.__i_);}
    835  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    836  1.1  joerg     void clear() {__table_.clear();}
    837  1.1  joerg 
    838  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    839  1.1  joerg     void swap(hash_multimap& __u) {__table_.swap(__u.__table_);}
    840  1.1  joerg 
    841  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    842  1.1  joerg     hasher hash_funct() const
    843  1.1  joerg         {return __table_.hash_function().hash_function();}
    844  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    845  1.1  joerg     key_equal key_eq() const
    846  1.1  joerg         {return __table_.key_eq().key_eq();}
    847  1.1  joerg 
    848  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    849  1.1  joerg     iterator       find(const key_type& __k)       {return __table_.find(__k);}
    850  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    851  1.1  joerg     const_iterator find(const key_type& __k) const {return __table_.find(__k);}
    852  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    853  1.1  joerg     size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
    854  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    855  1.1  joerg     std::pair<iterator, iterator>             equal_range(const key_type& __k)
    856  1.1  joerg         {return __table_.__equal_range_multi(__k);}
    857  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    858  1.1  joerg     std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
    859  1.1  joerg         {return __table_.__equal_range_multi(__k);}
    860  1.1  joerg 
    861  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    862  1.1  joerg     size_type bucket_count() const {return __table_.bucket_count();}
    863  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    864  1.1  joerg     size_type max_bucket_count() const {return __table_.max_bucket_count();}
    865  1.1  joerg 
    866  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    867  1.1  joerg     size_type elems_in_bucket(size_type __n) const
    868  1.1  joerg         {return __table_.bucket_size(__n);}
    869  1.1  joerg 
    870  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    871  1.1  joerg     void resize(size_type __n) {__table_.rehash(__n);}
    872  1.1  joerg };
    873  1.1  joerg 
    874  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    875  1.1  joerg hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
    876  1.1  joerg         size_type __n, const hasher& __hf, const key_equal& __eql)
    877  1.1  joerg     : __table_(__hf, __eql)
    878  1.1  joerg {
    879  1.1  joerg     __table_.rehash(__n);
    880  1.1  joerg }
    881  1.1  joerg 
    882  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    883  1.1  joerg hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
    884  1.1  joerg         size_type __n, const hasher& __hf, const key_equal& __eql,
    885  1.1  joerg         const allocator_type& __a)
    886  1.1  joerg     : __table_(__hf, __eql, __a)
    887  1.1  joerg {
    888  1.1  joerg     __table_.rehash(__n);
    889  1.1  joerg }
    890  1.1  joerg 
    891  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    892  1.1  joerg template <class _InputIterator>
    893  1.1  joerg hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
    894  1.1  joerg         _InputIterator __first, _InputIterator __last)
    895  1.1  joerg {
    896  1.1  joerg     insert(__first, __last);
    897  1.1  joerg }
    898  1.1  joerg 
    899  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    900  1.1  joerg template <class _InputIterator>
    901  1.1  joerg hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
    902  1.1  joerg         _InputIterator __first, _InputIterator __last, size_type __n,
    903  1.1  joerg         const hasher& __hf, const key_equal& __eql)
    904  1.1  joerg     : __table_(__hf, __eql)
    905  1.1  joerg {
    906  1.1  joerg     __table_.rehash(__n);
    907  1.1  joerg     insert(__first, __last);
    908  1.1  joerg }
    909  1.1  joerg 
    910  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    911  1.1  joerg template <class _InputIterator>
    912  1.1  joerg hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
    913  1.1  joerg         _InputIterator __first, _InputIterator __last, size_type __n,
    914  1.1  joerg         const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
    915  1.1  joerg     : __table_(__hf, __eql, __a)
    916  1.1  joerg {
    917  1.1  joerg     __table_.rehash(__n);
    918  1.1  joerg     insert(__first, __last);
    919  1.1  joerg }
    920  1.1  joerg 
    921  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    922  1.1  joerg hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
    923  1.1  joerg         const hash_multimap& __u)
    924  1.1  joerg     : __table_(__u.__table_)
    925  1.1  joerg {
    926  1.1  joerg     __table_.rehash(__u.bucket_count());
    927  1.1  joerg     insert(__u.begin(), __u.end());
    928  1.1  joerg }
    929  1.1  joerg 
    930  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    931  1.1  joerg template <class _InputIterator>
    932  1.1  joerg inline
    933  1.1  joerg void
    934  1.1  joerg hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
    935  1.1  joerg                                                             _InputIterator __last)
    936  1.1  joerg {
    937  1.1  joerg     for (; __first != __last; ++__first)
    938  1.1  joerg         __table_.__insert_multi(*__first);
    939  1.1  joerg }
    940  1.1  joerg 
    941  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    942  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY
    943  1.1  joerg void
    944  1.1  joerg swap(hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
    945  1.1  joerg      hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
    946  1.1  joerg {
    947  1.1  joerg     __x.swap(__y);
    948  1.1  joerg }
    949  1.1  joerg 
    950  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    951  1.1  joerg bool
    952  1.1  joerg operator==(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
    953  1.1  joerg            const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
    954  1.1  joerg {
    955  1.1  joerg     if (__x.size() != __y.size())
    956  1.1  joerg         return false;
    957  1.1  joerg     typedef typename hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
    958  1.1  joerg                                                                  const_iterator;
    959  1.1  joerg     typedef std::pair<const_iterator, const_iterator> _EqRng;
    960  1.1  joerg     for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
    961  1.1  joerg     {
    962  1.1  joerg         _EqRng __xeq = __x.equal_range(__i->first);
    963  1.1  joerg         _EqRng __yeq = __y.equal_range(__i->first);
    964  1.1  joerg         if (_VSTD::distance(__xeq.first, __xeq.second) !=
    965  1.1  joerg             _VSTD::distance(__yeq.first, __yeq.second) ||
    966  1.1  joerg                   !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
    967  1.1  joerg             return false;
    968  1.1  joerg         __i = __xeq.second;
    969  1.1  joerg     }
    970  1.1  joerg     return true;
    971  1.1  joerg }
    972  1.1  joerg 
    973  1.1  joerg template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
    974  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY
    975  1.1  joerg bool
    976  1.1  joerg operator!=(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
    977  1.1  joerg            const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
    978  1.1  joerg {
    979  1.1  joerg     return !(__x == __y);
    980  1.1  joerg }
    981  1.1  joerg 
    982  1.1  joerg } // __gnu_cxx
    983  1.1  joerg 
    984  1.1  joerg #endif // _LIBCPP_HASH_MAP
    985