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