blob: 3f430af1283e64c462636f3a94431e6b09289979 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00005//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP__HASH_TABLE
12#define _LIBCPP__HASH_TABLE
13
14#include <__config>
15#include <initializer_list>
16#include <memory>
17#include <iterator>
18#include <algorithm>
19#include <cmath>
Eric Fiselier75d0dcf2016-02-10 20:46:23 +000020#include <utility>
Eric Fiselier04333f92017-01-13 22:42:53 +000021#include <type_traits>
Howard Hinnant3e519522010-05-11 19:42:16 +000022
Eric Fiselierc1bd9192014-08-10 23:53:08 +000023#include <__debug>
Howard Hinnant42a30462013-08-02 00:26:35 +000024
Howard Hinnant073458b2011-10-17 20:05:10 +000025#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +000026#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +000027#endif
Howard Hinnant3e519522010-05-11 19:42:16 +000028
Eric Fiseliera016efb2017-05-31 22:07:49 +000029_LIBCPP_PUSH_MACROS
30#include <__undef_macros>
Howard Hinnant3e519522010-05-11 19:42:16 +000031
Eric Fiselierfcd02212016-02-11 11:59:44 +000032
Eric Fiseliera016efb2017-05-31 22:07:49 +000033_LIBCPP_BEGIN_NAMESPACE_STD
34
Eric Fiselierfcd02212016-02-11 11:59:44 +000035#ifndef _LIBCPP_CXX03_LANG
36template <class _Key, class _Tp>
37union __hash_value_type;
38#else
39template <class _Key, class _Tp>
40struct __hash_value_type;
41#endif
42
Eric Fiselier04333f92017-01-13 22:42:53 +000043template <class _Key, class _Cp, class _Hash,
44 bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value>
45class __unordered_map_hasher;
46
47template <class _Key, class _Cp, class _Pred,
48 bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value
49 >
50class __unordered_map_equal;
51
Eric Fiselierfcd02212016-02-11 11:59:44 +000052#ifndef _LIBCPP_CXX03_LANG
53template <class _Tp>
54struct __is_hash_value_type_imp : false_type {};
55
56template <class _Key, class _Value>
57struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {};
58
59template <class ..._Args>
60struct __is_hash_value_type : false_type {};
61
62template <class _One>
63struct __is_hash_value_type<_One> : __is_hash_value_type_imp<typename __uncvref<_One>::type> {};
64#endif
65
Howard Hinnant6e412562013-03-06 23:30:19 +000066_LIBCPP_FUNC_VIS
Howard Hinnantce534202011-06-14 19:58:17 +000067size_t __next_prime(size_t __n);
Howard Hinnant3e519522010-05-11 19:42:16 +000068
69template <class _NodePtr>
70struct __hash_node_base
71{
Eric Fiselier40492ba2016-07-23 20:36:55 +000072 typedef typename pointer_traits<_NodePtr>::element_type __node_type;
Howard Hinnant3e519522010-05-11 19:42:16 +000073 typedef __hash_node_base __first_node;
Eric Fiselier40492ba2016-07-23 20:36:55 +000074 typedef typename __rebind_pointer<_NodePtr, __first_node>::type __node_base_pointer;
75 typedef _NodePtr __node_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +000076
Eric Fiselier40492ba2016-07-23 20:36:55 +000077#if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB)
78 typedef __node_base_pointer __next_pointer;
79#else
80 typedef typename conditional<
81 is_pointer<__node_pointer>::value,
82 __node_base_pointer,
83 __node_pointer>::type __next_pointer;
84#endif
85
86 __next_pointer __next_;
87
88 _LIBCPP_INLINE_VISIBILITY
89 __next_pointer __ptr() _NOEXCEPT {
90 return static_cast<__next_pointer>(
91 pointer_traits<__node_base_pointer>::pointer_to(*this));
92 }
93
94 _LIBCPP_INLINE_VISIBILITY
95 __node_pointer __upcast() _NOEXCEPT {
96 return static_cast<__node_pointer>(
97 pointer_traits<__node_base_pointer>::pointer_to(*this));
98 }
99
100 _LIBCPP_INLINE_VISIBILITY
101 size_t __hash() const _NOEXCEPT {
102 return static_cast<__node_type const&>(*this).__hash_;
103 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000104
Howard Hinnant37141072011-06-04 18:54:24 +0000105 _LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000106};
107
108template <class _Tp, class _VoidPtr>
109struct __hash_node
110 : public __hash_node_base
111 <
Eric Fiselier934b0922015-12-30 21:52:00 +0000112 typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type
Howard Hinnant3e519522010-05-11 19:42:16 +0000113 >
114{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000115 typedef _Tp __node_value_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000116
Eric Fiselier40492ba2016-07-23 20:36:55 +0000117 size_t __hash_;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000118 __node_value_type __value_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000119};
120
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000121inline _LIBCPP_INLINE_VISIBILITY
122bool
Eric Fiselier9ba5c112015-02-02 21:31:48 +0000123__is_hash_power2(size_t __bc)
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000124{
125 return __bc > 2 && !(__bc & (__bc - 1));
126}
127
128inline _LIBCPP_INLINE_VISIBILITY
129size_t
130__constrain_hash(size_t __h, size_t __bc)
131{
Eric Fiselier118cb412016-07-11 22:02:02 +0000132 return !(__bc & (__bc - 1)) ? __h & (__bc - 1) :
133 (__h < __bc ? __h : __h % __bc);
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000134}
135
136inline _LIBCPP_INLINE_VISIBILITY
137size_t
Eric Fiselier9ba5c112015-02-02 21:31:48 +0000138__next_hash_pow2(size_t __n)
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000139{
Marshall Clow87af6462017-06-03 00:08:32 +0000140 return __n < 2 ? __n : (size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1)));
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000141}
142
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +0000143
Howard Hinnantce534202011-06-14 19:58:17 +0000144template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000145
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000146template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_iterator;
147template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
148template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_local_iterator;
149template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
150template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
151template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000152
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000153template <class _Tp>
Eric Fiselier43b121d2016-02-20 07:59:16 +0000154struct __hash_key_value_types {
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000155 static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, "");
156 typedef _Tp key_type;
157 typedef _Tp __node_value_type;
158 typedef _Tp __container_value_type;
159 static const bool __is_map = false;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000160
161 _LIBCPP_INLINE_VISIBILITY
162 static key_type const& __get_key(_Tp const& __v) {
163 return __v;
164 }
165 _LIBCPP_INLINE_VISIBILITY
166 static __container_value_type const& __get_value(__node_value_type const& __v) {
167 return __v;
168 }
169 _LIBCPP_INLINE_VISIBILITY
170 static __container_value_type* __get_ptr(__node_value_type& __n) {
171 return _VSTD::addressof(__n);
172 }
173#ifndef _LIBCPP_CXX03_LANG
174 _LIBCPP_INLINE_VISIBILITY
175 static __container_value_type&& __move(__node_value_type& __v) {
176 return _VSTD::move(__v);
177 }
178#endif
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000179};
180
181template <class _Key, class _Tp>
Eric Fiselier43b121d2016-02-20 07:59:16 +0000182struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > {
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000183 typedef _Key key_type;
184 typedef _Tp mapped_type;
185 typedef __hash_value_type<_Key, _Tp> __node_value_type;
186 typedef pair<const _Key, _Tp> __container_value_type;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000187 typedef pair<_Key, _Tp> __nc_value_type;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000188 typedef __container_value_type __map_value_type;
189 static const bool __is_map = true;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000190
191 _LIBCPP_INLINE_VISIBILITY
192 static key_type const& __get_key(__container_value_type const& __v) {
193 return __v.first;
194 }
195
196 template <class _Up>
197 _LIBCPP_INLINE_VISIBILITY
198 static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value,
199 __container_value_type const&>::type
200 __get_value(_Up& __t) {
201 return __t.__cc;
202 }
203
204 template <class _Up>
205 _LIBCPP_INLINE_VISIBILITY
206 static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value,
207 __container_value_type const&>::type
208 __get_value(_Up& __t) {
209 return __t;
210 }
211
212 _LIBCPP_INLINE_VISIBILITY
213 static __container_value_type* __get_ptr(__node_value_type& __n) {
214 return _VSTD::addressof(__n.__cc);
215 }
216#ifndef _LIBCPP_CXX03_LANG
217 _LIBCPP_INLINE_VISIBILITY
218 static __nc_value_type&& __move(__node_value_type& __v) {
219 return _VSTD::move(__v.__nc);
220 }
221#endif
222
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000223};
224
Eric Fiselier43b121d2016-02-20 07:59:16 +0000225template <class _Tp, class _AllocPtr, class _KVTypes = __hash_key_value_types<_Tp>,
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000226 bool = _KVTypes::__is_map>
Eric Fiselier43b121d2016-02-20 07:59:16 +0000227struct __hash_map_pointer_types {};
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000228
229template <class _Tp, class _AllocPtr, class _KVTypes>
Eric Fiselier43b121d2016-02-20 07:59:16 +0000230struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> {
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000231 typedef typename _KVTypes::__map_value_type _Mv;
232 typedef typename __rebind_pointer<_AllocPtr, _Mv>::type
233 __map_value_type_pointer;
234 typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type
235 __const_map_value_type_pointer;
236};
237
238template <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type>
239struct __hash_node_types;
240
241template <class _NodePtr, class _Tp, class _VoidPtr>
242struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> >
Eric Fiselier43b121d2016-02-20 07:59:16 +0000243 : public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr>
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000244
245{
Eric Fiselier43b121d2016-02-20 07:59:16 +0000246 typedef __hash_key_value_types<_Tp> __base;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000247
248public:
249 typedef ptrdiff_t difference_type;
250 typedef size_t size_type;
251
252 typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer;
253
254 typedef typename pointer_traits<_NodePtr>::element_type __node_type;
255 typedef _NodePtr __node_pointer;
256
257 typedef __hash_node_base<__node_pointer> __node_base_type;
258 typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type
259 __node_base_pointer;
260
Eric Fiselier40492ba2016-07-23 20:36:55 +0000261 typedef typename __node_base_type::__next_pointer __next_pointer;
262
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000263 typedef _Tp __node_value_type;
264 typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type
265 __node_value_type_pointer;
266 typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type
267 __const_node_value_type_pointer;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000268
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000269private:
270 static_assert(!is_const<__node_type>::value,
271 "_NodePtr should never be a pointer to const");
272 static_assert((is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value),
273 "_VoidPtr does not point to unqualified void type");
274 static_assert((is_same<typename __rebind_pointer<_VoidPtr, __node_type>::type,
275 _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr.");
276};
277
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000278template <class _HashIterator>
279struct __hash_node_types_from_iterator;
280template <class _NodePtr>
281struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
282template <class _NodePtr>
283struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
284template <class _NodePtr>
285struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
286template <class _NodePtr>
287struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
288
289
290template <class _NodeValueTp, class _VoidPtr>
291struct __make_hash_node_types {
292 typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp;
293 typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr;
294 typedef __hash_node_types<_NodePtr> type;
295};
296
Howard Hinnant3e519522010-05-11 19:42:16 +0000297template <class _NodePtr>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000298class _LIBCPP_TEMPLATE_VIS __hash_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000299{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000300 typedef __hash_node_types<_NodePtr> _NodeTypes;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000301 typedef _NodePtr __node_pointer;
302 typedef typename _NodeTypes::__next_pointer __next_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000303
Eric Fiselier40492ba2016-07-23 20:36:55 +0000304 __next_pointer __node_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000305
306public:
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000307 typedef forward_iterator_tag iterator_category;
308 typedef typename _NodeTypes::__node_value_type value_type;
309 typedef typename _NodeTypes::difference_type difference_type;
310 typedef value_type& reference;
311 typedef typename _NodeTypes::__node_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000312
Eric Fiselier40492ba2016-07-23 20:36:55 +0000313 _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT : __node_(nullptr) {
314 _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000315 }
316
317#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant43d99232010-09-21 17:32:39 +0000318 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000319 __hash_iterator(const __hash_iterator& __i)
320 : __node_(__i.__node_)
321 {
322 __get_db()->__iterator_copy(this, &__i);
323 }
324
Howard Hinnant43d99232010-09-21 17:32:39 +0000325 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000326 ~__hash_iterator()
327 {
328 __get_db()->__erase_i(this);
329 }
330
331 _LIBCPP_INLINE_VISIBILITY
332 __hash_iterator& operator=(const __hash_iterator& __i)
333 {
334 if (this != &__i)
335 {
336 __get_db()->__iterator_copy(this, &__i);
337 __node_ = __i.__node_;
338 }
339 return *this;
340 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000341#endif // _LIBCPP_DEBUG_LEVEL >= 2
342
343 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000344 reference operator*() const {
345 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
346 "Attempted to dereference a non-dereferenceable unordered container iterator");
347 return __node_->__upcast()->__value_;
348 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000349
Howard Hinnant43d99232010-09-21 17:32:39 +0000350 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000351 pointer operator->() const {
352 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
353 "Attempted to dereference a non-dereferenceable unordered container iterator");
354 return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
355 }
356
357 _LIBCPP_INLINE_VISIBILITY
358 __hash_iterator& operator++() {
359 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000360 "Attempted to increment non-incrementable unordered container iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +0000361 __node_ = __node_->__next_;
362 return *this;
363 }
364
Howard Hinnant43d99232010-09-21 17:32:39 +0000365 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000366 __hash_iterator operator++(int)
367 {
368 __hash_iterator __t(*this);
369 ++(*this);
370 return __t;
371 }
372
Howard Hinnant43d99232010-09-21 17:32:39 +0000373 friend _LIBCPP_INLINE_VISIBILITY
374 bool operator==(const __hash_iterator& __x, const __hash_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000375 {
Howard Hinnantb24c8022013-07-23 22:01:58 +0000376 return __x.__node_ == __y.__node_;
377 }
Howard Hinnant43d99232010-09-21 17:32:39 +0000378 friend _LIBCPP_INLINE_VISIBILITY
379 bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000380 {return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000381
382private:
Howard Hinnantb24c8022013-07-23 22:01:58 +0000383#if _LIBCPP_DEBUG_LEVEL >= 2
384 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000385 __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
Howard Hinnantb24c8022013-07-23 22:01:58 +0000386 : __node_(__node)
387 {
388 __get_db()->__insert_ic(this, __c);
389 }
390#else
Howard Hinnant43d99232010-09-21 17:32:39 +0000391 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000392 __hash_iterator(__next_pointer __node) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000393 : __node_(__node)
394 {}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000395#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000396 template <class, class, class, class> friend class __hash_table;
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000397 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
398 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
399 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
400 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000401};
402
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000403template <class _NodePtr>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000404class _LIBCPP_TEMPLATE_VIS __hash_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000405{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000406 static_assert(!is_const<typename pointer_traits<_NodePtr>::element_type>::value, "");
407 typedef __hash_node_types<_NodePtr> _NodeTypes;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000408 typedef _NodePtr __node_pointer;
409 typedef typename _NodeTypes::__next_pointer __next_pointer;
Eric Fiselier757373e2016-02-18 00:20:34 +0000410
Eric Fiselier40492ba2016-07-23 20:36:55 +0000411 __next_pointer __node_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000412
413public:
Eric Fiselier757373e2016-02-18 00:20:34 +0000414 typedef __hash_iterator<_NodePtr> __non_const_iterator;
415
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000416 typedef forward_iterator_tag iterator_category;
417 typedef typename _NodeTypes::__node_value_type value_type;
418 typedef typename _NodeTypes::difference_type difference_type;
419 typedef const value_type& reference;
420 typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
421
Howard Hinnant3e519522010-05-11 19:42:16 +0000422
Eric Fiselier40492ba2016-07-23 20:36:55 +0000423 _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT : __node_(nullptr) {
424 _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000425 }
Eric Fiselier40492ba2016-07-23 20:36:55 +0000426
Howard Hinnant43d99232010-09-21 17:32:39 +0000427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000428 __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000429 : __node_(__x.__node_)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000430 {
Eric Fiselier40492ba2016-07-23 20:36:55 +0000431 _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000432 }
433
434#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant43d99232010-09-21 17:32:39 +0000435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000436 __hash_const_iterator(const __hash_const_iterator& __i)
437 : __node_(__i.__node_)
438 {
439 __get_db()->__iterator_copy(this, &__i);
440 }
441
Howard Hinnant43d99232010-09-21 17:32:39 +0000442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000443 ~__hash_const_iterator()
444 {
445 __get_db()->__erase_i(this);
446 }
447
448 _LIBCPP_INLINE_VISIBILITY
449 __hash_const_iterator& operator=(const __hash_const_iterator& __i)
450 {
451 if (this != &__i)
452 {
453 __get_db()->__iterator_copy(this, &__i);
454 __node_ = __i.__node_;
455 }
456 return *this;
457 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000458#endif // _LIBCPP_DEBUG_LEVEL >= 2
459
460 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000461 reference operator*() const {
462 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000463 "Attempted to dereference a non-dereferenceable unordered container const_iterator");
Eric Fiselier40492ba2016-07-23 20:36:55 +0000464 return __node_->__upcast()->__value_;
465 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000466 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000467 pointer operator->() const {
468 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000469 "Attempted to dereference a non-dereferenceable unordered container const_iterator");
Eric Fiselier40492ba2016-07-23 20:36:55 +0000470 return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
471 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000472
Howard Hinnant43d99232010-09-21 17:32:39 +0000473 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000474 __hash_const_iterator& operator++() {
475 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
476 "Attempted to increment non-incrementable unordered container const_iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +0000477 __node_ = __node_->__next_;
478 return *this;
479 }
480
Howard Hinnant43d99232010-09-21 17:32:39 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000482 __hash_const_iterator operator++(int)
483 {
484 __hash_const_iterator __t(*this);
485 ++(*this);
486 return __t;
487 }
488
Howard Hinnant43d99232010-09-21 17:32:39 +0000489 friend _LIBCPP_INLINE_VISIBILITY
490 bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000491 {
Howard Hinnantb24c8022013-07-23 22:01:58 +0000492 return __x.__node_ == __y.__node_;
493 }
Howard Hinnant43d99232010-09-21 17:32:39 +0000494 friend _LIBCPP_INLINE_VISIBILITY
495 bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000496 {return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000497
498private:
Howard Hinnantb24c8022013-07-23 22:01:58 +0000499#if _LIBCPP_DEBUG_LEVEL >= 2
500 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000501 __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
Howard Hinnantb24c8022013-07-23 22:01:58 +0000502 : __node_(__node)
503 {
504 __get_db()->__insert_ic(this, __c);
505 }
506#else
Howard Hinnant43d99232010-09-21 17:32:39 +0000507 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000508 __hash_const_iterator(__next_pointer __node) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000509 : __node_(__node)
510 {}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000511#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000512 template <class, class, class, class> friend class __hash_table;
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000513 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
514 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
515 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000516};
517
Howard Hinnant3e519522010-05-11 19:42:16 +0000518template <class _NodePtr>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000519class _LIBCPP_TEMPLATE_VIS __hash_local_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000520{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000521 typedef __hash_node_types<_NodePtr> _NodeTypes;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000522 typedef _NodePtr __node_pointer;
523 typedef typename _NodeTypes::__next_pointer __next_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000524
Eric Fiselier40492ba2016-07-23 20:36:55 +0000525 __next_pointer __node_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000526 size_t __bucket_;
527 size_t __bucket_count_;
528
Howard Hinnant3e519522010-05-11 19:42:16 +0000529public:
530 typedef forward_iterator_tag iterator_category;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000531 typedef typename _NodeTypes::__node_value_type value_type;
532 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000533 typedef value_type& reference;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000534 typedef typename _NodeTypes::__node_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000535
Eric Fiselier40492ba2016-07-23 20:36:55 +0000536 _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT : __node_(nullptr) {
537 _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000538 }
539
540#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant43d99232010-09-21 17:32:39 +0000541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000542 __hash_local_iterator(const __hash_local_iterator& __i)
543 : __node_(__i.__node_),
544 __bucket_(__i.__bucket_),
545 __bucket_count_(__i.__bucket_count_)
546 {
547 __get_db()->__iterator_copy(this, &__i);
548 }
549
Howard Hinnant43d99232010-09-21 17:32:39 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000551 ~__hash_local_iterator()
552 {
553 __get_db()->__erase_i(this);
554 }
555
556 _LIBCPP_INLINE_VISIBILITY
557 __hash_local_iterator& operator=(const __hash_local_iterator& __i)
558 {
559 if (this != &__i)
560 {
561 __get_db()->__iterator_copy(this, &__i);
562 __node_ = __i.__node_;
563 __bucket_ = __i.__bucket_;
564 __bucket_count_ = __i.__bucket_count_;
565 }
566 return *this;
567 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000568#endif // _LIBCPP_DEBUG_LEVEL >= 2
569
570 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000571 reference operator*() const {
572 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000573 "Attempted to dereference a non-dereferenceable unordered container local_iterator");
Eric Fiselier40492ba2016-07-23 20:36:55 +0000574 return __node_->__upcast()->__value_;
575 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000576
Howard Hinnant43d99232010-09-21 17:32:39 +0000577 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000578 pointer operator->() const {
579 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
580 "Attempted to dereference a non-dereferenceable unordered container local_iterator");
581 return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
582 }
583
584 _LIBCPP_INLINE_VISIBILITY
585 __hash_local_iterator& operator++() {
586 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000587 "Attempted to increment non-incrementable unordered container local_iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +0000588 __node_ = __node_->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000589 if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_)
Howard Hinnant3e519522010-05-11 19:42:16 +0000590 __node_ = nullptr;
591 return *this;
592 }
593
Howard Hinnant43d99232010-09-21 17:32:39 +0000594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000595 __hash_local_iterator operator++(int)
596 {
597 __hash_local_iterator __t(*this);
598 ++(*this);
599 return __t;
600 }
601
Howard Hinnant43d99232010-09-21 17:32:39 +0000602 friend _LIBCPP_INLINE_VISIBILITY
603 bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000604 {
Howard Hinnantb24c8022013-07-23 22:01:58 +0000605 return __x.__node_ == __y.__node_;
606 }
Howard Hinnant43d99232010-09-21 17:32:39 +0000607 friend _LIBCPP_INLINE_VISIBILITY
608 bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000609 {return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000610
611private:
Howard Hinnantb24c8022013-07-23 22:01:58 +0000612#if _LIBCPP_DEBUG_LEVEL >= 2
613 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000614 __hash_local_iterator(__next_pointer __node, size_t __bucket,
Howard Hinnantb24c8022013-07-23 22:01:58 +0000615 size_t __bucket_count, const void* __c) _NOEXCEPT
616 : __node_(__node),
617 __bucket_(__bucket),
618 __bucket_count_(__bucket_count)
619 {
620 __get_db()->__insert_ic(this, __c);
621 if (__node_ != nullptr)
622 __node_ = __node_->__next_;
623 }
624#else
Howard Hinnant43d99232010-09-21 17:32:39 +0000625 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000626 __hash_local_iterator(__next_pointer __node, size_t __bucket,
Howard Hinnant37141072011-06-04 18:54:24 +0000627 size_t __bucket_count) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000628 : __node_(__node),
629 __bucket_(__bucket),
630 __bucket_count_(__bucket_count)
631 {
632 if (__node_ != nullptr)
633 __node_ = __node_->__next_;
634 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000635#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000636 template <class, class, class, class> friend class __hash_table;
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000637 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
638 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000639};
640
641template <class _ConstNodePtr>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000642class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000643{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000644 typedef __hash_node_types<_ConstNodePtr> _NodeTypes;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000645 typedef _ConstNodePtr __node_pointer;
646 typedef typename _NodeTypes::__next_pointer __next_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000647
Eric Fiselier40492ba2016-07-23 20:36:55 +0000648 __next_pointer __node_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000649 size_t __bucket_;
650 size_t __bucket_count_;
651
652 typedef pointer_traits<__node_pointer> __pointer_traits;
653 typedef typename __pointer_traits::element_type __node;
654 typedef typename remove_const<__node>::type __non_const_node;
Eric Fiselier934b0922015-12-30 21:52:00 +0000655 typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type
656 __non_const_node_pointer;
Eric Fiselier757373e2016-02-18 00:20:34 +0000657public:
Howard Hinnant3e519522010-05-11 19:42:16 +0000658 typedef __hash_local_iterator<__non_const_node_pointer>
659 __non_const_iterator;
Eric Fiselier757373e2016-02-18 00:20:34 +0000660
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000661 typedef forward_iterator_tag iterator_category;
662 typedef typename _NodeTypes::__node_value_type value_type;
663 typedef typename _NodeTypes::difference_type difference_type;
664 typedef const value_type& reference;
665 typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
Eric Fiselier934b0922015-12-30 21:52:00 +0000666
Howard Hinnant3e519522010-05-11 19:42:16 +0000667
Eric Fiselier40492ba2016-07-23 20:36:55 +0000668 _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) {
669 _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000670 }
671
Howard Hinnant43d99232010-09-21 17:32:39 +0000672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000673 __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000674 : __node_(__x.__node_),
675 __bucket_(__x.__bucket_),
676 __bucket_count_(__x.__bucket_count_)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000677 {
Eric Fiselier40492ba2016-07-23 20:36:55 +0000678 _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000679 }
680
681#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant43d99232010-09-21 17:32:39 +0000682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000683 __hash_const_local_iterator(const __hash_const_local_iterator& __i)
684 : __node_(__i.__node_),
685 __bucket_(__i.__bucket_),
686 __bucket_count_(__i.__bucket_count_)
687 {
688 __get_db()->__iterator_copy(this, &__i);
689 }
690
Howard Hinnant43d99232010-09-21 17:32:39 +0000691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000692 ~__hash_const_local_iterator()
693 {
694 __get_db()->__erase_i(this);
695 }
696
697 _LIBCPP_INLINE_VISIBILITY
698 __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i)
699 {
700 if (this != &__i)
701 {
702 __get_db()->__iterator_copy(this, &__i);
703 __node_ = __i.__node_;
704 __bucket_ = __i.__bucket_;
705 __bucket_count_ = __i.__bucket_count_;
706 }
707 return *this;
708 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000709#endif // _LIBCPP_DEBUG_LEVEL >= 2
710
711 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000712 reference operator*() const {
713 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000714 "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
Eric Fiselier40492ba2016-07-23 20:36:55 +0000715 return __node_->__upcast()->__value_;
716 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000717
Howard Hinnant43d99232010-09-21 17:32:39 +0000718 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000719 pointer operator->() const {
720 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
721 "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
722 return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
723 }
724
725 _LIBCPP_INLINE_VISIBILITY
726 __hash_const_local_iterator& operator++() {
727 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000728 "Attempted to increment non-incrementable unordered container const_local_iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +0000729 __node_ = __node_->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000730 if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_)
Howard Hinnant3e519522010-05-11 19:42:16 +0000731 __node_ = nullptr;
732 return *this;
733 }
734
Howard Hinnant43d99232010-09-21 17:32:39 +0000735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000736 __hash_const_local_iterator operator++(int)
737 {
738 __hash_const_local_iterator __t(*this);
739 ++(*this);
740 return __t;
741 }
742
Howard Hinnant43d99232010-09-21 17:32:39 +0000743 friend _LIBCPP_INLINE_VISIBILITY
744 bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000745 {
Howard Hinnantb24c8022013-07-23 22:01:58 +0000746 return __x.__node_ == __y.__node_;
747 }
Howard Hinnant43d99232010-09-21 17:32:39 +0000748 friend _LIBCPP_INLINE_VISIBILITY
749 bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000750 {return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000751
752private:
Howard Hinnantb24c8022013-07-23 22:01:58 +0000753#if _LIBCPP_DEBUG_LEVEL >= 2
754 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000755 __hash_const_local_iterator(__next_pointer __node, size_t __bucket,
Howard Hinnantb24c8022013-07-23 22:01:58 +0000756 size_t __bucket_count, const void* __c) _NOEXCEPT
757 : __node_(__node),
758 __bucket_(__bucket),
759 __bucket_count_(__bucket_count)
760 {
761 __get_db()->__insert_ic(this, __c);
762 if (__node_ != nullptr)
763 __node_ = __node_->__next_;
764 }
765#else
Howard Hinnant43d99232010-09-21 17:32:39 +0000766 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000767 __hash_const_local_iterator(__next_pointer __node, size_t __bucket,
Howard Hinnant37141072011-06-04 18:54:24 +0000768 size_t __bucket_count) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000769 : __node_(__node),
770 __bucket_(__bucket),
771 __bucket_count_(__bucket_count)
772 {
773 if (__node_ != nullptr)
774 __node_ = __node_->__next_;
775 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000776#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000777 template <class, class, class, class> friend class __hash_table;
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000778 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000779};
780
781template <class _Alloc>
782class __bucket_list_deallocator
783{
784 typedef _Alloc allocator_type;
785 typedef allocator_traits<allocator_type> __alloc_traits;
786 typedef typename __alloc_traits::size_type size_type;
787
788 __compressed_pair<size_type, allocator_type> __data_;
789public:
790 typedef typename __alloc_traits::pointer pointer;
791
Howard Hinnant43d99232010-09-21 17:32:39 +0000792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000793 __bucket_list_deallocator()
Howard Hinnant37141072011-06-04 18:54:24 +0000794 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000795 : __data_(0) {}
Howard Hinnant43d99232010-09-21 17:32:39 +0000796
797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000798 __bucket_list_deallocator(const allocator_type& __a, size_type __size)
Howard Hinnant37141072011-06-04 18:54:24 +0000799 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000800 : __data_(__size, __a) {}
801
Eric Fiselierafa7a952017-04-19 01:23:04 +0000802#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant43d99232010-09-21 17:32:39 +0000803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000804 __bucket_list_deallocator(__bucket_list_deallocator&& __x)
Howard Hinnant37141072011-06-04 18:54:24 +0000805 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000806 : __data_(_VSTD::move(__x.__data_))
Howard Hinnant3e519522010-05-11 19:42:16 +0000807 {
808 __x.size() = 0;
809 }
Eric Fiselierafa7a952017-04-19 01:23:04 +0000810#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000811
Howard Hinnant37141072011-06-04 18:54:24 +0000812 _LIBCPP_INLINE_VISIBILITY
813 size_type& size() _NOEXCEPT {return __data_.first();}
814 _LIBCPP_INLINE_VISIBILITY
815 size_type size() const _NOEXCEPT {return __data_.first();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000816
Howard Hinnant43d99232010-09-21 17:32:39 +0000817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000818 allocator_type& __alloc() _NOEXCEPT {return __data_.second();}
819 _LIBCPP_INLINE_VISIBILITY
820 const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();}
821
822 _LIBCPP_INLINE_VISIBILITY
823 void operator()(pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000824 {
825 __alloc_traits::deallocate(__alloc(), __p, size());
826 }
827};
828
Howard Hinnantce534202011-06-14 19:58:17 +0000829template <class _Alloc> class __hash_map_node_destructor;
Howard Hinnant3e519522010-05-11 19:42:16 +0000830
831template <class _Alloc>
832class __hash_node_destructor
833{
834 typedef _Alloc allocator_type;
835 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000836
Howard Hinnant3e519522010-05-11 19:42:16 +0000837public:
838 typedef typename __alloc_traits::pointer pointer;
839private:
Eric Fiselierfcd02212016-02-11 11:59:44 +0000840 typedef __hash_node_types<pointer> _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +0000841
842 allocator_type& __na_;
843
844 __hash_node_destructor& operator=(const __hash_node_destructor&);
845
846public:
847 bool __value_constructed;
848
Howard Hinnant43d99232010-09-21 17:32:39 +0000849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf622b582011-07-31 17:04:30 +0000850 explicit __hash_node_destructor(allocator_type& __na,
851 bool __constructed = false) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000852 : __na_(__na),
Howard Hinnantf622b582011-07-31 17:04:30 +0000853 __value_constructed(__constructed)
Howard Hinnant3e519522010-05-11 19:42:16 +0000854 {}
855
Howard Hinnant43d99232010-09-21 17:32:39 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000857 void operator()(pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000858 {
859 if (__value_constructed)
Eric Fiselierfcd02212016-02-11 11:59:44 +0000860 __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000861 if (__p)
862 __alloc_traits::deallocate(__na_, __p, 1);
863 }
864
865 template <class> friend class __hash_map_node_destructor;
866};
867
Eric Fiselier04333f92017-01-13 22:42:53 +0000868
869#ifndef _LIBCPP_CXX03_LANG
870template <class _Key, class _Hash, class _Equal, class _Alloc>
871struct __diagnose_hash_table_helper {
872 static constexpr bool __trigger_diagnostics()
Eric Fiselierbd6a2d82017-03-03 22:35:58 +0000873 _LIBCPP_DIAGNOSE_WARNING(__check_hash_requirements<_Key, _Hash>::value
Eric Fiselieracb21582017-03-01 02:02:28 +0000874 && !__invokable<_Hash const&, _Key const&>::value,
875 "the specified hash functor does not provide a const call operator")
876 _LIBCPP_DIAGNOSE_WARNING(is_copy_constructible<_Equal>::value
877 && !__invokable<_Equal const&, _Key const&, _Key const&>::value,
878 "the specified comparator type does not provide a const call operator")
879 {
Eric Fiselierbd6a2d82017-03-03 22:35:58 +0000880 static_assert(__check_hash_requirements<_Key, _Hash>::value,
881 "the specified hash does not meet the Hash requirements");
Eric Fiselieracb21582017-03-01 02:02:28 +0000882 static_assert(is_copy_constructible<_Equal>::value,
883 "the specified comparator is required to be copy constructible");
884 return true;
885 }
Eric Fiselier04333f92017-01-13 22:42:53 +0000886};
887
888template <class _Key, class _Value, class _Hash, class _Equal, class _Alloc>
889struct __diagnose_hash_table_helper<
890 __hash_value_type<_Key, _Value>,
891 __unordered_map_hasher<_Key, __hash_value_type<_Key, _Value>, _Hash>,
892 __unordered_map_equal<_Key, __hash_value_type<_Key, _Value>, _Equal>,
893 _Alloc>
894: __diagnose_hash_table_helper<_Key, _Hash, _Equal, _Alloc>
895{
896};
897#endif // _LIBCPP_CXX03_LANG
898
Howard Hinnant3e519522010-05-11 19:42:16 +0000899template <class _Tp, class _Hash, class _Equal, class _Alloc>
900class __hash_table
901{
902public:
903 typedef _Tp value_type;
904 typedef _Hash hasher;
905 typedef _Equal key_equal;
906 typedef _Alloc allocator_type;
907
908private:
909 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000910 typedef typename
911 __make_hash_node_types<value_type, typename __alloc_traits::void_pointer>::type
912 _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +0000913public:
Eric Fiselierfcd02212016-02-11 11:59:44 +0000914
915 typedef typename _NodeTypes::__node_value_type __node_value_type;
916 typedef typename _NodeTypes::__container_value_type __container_value_type;
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +0000917 typedef typename _NodeTypes::key_type key_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000918 typedef value_type& reference;
919 typedef const value_type& const_reference;
920 typedef typename __alloc_traits::pointer pointer;
921 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000922#ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
Howard Hinnant3e519522010-05-11 19:42:16 +0000923 typedef typename __alloc_traits::size_type size_type;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000924#else
925 typedef typename _NodeTypes::size_type size_type;
926#endif
927 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000928public:
929 // Create __node
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000930
931 typedef typename _NodeTypes::__node_type __node;
Marshall Clow1f508012015-04-07 05:21:38 +0000932 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000933 typedef allocator_traits<__node_allocator> __node_traits;
Eric Fiselier8e397682016-02-11 15:22:37 +0000934 typedef typename _NodeTypes::__void_pointer __void_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000935 typedef typename _NodeTypes::__node_pointer __node_pointer;
936 typedef typename _NodeTypes::__node_pointer __node_const_pointer;
937 typedef typename _NodeTypes::__node_base_type __first_node;
938 typedef typename _NodeTypes::__node_base_pointer __node_base_pointer;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000939 typedef typename _NodeTypes::__next_pointer __next_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000940
941private:
942 // check for sane allocator pointer rebinding semantics. Rebinding the
943 // allocator for a new pointer type should be exactly the same as rebinding
944 // the pointer using 'pointer_traits'.
945 static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value),
946 "Allocator does not rebind pointers in a sane manner.");
947 typedef typename __rebind_alloc_helper<__node_traits, __first_node>::type
948 __node_base_allocator;
949 typedef allocator_traits<__node_base_allocator> __node_base_traits;
950 static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value),
951 "Allocator does not rebind pointers in a sane manner.");
Howard Hinnant3e519522010-05-11 19:42:16 +0000952
953private:
954
Eric Fiselier40492ba2016-07-23 20:36:55 +0000955 typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000956 typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000957 typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list;
Howard Hinnant3e519522010-05-11 19:42:16 +0000958 typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000959 typedef typename __bucket_list_deleter::pointer __node_pointer_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000960
Eric Fiselieracb21582017-03-01 02:02:28 +0000961#ifndef _LIBCPP_CXX03_LANG
962 static_assert(__diagnose_hash_table_helper<_Tp, _Hash, _Equal, _Alloc>::__trigger_diagnostics(), "");
963#endif
964
Howard Hinnant3e519522010-05-11 19:42:16 +0000965 // --- Member data begin ---
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000966 __bucket_list __bucket_list_;
967 __compressed_pair<__first_node, __node_allocator> __p1_;
968 __compressed_pair<size_type, hasher> __p2_;
969 __compressed_pair<float, key_equal> __p3_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000970 // --- Member data end ---
971
Howard Hinnant37141072011-06-04 18:54:24 +0000972 _LIBCPP_INLINE_VISIBILITY
973 size_type& size() _NOEXCEPT {return __p2_.first();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000974public:
Howard Hinnant37141072011-06-04 18:54:24 +0000975 _LIBCPP_INLINE_VISIBILITY
976 size_type size() const _NOEXCEPT {return __p2_.first();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000977
Howard Hinnant37141072011-06-04 18:54:24 +0000978 _LIBCPP_INLINE_VISIBILITY
979 hasher& hash_function() _NOEXCEPT {return __p2_.second();}
980 _LIBCPP_INLINE_VISIBILITY
981 const hasher& hash_function() const _NOEXCEPT {return __p2_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000982
Howard Hinnant37141072011-06-04 18:54:24 +0000983 _LIBCPP_INLINE_VISIBILITY
984 float& max_load_factor() _NOEXCEPT {return __p3_.first();}
985 _LIBCPP_INLINE_VISIBILITY
986 float max_load_factor() const _NOEXCEPT {return __p3_.first();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000987
Howard Hinnant37141072011-06-04 18:54:24 +0000988 _LIBCPP_INLINE_VISIBILITY
989 key_equal& key_eq() _NOEXCEPT {return __p3_.second();}
990 _LIBCPP_INLINE_VISIBILITY
991 const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000992
Howard Hinnant37141072011-06-04 18:54:24 +0000993 _LIBCPP_INLINE_VISIBILITY
994 __node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();}
995 _LIBCPP_INLINE_VISIBILITY
996 const __node_allocator& __node_alloc() const _NOEXCEPT
997 {return __p1_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000998
999public:
1000 typedef __hash_iterator<__node_pointer> iterator;
Howard Hinnant307f8142013-06-22 15:21:29 +00001001 typedef __hash_const_iterator<__node_pointer> const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +00001002 typedef __hash_local_iterator<__node_pointer> local_iterator;
Howard Hinnant307f8142013-06-22 15:21:29 +00001003 typedef __hash_const_local_iterator<__node_pointer> const_local_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +00001004
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001006 __hash_table()
1007 _NOEXCEPT_(
1008 is_nothrow_default_constructible<__bucket_list>::value &&
1009 is_nothrow_default_constructible<__first_node>::value &&
1010 is_nothrow_default_constructible<__node_allocator>::value &&
1011 is_nothrow_default_constructible<hasher>::value &&
1012 is_nothrow_default_constructible<key_equal>::value);
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001014 __hash_table(const hasher& __hf, const key_equal& __eql);
1015 __hash_table(const hasher& __hf, const key_equal& __eql,
1016 const allocator_type& __a);
1017 explicit __hash_table(const allocator_type& __a);
1018 __hash_table(const __hash_table& __u);
1019 __hash_table(const __hash_table& __u, const allocator_type& __a);
Eric Fiselierfcd02212016-02-11 11:59:44 +00001020#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant37141072011-06-04 18:54:24 +00001021 __hash_table(__hash_table&& __u)
1022 _NOEXCEPT_(
1023 is_nothrow_move_constructible<__bucket_list>::value &&
1024 is_nothrow_move_constructible<__first_node>::value &&
1025 is_nothrow_move_constructible<__node_allocator>::value &&
1026 is_nothrow_move_constructible<hasher>::value &&
1027 is_nothrow_move_constructible<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001028 __hash_table(__hash_table&& __u, const allocator_type& __a);
Eric Fiselierfcd02212016-02-11 11:59:44 +00001029#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001030 ~__hash_table();
1031
1032 __hash_table& operator=(const __hash_table& __u);
Eric Fiselierfcd02212016-02-11 11:59:44 +00001033#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001035 __hash_table& operator=(__hash_table&& __u)
1036 _NOEXCEPT_(
1037 __node_traits::propagate_on_container_move_assignment::value &&
1038 is_nothrow_move_assignable<__node_allocator>::value &&
1039 is_nothrow_move_assignable<hasher>::value &&
1040 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001041#endif
1042 template <class _InputIterator>
1043 void __assign_unique(_InputIterator __first, _InputIterator __last);
1044 template <class _InputIterator>
1045 void __assign_multi(_InputIterator __first, _InputIterator __last);
1046
Howard Hinnant43d99232010-09-21 17:32:39 +00001047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001048 size_type max_size() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001049 {
Eric Fiselier55b31b4e2016-11-23 01:18:56 +00001050 return std::min<size_type>(
Eric Fiselier341c9dd2016-11-23 09:16:12 +00001051 __node_traits::max_size(__node_alloc()),
Eric Fiselier55b31b4e2016-11-23 01:18:56 +00001052 numeric_limits<difference_type >::max()
1053 );
Howard Hinnant3e519522010-05-11 19:42:16 +00001054 }
1055
1056 pair<iterator, bool> __node_insert_unique(__node_pointer __nd);
1057 iterator __node_insert_multi(__node_pointer __nd);
1058 iterator __node_insert_multi(const_iterator __p,
1059 __node_pointer __nd);
1060
Eric Fiselierfcd02212016-02-11 11:59:44 +00001061#ifndef _LIBCPP_CXX03_LANG
1062 template <class _Key, class ..._Args>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00001063 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001064 pair<iterator, bool> __emplace_unique_key_args(_Key const& __k, _Args&&... __args);
Howard Hinnant3e519522010-05-11 19:42:16 +00001065
Eric Fiselierfcd02212016-02-11 11:59:44 +00001066 template <class... _Args>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00001067 _LIBCPP_INLINE_VISIBILITY
1068 pair<iterator, bool> __emplace_unique_impl(_Args&&... __args);
1069
1070 template <class _Pp>
1071 _LIBCPP_INLINE_VISIBILITY
1072 pair<iterator, bool> __emplace_unique(_Pp&& __x) {
1073 return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x),
1074 __can_extract_key<_Pp, key_type>());
1075 }
Eric Fiselier50088682016-04-16 00:23:12 +00001076
1077 template <class _First, class _Second>
1078 _LIBCPP_INLINE_VISIBILITY
1079 typename enable_if<
1080 __can_extract_map_key<_First, key_type, __container_value_type>::value,
1081 pair<iterator, bool>
1082 >::type __emplace_unique(_First&& __f, _Second&& __s) {
1083 return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f),
1084 _VSTD::forward<_Second>(__s));
1085 }
1086
Eric Fiselierfcd02212016-02-11 11:59:44 +00001087 template <class... _Args>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00001088 _LIBCPP_INLINE_VISIBILITY
1089 pair<iterator, bool> __emplace_unique(_Args&&... __args) {
1090 return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...);
1091 }
1092
1093 template <class _Pp>
1094 _LIBCPP_INLINE_VISIBILITY
1095 pair<iterator, bool>
1096 __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) {
1097 return __emplace_unique_impl(_VSTD::forward<_Pp>(__x));
1098 }
1099 template <class _Pp>
1100 _LIBCPP_INLINE_VISIBILITY
1101 pair<iterator, bool>
1102 __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) {
1103 return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x));
1104 }
1105 template <class _Pp>
1106 _LIBCPP_INLINE_VISIBILITY
1107 pair<iterator, bool>
1108 __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) {
1109 return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x));
1110 }
1111
1112 template <class... _Args>
1113 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001114 iterator __emplace_multi(_Args&&... __args);
1115 template <class... _Args>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00001116 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001117 iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
1118
1119
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001120 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001121 pair<iterator, bool>
1122 __insert_unique(__container_value_type&& __x) {
1123 return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _VSTD::move(__x));
1124 }
1125
1126 template <class _Pp, class = typename enable_if<
1127 !__is_same_uncvref<_Pp, __container_value_type>::value
1128 >::type>
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001129 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001130 pair<iterator, bool> __insert_unique(_Pp&& __x) {
1131 return __emplace_unique(_VSTD::forward<_Pp>(__x));
1132 }
1133
1134 template <class _Pp>
1135 _LIBCPP_INLINE_VISIBILITY
1136 iterator __insert_multi(_Pp&& __x) {
1137 return __emplace_multi(_VSTD::forward<_Pp>(__x));
1138 }
1139
1140 template <class _Pp>
1141 _LIBCPP_INLINE_VISIBILITY
1142 iterator __insert_multi(const_iterator __p, _Pp&& __x) {
1143 return __emplace_hint_multi(__p, _VSTD::forward<_Pp>(__x));
1144 }
1145
1146#else // !defined(_LIBCPP_CXX03_LANG)
1147 template <class _Key, class _Args>
Eric Fiselier4271d012016-09-25 04:05:46 +00001148 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001149 pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args);
1150
1151 iterator __insert_multi(const __container_value_type& __x);
1152 iterator __insert_multi(const_iterator __p, const __container_value_type& __x);
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001153#endif
1154
Eric Fiselierfcd02212016-02-11 11:59:44 +00001155 _LIBCPP_INLINE_VISIBILITY
1156 pair<iterator, bool> __insert_unique(const __container_value_type& __x) {
1157 return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x);
1158 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001159
Howard Hinnant37141072011-06-04 18:54:24 +00001160 void clear() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +00001161 void rehash(size_type __n);
Howard Hinnant43d99232010-09-21 17:32:39 +00001162 _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n)
Howard Hinnant3e519522010-05-11 19:42:16 +00001163 {rehash(static_cast<size_type>(ceil(__n / max_load_factor())));}
Howard Hinnant43d99232010-09-21 17:32:39 +00001164
1165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001166 size_type bucket_count() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001167 {
1168 return __bucket_list_.get_deleter().size();
1169 }
1170
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001172 iterator begin() _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001174 iterator end() _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001176 const_iterator begin() const _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001177 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001178 const_iterator end() const _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +00001179
1180 template <class _Key>
Howard Hinnant43d99232010-09-21 17:32:39 +00001181 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001182 size_type bucket(const _Key& __k) const
Howard Hinnante5c13de2013-07-29 19:05:47 +00001183 {
1184 _LIBCPP_ASSERT(bucket_count() > 0,
1185 "unordered container::bucket(key) called when bucket_count() == 0");
1186 return __constrain_hash(hash_function()(__k), bucket_count());
1187 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001188
1189 template <class _Key>
1190 iterator find(const _Key& __x);
1191 template <class _Key>
1192 const_iterator find(const _Key& __x) const;
1193
Howard Hinnantc003db12011-11-29 18:15:50 +00001194 typedef __hash_node_destructor<__node_allocator> _Dp;
1195 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +00001196
1197 iterator erase(const_iterator __p);
1198 iterator erase(const_iterator __first, const_iterator __last);
1199 template <class _Key>
1200 size_type __erase_unique(const _Key& __k);
1201 template <class _Key>
1202 size_type __erase_multi(const _Key& __k);
Howard Hinnant37141072011-06-04 18:54:24 +00001203 __node_holder remove(const_iterator __p) _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +00001204
1205 template <class _Key>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001207 size_type __count_unique(const _Key& __k) const;
1208 template <class _Key>
1209 size_type __count_multi(const _Key& __k) const;
1210
1211 template <class _Key>
1212 pair<iterator, iterator>
1213 __equal_range_unique(const _Key& __k);
1214 template <class _Key>
1215 pair<const_iterator, const_iterator>
1216 __equal_range_unique(const _Key& __k) const;
1217
1218 template <class _Key>
1219 pair<iterator, iterator>
1220 __equal_range_multi(const _Key& __k);
1221 template <class _Key>
1222 pair<const_iterator, const_iterator>
1223 __equal_range_multi(const _Key& __k) const;
1224
Howard Hinnant37141072011-06-04 18:54:24 +00001225 void swap(__hash_table& __u)
Eric Fiselier87a82492015-07-18 20:40:46 +00001226#if _LIBCPP_STD_VER <= 11
Eric Fiselier780b51d2016-12-28 05:53:01 +00001227 _NOEXCEPT_DEBUG_(
Marshall Clowe3fbe142015-07-13 20:04:56 +00001228 __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
Marshall Clowe3fbe142015-07-13 20:04:56 +00001229 && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
1230 || __is_nothrow_swappable<__pointer_allocator>::value)
1231 && (!__node_traits::propagate_on_container_swap::value
1232 || __is_nothrow_swappable<__node_allocator>::value)
Marshall Clowe3fbe142015-07-13 20:04:56 +00001233 );
Eric Fiselier87a82492015-07-18 20:40:46 +00001234#else
Eric Fiselier780b51d2016-12-28 05:53:01 +00001235 _NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value);
Eric Fiselier87a82492015-07-18 20:40:46 +00001236#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001237
Howard Hinnant43d99232010-09-21 17:32:39 +00001238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001239 size_type max_bucket_count() const _NOEXCEPT
Eric Fiselier55b31b4e2016-11-23 01:18:56 +00001240 {return max_size(); }
Howard Hinnant3e519522010-05-11 19:42:16 +00001241 size_type bucket_size(size_type __n) const;
Howard Hinnant37141072011-06-04 18:54:24 +00001242 _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001243 {
1244 size_type __bc = bucket_count();
1245 return __bc != 0 ? (float)size() / __bc : 0.f;
1246 }
Howard Hinnant37141072011-06-04 18:54:24 +00001247 _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT
Howard Hinnante5c13de2013-07-29 19:05:47 +00001248 {
1249 _LIBCPP_ASSERT(__mlf > 0,
1250 "unordered container::max_load_factor(lf) called with lf <= 0");
1251 max_load_factor() = _VSTD::max(__mlf, load_factor());
1252 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001253
Howard Hinnantb24c8022013-07-23 22:01:58 +00001254 _LIBCPP_INLINE_VISIBILITY
1255 local_iterator
1256 begin(size_type __n)
1257 {
Howard Hinnante5c13de2013-07-29 19:05:47 +00001258 _LIBCPP_ASSERT(__n < bucket_count(),
1259 "unordered container::begin(n) called with n >= bucket_count()");
Howard Hinnantb24c8022013-07-23 22:01:58 +00001260#if _LIBCPP_DEBUG_LEVEL >= 2
1261 return local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
1262#else
1263 return local_iterator(__bucket_list_[__n], __n, bucket_count());
1264#endif
1265 }
1266
1267 _LIBCPP_INLINE_VISIBILITY
1268 local_iterator
1269 end(size_type __n)
1270 {
Howard Hinnante5c13de2013-07-29 19:05:47 +00001271 _LIBCPP_ASSERT(__n < bucket_count(),
1272 "unordered container::end(n) called with n >= bucket_count()");
Howard Hinnantb24c8022013-07-23 22:01:58 +00001273#if _LIBCPP_DEBUG_LEVEL >= 2
1274 return local_iterator(nullptr, __n, bucket_count(), this);
1275#else
1276 return local_iterator(nullptr, __n, bucket_count());
1277#endif
1278 }
1279
1280 _LIBCPP_INLINE_VISIBILITY
1281 const_local_iterator
1282 cbegin(size_type __n) const
1283 {
Howard Hinnante5c13de2013-07-29 19:05:47 +00001284 _LIBCPP_ASSERT(__n < bucket_count(),
1285 "unordered container::cbegin(n) called with n >= bucket_count()");
Howard Hinnantb24c8022013-07-23 22:01:58 +00001286#if _LIBCPP_DEBUG_LEVEL >= 2
1287 return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
1288#else
1289 return const_local_iterator(__bucket_list_[__n], __n, bucket_count());
1290#endif
1291 }
1292
1293 _LIBCPP_INLINE_VISIBILITY
1294 const_local_iterator
1295 cend(size_type __n) const
1296 {
Howard Hinnante5c13de2013-07-29 19:05:47 +00001297 _LIBCPP_ASSERT(__n < bucket_count(),
1298 "unordered container::cend(n) called with n >= bucket_count()");
Howard Hinnantb24c8022013-07-23 22:01:58 +00001299#if _LIBCPP_DEBUG_LEVEL >= 2
1300 return const_local_iterator(nullptr, __n, bucket_count(), this);
1301#else
1302 return const_local_iterator(nullptr, __n, bucket_count());
1303#endif
1304 }
1305
1306#if _LIBCPP_DEBUG_LEVEL >= 2
1307
1308 bool __dereferenceable(const const_iterator* __i) const;
1309 bool __decrementable(const const_iterator* __i) const;
1310 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1311 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1312
1313#endif // _LIBCPP_DEBUG_LEVEL >= 2
1314
Howard Hinnant3e519522010-05-11 19:42:16 +00001315private:
1316 void __rehash(size_type __n);
1317
Eric Fiselierfcd02212016-02-11 11:59:44 +00001318#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001319 template <class ..._Args>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001320 __node_holder __construct_node(_Args&& ...__args);
1321
1322 template <class _First, class ..._Rest>
1323 __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest);
1324#else // _LIBCPP_CXX03_LANG
1325 __node_holder __construct_node(const __container_value_type& __v);
1326 __node_holder __construct_node_hash(size_t __hash, const __container_value_type& __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001327#endif
Eric Fiselierfcd02212016-02-11 11:59:44 +00001328
Howard Hinnant3e519522010-05-11 19:42:16 +00001329
Howard Hinnant43d99232010-09-21 17:32:39 +00001330 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001331 void __copy_assign_alloc(const __hash_table& __u)
1332 {__copy_assign_alloc(__u, integral_constant<bool,
1333 __node_traits::propagate_on_container_copy_assignment::value>());}
1334 void __copy_assign_alloc(const __hash_table& __u, true_type);
Howard Hinnant43d99232010-09-21 17:32:39 +00001335 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc2063662011-12-01 20:21:04 +00001336 void __copy_assign_alloc(const __hash_table&, false_type) {}
Howard Hinnant3e519522010-05-11 19:42:16 +00001337
Eric Fiselierfcd02212016-02-11 11:59:44 +00001338#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001339 void __move_assign(__hash_table& __u, false_type);
Howard Hinnant37141072011-06-04 18:54:24 +00001340 void __move_assign(__hash_table& __u, true_type)
1341 _NOEXCEPT_(
1342 is_nothrow_move_assignable<__node_allocator>::value &&
1343 is_nothrow_move_assignable<hasher>::value &&
1344 is_nothrow_move_assignable<key_equal>::value);
1345 _LIBCPP_INLINE_VISIBILITY
1346 void __move_assign_alloc(__hash_table& __u)
1347 _NOEXCEPT_(
1348 !__node_traits::propagate_on_container_move_assignment::value ||
1349 (is_nothrow_move_assignable<__pointer_allocator>::value &&
1350 is_nothrow_move_assignable<__node_allocator>::value))
Howard Hinnant3e519522010-05-11 19:42:16 +00001351 {__move_assign_alloc(__u, integral_constant<bool,
1352 __node_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnant43d99232010-09-21 17:32:39 +00001353 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001354 void __move_assign_alloc(__hash_table& __u, true_type)
Howard Hinnant37141072011-06-04 18:54:24 +00001355 _NOEXCEPT_(
1356 is_nothrow_move_assignable<__pointer_allocator>::value &&
1357 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001358 {
1359 __bucket_list_.get_deleter().__alloc() =
Howard Hinnantce48a112011-06-30 21:18:19 +00001360 _VSTD::move(__u.__bucket_list_.get_deleter().__alloc());
1361 __node_alloc() = _VSTD::move(__u.__node_alloc());
Howard Hinnant3e519522010-05-11 19:42:16 +00001362 }
Howard Hinnant43d99232010-09-21 17:32:39 +00001363 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001364 void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {}
Eric Fiselierfcd02212016-02-11 11:59:44 +00001365#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001366
Eric Fiseliercd71f442017-01-07 03:01:24 +00001367 void __deallocate_node(__next_pointer __np) _NOEXCEPT;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001368 __next_pointer __detach() _NOEXCEPT;
Howard Hinnant307f8142013-06-22 15:21:29 +00001369
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +00001370 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
1371 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
Howard Hinnant3e519522010-05-11 19:42:16 +00001372};
1373
1374template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001375inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001376__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table()
Howard Hinnant37141072011-06-04 18:54:24 +00001377 _NOEXCEPT_(
1378 is_nothrow_default_constructible<__bucket_list>::value &&
1379 is_nothrow_default_constructible<__first_node>::value &&
Eric Fiseliere2e332a2015-12-16 00:53:04 +00001380 is_nothrow_default_constructible<__node_allocator>::value &&
Howard Hinnant37141072011-06-04 18:54:24 +00001381 is_nothrow_default_constructible<hasher>::value &&
1382 is_nothrow_default_constructible<key_equal>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001383 : __p2_(0),
1384 __p3_(1.0f)
1385{
1386}
1387
1388template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001389inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001390__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
1391 const key_equal& __eql)
1392 : __bucket_list_(nullptr, __bucket_list_deleter()),
1393 __p1_(),
1394 __p2_(0, __hf),
1395 __p3_(1.0f, __eql)
1396{
1397}
1398
1399template <class _Tp, class _Hash, class _Equal, class _Alloc>
1400__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
1401 const key_equal& __eql,
1402 const allocator_type& __a)
1403 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
Eric Fiselierc88580c2017-04-12 23:45:53 +00001404 __p1_(__second_tag(), __node_allocator(__a)),
Howard Hinnant3e519522010-05-11 19:42:16 +00001405 __p2_(0, __hf),
1406 __p3_(1.0f, __eql)
1407{
1408}
1409
1410template <class _Tp, class _Hash, class _Equal, class _Alloc>
1411__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a)
1412 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
Eric Fiselierc88580c2017-04-12 23:45:53 +00001413 __p1_(__second_tag(), __node_allocator(__a)),
Howard Hinnant3e519522010-05-11 19:42:16 +00001414 __p2_(0),
1415 __p3_(1.0f)
1416{
1417}
1418
1419template <class _Tp, class _Hash, class _Equal, class _Alloc>
1420__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u)
1421 : __bucket_list_(nullptr,
1422 __bucket_list_deleter(allocator_traits<__pointer_allocator>::
1423 select_on_container_copy_construction(
1424 __u.__bucket_list_.get_deleter().__alloc()), 0)),
Eric Fiselierc88580c2017-04-12 23:45:53 +00001425 __p1_(__second_tag(), allocator_traits<__node_allocator>::
Howard Hinnant3e519522010-05-11 19:42:16 +00001426 select_on_container_copy_construction(__u.__node_alloc())),
1427 __p2_(0, __u.hash_function()),
1428 __p3_(__u.__p3_)
1429{
1430}
1431
1432template <class _Tp, class _Hash, class _Equal, class _Alloc>
1433__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u,
1434 const allocator_type& __a)
1435 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
Eric Fiselierc88580c2017-04-12 23:45:53 +00001436 __p1_(__second_tag(), __node_allocator(__a)),
Howard Hinnant3e519522010-05-11 19:42:16 +00001437 __p2_(0, __u.hash_function()),
1438 __p3_(__u.__p3_)
1439{
1440}
1441
Eric Fiselierfcd02212016-02-11 11:59:44 +00001442#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001443
1444template <class _Tp, class _Hash, class _Equal, class _Alloc>
1445__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001446 _NOEXCEPT_(
1447 is_nothrow_move_constructible<__bucket_list>::value &&
1448 is_nothrow_move_constructible<__first_node>::value &&
Eric Fiseliere2e332a2015-12-16 00:53:04 +00001449 is_nothrow_move_constructible<__node_allocator>::value &&
Howard Hinnant37141072011-06-04 18:54:24 +00001450 is_nothrow_move_constructible<hasher>::value &&
1451 is_nothrow_move_constructible<key_equal>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001452 : __bucket_list_(_VSTD::move(__u.__bucket_list_)),
1453 __p1_(_VSTD::move(__u.__p1_)),
1454 __p2_(_VSTD::move(__u.__p2_)),
1455 __p3_(_VSTD::move(__u.__p3_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001456{
1457 if (size() > 0)
1458 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001459 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
1460 __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001461 __u.__p1_.first().__next_ = nullptr;
1462 __u.size() = 0;
1463 }
1464}
1465
1466template <class _Tp, class _Hash, class _Equal, class _Alloc>
1467__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u,
1468 const allocator_type& __a)
1469 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
Eric Fiselierc88580c2017-04-12 23:45:53 +00001470 __p1_(__second_tag(), __node_allocator(__a)),
Howard Hinnantce48a112011-06-30 21:18:19 +00001471 __p2_(0, _VSTD::move(__u.hash_function())),
1472 __p3_(_VSTD::move(__u.__p3_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001473{
1474 if (__a == allocator_type(__u.__node_alloc()))
1475 {
1476 __bucket_list_.reset(__u.__bucket_list_.release());
1477 __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
1478 __u.__bucket_list_.get_deleter().size() = 0;
1479 if (__u.size() > 0)
1480 {
1481 __p1_.first().__next_ = __u.__p1_.first().__next_;
1482 __u.__p1_.first().__next_ = nullptr;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001483 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
1484 __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001485 size() = __u.size();
1486 __u.size() = 0;
1487 }
1488 }
1489}
1490
Eric Fiselierfcd02212016-02-11 11:59:44 +00001491#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001492
1493template <class _Tp, class _Hash, class _Equal, class _Alloc>
1494__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
1495{
Eric Fiselieracb21582017-03-01 02:02:28 +00001496#if defined(_LIBCPP_CXX03_LANG)
Marshall Clow3b8669e2016-06-30 22:05:45 +00001497 static_assert((is_copy_constructible<key_equal>::value),
1498 "Predicate must be copy-constructible.");
1499 static_assert((is_copy_constructible<hasher>::value),
1500 "Hasher must be copy-constructible.");
Eric Fiselier04333f92017-01-13 22:42:53 +00001501#endif
Eric Fiselieracb21582017-03-01 02:02:28 +00001502
Eric Fiseliercd71f442017-01-07 03:01:24 +00001503 __deallocate_node(__p1_.first().__next_);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001504#if _LIBCPP_DEBUG_LEVEL >= 2
1505 __get_db()->__erase_c(this);
1506#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001507}
1508
1509template <class _Tp, class _Hash, class _Equal, class _Alloc>
1510void
1511__hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc(
1512 const __hash_table& __u, true_type)
1513{
1514 if (__node_alloc() != __u.__node_alloc())
1515 {
1516 clear();
1517 __bucket_list_.reset();
1518 __bucket_list_.get_deleter().size() = 0;
1519 }
1520 __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc();
1521 __node_alloc() = __u.__node_alloc();
1522}
1523
1524template <class _Tp, class _Hash, class _Equal, class _Alloc>
1525__hash_table<_Tp, _Hash, _Equal, _Alloc>&
1526__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u)
1527{
1528 if (this != &__u)
1529 {
1530 __copy_assign_alloc(__u);
1531 hash_function() = __u.hash_function();
1532 key_eq() = __u.key_eq();
1533 max_load_factor() = __u.max_load_factor();
1534 __assign_multi(__u.begin(), __u.end());
1535 }
1536 return *this;
1537}
1538
1539template <class _Tp, class _Hash, class _Equal, class _Alloc>
1540void
Eric Fiseliercd71f442017-01-07 03:01:24 +00001541__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np)
Howard Hinnant37141072011-06-04 18:54:24 +00001542 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001543{
1544 __node_allocator& __na = __node_alloc();
1545 while (__np != nullptr)
1546 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001547 __next_pointer __next = __np->__next_;
Howard Hinnantb24c8022013-07-23 22:01:58 +00001548#if _LIBCPP_DEBUG_LEVEL >= 2
1549 __c_node* __c = __get_db()->__find_c_and_lock(this);
1550 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1551 {
1552 --__p;
1553 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1554 if (__i->__node_ == __np)
1555 {
1556 (*__p)->__c_ = nullptr;
1557 if (--__c->end_ != __p)
1558 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1559 }
1560 }
1561 __get_db()->unlock();
1562#endif
Eric Fiselier40492ba2016-07-23 20:36:55 +00001563 __node_pointer __real_np = __np->__upcast();
1564 __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__value_));
1565 __node_traits::deallocate(__na, __real_np, 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001566 __np = __next;
1567 }
1568}
1569
1570template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselier40492ba2016-07-23 20:36:55 +00001571typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer
Howard Hinnant37141072011-06-04 18:54:24 +00001572__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001573{
1574 size_type __bc = bucket_count();
1575 for (size_type __i = 0; __i < __bc; ++__i)
1576 __bucket_list_[__i] = nullptr;
1577 size() = 0;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001578 __next_pointer __cache = __p1_.first().__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001579 __p1_.first().__next_ = nullptr;
1580 return __cache;
1581}
1582
Eric Fiselierfcd02212016-02-11 11:59:44 +00001583#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001584
1585template <class _Tp, class _Hash, class _Equal, class _Alloc>
1586void
1587__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
1588 __hash_table& __u, true_type)
Howard Hinnant37141072011-06-04 18:54:24 +00001589 _NOEXCEPT_(
1590 is_nothrow_move_assignable<__node_allocator>::value &&
1591 is_nothrow_move_assignable<hasher>::value &&
1592 is_nothrow_move_assignable<key_equal>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001593{
1594 clear();
1595 __bucket_list_.reset(__u.__bucket_list_.release());
1596 __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
1597 __u.__bucket_list_.get_deleter().size() = 0;
1598 __move_assign_alloc(__u);
1599 size() = __u.size();
Howard Hinnantce48a112011-06-30 21:18:19 +00001600 hash_function() = _VSTD::move(__u.hash_function());
Howard Hinnant3e519522010-05-11 19:42:16 +00001601 max_load_factor() = __u.max_load_factor();
Howard Hinnantce48a112011-06-30 21:18:19 +00001602 key_eq() = _VSTD::move(__u.key_eq());
Howard Hinnant3e519522010-05-11 19:42:16 +00001603 __p1_.first().__next_ = __u.__p1_.first().__next_;
1604 if (size() > 0)
1605 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001606 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
1607 __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001608 __u.__p1_.first().__next_ = nullptr;
1609 __u.size() = 0;
1610 }
Howard Hinnantb24c8022013-07-23 22:01:58 +00001611#if _LIBCPP_DEBUG_LEVEL >= 2
1612 __get_db()->swap(this, &__u);
1613#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001614}
1615
1616template <class _Tp, class _Hash, class _Equal, class _Alloc>
1617void
1618__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
1619 __hash_table& __u, false_type)
1620{
1621 if (__node_alloc() == __u.__node_alloc())
1622 __move_assign(__u, true_type());
1623 else
1624 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001625 hash_function() = _VSTD::move(__u.hash_function());
1626 key_eq() = _VSTD::move(__u.key_eq());
Howard Hinnant3e519522010-05-11 19:42:16 +00001627 max_load_factor() = __u.max_load_factor();
1628 if (bucket_count() != 0)
1629 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001630 __next_pointer __cache = __detach();
Howard Hinnant3e519522010-05-11 19:42:16 +00001631#ifndef _LIBCPP_NO_EXCEPTIONS
1632 try
1633 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001634#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001635 const_iterator __i = __u.begin();
1636 while (__cache != nullptr && __u.size() != 0)
1637 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001638 __cache->__upcast()->__value_ =
1639 _VSTD::move(__u.remove(__i++)->__value_);
1640 __next_pointer __next = __cache->__next_;
1641 __node_insert_multi(__cache->__upcast());
Howard Hinnant3e519522010-05-11 19:42:16 +00001642 __cache = __next;
1643 }
1644#ifndef _LIBCPP_NO_EXCEPTIONS
1645 }
1646 catch (...)
1647 {
Eric Fiseliercd71f442017-01-07 03:01:24 +00001648 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001649 throw;
1650 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001651#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiseliercd71f442017-01-07 03:01:24 +00001652 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001653 }
1654 const_iterator __i = __u.begin();
1655 while (__u.size() != 0)
1656 {
Eric Fiselierfcd02212016-02-11 11:59:44 +00001657 __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001658 __node_insert_multi(__h.get());
1659 __h.release();
1660 }
1661 }
1662}
1663
1664template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001665inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001666__hash_table<_Tp, _Hash, _Equal, _Alloc>&
1667__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001668 _NOEXCEPT_(
1669 __node_traits::propagate_on_container_move_assignment::value &&
1670 is_nothrow_move_assignable<__node_allocator>::value &&
1671 is_nothrow_move_assignable<hasher>::value &&
1672 is_nothrow_move_assignable<key_equal>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001673{
1674 __move_assign(__u, integral_constant<bool,
1675 __node_traits::propagate_on_container_move_assignment::value>());
1676 return *this;
1677}
1678
Eric Fiselierfcd02212016-02-11 11:59:44 +00001679#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001680
1681template <class _Tp, class _Hash, class _Equal, class _Alloc>
1682template <class _InputIterator>
1683void
1684__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first,
1685 _InputIterator __last)
1686{
Eric Fiselierfcd02212016-02-11 11:59:44 +00001687 typedef iterator_traits<_InputIterator> _ITraits;
1688 typedef typename _ITraits::value_type _ItValueType;
1689 static_assert((is_same<_ItValueType, __container_value_type>::value),
1690 "__assign_unique may only be called with the containers value type");
1691
Howard Hinnant3e519522010-05-11 19:42:16 +00001692 if (bucket_count() != 0)
1693 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001694 __next_pointer __cache = __detach();
Howard Hinnant3e519522010-05-11 19:42:16 +00001695#ifndef _LIBCPP_NO_EXCEPTIONS
1696 try
1697 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001698#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001699 for (; __cache != nullptr && __first != __last; ++__first)
1700 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001701 __cache->__upcast()->__value_ = *__first;
1702 __next_pointer __next = __cache->__next_;
1703 __node_insert_unique(__cache->__upcast());
Howard Hinnant3e519522010-05-11 19:42:16 +00001704 __cache = __next;
1705 }
1706#ifndef _LIBCPP_NO_EXCEPTIONS
1707 }
1708 catch (...)
1709 {
Eric Fiseliercd71f442017-01-07 03:01:24 +00001710 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001711 throw;
1712 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001713#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiseliercd71f442017-01-07 03:01:24 +00001714 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001715 }
1716 for (; __first != __last; ++__first)
1717 __insert_unique(*__first);
1718}
1719
1720template <class _Tp, class _Hash, class _Equal, class _Alloc>
1721template <class _InputIterator>
1722void
1723__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first,
1724 _InputIterator __last)
1725{
Eric Fiselierfcd02212016-02-11 11:59:44 +00001726 typedef iterator_traits<_InputIterator> _ITraits;
1727 typedef typename _ITraits::value_type _ItValueType;
1728 static_assert((is_same<_ItValueType, __container_value_type>::value ||
1729 is_same<_ItValueType, __node_value_type>::value),
1730 "__assign_multi may only be called with the containers value type"
1731 " or the nodes value type");
Howard Hinnant3e519522010-05-11 19:42:16 +00001732 if (bucket_count() != 0)
1733 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001734 __next_pointer __cache = __detach();
Howard Hinnant3e519522010-05-11 19:42:16 +00001735#ifndef _LIBCPP_NO_EXCEPTIONS
1736 try
1737 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001738#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001739 for (; __cache != nullptr && __first != __last; ++__first)
1740 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001741 __cache->__upcast()->__value_ = *__first;
1742 __next_pointer __next = __cache->__next_;
1743 __node_insert_multi(__cache->__upcast());
Howard Hinnant3e519522010-05-11 19:42:16 +00001744 __cache = __next;
1745 }
1746#ifndef _LIBCPP_NO_EXCEPTIONS
1747 }
1748 catch (...)
1749 {
Eric Fiseliercd71f442017-01-07 03:01:24 +00001750 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001751 throw;
1752 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001753#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiseliercd71f442017-01-07 03:01:24 +00001754 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001755 }
1756 for (; __first != __last; ++__first)
Eric Fiselierfcd02212016-02-11 11:59:44 +00001757 __insert_multi(_NodeTypes::__get_value(*__first));
Howard Hinnant3e519522010-05-11 19:42:16 +00001758}
1759
1760template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001761inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001762typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Howard Hinnant37141072011-06-04 18:54:24 +00001763__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001764{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001765#if _LIBCPP_DEBUG_LEVEL >= 2
1766 return iterator(__p1_.first().__next_, this);
1767#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001768 return iterator(__p1_.first().__next_);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001769#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001770}
1771
1772template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001773inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001774typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Howard Hinnant37141072011-06-04 18:54:24 +00001775__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001776{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001777#if _LIBCPP_DEBUG_LEVEL >= 2
1778 return iterator(nullptr, this);
1779#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001780 return iterator(nullptr);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001781#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001782}
1783
1784template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001785inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001786typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
Howard Hinnant37141072011-06-04 18:54:24 +00001787__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001788{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001789#if _LIBCPP_DEBUG_LEVEL >= 2
1790 return const_iterator(__p1_.first().__next_, this);
1791#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001792 return const_iterator(__p1_.first().__next_);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001793#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001794}
1795
1796template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001797inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001798typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
Howard Hinnant37141072011-06-04 18:54:24 +00001799__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001800{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001801#if _LIBCPP_DEBUG_LEVEL >= 2
1802 return const_iterator(nullptr, this);
1803#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001804 return const_iterator(nullptr);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001805#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001806}
1807
1808template <class _Tp, class _Hash, class _Equal, class _Alloc>
1809void
Howard Hinnant37141072011-06-04 18:54:24 +00001810__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001811{
1812 if (size() > 0)
1813 {
Eric Fiseliercd71f442017-01-07 03:01:24 +00001814 __deallocate_node(__p1_.first().__next_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001815 __p1_.first().__next_ = nullptr;
1816 size_type __bc = bucket_count();
Howard Hinnant1f8da842011-07-05 14:14:17 +00001817 for (size_type __i = 0; __i < __bc; ++__i)
Howard Hinnant3e519522010-05-11 19:42:16 +00001818 __bucket_list_[__i] = nullptr;
1819 size() = 0;
1820 }
1821}
1822
1823template <class _Tp, class _Hash, class _Equal, class _Alloc>
1824pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1825__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd)
1826{
1827 __nd->__hash_ = hash_function()(__nd->__value_);
1828 size_type __bc = bucket_count();
1829 bool __inserted = false;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001830 __next_pointer __ndptr;
Howard Hinnant3e519522010-05-11 19:42:16 +00001831 size_t __chash;
1832 if (__bc != 0)
1833 {
Howard Hinnant4cb38a82012-07-06 17:31:14 +00001834 __chash = __constrain_hash(__nd->__hash_, __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00001835 __ndptr = __bucket_list_[__chash];
1836 if (__ndptr != nullptr)
1837 {
1838 for (__ndptr = __ndptr->__next_; __ndptr != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00001839 __constrain_hash(__ndptr->__hash(), __bc) == __chash;
Howard Hinnant3e519522010-05-11 19:42:16 +00001840 __ndptr = __ndptr->__next_)
1841 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001842 if (key_eq()(__ndptr->__upcast()->__value_, __nd->__value_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001843 goto __done;
1844 }
1845 }
1846 }
1847 {
1848 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1849 {
Eric Fiselier9ba5c112015-02-02 21:31:48 +00001850 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnant3e519522010-05-11 19:42:16 +00001851 size_type(ceil(float(size() + 1) / max_load_factor()))));
1852 __bc = bucket_count();
Howard Hinnant4cb38a82012-07-06 17:31:14 +00001853 __chash = __constrain_hash(__nd->__hash_, __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00001854 }
1855 // insert_after __bucket_list_[__chash], or __first_node if bucket is null
Eric Fiselier40492ba2016-07-23 20:36:55 +00001856 __next_pointer __pn = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00001857 if (__pn == nullptr)
1858 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001859 __pn =__p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001860 __nd->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001861 __pn->__next_ = __nd->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001862 // fix up __bucket_list_
1863 __bucket_list_[__chash] = __pn;
1864 if (__nd->__next_ != nullptr)
Eric Fiselier40492ba2016-07-23 20:36:55 +00001865 __bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001866 }
1867 else
1868 {
1869 __nd->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001870 __pn->__next_ = __nd->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001871 }
Eric Fiselier40492ba2016-07-23 20:36:55 +00001872 __ndptr = __nd->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001873 // increment size
1874 ++size();
1875 __inserted = true;
1876 }
1877__done:
Howard Hinnantb24c8022013-07-23 22:01:58 +00001878#if _LIBCPP_DEBUG_LEVEL >= 2
1879 return pair<iterator, bool>(iterator(__ndptr, this), __inserted);
1880#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001881 return pair<iterator, bool>(iterator(__ndptr), __inserted);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001882#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001883}
1884
1885template <class _Tp, class _Hash, class _Equal, class _Alloc>
1886typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1887__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp)
1888{
1889 __cp->__hash_ = hash_function()(__cp->__value_);
1890 size_type __bc = bucket_count();
1891 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1892 {
Eric Fiselier9ba5c112015-02-02 21:31:48 +00001893 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnant3e519522010-05-11 19:42:16 +00001894 size_type(ceil(float(size() + 1) / max_load_factor()))));
1895 __bc = bucket_count();
1896 }
Howard Hinnant4cb38a82012-07-06 17:31:14 +00001897 size_t __chash = __constrain_hash(__cp->__hash_, __bc);
Eric Fiselier40492ba2016-07-23 20:36:55 +00001898 __next_pointer __pn = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00001899 if (__pn == nullptr)
1900 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001901 __pn =__p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001902 __cp->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001903 __pn->__next_ = __cp->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001904 // fix up __bucket_list_
1905 __bucket_list_[__chash] = __pn;
1906 if (__cp->__next_ != nullptr)
Eric Fiselier40492ba2016-07-23 20:36:55 +00001907 __bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)]
1908 = __cp->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001909 }
1910 else
1911 {
1912 for (bool __found = false; __pn->__next_ != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00001913 __constrain_hash(__pn->__next_->__hash(), __bc) == __chash;
Howard Hinnant3e519522010-05-11 19:42:16 +00001914 __pn = __pn->__next_)
Howard Hinnantb3371f62010-08-22 00:02:43 +00001915 {
Howard Hinnant3e519522010-05-11 19:42:16 +00001916 // __found key_eq() action
1917 // false false loop
1918 // true true loop
1919 // false true set __found to true
1920 // true false break
Eric Fiselier40492ba2016-07-23 20:36:55 +00001921 if (__found != (__pn->__next_->__hash() == __cp->__hash_ &&
1922 key_eq()(__pn->__next_->__upcast()->__value_, __cp->__value_)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001923 {
1924 if (!__found)
1925 __found = true;
1926 else
1927 break;
1928 }
1929 }
1930 __cp->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001931 __pn->__next_ = __cp->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001932 if (__cp->__next_ != nullptr)
1933 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001934 size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00001935 if (__nhash != __chash)
Eric Fiselier40492ba2016-07-23 20:36:55 +00001936 __bucket_list_[__nhash] = __cp->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001937 }
1938 }
1939 ++size();
Howard Hinnantb24c8022013-07-23 22:01:58 +00001940#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier40492ba2016-07-23 20:36:55 +00001941 return iterator(__cp->__ptr(), this);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001942#else
Eric Fiselier40492ba2016-07-23 20:36:55 +00001943 return iterator(__cp->__ptr());
Howard Hinnantb24c8022013-07-23 22:01:58 +00001944#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001945}
1946
1947template <class _Tp, class _Hash, class _Equal, class _Alloc>
1948typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1949__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
1950 const_iterator __p, __node_pointer __cp)
1951{
Howard Hinnant2f51de52013-08-02 17:50:49 +00001952#if _LIBCPP_DEBUG_LEVEL >= 2
1953 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1954 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
1955 " referring to this unordered container");
1956#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001957 if (__p != end() && key_eq()(*__p, __cp->__value_))
1958 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001959 __next_pointer __np = __p.__node_;
1960 __cp->__hash_ = __np->__hash();
Howard Hinnant3e519522010-05-11 19:42:16 +00001961 size_type __bc = bucket_count();
1962 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1963 {
Eric Fiselier9ba5c112015-02-02 21:31:48 +00001964 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnant3e519522010-05-11 19:42:16 +00001965 size_type(ceil(float(size() + 1) / max_load_factor()))));
1966 __bc = bucket_count();
1967 }
Howard Hinnant4cb38a82012-07-06 17:31:14 +00001968 size_t __chash = __constrain_hash(__cp->__hash_, __bc);
Eric Fiselier40492ba2016-07-23 20:36:55 +00001969 __next_pointer __pp = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00001970 while (__pp->__next_ != __np)
1971 __pp = __pp->__next_;
1972 __cp->__next_ = __np;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001973 __pp->__next_ = static_cast<__next_pointer>(__cp);
Howard Hinnant3e519522010-05-11 19:42:16 +00001974 ++size();
Howard Hinnantb24c8022013-07-23 22:01:58 +00001975#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier40492ba2016-07-23 20:36:55 +00001976 return iterator(static_cast<__next_pointer>(__cp), this);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001977#else
Eric Fiselier40492ba2016-07-23 20:36:55 +00001978 return iterator(static_cast<__next_pointer>(__cp));
Howard Hinnantb24c8022013-07-23 22:01:58 +00001979#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001980 }
1981 return __node_insert_multi(__cp);
1982}
1983
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001984
1985
Eric Fiselierfcd02212016-02-11 11:59:44 +00001986#ifndef _LIBCPP_CXX03_LANG
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001987template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001988template <class _Key, class ..._Args>
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001989pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001990__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args)
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001991#else
1992template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001993template <class _Key, class _Args>
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001994pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001995__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args)
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001996#endif
1997{
Eric Fiselierfcd02212016-02-11 11:59:44 +00001998
1999 size_t __hash = hash_function()(__k);
Howard Hinnant3e519522010-05-11 19:42:16 +00002000 size_type __bc = bucket_count();
2001 bool __inserted = false;
Eric Fiselier40492ba2016-07-23 20:36:55 +00002002 __next_pointer __nd;
Howard Hinnant3e519522010-05-11 19:42:16 +00002003 size_t __chash;
2004 if (__bc != 0)
2005 {
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002006 __chash = __constrain_hash(__hash, __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002007 __nd = __bucket_list_[__chash];
2008 if (__nd != nullptr)
2009 {
2010 for (__nd = __nd->__next_; __nd != nullptr &&
Eric Fiselier1a06fe52016-07-24 06:22:25 +00002011 (__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash);
Howard Hinnant3e519522010-05-11 19:42:16 +00002012 __nd = __nd->__next_)
2013 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002014 if (key_eq()(__nd->__upcast()->__value_, __k))
Howard Hinnant3e519522010-05-11 19:42:16 +00002015 goto __done;
2016 }
2017 }
2018 }
2019 {
Eric Fiselierfcd02212016-02-11 11:59:44 +00002020#ifndef _LIBCPP_CXX03_LANG
2021 __node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...);
2022#else
2023 __node_holder __h = __construct_node_hash(__hash, __args);
2024#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002025 if (size()+1 > __bc * max_load_factor() || __bc == 0)
2026 {
Eric Fiselier9ba5c112015-02-02 21:31:48 +00002027 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnant3e519522010-05-11 19:42:16 +00002028 size_type(ceil(float(size() + 1) / max_load_factor()))));
2029 __bc = bucket_count();
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002030 __chash = __constrain_hash(__hash, __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002031 }
2032 // insert_after __bucket_list_[__chash], or __first_node if bucket is null
Eric Fiselier40492ba2016-07-23 20:36:55 +00002033 __next_pointer __pn = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00002034 if (__pn == nullptr)
2035 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002036 __pn = __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00002037 __h->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00002038 __pn->__next_ = __h.get()->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00002039 // fix up __bucket_list_
2040 __bucket_list_[__chash] = __pn;
2041 if (__h->__next_ != nullptr)
Eric Fiselier40492ba2016-07-23 20:36:55 +00002042 __bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)]
2043 = __h.get()->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00002044 }
2045 else
2046 {
2047 __h->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00002048 __pn->__next_ = static_cast<__next_pointer>(__h.get());
Howard Hinnant3e519522010-05-11 19:42:16 +00002049 }
Eric Fiselier40492ba2016-07-23 20:36:55 +00002050 __nd = static_cast<__next_pointer>(__h.release());
Howard Hinnant3e519522010-05-11 19:42:16 +00002051 // increment size
2052 ++size();
2053 __inserted = true;
2054 }
2055__done:
Howard Hinnantb24c8022013-07-23 22:01:58 +00002056#if _LIBCPP_DEBUG_LEVEL >= 2
2057 return pair<iterator, bool>(iterator(__nd, this), __inserted);
2058#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002059 return pair<iterator, bool>(iterator(__nd), __inserted);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002060#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002061}
2062
Eric Fiselierfcd02212016-02-11 11:59:44 +00002063#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002064
2065template <class _Tp, class _Hash, class _Equal, class _Alloc>
2066template <class... _Args>
2067pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00002068__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args)
Howard Hinnant3e519522010-05-11 19:42:16 +00002069{
Howard Hinnantce48a112011-06-30 21:18:19 +00002070 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002071 pair<iterator, bool> __r = __node_insert_unique(__h.get());
2072 if (__r.second)
2073 __h.release();
2074 return __r;
2075}
2076
2077template <class _Tp, class _Hash, class _Equal, class _Alloc>
2078template <class... _Args>
2079typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2080__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args)
2081{
Howard Hinnantce48a112011-06-30 21:18:19 +00002082 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002083 iterator __r = __node_insert_multi(__h.get());
2084 __h.release();
2085 return __r;
2086}
2087
2088template <class _Tp, class _Hash, class _Equal, class _Alloc>
2089template <class... _Args>
2090typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2091__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(
2092 const_iterator __p, _Args&&... __args)
2093{
Howard Hinnante5c13de2013-07-29 19:05:47 +00002094#if _LIBCPP_DEBUG_LEVEL >= 2
2095 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2096 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
2097 " referring to this unordered container");
2098#endif
Howard Hinnantce48a112011-06-30 21:18:19 +00002099 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002100 iterator __r = __node_insert_multi(__p, __h.get());
2101 __h.release();
2102 return __r;
2103}
2104
Eric Fiselierfcd02212016-02-11 11:59:44 +00002105#else // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002106
2107template <class _Tp, class _Hash, class _Equal, class _Alloc>
2108typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Eric Fiselierfcd02212016-02-11 11:59:44 +00002109__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const __container_value_type& __x)
Howard Hinnant3e519522010-05-11 19:42:16 +00002110{
2111 __node_holder __h = __construct_node(__x);
2112 iterator __r = __node_insert_multi(__h.get());
2113 __h.release();
2114 return __r;
2115}
2116
2117template <class _Tp, class _Hash, class _Equal, class _Alloc>
2118typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2119__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
Eric Fiselierfcd02212016-02-11 11:59:44 +00002120 const __container_value_type& __x)
Howard Hinnant3e519522010-05-11 19:42:16 +00002121{
Howard Hinnante5c13de2013-07-29 19:05:47 +00002122#if _LIBCPP_DEBUG_LEVEL >= 2
2123 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2124 "unordered container::insert(const_iterator, lvalue) called with an iterator not"
2125 " referring to this unordered container");
2126#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002127 __node_holder __h = __construct_node(__x);
2128 iterator __r = __node_insert_multi(__p, __h.get());
2129 __h.release();
2130 return __r;
2131}
2132
Eric Fiselierfcd02212016-02-11 11:59:44 +00002133#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002134
2135template <class _Tp, class _Hash, class _Equal, class _Alloc>
2136void
2137__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
2138{
Dan Albert553b09b2018-01-08 22:57:12 +00002139 if (__n == 1)
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002140 __n = 2;
2141 else if (__n & (__n - 1))
2142 __n = __next_prime(__n);
Howard Hinnant3e519522010-05-11 19:42:16 +00002143 size_type __bc = bucket_count();
2144 if (__n > __bc)
2145 __rehash(__n);
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002146 else if (__n < __bc)
Howard Hinnant3e519522010-05-11 19:42:16 +00002147 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002148 __n = _VSTD::max<size_type>
Howard Hinnant3e519522010-05-11 19:42:16 +00002149 (
2150 __n,
Eric Fiselier9ba5c112015-02-02 21:31:48 +00002151 __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) :
2152 __next_prime(size_t(ceil(float(size()) / max_load_factor())))
Howard Hinnant3e519522010-05-11 19:42:16 +00002153 );
2154 if (__n < __bc)
2155 __rehash(__n);
2156 }
2157}
2158
2159template <class _Tp, class _Hash, class _Equal, class _Alloc>
2160void
2161__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
2162{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002163#if _LIBCPP_DEBUG_LEVEL >= 2
2164 __get_db()->__invalidate_all(this);
2165#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant3e519522010-05-11 19:42:16 +00002166 __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc();
2167 __bucket_list_.reset(__nbc > 0 ?
2168 __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr);
2169 __bucket_list_.get_deleter().size() = __nbc;
2170 if (__nbc > 0)
2171 {
2172 for (size_type __i = 0; __i < __nbc; ++__i)
2173 __bucket_list_[__i] = nullptr;
Eric Fiselier40492ba2016-07-23 20:36:55 +00002174 __next_pointer __pp = __p1_.first().__ptr();
2175 __next_pointer __cp = __pp->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002176 if (__cp != nullptr)
2177 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002178 size_type __chash = __constrain_hash(__cp->__hash(), __nbc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002179 __bucket_list_[__chash] = __pp;
2180 size_type __phash = __chash;
2181 for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
2182 __cp = __pp->__next_)
2183 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002184 __chash = __constrain_hash(__cp->__hash(), __nbc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002185 if (__chash == __phash)
2186 __pp = __cp;
2187 else
2188 {
2189 if (__bucket_list_[__chash] == nullptr)
2190 {
2191 __bucket_list_[__chash] = __pp;
2192 __pp = __cp;
2193 __phash = __chash;
2194 }
2195 else
2196 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002197 __next_pointer __np = __cp;
Howard Hinnant3e519522010-05-11 19:42:16 +00002198 for (; __np->__next_ != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00002199 key_eq()(__cp->__upcast()->__value_,
2200 __np->__next_->__upcast()->__value_);
Howard Hinnant3e519522010-05-11 19:42:16 +00002201 __np = __np->__next_)
2202 ;
2203 __pp->__next_ = __np->__next_;
2204 __np->__next_ = __bucket_list_[__chash]->__next_;
2205 __bucket_list_[__chash]->__next_ = __cp;
Howard Hinnantb3371f62010-08-22 00:02:43 +00002206
Howard Hinnant3e519522010-05-11 19:42:16 +00002207 }
2208 }
2209 }
2210 }
2211 }
2212}
2213
2214template <class _Tp, class _Hash, class _Equal, class _Alloc>
2215template <class _Key>
2216typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2217__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k)
2218{
2219 size_t __hash = hash_function()(__k);
2220 size_type __bc = bucket_count();
2221 if (__bc != 0)
2222 {
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002223 size_t __chash = __constrain_hash(__hash, __bc);
Eric Fiselier40492ba2016-07-23 20:36:55 +00002224 __next_pointer __nd = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00002225 if (__nd != nullptr)
2226 {
2227 for (__nd = __nd->__next_; __nd != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00002228 (__nd->__hash() == __hash
2229 || __constrain_hash(__nd->__hash(), __bc) == __chash);
Howard Hinnant3e519522010-05-11 19:42:16 +00002230 __nd = __nd->__next_)
2231 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002232 if ((__nd->__hash() == __hash)
2233 && key_eq()(__nd->__upcast()->__value_, __k))
Howard Hinnantb24c8022013-07-23 22:01:58 +00002234#if _LIBCPP_DEBUG_LEVEL >= 2
2235 return iterator(__nd, this);
2236#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002237 return iterator(__nd);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002238#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002239 }
2240 }
2241 }
2242 return end();
2243}
2244
2245template <class _Tp, class _Hash, class _Equal, class _Alloc>
2246template <class _Key>
2247typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
2248__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const
2249{
2250 size_t __hash = hash_function()(__k);
2251 size_type __bc = bucket_count();
2252 if (__bc != 0)
2253 {
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002254 size_t __chash = __constrain_hash(__hash, __bc);
Eric Fiselier40492ba2016-07-23 20:36:55 +00002255 __next_pointer __nd = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00002256 if (__nd != nullptr)
2257 {
2258 for (__nd = __nd->__next_; __nd != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00002259 (__hash == __nd->__hash()
2260 || __constrain_hash(__nd->__hash(), __bc) == __chash);
Howard Hinnant3e519522010-05-11 19:42:16 +00002261 __nd = __nd->__next_)
2262 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002263 if ((__nd->__hash() == __hash)
2264 && key_eq()(__nd->__upcast()->__value_, __k))
Howard Hinnantb24c8022013-07-23 22:01:58 +00002265#if _LIBCPP_DEBUG_LEVEL >= 2
2266 return const_iterator(__nd, this);
2267#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002268 return const_iterator(__nd);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002269#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002270 }
2271 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00002272
Howard Hinnant3e519522010-05-11 19:42:16 +00002273 }
2274 return end();
2275}
2276
Eric Fiselierfcd02212016-02-11 11:59:44 +00002277#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002278
2279template <class _Tp, class _Hash, class _Equal, class _Alloc>
2280template <class ..._Args>
2281typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
2282__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args)
2283{
Eric Fiselierfcd02212016-02-11 11:59:44 +00002284 static_assert(!__is_hash_value_type<_Args...>::value,
2285 "Construct cannot be called with a hash value type");
Howard Hinnant3e519522010-05-11 19:42:16 +00002286 __node_allocator& __na = __node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00002287 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Eric Fiselierfcd02212016-02-11 11:59:44 +00002288 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002289 __h.get_deleter().__value_constructed = true;
2290 __h->__hash_ = hash_function()(__h->__value_);
2291 __h->__next_ = nullptr;
2292 return __h;
2293}
2294
2295template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselierfcd02212016-02-11 11:59:44 +00002296template <class _First, class ..._Rest>
Howard Hinnant3e519522010-05-11 19:42:16 +00002297typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Eric Fiselierfcd02212016-02-11 11:59:44 +00002298__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(
2299 size_t __hash, _First&& __f, _Rest&& ...__rest)
Howard Hinnant3e519522010-05-11 19:42:16 +00002300{
Eric Fiselierfcd02212016-02-11 11:59:44 +00002301 static_assert(!__is_hash_value_type<_First, _Rest...>::value,
2302 "Construct cannot be called with a hash value type");
Howard Hinnant3e519522010-05-11 19:42:16 +00002303 __node_allocator& __na = __node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00002304 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Eric Fiselierfcd02212016-02-11 11:59:44 +00002305 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_),
2306 _VSTD::forward<_First>(__f),
2307 _VSTD::forward<_Rest>(__rest)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002308 __h.get_deleter().__value_constructed = true;
2309 __h->__hash_ = __hash;
2310 __h->__next_ = nullptr;
Howard Hinnant179b1f82013-08-22 18:29:50 +00002311 return __h;
Howard Hinnant3e519522010-05-11 19:42:16 +00002312}
2313
Eric Fiselierfcd02212016-02-11 11:59:44 +00002314#else // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002315
2316template <class _Tp, class _Hash, class _Equal, class _Alloc>
2317typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Eric Fiselierfcd02212016-02-11 11:59:44 +00002318__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const __container_value_type& __v)
Howard Hinnant3e519522010-05-11 19:42:16 +00002319{
2320 __node_allocator& __na = __node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00002321 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Eric Fiselierfcd02212016-02-11 11:59:44 +00002322 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00002323 __h.get_deleter().__value_constructed = true;
2324 __h->__hash_ = hash_function()(__h->__value_);
2325 __h->__next_ = nullptr;
Dimitry Andric251c6292015-08-19 06:43:33 +00002326 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnant3e519522010-05-11 19:42:16 +00002327}
2328
Howard Hinnant3e519522010-05-11 19:42:16 +00002329template <class _Tp, class _Hash, class _Equal, class _Alloc>
2330typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Eric Fiselierfcd02212016-02-11 11:59:44 +00002331__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash,
2332 const __container_value_type& __v)
Howard Hinnant3e519522010-05-11 19:42:16 +00002333{
2334 __node_allocator& __na = __node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00002335 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Eric Fiselierfcd02212016-02-11 11:59:44 +00002336 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00002337 __h.get_deleter().__value_constructed = true;
2338 __h->__hash_ = __hash;
2339 __h->__next_ = nullptr;
Dimitry Andric251c6292015-08-19 06:43:33 +00002340 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnant3e519522010-05-11 19:42:16 +00002341}
2342
Eric Fiselierfcd02212016-02-11 11:59:44 +00002343#endif // _LIBCPP_CXX03_LANG
2344
Howard Hinnant3e519522010-05-11 19:42:16 +00002345template <class _Tp, class _Hash, class _Equal, class _Alloc>
2346typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2347__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
2348{
Eric Fiselier40492ba2016-07-23 20:36:55 +00002349 __next_pointer __np = __p.__node_;
Howard Hinnantb24c8022013-07-23 22:01:58 +00002350#if _LIBCPP_DEBUG_LEVEL >= 2
2351 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2352 "unordered container erase(iterator) called with an iterator not"
2353 " referring to this container");
2354 _LIBCPP_ASSERT(__p != end(),
2355 "unordered container erase(iterator) called with a non-dereferenceable iterator");
2356 iterator __r(__np, this);
2357#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002358 iterator __r(__np);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002359#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002360 ++__r;
2361 remove(__p);
2362 return __r;
2363}
2364
2365template <class _Tp, class _Hash, class _Equal, class _Alloc>
2366typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2367__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
2368 const_iterator __last)
2369{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002370#if _LIBCPP_DEBUG_LEVEL >= 2
2371 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2372 "unodered container::erase(iterator, iterator) called with an iterator not"
2373 " referring to this unodered container");
2374 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
2375 "unodered container::erase(iterator, iterator) called with an iterator not"
2376 " referring to this unodered container");
2377#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002378 for (const_iterator __p = __first; __first != __last; __p = __first)
2379 {
2380 ++__first;
2381 erase(__p);
2382 }
Eric Fiselier40492ba2016-07-23 20:36:55 +00002383 __next_pointer __np = __last.__node_;
Howard Hinnantb24c8022013-07-23 22:01:58 +00002384#if _LIBCPP_DEBUG_LEVEL >= 2
2385 return iterator (__np, this);
2386#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002387 return iterator (__np);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002388#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002389}
2390
2391template <class _Tp, class _Hash, class _Equal, class _Alloc>
2392template <class _Key>
2393typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2394__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k)
2395{
2396 iterator __i = find(__k);
2397 if (__i == end())
2398 return 0;
2399 erase(__i);
2400 return 1;
2401}
2402
2403template <class _Tp, class _Hash, class _Equal, class _Alloc>
2404template <class _Key>
2405typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2406__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k)
2407{
2408 size_type __r = 0;
2409 iterator __i = find(__k);
2410 if (__i != end())
2411 {
2412 iterator __e = end();
2413 do
2414 {
2415 erase(__i++);
2416 ++__r;
2417 } while (__i != __e && key_eq()(*__i, __k));
2418 }
2419 return __r;
2420}
2421
2422template <class _Tp, class _Hash, class _Equal, class _Alloc>
2423typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Howard Hinnant37141072011-06-04 18:54:24 +00002424__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00002425{
2426 // current node
Eric Fiselier40492ba2016-07-23 20:36:55 +00002427 __next_pointer __cn = __p.__node_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002428 size_type __bc = bucket_count();
Eric Fiselier40492ba2016-07-23 20:36:55 +00002429 size_t __chash = __constrain_hash(__cn->__hash(), __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002430 // find previous node
Eric Fiselier40492ba2016-07-23 20:36:55 +00002431 __next_pointer __pn = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00002432 for (; __pn->__next_ != __cn; __pn = __pn->__next_)
2433 ;
2434 // Fix up __bucket_list_
2435 // if __pn is not in same bucket (before begin is not in same bucket) &&
2436 // if __cn->__next_ is not in same bucket (nullptr is not in same bucket)
Eric Fiselier40492ba2016-07-23 20:36:55 +00002437 if (__pn == __p1_.first().__ptr()
2438 || __constrain_hash(__pn->__hash(), __bc) != __chash)
Howard Hinnant3e519522010-05-11 19:42:16 +00002439 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002440 if (__cn->__next_ == nullptr
2441 || __constrain_hash(__cn->__next_->__hash(), __bc) != __chash)
Howard Hinnant3e519522010-05-11 19:42:16 +00002442 __bucket_list_[__chash] = nullptr;
2443 }
2444 // if __cn->__next_ is not in same bucket (nullptr is in same bucket)
2445 if (__cn->__next_ != nullptr)
2446 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002447 size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002448 if (__nhash != __chash)
2449 __bucket_list_[__nhash] = __pn;
2450 }
2451 // remove __cn
2452 __pn->__next_ = __cn->__next_;
2453 __cn->__next_ = nullptr;
2454 --size();
Howard Hinnantb24c8022013-07-23 22:01:58 +00002455#if _LIBCPP_DEBUG_LEVEL >= 2
2456 __c_node* __c = __get_db()->__find_c_and_lock(this);
Eric Fiselier780b51d2016-12-28 05:53:01 +00002457 for (__i_node** __dp = __c->end_; __dp != __c->beg_; )
Howard Hinnantb24c8022013-07-23 22:01:58 +00002458 {
Eric Fiselier780b51d2016-12-28 05:53:01 +00002459 --__dp;
2460 iterator* __i = static_cast<iterator*>((*__dp)->__i_);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002461 if (__i->__node_ == __cn)
2462 {
Eric Fiselier780b51d2016-12-28 05:53:01 +00002463 (*__dp)->__c_ = nullptr;
2464 if (--__c->end_ != __dp)
2465 memmove(__dp, __dp+1, (__c->end_ - __dp)*sizeof(__i_node*));
Howard Hinnantb24c8022013-07-23 22:01:58 +00002466 }
2467 }
2468 __get_db()->unlock();
2469#endif
Eric Fiselier40492ba2016-07-23 20:36:55 +00002470 return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true));
Howard Hinnant3e519522010-05-11 19:42:16 +00002471}
2472
2473template <class _Tp, class _Hash, class _Equal, class _Alloc>
2474template <class _Key>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00002475inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002476typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2477__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const
2478{
2479 return static_cast<size_type>(find(__k) != end());
2480}
2481
2482template <class _Tp, class _Hash, class _Equal, class _Alloc>
2483template <class _Key>
2484typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2485__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const
2486{
2487 size_type __r = 0;
2488 const_iterator __i = find(__k);
2489 if (__i != end())
2490 {
2491 const_iterator __e = end();
2492 do
2493 {
2494 ++__i;
2495 ++__r;
2496 } while (__i != __e && key_eq()(*__i, __k));
2497 }
2498 return __r;
2499}
2500
2501template <class _Tp, class _Hash, class _Equal, class _Alloc>
2502template <class _Key>
2503pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
2504 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
2505__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
2506 const _Key& __k)
2507{
2508 iterator __i = find(__k);
2509 iterator __j = __i;
2510 if (__i != end())
2511 ++__j;
2512 return pair<iterator, iterator>(__i, __j);
2513}
2514
2515template <class _Tp, class _Hash, class _Equal, class _Alloc>
2516template <class _Key>
2517pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
2518 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
2519__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
2520 const _Key& __k) const
2521{
2522 const_iterator __i = find(__k);
2523 const_iterator __j = __i;
2524 if (__i != end())
2525 ++__j;
2526 return pair<const_iterator, const_iterator>(__i, __j);
2527}
2528
2529template <class _Tp, class _Hash, class _Equal, class _Alloc>
2530template <class _Key>
2531pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
2532 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
2533__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
2534 const _Key& __k)
2535{
2536 iterator __i = find(__k);
2537 iterator __j = __i;
2538 if (__i != end())
2539 {
2540 iterator __e = end();
2541 do
2542 {
2543 ++__j;
2544 } while (__j != __e && key_eq()(*__j, __k));
2545 }
2546 return pair<iterator, iterator>(__i, __j);
2547}
2548
2549template <class _Tp, class _Hash, class _Equal, class _Alloc>
2550template <class _Key>
2551pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
2552 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
2553__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
2554 const _Key& __k) const
2555{
2556 const_iterator __i = find(__k);
2557 const_iterator __j = __i;
2558 if (__i != end())
2559 {
2560 const_iterator __e = end();
2561 do
2562 {
2563 ++__j;
2564 } while (__j != __e && key_eq()(*__j, __k));
2565 }
2566 return pair<const_iterator, const_iterator>(__i, __j);
2567}
2568
2569template <class _Tp, class _Hash, class _Equal, class _Alloc>
2570void
2571__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
Eric Fiselier87a82492015-07-18 20:40:46 +00002572#if _LIBCPP_STD_VER <= 11
Eric Fiselier780b51d2016-12-28 05:53:01 +00002573 _NOEXCEPT_DEBUG_(
Marshall Clowe3fbe142015-07-13 20:04:56 +00002574 __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
Marshall Clowe3fbe142015-07-13 20:04:56 +00002575 && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
2576 || __is_nothrow_swappable<__pointer_allocator>::value)
2577 && (!__node_traits::propagate_on_container_swap::value
2578 || __is_nothrow_swappable<__node_allocator>::value)
Marshall Clowe3fbe142015-07-13 20:04:56 +00002579 )
Eric Fiselier87a82492015-07-18 20:40:46 +00002580#else
Eric Fiselier780b51d2016-12-28 05:53:01 +00002581 _NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value)
Eric Fiselier87a82492015-07-18 20:40:46 +00002582#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002583{
Eric Fiselier780b51d2016-12-28 05:53:01 +00002584 _LIBCPP_ASSERT(__node_traits::propagate_on_container_swap::value ||
2585 this->__node_alloc() == __u.__node_alloc(),
2586 "list::swap: Either propagate_on_container_swap must be true"
2587 " or the allocators must compare equal");
Howard Hinnant3e519522010-05-11 19:42:16 +00002588 {
2589 __node_pointer_pointer __npp = __bucket_list_.release();
2590 __bucket_list_.reset(__u.__bucket_list_.release());
2591 __u.__bucket_list_.reset(__npp);
2592 }
Howard Hinnantce48a112011-06-30 21:18:19 +00002593 _VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size());
Marshall Clowe3fbe142015-07-13 20:04:56 +00002594 __swap_allocator(__bucket_list_.get_deleter().__alloc(),
Howard Hinnant3e519522010-05-11 19:42:16 +00002595 __u.__bucket_list_.get_deleter().__alloc());
Marshall Clowe3fbe142015-07-13 20:04:56 +00002596 __swap_allocator(__node_alloc(), __u.__node_alloc());
Howard Hinnantce48a112011-06-30 21:18:19 +00002597 _VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_);
Howard Hinnant3e519522010-05-11 19:42:16 +00002598 __p2_.swap(__u.__p2_);
2599 __p3_.swap(__u.__p3_);
2600 if (size() > 0)
Eric Fiselier40492ba2016-07-23 20:36:55 +00002601 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
2602 __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00002603 if (__u.size() > 0)
Eric Fiselier40492ba2016-07-23 20:36:55 +00002604 __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] =
2605 __u.__p1_.first().__ptr();
Howard Hinnantb24c8022013-07-23 22:01:58 +00002606#if _LIBCPP_DEBUG_LEVEL >= 2
2607 __get_db()->swap(this, &__u);
2608#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002609}
2610
2611template <class _Tp, class _Hash, class _Equal, class _Alloc>
2612typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2613__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const
2614{
Howard Hinnante5c13de2013-07-29 19:05:47 +00002615 _LIBCPP_ASSERT(__n < bucket_count(),
2616 "unordered container::bucket_size(n) called with n >= bucket_count()");
Eric Fiselier40492ba2016-07-23 20:36:55 +00002617 __next_pointer __np = __bucket_list_[__n];
Howard Hinnant3e519522010-05-11 19:42:16 +00002618 size_type __bc = bucket_count();
2619 size_type __r = 0;
2620 if (__np != nullptr)
2621 {
2622 for (__np = __np->__next_; __np != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00002623 __constrain_hash(__np->__hash(), __bc) == __n;
Howard Hinnant3e519522010-05-11 19:42:16 +00002624 __np = __np->__next_, ++__r)
2625 ;
2626 }
2627 return __r;
2628}
2629
Howard Hinnant37141072011-06-04 18:54:24 +00002630template <class _Tp, class _Hash, class _Equal, class _Alloc>
2631inline _LIBCPP_INLINE_VISIBILITY
2632void
2633swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x,
2634 __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y)
2635 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2636{
2637 __x.swap(__y);
2638}
2639
Howard Hinnantb24c8022013-07-23 22:01:58 +00002640#if _LIBCPP_DEBUG_LEVEL >= 2
2641
2642template <class _Tp, class _Hash, class _Equal, class _Alloc>
2643bool
2644__hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const
2645{
2646 return __i->__node_ != nullptr;
2647}
2648
2649template <class _Tp, class _Hash, class _Equal, class _Alloc>
2650bool
2651__hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const
2652{
2653 return false;
2654}
2655
2656template <class _Tp, class _Hash, class _Equal, class _Alloc>
2657bool
2658__hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
2659{
2660 return false;
2661}
2662
2663template <class _Tp, class _Hash, class _Equal, class _Alloc>
2664bool
2665__hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
2666{
2667 return false;
2668}
2669
2670#endif // _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiseliera016efb2017-05-31 22:07:49 +00002671
Howard Hinnant3e519522010-05-11 19:42:16 +00002672_LIBCPP_END_NAMESPACE_STD
2673
Eric Fiseliera016efb2017-05-31 22:07:49 +00002674_LIBCPP_POP_MACROS
2675
Howard Hinnant3e519522010-05-11 19:42:16 +00002676#endif // _LIBCPP__HASH_TABLE