blob: 216149371b7e0f8554d5d4efaa069a37fc3a3418 [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
Howard Hinnantab4f4382011-11-29 16:45:27 +000023#include <__undef_min_max>
24
Eric Fiselierc1bd9192014-08-10 23:53:08 +000025#include <__debug>
Howard Hinnant42a30462013-08-02 00:26:35 +000026
Howard Hinnant073458b2011-10-17 20:05:10 +000027#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +000028#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +000029#endif
Howard Hinnant3e519522010-05-11 19:42:16 +000030
31_LIBCPP_BEGIN_NAMESPACE_STD
32
Eric Fiselierfcd02212016-02-11 11:59:44 +000033
34#ifndef _LIBCPP_CXX03_LANG
35template <class _Key, class _Tp>
36union __hash_value_type;
37#else
38template <class _Key, class _Tp>
39struct __hash_value_type;
40#endif
41
Eric Fiselier04333f92017-01-13 22:42:53 +000042template <class _Key, class _Cp, class _Hash,
43 bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value>
44class __unordered_map_hasher;
45
46template <class _Key, class _Cp, class _Pred,
47 bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value
48 >
49class __unordered_map_equal;
50
Eric Fiselierfcd02212016-02-11 11:59:44 +000051#ifndef _LIBCPP_CXX03_LANG
52template <class _Tp>
53struct __is_hash_value_type_imp : false_type {};
54
55template <class _Key, class _Value>
56struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {};
57
58template <class ..._Args>
59struct __is_hash_value_type : false_type {};
60
61template <class _One>
62struct __is_hash_value_type<_One> : __is_hash_value_type_imp<typename __uncvref<_One>::type> {};
63#endif
64
Howard Hinnant6e412562013-03-06 23:30:19 +000065_LIBCPP_FUNC_VIS
Howard Hinnantce534202011-06-14 19:58:17 +000066size_t __next_prime(size_t __n);
Howard Hinnant3e519522010-05-11 19:42:16 +000067
68template <class _NodePtr>
69struct __hash_node_base
70{
Eric Fiselier40492ba2016-07-23 20:36:55 +000071 typedef typename pointer_traits<_NodePtr>::element_type __node_type;
Howard Hinnant3e519522010-05-11 19:42:16 +000072 typedef __hash_node_base __first_node;
Eric Fiselier40492ba2016-07-23 20:36:55 +000073 typedef typename __rebind_pointer<_NodePtr, __first_node>::type __node_base_pointer;
74 typedef _NodePtr __node_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +000075
Eric Fiselier40492ba2016-07-23 20:36:55 +000076#if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB)
77 typedef __node_base_pointer __next_pointer;
78#else
79 typedef typename conditional<
80 is_pointer<__node_pointer>::value,
81 __node_base_pointer,
82 __node_pointer>::type __next_pointer;
83#endif
84
85 __next_pointer __next_;
86
87 _LIBCPP_INLINE_VISIBILITY
88 __next_pointer __ptr() _NOEXCEPT {
89 return static_cast<__next_pointer>(
90 pointer_traits<__node_base_pointer>::pointer_to(*this));
91 }
92
93 _LIBCPP_INLINE_VISIBILITY
94 __node_pointer __upcast() _NOEXCEPT {
95 return static_cast<__node_pointer>(
96 pointer_traits<__node_base_pointer>::pointer_to(*this));
97 }
98
99 _LIBCPP_INLINE_VISIBILITY
100 size_t __hash() const _NOEXCEPT {
101 return static_cast<__node_type const&>(*this).__hash_;
102 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000103
Howard Hinnant37141072011-06-04 18:54:24 +0000104 _LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000105};
106
107template <class _Tp, class _VoidPtr>
108struct __hash_node
109 : public __hash_node_base
110 <
Eric Fiselier934b0922015-12-30 21:52:00 +0000111 typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type
Howard Hinnant3e519522010-05-11 19:42:16 +0000112 >
113{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000114 typedef _Tp __node_value_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000115
Eric Fiselier40492ba2016-07-23 20:36:55 +0000116 size_t __hash_;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000117 __node_value_type __value_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000118};
119
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000120inline _LIBCPP_INLINE_VISIBILITY
121bool
Eric Fiselier9ba5c112015-02-02 21:31:48 +0000122__is_hash_power2(size_t __bc)
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000123{
124 return __bc > 2 && !(__bc & (__bc - 1));
125}
126
127inline _LIBCPP_INLINE_VISIBILITY
128size_t
129__constrain_hash(size_t __h, size_t __bc)
130{
Eric Fiselier118cb412016-07-11 22:02:02 +0000131 return !(__bc & (__bc - 1)) ? __h & (__bc - 1) :
132 (__h < __bc ? __h : __h % __bc);
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000133}
134
135inline _LIBCPP_INLINE_VISIBILITY
136size_t
Eric Fiselier9ba5c112015-02-02 21:31:48 +0000137__next_hash_pow2(size_t __n)
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000138{
139 return size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1));
140}
141
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +0000142
Howard Hinnantce534202011-06-14 19:58:17 +0000143template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000144
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000145template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_iterator;
146template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
147template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_local_iterator;
148template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
149template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
150template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000151
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000152template <class _Tp>
Eric Fiselier43b121d2016-02-20 07:59:16 +0000153struct __hash_key_value_types {
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000154 static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, "");
155 typedef _Tp key_type;
156 typedef _Tp __node_value_type;
157 typedef _Tp __container_value_type;
158 static const bool __is_map = false;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000159
160 _LIBCPP_INLINE_VISIBILITY
161 static key_type const& __get_key(_Tp const& __v) {
162 return __v;
163 }
164 _LIBCPP_INLINE_VISIBILITY
165 static __container_value_type const& __get_value(__node_value_type const& __v) {
166 return __v;
167 }
168 _LIBCPP_INLINE_VISIBILITY
169 static __container_value_type* __get_ptr(__node_value_type& __n) {
170 return _VSTD::addressof(__n);
171 }
172#ifndef _LIBCPP_CXX03_LANG
173 _LIBCPP_INLINE_VISIBILITY
174 static __container_value_type&& __move(__node_value_type& __v) {
175 return _VSTD::move(__v);
176 }
177#endif
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000178};
179
180template <class _Key, class _Tp>
Eric Fiselier43b121d2016-02-20 07:59:16 +0000181struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > {
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000182 typedef _Key key_type;
183 typedef _Tp mapped_type;
184 typedef __hash_value_type<_Key, _Tp> __node_value_type;
185 typedef pair<const _Key, _Tp> __container_value_type;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000186 typedef pair<_Key, _Tp> __nc_value_type;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000187 typedef __container_value_type __map_value_type;
188 static const bool __is_map = true;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000189
190 _LIBCPP_INLINE_VISIBILITY
191 static key_type const& __get_key(__container_value_type const& __v) {
192 return __v.first;
193 }
194
195 template <class _Up>
196 _LIBCPP_INLINE_VISIBILITY
197 static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value,
198 __container_value_type const&>::type
199 __get_value(_Up& __t) {
200 return __t.__cc;
201 }
202
203 template <class _Up>
204 _LIBCPP_INLINE_VISIBILITY
205 static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value,
206 __container_value_type const&>::type
207 __get_value(_Up& __t) {
208 return __t;
209 }
210
211 _LIBCPP_INLINE_VISIBILITY
212 static __container_value_type* __get_ptr(__node_value_type& __n) {
213 return _VSTD::addressof(__n.__cc);
214 }
215#ifndef _LIBCPP_CXX03_LANG
216 _LIBCPP_INLINE_VISIBILITY
217 static __nc_value_type&& __move(__node_value_type& __v) {
218 return _VSTD::move(__v.__nc);
219 }
220#endif
221
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000222};
223
Eric Fiselier43b121d2016-02-20 07:59:16 +0000224template <class _Tp, class _AllocPtr, class _KVTypes = __hash_key_value_types<_Tp>,
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000225 bool = _KVTypes::__is_map>
Eric Fiselier43b121d2016-02-20 07:59:16 +0000226struct __hash_map_pointer_types {};
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000227
228template <class _Tp, class _AllocPtr, class _KVTypes>
Eric Fiselier43b121d2016-02-20 07:59:16 +0000229struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> {
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000230 typedef typename _KVTypes::__map_value_type _Mv;
231 typedef typename __rebind_pointer<_AllocPtr, _Mv>::type
232 __map_value_type_pointer;
233 typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type
234 __const_map_value_type_pointer;
235};
236
237template <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type>
238struct __hash_node_types;
239
240template <class _NodePtr, class _Tp, class _VoidPtr>
241struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> >
Eric Fiselier43b121d2016-02-20 07:59:16 +0000242 : public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr>
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000243
244{
Eric Fiselier43b121d2016-02-20 07:59:16 +0000245 typedef __hash_key_value_types<_Tp> __base;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000246
247public:
248 typedef ptrdiff_t difference_type;
249 typedef size_t size_type;
250
251 typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer;
252
253 typedef typename pointer_traits<_NodePtr>::element_type __node_type;
254 typedef _NodePtr __node_pointer;
255
256 typedef __hash_node_base<__node_pointer> __node_base_type;
257 typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type
258 __node_base_pointer;
259
Eric Fiselier40492ba2016-07-23 20:36:55 +0000260 typedef typename __node_base_type::__next_pointer __next_pointer;
261
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000262 typedef _Tp __node_value_type;
263 typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type
264 __node_value_type_pointer;
265 typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type
266 __const_node_value_type_pointer;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000267
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000268private:
269 static_assert(!is_const<__node_type>::value,
270 "_NodePtr should never be a pointer to const");
271 static_assert((is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value),
272 "_VoidPtr does not point to unqualified void type");
273 static_assert((is_same<typename __rebind_pointer<_VoidPtr, __node_type>::type,
274 _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr.");
275};
276
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000277template <class _HashIterator>
278struct __hash_node_types_from_iterator;
279template <class _NodePtr>
280struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
281template <class _NodePtr>
282struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
283template <class _NodePtr>
284struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
285template <class _NodePtr>
286struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
287
288
289template <class _NodeValueTp, class _VoidPtr>
290struct __make_hash_node_types {
291 typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp;
292 typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr;
293 typedef __hash_node_types<_NodePtr> type;
294};
295
Howard Hinnant3e519522010-05-11 19:42:16 +0000296template <class _NodePtr>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000297class _LIBCPP_TEMPLATE_VIS __hash_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000298{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000299 typedef __hash_node_types<_NodePtr> _NodeTypes;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000300 typedef _NodePtr __node_pointer;
301 typedef typename _NodeTypes::__next_pointer __next_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000302
Eric Fiselier40492ba2016-07-23 20:36:55 +0000303 __next_pointer __node_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000304
305public:
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000306 typedef forward_iterator_tag iterator_category;
307 typedef typename _NodeTypes::__node_value_type value_type;
308 typedef typename _NodeTypes::difference_type difference_type;
309 typedef value_type& reference;
310 typedef typename _NodeTypes::__node_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000311
Eric Fiselier40492ba2016-07-23 20:36:55 +0000312 _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT : __node_(nullptr) {
313 _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000314 }
315
316#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant43d99232010-09-21 17:32:39 +0000317 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000318 __hash_iterator(const __hash_iterator& __i)
319 : __node_(__i.__node_)
320 {
321 __get_db()->__iterator_copy(this, &__i);
322 }
323
Howard Hinnant43d99232010-09-21 17:32:39 +0000324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000325 ~__hash_iterator()
326 {
327 __get_db()->__erase_i(this);
328 }
329
330 _LIBCPP_INLINE_VISIBILITY
331 __hash_iterator& operator=(const __hash_iterator& __i)
332 {
333 if (this != &__i)
334 {
335 __get_db()->__iterator_copy(this, &__i);
336 __node_ = __i.__node_;
337 }
338 return *this;
339 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000340#endif // _LIBCPP_DEBUG_LEVEL >= 2
341
342 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000343 reference operator*() const {
344 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
345 "Attempted to dereference a non-dereferenceable unordered container iterator");
346 return __node_->__upcast()->__value_;
347 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000348
Howard Hinnant43d99232010-09-21 17:32:39 +0000349 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000350 pointer operator->() const {
351 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
352 "Attempted to dereference a non-dereferenceable unordered container iterator");
353 return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
354 }
355
356 _LIBCPP_INLINE_VISIBILITY
357 __hash_iterator& operator++() {
358 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000359 "Attempted to increment non-incrementable unordered container iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +0000360 __node_ = __node_->__next_;
361 return *this;
362 }
363
Howard Hinnant43d99232010-09-21 17:32:39 +0000364 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000365 __hash_iterator operator++(int)
366 {
367 __hash_iterator __t(*this);
368 ++(*this);
369 return __t;
370 }
371
Howard Hinnant43d99232010-09-21 17:32:39 +0000372 friend _LIBCPP_INLINE_VISIBILITY
373 bool operator==(const __hash_iterator& __x, const __hash_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000374 {
Howard Hinnantb24c8022013-07-23 22:01:58 +0000375 return __x.__node_ == __y.__node_;
376 }
Howard Hinnant43d99232010-09-21 17:32:39 +0000377 friend _LIBCPP_INLINE_VISIBILITY
378 bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000379 {return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000380
381private:
Howard Hinnantb24c8022013-07-23 22:01:58 +0000382#if _LIBCPP_DEBUG_LEVEL >= 2
383 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000384 __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
Howard Hinnantb24c8022013-07-23 22:01:58 +0000385 : __node_(__node)
386 {
387 __get_db()->__insert_ic(this, __c);
388 }
389#else
Howard Hinnant43d99232010-09-21 17:32:39 +0000390 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000391 __hash_iterator(__next_pointer __node) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000392 : __node_(__node)
393 {}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000394#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000395 template <class, class, class, class> friend class __hash_table;
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000396 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
397 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
398 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
399 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000400};
401
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000402template <class _NodePtr>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000403class _LIBCPP_TEMPLATE_VIS __hash_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000404{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000405 static_assert(!is_const<typename pointer_traits<_NodePtr>::element_type>::value, "");
406 typedef __hash_node_types<_NodePtr> _NodeTypes;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000407 typedef _NodePtr __node_pointer;
408 typedef typename _NodeTypes::__next_pointer __next_pointer;
Eric Fiselier757373e2016-02-18 00:20:34 +0000409
Eric Fiselier40492ba2016-07-23 20:36:55 +0000410 __next_pointer __node_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000411
412public:
Eric Fiselier757373e2016-02-18 00:20:34 +0000413 typedef __hash_iterator<_NodePtr> __non_const_iterator;
414
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000415 typedef forward_iterator_tag iterator_category;
416 typedef typename _NodeTypes::__node_value_type value_type;
417 typedef typename _NodeTypes::difference_type difference_type;
418 typedef const value_type& reference;
419 typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
420
Howard Hinnant3e519522010-05-11 19:42:16 +0000421
Eric Fiselier40492ba2016-07-23 20:36:55 +0000422 _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT : __node_(nullptr) {
423 _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000424 }
Eric Fiselier40492ba2016-07-23 20:36:55 +0000425
Howard Hinnant43d99232010-09-21 17:32:39 +0000426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000427 __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000428 : __node_(__x.__node_)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000429 {
Eric Fiselier40492ba2016-07-23 20:36:55 +0000430 _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000431 }
432
433#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant43d99232010-09-21 17:32:39 +0000434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000435 __hash_const_iterator(const __hash_const_iterator& __i)
436 : __node_(__i.__node_)
437 {
438 __get_db()->__iterator_copy(this, &__i);
439 }
440
Howard Hinnant43d99232010-09-21 17:32:39 +0000441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000442 ~__hash_const_iterator()
443 {
444 __get_db()->__erase_i(this);
445 }
446
447 _LIBCPP_INLINE_VISIBILITY
448 __hash_const_iterator& operator=(const __hash_const_iterator& __i)
449 {
450 if (this != &__i)
451 {
452 __get_db()->__iterator_copy(this, &__i);
453 __node_ = __i.__node_;
454 }
455 return *this;
456 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000457#endif // _LIBCPP_DEBUG_LEVEL >= 2
458
459 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000460 reference operator*() const {
461 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000462 "Attempted to dereference a non-dereferenceable unordered container const_iterator");
Eric Fiselier40492ba2016-07-23 20:36:55 +0000463 return __node_->__upcast()->__value_;
464 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000465 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000466 pointer operator->() const {
467 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000468 "Attempted to dereference a non-dereferenceable unordered container const_iterator");
Eric Fiselier40492ba2016-07-23 20:36:55 +0000469 return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
470 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000471
Howard Hinnant43d99232010-09-21 17:32:39 +0000472 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000473 __hash_const_iterator& operator++() {
474 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
475 "Attempted to increment non-incrementable unordered container const_iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +0000476 __node_ = __node_->__next_;
477 return *this;
478 }
479
Howard Hinnant43d99232010-09-21 17:32:39 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000481 __hash_const_iterator operator++(int)
482 {
483 __hash_const_iterator __t(*this);
484 ++(*this);
485 return __t;
486 }
487
Howard Hinnant43d99232010-09-21 17:32:39 +0000488 friend _LIBCPP_INLINE_VISIBILITY
489 bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000490 {
Howard Hinnantb24c8022013-07-23 22:01:58 +0000491 return __x.__node_ == __y.__node_;
492 }
Howard Hinnant43d99232010-09-21 17:32:39 +0000493 friend _LIBCPP_INLINE_VISIBILITY
494 bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000495 {return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000496
497private:
Howard Hinnantb24c8022013-07-23 22:01:58 +0000498#if _LIBCPP_DEBUG_LEVEL >= 2
499 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000500 __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
Howard Hinnantb24c8022013-07-23 22:01:58 +0000501 : __node_(__node)
502 {
503 __get_db()->__insert_ic(this, __c);
504 }
505#else
Howard Hinnant43d99232010-09-21 17:32:39 +0000506 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000507 __hash_const_iterator(__next_pointer __node) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000508 : __node_(__node)
509 {}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000510#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000511 template <class, class, class, class> friend class __hash_table;
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000512 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
513 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
514 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000515};
516
Howard Hinnant3e519522010-05-11 19:42:16 +0000517template <class _NodePtr>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000518class _LIBCPP_TEMPLATE_VIS __hash_local_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000519{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000520 typedef __hash_node_types<_NodePtr> _NodeTypes;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000521 typedef _NodePtr __node_pointer;
522 typedef typename _NodeTypes::__next_pointer __next_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000523
Eric Fiselier40492ba2016-07-23 20:36:55 +0000524 __next_pointer __node_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000525 size_t __bucket_;
526 size_t __bucket_count_;
527
Howard Hinnant3e519522010-05-11 19:42:16 +0000528public:
529 typedef forward_iterator_tag iterator_category;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000530 typedef typename _NodeTypes::__node_value_type value_type;
531 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000532 typedef value_type& reference;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000533 typedef typename _NodeTypes::__node_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000534
Eric Fiselier40492ba2016-07-23 20:36:55 +0000535 _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT : __node_(nullptr) {
536 _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000537 }
538
539#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant43d99232010-09-21 17:32:39 +0000540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000541 __hash_local_iterator(const __hash_local_iterator& __i)
542 : __node_(__i.__node_),
543 __bucket_(__i.__bucket_),
544 __bucket_count_(__i.__bucket_count_)
545 {
546 __get_db()->__iterator_copy(this, &__i);
547 }
548
Howard Hinnant43d99232010-09-21 17:32:39 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000550 ~__hash_local_iterator()
551 {
552 __get_db()->__erase_i(this);
553 }
554
555 _LIBCPP_INLINE_VISIBILITY
556 __hash_local_iterator& operator=(const __hash_local_iterator& __i)
557 {
558 if (this != &__i)
559 {
560 __get_db()->__iterator_copy(this, &__i);
561 __node_ = __i.__node_;
562 __bucket_ = __i.__bucket_;
563 __bucket_count_ = __i.__bucket_count_;
564 }
565 return *this;
566 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000567#endif // _LIBCPP_DEBUG_LEVEL >= 2
568
569 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000570 reference operator*() const {
571 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000572 "Attempted to dereference a non-dereferenceable unordered container local_iterator");
Eric Fiselier40492ba2016-07-23 20:36:55 +0000573 return __node_->__upcast()->__value_;
574 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000575
Howard Hinnant43d99232010-09-21 17:32:39 +0000576 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000577 pointer operator->() const {
578 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
579 "Attempted to dereference a non-dereferenceable unordered container local_iterator");
580 return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
581 }
582
583 _LIBCPP_INLINE_VISIBILITY
584 __hash_local_iterator& operator++() {
585 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000586 "Attempted to increment non-incrementable unordered container local_iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +0000587 __node_ = __node_->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000588 if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_)
Howard Hinnant3e519522010-05-11 19:42:16 +0000589 __node_ = nullptr;
590 return *this;
591 }
592
Howard Hinnant43d99232010-09-21 17:32:39 +0000593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000594 __hash_local_iterator operator++(int)
595 {
596 __hash_local_iterator __t(*this);
597 ++(*this);
598 return __t;
599 }
600
Howard Hinnant43d99232010-09-21 17:32:39 +0000601 friend _LIBCPP_INLINE_VISIBILITY
602 bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000603 {
Howard Hinnantb24c8022013-07-23 22:01:58 +0000604 return __x.__node_ == __y.__node_;
605 }
Howard Hinnant43d99232010-09-21 17:32:39 +0000606 friend _LIBCPP_INLINE_VISIBILITY
607 bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000608 {return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000609
610private:
Howard Hinnantb24c8022013-07-23 22:01:58 +0000611#if _LIBCPP_DEBUG_LEVEL >= 2
612 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000613 __hash_local_iterator(__next_pointer __node, size_t __bucket,
Howard Hinnantb24c8022013-07-23 22:01:58 +0000614 size_t __bucket_count, const void* __c) _NOEXCEPT
615 : __node_(__node),
616 __bucket_(__bucket),
617 __bucket_count_(__bucket_count)
618 {
619 __get_db()->__insert_ic(this, __c);
620 if (__node_ != nullptr)
621 __node_ = __node_->__next_;
622 }
623#else
Howard Hinnant43d99232010-09-21 17:32:39 +0000624 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000625 __hash_local_iterator(__next_pointer __node, size_t __bucket,
Howard Hinnant37141072011-06-04 18:54:24 +0000626 size_t __bucket_count) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000627 : __node_(__node),
628 __bucket_(__bucket),
629 __bucket_count_(__bucket_count)
630 {
631 if (__node_ != nullptr)
632 __node_ = __node_->__next_;
633 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000634#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000635 template <class, class, class, class> friend class __hash_table;
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000636 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
637 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000638};
639
640template <class _ConstNodePtr>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000641class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000642{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000643 typedef __hash_node_types<_ConstNodePtr> _NodeTypes;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000644 typedef _ConstNodePtr __node_pointer;
645 typedef typename _NodeTypes::__next_pointer __next_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000646
Eric Fiselier40492ba2016-07-23 20:36:55 +0000647 __next_pointer __node_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000648 size_t __bucket_;
649 size_t __bucket_count_;
650
651 typedef pointer_traits<__node_pointer> __pointer_traits;
652 typedef typename __pointer_traits::element_type __node;
653 typedef typename remove_const<__node>::type __non_const_node;
Eric Fiselier934b0922015-12-30 21:52:00 +0000654 typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type
655 __non_const_node_pointer;
Eric Fiselier757373e2016-02-18 00:20:34 +0000656public:
Howard Hinnant3e519522010-05-11 19:42:16 +0000657 typedef __hash_local_iterator<__non_const_node_pointer>
658 __non_const_iterator;
Eric Fiselier757373e2016-02-18 00:20:34 +0000659
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000660 typedef forward_iterator_tag iterator_category;
661 typedef typename _NodeTypes::__node_value_type value_type;
662 typedef typename _NodeTypes::difference_type difference_type;
663 typedef const value_type& reference;
664 typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
Eric Fiselier934b0922015-12-30 21:52:00 +0000665
Howard Hinnant3e519522010-05-11 19:42:16 +0000666
Eric Fiselier40492ba2016-07-23 20:36:55 +0000667 _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) {
668 _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000669 }
670
Howard Hinnant43d99232010-09-21 17:32:39 +0000671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000672 __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000673 : __node_(__x.__node_),
674 __bucket_(__x.__bucket_),
675 __bucket_count_(__x.__bucket_count_)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000676 {
Eric Fiselier40492ba2016-07-23 20:36:55 +0000677 _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000678 }
679
680#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant43d99232010-09-21 17:32:39 +0000681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000682 __hash_const_local_iterator(const __hash_const_local_iterator& __i)
683 : __node_(__i.__node_),
684 __bucket_(__i.__bucket_),
685 __bucket_count_(__i.__bucket_count_)
686 {
687 __get_db()->__iterator_copy(this, &__i);
688 }
689
Howard Hinnant43d99232010-09-21 17:32:39 +0000690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000691 ~__hash_const_local_iterator()
692 {
693 __get_db()->__erase_i(this);
694 }
695
696 _LIBCPP_INLINE_VISIBILITY
697 __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i)
698 {
699 if (this != &__i)
700 {
701 __get_db()->__iterator_copy(this, &__i);
702 __node_ = __i.__node_;
703 __bucket_ = __i.__bucket_;
704 __bucket_count_ = __i.__bucket_count_;
705 }
706 return *this;
707 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000708#endif // _LIBCPP_DEBUG_LEVEL >= 2
709
710 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000711 reference operator*() const {
712 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000713 "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
Eric Fiselier40492ba2016-07-23 20:36:55 +0000714 return __node_->__upcast()->__value_;
715 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000716
Howard Hinnant43d99232010-09-21 17:32:39 +0000717 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000718 pointer operator->() const {
719 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
720 "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
721 return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
722 }
723
724 _LIBCPP_INLINE_VISIBILITY
725 __hash_const_local_iterator& operator++() {
726 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000727 "Attempted to increment non-incrementable unordered container const_local_iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +0000728 __node_ = __node_->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000729 if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_)
Howard Hinnant3e519522010-05-11 19:42:16 +0000730 __node_ = nullptr;
731 return *this;
732 }
733
Howard Hinnant43d99232010-09-21 17:32:39 +0000734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000735 __hash_const_local_iterator operator++(int)
736 {
737 __hash_const_local_iterator __t(*this);
738 ++(*this);
739 return __t;
740 }
741
Howard Hinnant43d99232010-09-21 17:32:39 +0000742 friend _LIBCPP_INLINE_VISIBILITY
743 bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000744 {
Howard Hinnantb24c8022013-07-23 22:01:58 +0000745 return __x.__node_ == __y.__node_;
746 }
Howard Hinnant43d99232010-09-21 17:32:39 +0000747 friend _LIBCPP_INLINE_VISIBILITY
748 bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000749 {return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000750
751private:
Howard Hinnantb24c8022013-07-23 22:01:58 +0000752#if _LIBCPP_DEBUG_LEVEL >= 2
753 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000754 __hash_const_local_iterator(__next_pointer __node, size_t __bucket,
Howard Hinnantb24c8022013-07-23 22:01:58 +0000755 size_t __bucket_count, const void* __c) _NOEXCEPT
756 : __node_(__node),
757 __bucket_(__bucket),
758 __bucket_count_(__bucket_count)
759 {
760 __get_db()->__insert_ic(this, __c);
761 if (__node_ != nullptr)
762 __node_ = __node_->__next_;
763 }
764#else
Howard Hinnant43d99232010-09-21 17:32:39 +0000765 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000766 __hash_const_local_iterator(__next_pointer __node, size_t __bucket,
Howard Hinnant37141072011-06-04 18:54:24 +0000767 size_t __bucket_count) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000768 : __node_(__node),
769 __bucket_(__bucket),
770 __bucket_count_(__bucket_count)
771 {
772 if (__node_ != nullptr)
773 __node_ = __node_->__next_;
774 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000775#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000776 template <class, class, class, class> friend class __hash_table;
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000777 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000778};
779
780template <class _Alloc>
781class __bucket_list_deallocator
782{
783 typedef _Alloc allocator_type;
784 typedef allocator_traits<allocator_type> __alloc_traits;
785 typedef typename __alloc_traits::size_type size_type;
786
787 __compressed_pair<size_type, allocator_type> __data_;
788public:
789 typedef typename __alloc_traits::pointer pointer;
790
Howard Hinnant43d99232010-09-21 17:32:39 +0000791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000792 __bucket_list_deallocator()
Howard Hinnant37141072011-06-04 18:54:24 +0000793 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000794 : __data_(0) {}
Howard Hinnant43d99232010-09-21 17:32:39 +0000795
796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000797 __bucket_list_deallocator(const allocator_type& __a, size_type __size)
Howard Hinnant37141072011-06-04 18:54:24 +0000798 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000799 : __data_(__size, __a) {}
800
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000801#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000802
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 }
810
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000811#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000812
Howard Hinnant37141072011-06-04 18:54:24 +0000813 _LIBCPP_INLINE_VISIBILITY
814 size_type& size() _NOEXCEPT {return __data_.first();}
815 _LIBCPP_INLINE_VISIBILITY
816 size_type size() const _NOEXCEPT {return __data_.first();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000817
Howard Hinnant43d99232010-09-21 17:32:39 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000819 allocator_type& __alloc() _NOEXCEPT {return __data_.second();}
820 _LIBCPP_INLINE_VISIBILITY
821 const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();}
822
823 _LIBCPP_INLINE_VISIBILITY
824 void operator()(pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000825 {
826 __alloc_traits::deallocate(__alloc(), __p, size());
827 }
828};
829
Howard Hinnantce534202011-06-14 19:58:17 +0000830template <class _Alloc> class __hash_map_node_destructor;
Howard Hinnant3e519522010-05-11 19:42:16 +0000831
832template <class _Alloc>
833class __hash_node_destructor
834{
835 typedef _Alloc allocator_type;
836 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000837
Howard Hinnant3e519522010-05-11 19:42:16 +0000838public:
839 typedef typename __alloc_traits::pointer pointer;
840private:
Eric Fiselierfcd02212016-02-11 11:59:44 +0000841 typedef __hash_node_types<pointer> _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +0000842
843 allocator_type& __na_;
844
845 __hash_node_destructor& operator=(const __hash_node_destructor&);
846
847public:
848 bool __value_constructed;
849
Howard Hinnant43d99232010-09-21 17:32:39 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf622b582011-07-31 17:04:30 +0000851 explicit __hash_node_destructor(allocator_type& __na,
852 bool __constructed = false) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000853 : __na_(__na),
Howard Hinnantf622b582011-07-31 17:04:30 +0000854 __value_constructed(__constructed)
Howard Hinnant3e519522010-05-11 19:42:16 +0000855 {}
856
Howard Hinnant43d99232010-09-21 17:32:39 +0000857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000858 void operator()(pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000859 {
860 if (__value_constructed)
Eric Fiselierfcd02212016-02-11 11:59:44 +0000861 __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000862 if (__p)
863 __alloc_traits::deallocate(__na_, __p, 1);
864 }
865
866 template <class> friend class __hash_map_node_destructor;
867};
868
Eric Fiselier04333f92017-01-13 22:42:53 +0000869
870#ifndef _LIBCPP_CXX03_LANG
871template <class _Key, class _Hash, class _Equal, class _Alloc>
872struct __diagnose_hash_table_helper {
873 static constexpr bool __trigger_diagnostics()
Eric Fiselierbd6a2d82017-03-03 22:35:58 +0000874 _LIBCPP_DIAGNOSE_WARNING(__check_hash_requirements<_Key, _Hash>::value
Eric Fiselieracb21582017-03-01 02:02:28 +0000875 && !__invokable<_Hash const&, _Key const&>::value,
876 "the specified hash functor does not provide a const call operator")
877 _LIBCPP_DIAGNOSE_WARNING(is_copy_constructible<_Equal>::value
878 && !__invokable<_Equal const&, _Key const&, _Key const&>::value,
879 "the specified comparator type does not provide a const call operator")
880 {
Eric Fiselierbd6a2d82017-03-03 22:35:58 +0000881 static_assert(__check_hash_requirements<_Key, _Hash>::value,
882 "the specified hash does not meet the Hash requirements");
Eric Fiselieracb21582017-03-01 02:02:28 +0000883 static_assert(is_copy_constructible<_Equal>::value,
884 "the specified comparator is required to be copy constructible");
885 return true;
886 }
Eric Fiselier04333f92017-01-13 22:42:53 +0000887};
888
889template <class _Key, class _Value, class _Hash, class _Equal, class _Alloc>
890struct __diagnose_hash_table_helper<
891 __hash_value_type<_Key, _Value>,
892 __unordered_map_hasher<_Key, __hash_value_type<_Key, _Value>, _Hash>,
893 __unordered_map_equal<_Key, __hash_value_type<_Key, _Value>, _Equal>,
894 _Alloc>
895: __diagnose_hash_table_helper<_Key, _Hash, _Equal, _Alloc>
896{
897};
898#endif // _LIBCPP_CXX03_LANG
899
Howard Hinnant3e519522010-05-11 19:42:16 +0000900template <class _Tp, class _Hash, class _Equal, class _Alloc>
901class __hash_table
902{
903public:
904 typedef _Tp value_type;
905 typedef _Hash hasher;
906 typedef _Equal key_equal;
907 typedef _Alloc allocator_type;
908
909private:
910 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000911 typedef typename
912 __make_hash_node_types<value_type, typename __alloc_traits::void_pointer>::type
913 _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +0000914public:
Eric Fiselierfcd02212016-02-11 11:59:44 +0000915
916 typedef typename _NodeTypes::__node_value_type __node_value_type;
917 typedef typename _NodeTypes::__container_value_type __container_value_type;
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +0000918 typedef typename _NodeTypes::key_type key_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000919 typedef value_type& reference;
920 typedef const value_type& const_reference;
921 typedef typename __alloc_traits::pointer pointer;
922 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000923#ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
Howard Hinnant3e519522010-05-11 19:42:16 +0000924 typedef typename __alloc_traits::size_type size_type;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000925#else
926 typedef typename _NodeTypes::size_type size_type;
927#endif
928 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000929public:
930 // Create __node
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000931
932 typedef typename _NodeTypes::__node_type __node;
Marshall Clow1f508012015-04-07 05:21:38 +0000933 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000934 typedef allocator_traits<__node_allocator> __node_traits;
Eric Fiselier8e397682016-02-11 15:22:37 +0000935 typedef typename _NodeTypes::__void_pointer __void_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000936 typedef typename _NodeTypes::__node_pointer __node_pointer;
937 typedef typename _NodeTypes::__node_pointer __node_const_pointer;
938 typedef typename _NodeTypes::__node_base_type __first_node;
939 typedef typename _NodeTypes::__node_base_pointer __node_base_pointer;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000940 typedef typename _NodeTypes::__next_pointer __next_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000941
942private:
943 // check for sane allocator pointer rebinding semantics. Rebinding the
944 // allocator for a new pointer type should be exactly the same as rebinding
945 // the pointer using 'pointer_traits'.
946 static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value),
947 "Allocator does not rebind pointers in a sane manner.");
948 typedef typename __rebind_alloc_helper<__node_traits, __first_node>::type
949 __node_base_allocator;
950 typedef allocator_traits<__node_base_allocator> __node_base_traits;
951 static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value),
952 "Allocator does not rebind pointers in a sane manner.");
Howard Hinnant3e519522010-05-11 19:42:16 +0000953
954private:
955
Eric Fiselier40492ba2016-07-23 20:36:55 +0000956 typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000957 typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000958 typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list;
Howard Hinnant3e519522010-05-11 19:42:16 +0000959 typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000960 typedef typename __bucket_list_deleter::pointer __node_pointer_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000961
Eric Fiselieracb21582017-03-01 02:02:28 +0000962#ifndef _LIBCPP_CXX03_LANG
963 static_assert(__diagnose_hash_table_helper<_Tp, _Hash, _Equal, _Alloc>::__trigger_diagnostics(), "");
964#endif
965
Howard Hinnant3e519522010-05-11 19:42:16 +0000966 // --- Member data begin ---
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000967 __bucket_list __bucket_list_;
968 __compressed_pair<__first_node, __node_allocator> __p1_;
969 __compressed_pair<size_type, hasher> __p2_;
970 __compressed_pair<float, key_equal> __p3_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000971 // --- Member data end ---
972
Howard Hinnant37141072011-06-04 18:54:24 +0000973 _LIBCPP_INLINE_VISIBILITY
974 size_type& size() _NOEXCEPT {return __p2_.first();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000975public:
Howard Hinnant37141072011-06-04 18:54:24 +0000976 _LIBCPP_INLINE_VISIBILITY
977 size_type size() const _NOEXCEPT {return __p2_.first();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000978
Howard Hinnant37141072011-06-04 18:54:24 +0000979 _LIBCPP_INLINE_VISIBILITY
980 hasher& hash_function() _NOEXCEPT {return __p2_.second();}
981 _LIBCPP_INLINE_VISIBILITY
982 const hasher& hash_function() const _NOEXCEPT {return __p2_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000983
Howard Hinnant37141072011-06-04 18:54:24 +0000984 _LIBCPP_INLINE_VISIBILITY
985 float& max_load_factor() _NOEXCEPT {return __p3_.first();}
986 _LIBCPP_INLINE_VISIBILITY
987 float max_load_factor() const _NOEXCEPT {return __p3_.first();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000988
Howard Hinnant37141072011-06-04 18:54:24 +0000989 _LIBCPP_INLINE_VISIBILITY
990 key_equal& key_eq() _NOEXCEPT {return __p3_.second();}
991 _LIBCPP_INLINE_VISIBILITY
992 const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000993
Howard Hinnant37141072011-06-04 18:54:24 +0000994 _LIBCPP_INLINE_VISIBILITY
995 __node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();}
996 _LIBCPP_INLINE_VISIBILITY
997 const __node_allocator& __node_alloc() const _NOEXCEPT
998 {return __p1_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000999
1000public:
1001 typedef __hash_iterator<__node_pointer> iterator;
Howard Hinnant307f8142013-06-22 15:21:29 +00001002 typedef __hash_const_iterator<__node_pointer> const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +00001003 typedef __hash_local_iterator<__node_pointer> local_iterator;
Howard Hinnant307f8142013-06-22 15:21:29 +00001004 typedef __hash_const_local_iterator<__node_pointer> const_local_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +00001005
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001007 __hash_table()
1008 _NOEXCEPT_(
1009 is_nothrow_default_constructible<__bucket_list>::value &&
1010 is_nothrow_default_constructible<__first_node>::value &&
1011 is_nothrow_default_constructible<__node_allocator>::value &&
1012 is_nothrow_default_constructible<hasher>::value &&
1013 is_nothrow_default_constructible<key_equal>::value);
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001015 __hash_table(const hasher& __hf, const key_equal& __eql);
1016 __hash_table(const hasher& __hf, const key_equal& __eql,
1017 const allocator_type& __a);
1018 explicit __hash_table(const allocator_type& __a);
1019 __hash_table(const __hash_table& __u);
1020 __hash_table(const __hash_table& __u, const allocator_type& __a);
Eric Fiselierfcd02212016-02-11 11:59:44 +00001021#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant37141072011-06-04 18:54:24 +00001022 __hash_table(__hash_table&& __u)
1023 _NOEXCEPT_(
1024 is_nothrow_move_constructible<__bucket_list>::value &&
1025 is_nothrow_move_constructible<__first_node>::value &&
1026 is_nothrow_move_constructible<__node_allocator>::value &&
1027 is_nothrow_move_constructible<hasher>::value &&
1028 is_nothrow_move_constructible<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001029 __hash_table(__hash_table&& __u, const allocator_type& __a);
Eric Fiselierfcd02212016-02-11 11:59:44 +00001030#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001031 ~__hash_table();
1032
1033 __hash_table& operator=(const __hash_table& __u);
Eric Fiselierfcd02212016-02-11 11:59:44 +00001034#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001036 __hash_table& operator=(__hash_table&& __u)
1037 _NOEXCEPT_(
1038 __node_traits::propagate_on_container_move_assignment::value &&
1039 is_nothrow_move_assignable<__node_allocator>::value &&
1040 is_nothrow_move_assignable<hasher>::value &&
1041 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001042#endif
1043 template <class _InputIterator>
1044 void __assign_unique(_InputIterator __first, _InputIterator __last);
1045 template <class _InputIterator>
1046 void __assign_multi(_InputIterator __first, _InputIterator __last);
1047
Howard Hinnant43d99232010-09-21 17:32:39 +00001048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001049 size_type max_size() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001050 {
Eric Fiselier55b31b4e2016-11-23 01:18:56 +00001051 return std::min<size_type>(
Eric Fiselier341c9dd2016-11-23 09:16:12 +00001052 __node_traits::max_size(__node_alloc()),
Eric Fiselier55b31b4e2016-11-23 01:18:56 +00001053 numeric_limits<difference_type >::max()
1054 );
Howard Hinnant3e519522010-05-11 19:42:16 +00001055 }
1056
1057 pair<iterator, bool> __node_insert_unique(__node_pointer __nd);
1058 iterator __node_insert_multi(__node_pointer __nd);
1059 iterator __node_insert_multi(const_iterator __p,
1060 __node_pointer __nd);
1061
Eric Fiselierfcd02212016-02-11 11:59:44 +00001062#ifndef _LIBCPP_CXX03_LANG
1063 template <class _Key, class ..._Args>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00001064 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001065 pair<iterator, bool> __emplace_unique_key_args(_Key const& __k, _Args&&... __args);
Howard Hinnant3e519522010-05-11 19:42:16 +00001066
Eric Fiselierfcd02212016-02-11 11:59:44 +00001067 template <class... _Args>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00001068 _LIBCPP_INLINE_VISIBILITY
1069 pair<iterator, bool> __emplace_unique_impl(_Args&&... __args);
1070
1071 template <class _Pp>
1072 _LIBCPP_INLINE_VISIBILITY
1073 pair<iterator, bool> __emplace_unique(_Pp&& __x) {
1074 return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x),
1075 __can_extract_key<_Pp, key_type>());
1076 }
Eric Fiselier50088682016-04-16 00:23:12 +00001077
1078 template <class _First, class _Second>
1079 _LIBCPP_INLINE_VISIBILITY
1080 typename enable_if<
1081 __can_extract_map_key<_First, key_type, __container_value_type>::value,
1082 pair<iterator, bool>
1083 >::type __emplace_unique(_First&& __f, _Second&& __s) {
1084 return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f),
1085 _VSTD::forward<_Second>(__s));
1086 }
1087
Eric Fiselierfcd02212016-02-11 11:59:44 +00001088 template <class... _Args>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00001089 _LIBCPP_INLINE_VISIBILITY
1090 pair<iterator, bool> __emplace_unique(_Args&&... __args) {
1091 return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...);
1092 }
1093
1094 template <class _Pp>
1095 _LIBCPP_INLINE_VISIBILITY
1096 pair<iterator, bool>
1097 __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) {
1098 return __emplace_unique_impl(_VSTD::forward<_Pp>(__x));
1099 }
1100 template <class _Pp>
1101 _LIBCPP_INLINE_VISIBILITY
1102 pair<iterator, bool>
1103 __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) {
1104 return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x));
1105 }
1106 template <class _Pp>
1107 _LIBCPP_INLINE_VISIBILITY
1108 pair<iterator, bool>
1109 __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) {
1110 return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x));
1111 }
1112
1113 template <class... _Args>
1114 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001115 iterator __emplace_multi(_Args&&... __args);
1116 template <class... _Args>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00001117 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001118 iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
1119
1120
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001121 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001122 pair<iterator, bool>
1123 __insert_unique(__container_value_type&& __x) {
1124 return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _VSTD::move(__x));
1125 }
1126
1127 template <class _Pp, class = typename enable_if<
1128 !__is_same_uncvref<_Pp, __container_value_type>::value
1129 >::type>
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001130 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001131 pair<iterator, bool> __insert_unique(_Pp&& __x) {
1132 return __emplace_unique(_VSTD::forward<_Pp>(__x));
1133 }
1134
1135 template <class _Pp>
1136 _LIBCPP_INLINE_VISIBILITY
1137 iterator __insert_multi(_Pp&& __x) {
1138 return __emplace_multi(_VSTD::forward<_Pp>(__x));
1139 }
1140
1141 template <class _Pp>
1142 _LIBCPP_INLINE_VISIBILITY
1143 iterator __insert_multi(const_iterator __p, _Pp&& __x) {
1144 return __emplace_hint_multi(__p, _VSTD::forward<_Pp>(__x));
1145 }
1146
1147#else // !defined(_LIBCPP_CXX03_LANG)
1148 template <class _Key, class _Args>
Eric Fiselier4271d012016-09-25 04:05:46 +00001149 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001150 pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args);
1151
1152 iterator __insert_multi(const __container_value_type& __x);
1153 iterator __insert_multi(const_iterator __p, const __container_value_type& __x);
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001154#endif
1155
Eric Fiselierfcd02212016-02-11 11:59:44 +00001156 _LIBCPP_INLINE_VISIBILITY
1157 pair<iterator, bool> __insert_unique(const __container_value_type& __x) {
1158 return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x);
1159 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001160
Howard Hinnant37141072011-06-04 18:54:24 +00001161 void clear() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +00001162 void rehash(size_type __n);
Howard Hinnant43d99232010-09-21 17:32:39 +00001163 _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n)
Howard Hinnant3e519522010-05-11 19:42:16 +00001164 {rehash(static_cast<size_type>(ceil(__n / max_load_factor())));}
Howard Hinnant43d99232010-09-21 17:32:39 +00001165
1166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001167 size_type bucket_count() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001168 {
1169 return __bucket_list_.get_deleter().size();
1170 }
1171
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001173 iterator begin() _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001174 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001175 iterator end() _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001177 const_iterator begin() const _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001178 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001179 const_iterator end() const _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +00001180
1181 template <class _Key>
Howard Hinnant43d99232010-09-21 17:32:39 +00001182 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001183 size_type bucket(const _Key& __k) const
Howard Hinnante5c13de2013-07-29 19:05:47 +00001184 {
1185 _LIBCPP_ASSERT(bucket_count() > 0,
1186 "unordered container::bucket(key) called when bucket_count() == 0");
1187 return __constrain_hash(hash_function()(__k), bucket_count());
1188 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001189
1190 template <class _Key>
1191 iterator find(const _Key& __x);
1192 template <class _Key>
1193 const_iterator find(const _Key& __x) const;
1194
Howard Hinnantc003db12011-11-29 18:15:50 +00001195 typedef __hash_node_destructor<__node_allocator> _Dp;
1196 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +00001197
1198 iterator erase(const_iterator __p);
1199 iterator erase(const_iterator __first, const_iterator __last);
1200 template <class _Key>
1201 size_type __erase_unique(const _Key& __k);
1202 template <class _Key>
1203 size_type __erase_multi(const _Key& __k);
Howard Hinnant37141072011-06-04 18:54:24 +00001204 __node_holder remove(const_iterator __p) _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +00001205
1206 template <class _Key>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001208 size_type __count_unique(const _Key& __k) const;
1209 template <class _Key>
1210 size_type __count_multi(const _Key& __k) const;
1211
1212 template <class _Key>
1213 pair<iterator, iterator>
1214 __equal_range_unique(const _Key& __k);
1215 template <class _Key>
1216 pair<const_iterator, const_iterator>
1217 __equal_range_unique(const _Key& __k) const;
1218
1219 template <class _Key>
1220 pair<iterator, iterator>
1221 __equal_range_multi(const _Key& __k);
1222 template <class _Key>
1223 pair<const_iterator, const_iterator>
1224 __equal_range_multi(const _Key& __k) const;
1225
Howard Hinnant37141072011-06-04 18:54:24 +00001226 void swap(__hash_table& __u)
Eric Fiselier87a82492015-07-18 20:40:46 +00001227#if _LIBCPP_STD_VER <= 11
Eric Fiselier780b51d2016-12-28 05:53:01 +00001228 _NOEXCEPT_DEBUG_(
Marshall Clowe3fbe142015-07-13 20:04:56 +00001229 __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
Marshall Clowe3fbe142015-07-13 20:04:56 +00001230 && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
1231 || __is_nothrow_swappable<__pointer_allocator>::value)
1232 && (!__node_traits::propagate_on_container_swap::value
1233 || __is_nothrow_swappable<__node_allocator>::value)
Marshall Clowe3fbe142015-07-13 20:04:56 +00001234 );
Eric Fiselier87a82492015-07-18 20:40:46 +00001235#else
Eric Fiselier780b51d2016-12-28 05:53:01 +00001236 _NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value);
Eric Fiselier87a82492015-07-18 20:40:46 +00001237#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001238
Howard Hinnant43d99232010-09-21 17:32:39 +00001239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001240 size_type max_bucket_count() const _NOEXCEPT
Eric Fiselier55b31b4e2016-11-23 01:18:56 +00001241 {return max_size(); }
Howard Hinnant3e519522010-05-11 19:42:16 +00001242 size_type bucket_size(size_type __n) const;
Howard Hinnant37141072011-06-04 18:54:24 +00001243 _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001244 {
1245 size_type __bc = bucket_count();
1246 return __bc != 0 ? (float)size() / __bc : 0.f;
1247 }
Howard Hinnant37141072011-06-04 18:54:24 +00001248 _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT
Howard Hinnante5c13de2013-07-29 19:05:47 +00001249 {
1250 _LIBCPP_ASSERT(__mlf > 0,
1251 "unordered container::max_load_factor(lf) called with lf <= 0");
1252 max_load_factor() = _VSTD::max(__mlf, load_factor());
1253 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001254
Howard Hinnantb24c8022013-07-23 22:01:58 +00001255 _LIBCPP_INLINE_VISIBILITY
1256 local_iterator
1257 begin(size_type __n)
1258 {
Howard Hinnante5c13de2013-07-29 19:05:47 +00001259 _LIBCPP_ASSERT(__n < bucket_count(),
1260 "unordered container::begin(n) called with n >= bucket_count()");
Howard Hinnantb24c8022013-07-23 22:01:58 +00001261#if _LIBCPP_DEBUG_LEVEL >= 2
1262 return local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
1263#else
1264 return local_iterator(__bucket_list_[__n], __n, bucket_count());
1265#endif
1266 }
1267
1268 _LIBCPP_INLINE_VISIBILITY
1269 local_iterator
1270 end(size_type __n)
1271 {
Howard Hinnante5c13de2013-07-29 19:05:47 +00001272 _LIBCPP_ASSERT(__n < bucket_count(),
1273 "unordered container::end(n) called with n >= bucket_count()");
Howard Hinnantb24c8022013-07-23 22:01:58 +00001274#if _LIBCPP_DEBUG_LEVEL >= 2
1275 return local_iterator(nullptr, __n, bucket_count(), this);
1276#else
1277 return local_iterator(nullptr, __n, bucket_count());
1278#endif
1279 }
1280
1281 _LIBCPP_INLINE_VISIBILITY
1282 const_local_iterator
1283 cbegin(size_type __n) const
1284 {
Howard Hinnante5c13de2013-07-29 19:05:47 +00001285 _LIBCPP_ASSERT(__n < bucket_count(),
1286 "unordered container::cbegin(n) called with n >= bucket_count()");
Howard Hinnantb24c8022013-07-23 22:01:58 +00001287#if _LIBCPP_DEBUG_LEVEL >= 2
1288 return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
1289#else
1290 return const_local_iterator(__bucket_list_[__n], __n, bucket_count());
1291#endif
1292 }
1293
1294 _LIBCPP_INLINE_VISIBILITY
1295 const_local_iterator
1296 cend(size_type __n) const
1297 {
Howard Hinnante5c13de2013-07-29 19:05:47 +00001298 _LIBCPP_ASSERT(__n < bucket_count(),
1299 "unordered container::cend(n) called with n >= bucket_count()");
Howard Hinnantb24c8022013-07-23 22:01:58 +00001300#if _LIBCPP_DEBUG_LEVEL >= 2
1301 return const_local_iterator(nullptr, __n, bucket_count(), this);
1302#else
1303 return const_local_iterator(nullptr, __n, bucket_count());
1304#endif
1305 }
1306
1307#if _LIBCPP_DEBUG_LEVEL >= 2
1308
1309 bool __dereferenceable(const const_iterator* __i) const;
1310 bool __decrementable(const const_iterator* __i) const;
1311 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1312 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1313
1314#endif // _LIBCPP_DEBUG_LEVEL >= 2
1315
Howard Hinnant3e519522010-05-11 19:42:16 +00001316private:
1317 void __rehash(size_type __n);
1318
Eric Fiselierfcd02212016-02-11 11:59:44 +00001319#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001320 template <class ..._Args>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001321 __node_holder __construct_node(_Args&& ...__args);
1322
1323 template <class _First, class ..._Rest>
1324 __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest);
1325#else // _LIBCPP_CXX03_LANG
1326 __node_holder __construct_node(const __container_value_type& __v);
1327 __node_holder __construct_node_hash(size_t __hash, const __container_value_type& __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001328#endif
Eric Fiselierfcd02212016-02-11 11:59:44 +00001329
Howard Hinnant3e519522010-05-11 19:42:16 +00001330
Howard Hinnant43d99232010-09-21 17:32:39 +00001331 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001332 void __copy_assign_alloc(const __hash_table& __u)
1333 {__copy_assign_alloc(__u, integral_constant<bool,
1334 __node_traits::propagate_on_container_copy_assignment::value>());}
1335 void __copy_assign_alloc(const __hash_table& __u, true_type);
Howard Hinnant43d99232010-09-21 17:32:39 +00001336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc2063662011-12-01 20:21:04 +00001337 void __copy_assign_alloc(const __hash_table&, false_type) {}
Howard Hinnant3e519522010-05-11 19:42:16 +00001338
Eric Fiselierfcd02212016-02-11 11:59:44 +00001339#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001340 void __move_assign(__hash_table& __u, false_type);
Howard Hinnant37141072011-06-04 18:54:24 +00001341 void __move_assign(__hash_table& __u, true_type)
1342 _NOEXCEPT_(
1343 is_nothrow_move_assignable<__node_allocator>::value &&
1344 is_nothrow_move_assignable<hasher>::value &&
1345 is_nothrow_move_assignable<key_equal>::value);
1346 _LIBCPP_INLINE_VISIBILITY
1347 void __move_assign_alloc(__hash_table& __u)
1348 _NOEXCEPT_(
1349 !__node_traits::propagate_on_container_move_assignment::value ||
1350 (is_nothrow_move_assignable<__pointer_allocator>::value &&
1351 is_nothrow_move_assignable<__node_allocator>::value))
Howard Hinnant3e519522010-05-11 19:42:16 +00001352 {__move_assign_alloc(__u, integral_constant<bool,
1353 __node_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnant43d99232010-09-21 17:32:39 +00001354 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001355 void __move_assign_alloc(__hash_table& __u, true_type)
Howard Hinnant37141072011-06-04 18:54:24 +00001356 _NOEXCEPT_(
1357 is_nothrow_move_assignable<__pointer_allocator>::value &&
1358 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001359 {
1360 __bucket_list_.get_deleter().__alloc() =
Howard Hinnantce48a112011-06-30 21:18:19 +00001361 _VSTD::move(__u.__bucket_list_.get_deleter().__alloc());
1362 __node_alloc() = _VSTD::move(__u.__node_alloc());
Howard Hinnant3e519522010-05-11 19:42:16 +00001363 }
Howard Hinnant43d99232010-09-21 17:32:39 +00001364 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001365 void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {}
Eric Fiselierfcd02212016-02-11 11:59:44 +00001366#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001367
Eric Fiseliercd71f442017-01-07 03:01:24 +00001368 void __deallocate_node(__next_pointer __np) _NOEXCEPT;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001369 __next_pointer __detach() _NOEXCEPT;
Howard Hinnant307f8142013-06-22 15:21:29 +00001370
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +00001371 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
1372 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
Howard Hinnant3e519522010-05-11 19:42:16 +00001373};
1374
1375template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001376inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001377__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table()
Howard Hinnant37141072011-06-04 18:54:24 +00001378 _NOEXCEPT_(
1379 is_nothrow_default_constructible<__bucket_list>::value &&
1380 is_nothrow_default_constructible<__first_node>::value &&
Eric Fiseliere2e332a2015-12-16 00:53:04 +00001381 is_nothrow_default_constructible<__node_allocator>::value &&
Howard Hinnant37141072011-06-04 18:54:24 +00001382 is_nothrow_default_constructible<hasher>::value &&
1383 is_nothrow_default_constructible<key_equal>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001384 : __p2_(0),
1385 __p3_(1.0f)
1386{
1387}
1388
1389template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001390inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001391__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
1392 const key_equal& __eql)
1393 : __bucket_list_(nullptr, __bucket_list_deleter()),
1394 __p1_(),
1395 __p2_(0, __hf),
1396 __p3_(1.0f, __eql)
1397{
1398}
1399
1400template <class _Tp, class _Hash, class _Equal, class _Alloc>
1401__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
1402 const key_equal& __eql,
1403 const allocator_type& __a)
1404 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1405 __p1_(__node_allocator(__a)),
1406 __p2_(0, __hf),
1407 __p3_(1.0f, __eql)
1408{
1409}
1410
1411template <class _Tp, class _Hash, class _Equal, class _Alloc>
1412__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a)
1413 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1414 __p1_(__node_allocator(__a)),
1415 __p2_(0),
1416 __p3_(1.0f)
1417{
1418}
1419
1420template <class _Tp, class _Hash, class _Equal, class _Alloc>
1421__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u)
1422 : __bucket_list_(nullptr,
1423 __bucket_list_deleter(allocator_traits<__pointer_allocator>::
1424 select_on_container_copy_construction(
1425 __u.__bucket_list_.get_deleter().__alloc()), 0)),
1426 __p1_(allocator_traits<__node_allocator>::
1427 select_on_container_copy_construction(__u.__node_alloc())),
1428 __p2_(0, __u.hash_function()),
1429 __p3_(__u.__p3_)
1430{
1431}
1432
1433template <class _Tp, class _Hash, class _Equal, class _Alloc>
1434__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u,
1435 const allocator_type& __a)
1436 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1437 __p1_(__node_allocator(__a)),
1438 __p2_(0, __u.hash_function()),
1439 __p3_(__u.__p3_)
1440{
1441}
1442
Eric Fiselierfcd02212016-02-11 11:59:44 +00001443#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001444
1445template <class _Tp, class _Hash, class _Equal, class _Alloc>
1446__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001447 _NOEXCEPT_(
1448 is_nothrow_move_constructible<__bucket_list>::value &&
1449 is_nothrow_move_constructible<__first_node>::value &&
Eric Fiseliere2e332a2015-12-16 00:53:04 +00001450 is_nothrow_move_constructible<__node_allocator>::value &&
Howard Hinnant37141072011-06-04 18:54:24 +00001451 is_nothrow_move_constructible<hasher>::value &&
1452 is_nothrow_move_constructible<key_equal>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001453 : __bucket_list_(_VSTD::move(__u.__bucket_list_)),
1454 __p1_(_VSTD::move(__u.__p1_)),
1455 __p2_(_VSTD::move(__u.__p2_)),
1456 __p3_(_VSTD::move(__u.__p3_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001457{
1458 if (size() > 0)
1459 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001460 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
1461 __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001462 __u.__p1_.first().__next_ = nullptr;
1463 __u.size() = 0;
1464 }
1465}
1466
1467template <class _Tp, class _Hash, class _Equal, class _Alloc>
1468__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u,
1469 const allocator_type& __a)
1470 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1471 __p1_(__node_allocator(__a)),
Howard Hinnantce48a112011-06-30 21:18:19 +00001472 __p2_(0, _VSTD::move(__u.hash_function())),
1473 __p3_(_VSTD::move(__u.__p3_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001474{
1475 if (__a == allocator_type(__u.__node_alloc()))
1476 {
1477 __bucket_list_.reset(__u.__bucket_list_.release());
1478 __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
1479 __u.__bucket_list_.get_deleter().size() = 0;
1480 if (__u.size() > 0)
1481 {
1482 __p1_.first().__next_ = __u.__p1_.first().__next_;
1483 __u.__p1_.first().__next_ = nullptr;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001484 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
1485 __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001486 size() = __u.size();
1487 __u.size() = 0;
1488 }
1489 }
1490}
1491
Eric Fiselierfcd02212016-02-11 11:59:44 +00001492#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001493
1494template <class _Tp, class _Hash, class _Equal, class _Alloc>
1495__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
1496{
Eric Fiselieracb21582017-03-01 02:02:28 +00001497#if defined(_LIBCPP_CXX03_LANG)
Marshall Clow3b8669e2016-06-30 22:05:45 +00001498 static_assert((is_copy_constructible<key_equal>::value),
1499 "Predicate must be copy-constructible.");
1500 static_assert((is_copy_constructible<hasher>::value),
1501 "Hasher must be copy-constructible.");
Eric Fiselier04333f92017-01-13 22:42:53 +00001502#endif
Eric Fiselieracb21582017-03-01 02:02:28 +00001503
Eric Fiseliercd71f442017-01-07 03:01:24 +00001504 __deallocate_node(__p1_.first().__next_);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001505#if _LIBCPP_DEBUG_LEVEL >= 2
1506 __get_db()->__erase_c(this);
1507#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001508}
1509
1510template <class _Tp, class _Hash, class _Equal, class _Alloc>
1511void
1512__hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc(
1513 const __hash_table& __u, true_type)
1514{
1515 if (__node_alloc() != __u.__node_alloc())
1516 {
1517 clear();
1518 __bucket_list_.reset();
1519 __bucket_list_.get_deleter().size() = 0;
1520 }
1521 __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc();
1522 __node_alloc() = __u.__node_alloc();
1523}
1524
1525template <class _Tp, class _Hash, class _Equal, class _Alloc>
1526__hash_table<_Tp, _Hash, _Equal, _Alloc>&
1527__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u)
1528{
1529 if (this != &__u)
1530 {
1531 __copy_assign_alloc(__u);
1532 hash_function() = __u.hash_function();
1533 key_eq() = __u.key_eq();
1534 max_load_factor() = __u.max_load_factor();
1535 __assign_multi(__u.begin(), __u.end());
1536 }
1537 return *this;
1538}
1539
1540template <class _Tp, class _Hash, class _Equal, class _Alloc>
1541void
Eric Fiseliercd71f442017-01-07 03:01:24 +00001542__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np)
Howard Hinnant37141072011-06-04 18:54:24 +00001543 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001544{
1545 __node_allocator& __na = __node_alloc();
1546 while (__np != nullptr)
1547 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001548 __next_pointer __next = __np->__next_;
Howard Hinnantb24c8022013-07-23 22:01:58 +00001549#if _LIBCPP_DEBUG_LEVEL >= 2
1550 __c_node* __c = __get_db()->__find_c_and_lock(this);
1551 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1552 {
1553 --__p;
1554 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1555 if (__i->__node_ == __np)
1556 {
1557 (*__p)->__c_ = nullptr;
1558 if (--__c->end_ != __p)
1559 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1560 }
1561 }
1562 __get_db()->unlock();
1563#endif
Eric Fiselier40492ba2016-07-23 20:36:55 +00001564 __node_pointer __real_np = __np->__upcast();
1565 __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__value_));
1566 __node_traits::deallocate(__na, __real_np, 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001567 __np = __next;
1568 }
1569}
1570
1571template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselier40492ba2016-07-23 20:36:55 +00001572typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer
Howard Hinnant37141072011-06-04 18:54:24 +00001573__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001574{
1575 size_type __bc = bucket_count();
1576 for (size_type __i = 0; __i < __bc; ++__i)
1577 __bucket_list_[__i] = nullptr;
1578 size() = 0;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001579 __next_pointer __cache = __p1_.first().__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001580 __p1_.first().__next_ = nullptr;
1581 return __cache;
1582}
1583
Eric Fiselierfcd02212016-02-11 11:59:44 +00001584#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001585
1586template <class _Tp, class _Hash, class _Equal, class _Alloc>
1587void
1588__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
1589 __hash_table& __u, true_type)
Howard Hinnant37141072011-06-04 18:54:24 +00001590 _NOEXCEPT_(
1591 is_nothrow_move_assignable<__node_allocator>::value &&
1592 is_nothrow_move_assignable<hasher>::value &&
1593 is_nothrow_move_assignable<key_equal>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001594{
1595 clear();
1596 __bucket_list_.reset(__u.__bucket_list_.release());
1597 __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
1598 __u.__bucket_list_.get_deleter().size() = 0;
1599 __move_assign_alloc(__u);
1600 size() = __u.size();
Howard Hinnantce48a112011-06-30 21:18:19 +00001601 hash_function() = _VSTD::move(__u.hash_function());
Howard Hinnant3e519522010-05-11 19:42:16 +00001602 max_load_factor() = __u.max_load_factor();
Howard Hinnantce48a112011-06-30 21:18:19 +00001603 key_eq() = _VSTD::move(__u.key_eq());
Howard Hinnant3e519522010-05-11 19:42:16 +00001604 __p1_.first().__next_ = __u.__p1_.first().__next_;
1605 if (size() > 0)
1606 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001607 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
1608 __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001609 __u.__p1_.first().__next_ = nullptr;
1610 __u.size() = 0;
1611 }
Howard Hinnantb24c8022013-07-23 22:01:58 +00001612#if _LIBCPP_DEBUG_LEVEL >= 2
1613 __get_db()->swap(this, &__u);
1614#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001615}
1616
1617template <class _Tp, class _Hash, class _Equal, class _Alloc>
1618void
1619__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
1620 __hash_table& __u, false_type)
1621{
1622 if (__node_alloc() == __u.__node_alloc())
1623 __move_assign(__u, true_type());
1624 else
1625 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001626 hash_function() = _VSTD::move(__u.hash_function());
1627 key_eq() = _VSTD::move(__u.key_eq());
Howard Hinnant3e519522010-05-11 19:42:16 +00001628 max_load_factor() = __u.max_load_factor();
1629 if (bucket_count() != 0)
1630 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001631 __next_pointer __cache = __detach();
Howard Hinnant3e519522010-05-11 19:42:16 +00001632#ifndef _LIBCPP_NO_EXCEPTIONS
1633 try
1634 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001635#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001636 const_iterator __i = __u.begin();
1637 while (__cache != nullptr && __u.size() != 0)
1638 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001639 __cache->__upcast()->__value_ =
1640 _VSTD::move(__u.remove(__i++)->__value_);
1641 __next_pointer __next = __cache->__next_;
1642 __node_insert_multi(__cache->__upcast());
Howard Hinnant3e519522010-05-11 19:42:16 +00001643 __cache = __next;
1644 }
1645#ifndef _LIBCPP_NO_EXCEPTIONS
1646 }
1647 catch (...)
1648 {
Eric Fiseliercd71f442017-01-07 03:01:24 +00001649 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001650 throw;
1651 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001652#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiseliercd71f442017-01-07 03:01:24 +00001653 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001654 }
1655 const_iterator __i = __u.begin();
1656 while (__u.size() != 0)
1657 {
Eric Fiselierfcd02212016-02-11 11:59:44 +00001658 __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001659 __node_insert_multi(__h.get());
1660 __h.release();
1661 }
1662 }
1663}
1664
1665template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001666inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001667__hash_table<_Tp, _Hash, _Equal, _Alloc>&
1668__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001669 _NOEXCEPT_(
1670 __node_traits::propagate_on_container_move_assignment::value &&
1671 is_nothrow_move_assignable<__node_allocator>::value &&
1672 is_nothrow_move_assignable<hasher>::value &&
1673 is_nothrow_move_assignable<key_equal>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001674{
1675 __move_assign(__u, integral_constant<bool,
1676 __node_traits::propagate_on_container_move_assignment::value>());
1677 return *this;
1678}
1679
Eric Fiselierfcd02212016-02-11 11:59:44 +00001680#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001681
1682template <class _Tp, class _Hash, class _Equal, class _Alloc>
1683template <class _InputIterator>
1684void
1685__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first,
1686 _InputIterator __last)
1687{
Eric Fiselierfcd02212016-02-11 11:59:44 +00001688 typedef iterator_traits<_InputIterator> _ITraits;
1689 typedef typename _ITraits::value_type _ItValueType;
1690 static_assert((is_same<_ItValueType, __container_value_type>::value),
1691 "__assign_unique may only be called with the containers value type");
1692
Howard Hinnant3e519522010-05-11 19:42:16 +00001693 if (bucket_count() != 0)
1694 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001695 __next_pointer __cache = __detach();
Howard Hinnant3e519522010-05-11 19:42:16 +00001696#ifndef _LIBCPP_NO_EXCEPTIONS
1697 try
1698 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001699#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001700 for (; __cache != nullptr && __first != __last; ++__first)
1701 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001702 __cache->__upcast()->__value_ = *__first;
1703 __next_pointer __next = __cache->__next_;
1704 __node_insert_unique(__cache->__upcast());
Howard Hinnant3e519522010-05-11 19:42:16 +00001705 __cache = __next;
1706 }
1707#ifndef _LIBCPP_NO_EXCEPTIONS
1708 }
1709 catch (...)
1710 {
Eric Fiseliercd71f442017-01-07 03:01:24 +00001711 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001712 throw;
1713 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001714#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiseliercd71f442017-01-07 03:01:24 +00001715 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001716 }
1717 for (; __first != __last; ++__first)
1718 __insert_unique(*__first);
1719}
1720
1721template <class _Tp, class _Hash, class _Equal, class _Alloc>
1722template <class _InputIterator>
1723void
1724__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first,
1725 _InputIterator __last)
1726{
Eric Fiselierfcd02212016-02-11 11:59:44 +00001727 typedef iterator_traits<_InputIterator> _ITraits;
1728 typedef typename _ITraits::value_type _ItValueType;
1729 static_assert((is_same<_ItValueType, __container_value_type>::value ||
1730 is_same<_ItValueType, __node_value_type>::value),
1731 "__assign_multi may only be called with the containers value type"
1732 " or the nodes value type");
Howard Hinnant3e519522010-05-11 19:42:16 +00001733 if (bucket_count() != 0)
1734 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001735 __next_pointer __cache = __detach();
Howard Hinnant3e519522010-05-11 19:42:16 +00001736#ifndef _LIBCPP_NO_EXCEPTIONS
1737 try
1738 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001739#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001740 for (; __cache != nullptr && __first != __last; ++__first)
1741 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001742 __cache->__upcast()->__value_ = *__first;
1743 __next_pointer __next = __cache->__next_;
1744 __node_insert_multi(__cache->__upcast());
Howard Hinnant3e519522010-05-11 19:42:16 +00001745 __cache = __next;
1746 }
1747#ifndef _LIBCPP_NO_EXCEPTIONS
1748 }
1749 catch (...)
1750 {
Eric Fiseliercd71f442017-01-07 03:01:24 +00001751 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001752 throw;
1753 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001754#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiseliercd71f442017-01-07 03:01:24 +00001755 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001756 }
1757 for (; __first != __last; ++__first)
Eric Fiselierfcd02212016-02-11 11:59:44 +00001758 __insert_multi(_NodeTypes::__get_value(*__first));
Howard Hinnant3e519522010-05-11 19:42:16 +00001759}
1760
1761template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001762inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001763typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Howard Hinnant37141072011-06-04 18:54:24 +00001764__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001765{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001766#if _LIBCPP_DEBUG_LEVEL >= 2
1767 return iterator(__p1_.first().__next_, this);
1768#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001769 return iterator(__p1_.first().__next_);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001770#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001771}
1772
1773template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001774inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001775typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Howard Hinnant37141072011-06-04 18:54:24 +00001776__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001777{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001778#if _LIBCPP_DEBUG_LEVEL >= 2
1779 return iterator(nullptr, this);
1780#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001781 return iterator(nullptr);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001782#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001783}
1784
1785template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001786inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001787typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
Howard Hinnant37141072011-06-04 18:54:24 +00001788__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001789{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001790#if _LIBCPP_DEBUG_LEVEL >= 2
1791 return const_iterator(__p1_.first().__next_, this);
1792#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001793 return const_iterator(__p1_.first().__next_);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001794#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001795}
1796
1797template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001798inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001799typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
Howard Hinnant37141072011-06-04 18:54:24 +00001800__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001801{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001802#if _LIBCPP_DEBUG_LEVEL >= 2
1803 return const_iterator(nullptr, this);
1804#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001805 return const_iterator(nullptr);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001806#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001807}
1808
1809template <class _Tp, class _Hash, class _Equal, class _Alloc>
1810void
Howard Hinnant37141072011-06-04 18:54:24 +00001811__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001812{
1813 if (size() > 0)
1814 {
Eric Fiseliercd71f442017-01-07 03:01:24 +00001815 __deallocate_node(__p1_.first().__next_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001816 __p1_.first().__next_ = nullptr;
1817 size_type __bc = bucket_count();
Howard Hinnant1f8da842011-07-05 14:14:17 +00001818 for (size_type __i = 0; __i < __bc; ++__i)
Howard Hinnant3e519522010-05-11 19:42:16 +00001819 __bucket_list_[__i] = nullptr;
1820 size() = 0;
1821 }
1822}
1823
1824template <class _Tp, class _Hash, class _Equal, class _Alloc>
1825pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1826__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd)
1827{
1828 __nd->__hash_ = hash_function()(__nd->__value_);
1829 size_type __bc = bucket_count();
1830 bool __inserted = false;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001831 __next_pointer __ndptr;
Howard Hinnant3e519522010-05-11 19:42:16 +00001832 size_t __chash;
1833 if (__bc != 0)
1834 {
Howard Hinnant4cb38a82012-07-06 17:31:14 +00001835 __chash = __constrain_hash(__nd->__hash_, __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00001836 __ndptr = __bucket_list_[__chash];
1837 if (__ndptr != nullptr)
1838 {
1839 for (__ndptr = __ndptr->__next_; __ndptr != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00001840 __constrain_hash(__ndptr->__hash(), __bc) == __chash;
Howard Hinnant3e519522010-05-11 19:42:16 +00001841 __ndptr = __ndptr->__next_)
1842 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001843 if (key_eq()(__ndptr->__upcast()->__value_, __nd->__value_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001844 goto __done;
1845 }
1846 }
1847 }
1848 {
1849 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1850 {
Eric Fiselier9ba5c112015-02-02 21:31:48 +00001851 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnant3e519522010-05-11 19:42:16 +00001852 size_type(ceil(float(size() + 1) / max_load_factor()))));
1853 __bc = bucket_count();
Howard Hinnant4cb38a82012-07-06 17:31:14 +00001854 __chash = __constrain_hash(__nd->__hash_, __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00001855 }
1856 // insert_after __bucket_list_[__chash], or __first_node if bucket is null
Eric Fiselier40492ba2016-07-23 20:36:55 +00001857 __next_pointer __pn = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00001858 if (__pn == nullptr)
1859 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001860 __pn =__p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001861 __nd->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001862 __pn->__next_ = __nd->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001863 // fix up __bucket_list_
1864 __bucket_list_[__chash] = __pn;
1865 if (__nd->__next_ != nullptr)
Eric Fiselier40492ba2016-07-23 20:36:55 +00001866 __bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001867 }
1868 else
1869 {
1870 __nd->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001871 __pn->__next_ = __nd->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001872 }
Eric Fiselier40492ba2016-07-23 20:36:55 +00001873 __ndptr = __nd->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001874 // increment size
1875 ++size();
1876 __inserted = true;
1877 }
1878__done:
Howard Hinnantb24c8022013-07-23 22:01:58 +00001879#if _LIBCPP_DEBUG_LEVEL >= 2
1880 return pair<iterator, bool>(iterator(__ndptr, this), __inserted);
1881#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001882 return pair<iterator, bool>(iterator(__ndptr), __inserted);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001883#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001884}
1885
1886template <class _Tp, class _Hash, class _Equal, class _Alloc>
1887typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1888__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp)
1889{
1890 __cp->__hash_ = hash_function()(__cp->__value_);
1891 size_type __bc = bucket_count();
1892 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1893 {
Eric Fiselier9ba5c112015-02-02 21:31:48 +00001894 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnant3e519522010-05-11 19:42:16 +00001895 size_type(ceil(float(size() + 1) / max_load_factor()))));
1896 __bc = bucket_count();
1897 }
Howard Hinnant4cb38a82012-07-06 17:31:14 +00001898 size_t __chash = __constrain_hash(__cp->__hash_, __bc);
Eric Fiselier40492ba2016-07-23 20:36:55 +00001899 __next_pointer __pn = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00001900 if (__pn == nullptr)
1901 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001902 __pn =__p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001903 __cp->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001904 __pn->__next_ = __cp->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001905 // fix up __bucket_list_
1906 __bucket_list_[__chash] = __pn;
1907 if (__cp->__next_ != nullptr)
Eric Fiselier40492ba2016-07-23 20:36:55 +00001908 __bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)]
1909 = __cp->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001910 }
1911 else
1912 {
1913 for (bool __found = false; __pn->__next_ != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00001914 __constrain_hash(__pn->__next_->__hash(), __bc) == __chash;
Howard Hinnant3e519522010-05-11 19:42:16 +00001915 __pn = __pn->__next_)
Howard Hinnantb3371f62010-08-22 00:02:43 +00001916 {
Howard Hinnant3e519522010-05-11 19:42:16 +00001917 // __found key_eq() action
1918 // false false loop
1919 // true true loop
1920 // false true set __found to true
1921 // true false break
Eric Fiselier40492ba2016-07-23 20:36:55 +00001922 if (__found != (__pn->__next_->__hash() == __cp->__hash_ &&
1923 key_eq()(__pn->__next_->__upcast()->__value_, __cp->__value_)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001924 {
1925 if (!__found)
1926 __found = true;
1927 else
1928 break;
1929 }
1930 }
1931 __cp->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001932 __pn->__next_ = __cp->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001933 if (__cp->__next_ != nullptr)
1934 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001935 size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00001936 if (__nhash != __chash)
Eric Fiselier40492ba2016-07-23 20:36:55 +00001937 __bucket_list_[__nhash] = __cp->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001938 }
1939 }
1940 ++size();
Howard Hinnantb24c8022013-07-23 22:01:58 +00001941#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier40492ba2016-07-23 20:36:55 +00001942 return iterator(__cp->__ptr(), this);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001943#else
Eric Fiselier40492ba2016-07-23 20:36:55 +00001944 return iterator(__cp->__ptr());
Howard Hinnantb24c8022013-07-23 22:01:58 +00001945#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001946}
1947
1948template <class _Tp, class _Hash, class _Equal, class _Alloc>
1949typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1950__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
1951 const_iterator __p, __node_pointer __cp)
1952{
Howard Hinnant2f51de52013-08-02 17:50:49 +00001953#if _LIBCPP_DEBUG_LEVEL >= 2
1954 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1955 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
1956 " referring to this unordered container");
1957#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001958 if (__p != end() && key_eq()(*__p, __cp->__value_))
1959 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001960 __next_pointer __np = __p.__node_;
1961 __cp->__hash_ = __np->__hash();
Howard Hinnant3e519522010-05-11 19:42:16 +00001962 size_type __bc = bucket_count();
1963 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1964 {
Eric Fiselier9ba5c112015-02-02 21:31:48 +00001965 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnant3e519522010-05-11 19:42:16 +00001966 size_type(ceil(float(size() + 1) / max_load_factor()))));
1967 __bc = bucket_count();
1968 }
Howard Hinnant4cb38a82012-07-06 17:31:14 +00001969 size_t __chash = __constrain_hash(__cp->__hash_, __bc);
Eric Fiselier40492ba2016-07-23 20:36:55 +00001970 __next_pointer __pp = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00001971 while (__pp->__next_ != __np)
1972 __pp = __pp->__next_;
1973 __cp->__next_ = __np;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001974 __pp->__next_ = static_cast<__next_pointer>(__cp);
Howard Hinnant3e519522010-05-11 19:42:16 +00001975 ++size();
Howard Hinnantb24c8022013-07-23 22:01:58 +00001976#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier40492ba2016-07-23 20:36:55 +00001977 return iterator(static_cast<__next_pointer>(__cp), this);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001978#else
Eric Fiselier40492ba2016-07-23 20:36:55 +00001979 return iterator(static_cast<__next_pointer>(__cp));
Howard Hinnantb24c8022013-07-23 22:01:58 +00001980#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001981 }
1982 return __node_insert_multi(__cp);
1983}
1984
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001985
1986
Eric Fiselierfcd02212016-02-11 11:59:44 +00001987#ifndef _LIBCPP_CXX03_LANG
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001988template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001989template <class _Key, class ..._Args>
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001990pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001991__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args)
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001992#else
1993template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001994template <class _Key, class _Args>
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001995pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001996__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args)
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001997#endif
1998{
Eric Fiselierfcd02212016-02-11 11:59:44 +00001999
2000 size_t __hash = hash_function()(__k);
Howard Hinnant3e519522010-05-11 19:42:16 +00002001 size_type __bc = bucket_count();
2002 bool __inserted = false;
Eric Fiselier40492ba2016-07-23 20:36:55 +00002003 __next_pointer __nd;
Howard Hinnant3e519522010-05-11 19:42:16 +00002004 size_t __chash;
2005 if (__bc != 0)
2006 {
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002007 __chash = __constrain_hash(__hash, __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002008 __nd = __bucket_list_[__chash];
2009 if (__nd != nullptr)
2010 {
2011 for (__nd = __nd->__next_; __nd != nullptr &&
Eric Fiselier1a06fe52016-07-24 06:22:25 +00002012 (__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash);
Howard Hinnant3e519522010-05-11 19:42:16 +00002013 __nd = __nd->__next_)
2014 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002015 if (key_eq()(__nd->__upcast()->__value_, __k))
Howard Hinnant3e519522010-05-11 19:42:16 +00002016 goto __done;
2017 }
2018 }
2019 }
2020 {
Eric Fiselierfcd02212016-02-11 11:59:44 +00002021#ifndef _LIBCPP_CXX03_LANG
2022 __node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...);
2023#else
2024 __node_holder __h = __construct_node_hash(__hash, __args);
2025#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002026 if (size()+1 > __bc * max_load_factor() || __bc == 0)
2027 {
Eric Fiselier9ba5c112015-02-02 21:31:48 +00002028 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnant3e519522010-05-11 19:42:16 +00002029 size_type(ceil(float(size() + 1) / max_load_factor()))));
2030 __bc = bucket_count();
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002031 __chash = __constrain_hash(__hash, __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002032 }
2033 // insert_after __bucket_list_[__chash], or __first_node if bucket is null
Eric Fiselier40492ba2016-07-23 20:36:55 +00002034 __next_pointer __pn = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00002035 if (__pn == nullptr)
2036 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002037 __pn = __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00002038 __h->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00002039 __pn->__next_ = __h.get()->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00002040 // fix up __bucket_list_
2041 __bucket_list_[__chash] = __pn;
2042 if (__h->__next_ != nullptr)
Eric Fiselier40492ba2016-07-23 20:36:55 +00002043 __bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)]
2044 = __h.get()->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00002045 }
2046 else
2047 {
2048 __h->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00002049 __pn->__next_ = static_cast<__next_pointer>(__h.get());
Howard Hinnant3e519522010-05-11 19:42:16 +00002050 }
Eric Fiselier40492ba2016-07-23 20:36:55 +00002051 __nd = static_cast<__next_pointer>(__h.release());
Howard Hinnant3e519522010-05-11 19:42:16 +00002052 // increment size
2053 ++size();
2054 __inserted = true;
2055 }
2056__done:
Howard Hinnantb24c8022013-07-23 22:01:58 +00002057#if _LIBCPP_DEBUG_LEVEL >= 2
2058 return pair<iterator, bool>(iterator(__nd, this), __inserted);
2059#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002060 return pair<iterator, bool>(iterator(__nd), __inserted);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002061#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002062}
2063
Eric Fiselierfcd02212016-02-11 11:59:44 +00002064#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002065
2066template <class _Tp, class _Hash, class _Equal, class _Alloc>
2067template <class... _Args>
2068pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00002069__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args)
Howard Hinnant3e519522010-05-11 19:42:16 +00002070{
Howard Hinnantce48a112011-06-30 21:18:19 +00002071 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002072 pair<iterator, bool> __r = __node_insert_unique(__h.get());
2073 if (__r.second)
2074 __h.release();
2075 return __r;
2076}
2077
2078template <class _Tp, class _Hash, class _Equal, class _Alloc>
2079template <class... _Args>
2080typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2081__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args)
2082{
Howard Hinnantce48a112011-06-30 21:18:19 +00002083 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002084 iterator __r = __node_insert_multi(__h.get());
2085 __h.release();
2086 return __r;
2087}
2088
2089template <class _Tp, class _Hash, class _Equal, class _Alloc>
2090template <class... _Args>
2091typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2092__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(
2093 const_iterator __p, _Args&&... __args)
2094{
Howard Hinnante5c13de2013-07-29 19:05:47 +00002095#if _LIBCPP_DEBUG_LEVEL >= 2
2096 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2097 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
2098 " referring to this unordered container");
2099#endif
Howard Hinnantce48a112011-06-30 21:18:19 +00002100 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002101 iterator __r = __node_insert_multi(__p, __h.get());
2102 __h.release();
2103 return __r;
2104}
2105
Eric Fiselierfcd02212016-02-11 11:59:44 +00002106#else // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002107
2108template <class _Tp, class _Hash, class _Equal, class _Alloc>
2109typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Eric Fiselierfcd02212016-02-11 11:59:44 +00002110__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const __container_value_type& __x)
Howard Hinnant3e519522010-05-11 19:42:16 +00002111{
2112 __node_holder __h = __construct_node(__x);
2113 iterator __r = __node_insert_multi(__h.get());
2114 __h.release();
2115 return __r;
2116}
2117
2118template <class _Tp, class _Hash, class _Equal, class _Alloc>
2119typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2120__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
Eric Fiselierfcd02212016-02-11 11:59:44 +00002121 const __container_value_type& __x)
Howard Hinnant3e519522010-05-11 19:42:16 +00002122{
Howard Hinnante5c13de2013-07-29 19:05:47 +00002123#if _LIBCPP_DEBUG_LEVEL >= 2
2124 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2125 "unordered container::insert(const_iterator, lvalue) called with an iterator not"
2126 " referring to this unordered container");
2127#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002128 __node_holder __h = __construct_node(__x);
2129 iterator __r = __node_insert_multi(__p, __h.get());
2130 __h.release();
2131 return __r;
2132}
2133
Eric Fiselierfcd02212016-02-11 11:59:44 +00002134#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002135
2136template <class _Tp, class _Hash, class _Equal, class _Alloc>
2137void
2138__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
2139{
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002140 if (__n == 1)
2141 __n = 2;
2142 else if (__n & (__n - 1))
2143 __n = __next_prime(__n);
Howard Hinnant3e519522010-05-11 19:42:16 +00002144 size_type __bc = bucket_count();
2145 if (__n > __bc)
2146 __rehash(__n);
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002147 else if (__n < __bc)
Howard Hinnant3e519522010-05-11 19:42:16 +00002148 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002149 __n = _VSTD::max<size_type>
Howard Hinnant3e519522010-05-11 19:42:16 +00002150 (
2151 __n,
Eric Fiselier9ba5c112015-02-02 21:31:48 +00002152 __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) :
2153 __next_prime(size_t(ceil(float(size()) / max_load_factor())))
Howard Hinnant3e519522010-05-11 19:42:16 +00002154 );
2155 if (__n < __bc)
2156 __rehash(__n);
2157 }
2158}
2159
2160template <class _Tp, class _Hash, class _Equal, class _Alloc>
2161void
2162__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
2163{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002164#if _LIBCPP_DEBUG_LEVEL >= 2
2165 __get_db()->__invalidate_all(this);
2166#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant3e519522010-05-11 19:42:16 +00002167 __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc();
2168 __bucket_list_.reset(__nbc > 0 ?
2169 __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr);
2170 __bucket_list_.get_deleter().size() = __nbc;
2171 if (__nbc > 0)
2172 {
2173 for (size_type __i = 0; __i < __nbc; ++__i)
2174 __bucket_list_[__i] = nullptr;
Eric Fiselier40492ba2016-07-23 20:36:55 +00002175 __next_pointer __pp = __p1_.first().__ptr();
2176 __next_pointer __cp = __pp->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002177 if (__cp != nullptr)
2178 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002179 size_type __chash = __constrain_hash(__cp->__hash(), __nbc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002180 __bucket_list_[__chash] = __pp;
2181 size_type __phash = __chash;
2182 for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
2183 __cp = __pp->__next_)
2184 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002185 __chash = __constrain_hash(__cp->__hash(), __nbc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002186 if (__chash == __phash)
2187 __pp = __cp;
2188 else
2189 {
2190 if (__bucket_list_[__chash] == nullptr)
2191 {
2192 __bucket_list_[__chash] = __pp;
2193 __pp = __cp;
2194 __phash = __chash;
2195 }
2196 else
2197 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002198 __next_pointer __np = __cp;
Howard Hinnant3e519522010-05-11 19:42:16 +00002199 for (; __np->__next_ != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00002200 key_eq()(__cp->__upcast()->__value_,
2201 __np->__next_->__upcast()->__value_);
Howard Hinnant3e519522010-05-11 19:42:16 +00002202 __np = __np->__next_)
2203 ;
2204 __pp->__next_ = __np->__next_;
2205 __np->__next_ = __bucket_list_[__chash]->__next_;
2206 __bucket_list_[__chash]->__next_ = __cp;
Howard Hinnantb3371f62010-08-22 00:02:43 +00002207
Howard Hinnant3e519522010-05-11 19:42:16 +00002208 }
2209 }
2210 }
2211 }
2212 }
2213}
2214
2215template <class _Tp, class _Hash, class _Equal, class _Alloc>
2216template <class _Key>
2217typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2218__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k)
2219{
2220 size_t __hash = hash_function()(__k);
2221 size_type __bc = bucket_count();
2222 if (__bc != 0)
2223 {
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002224 size_t __chash = __constrain_hash(__hash, __bc);
Eric Fiselier40492ba2016-07-23 20:36:55 +00002225 __next_pointer __nd = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00002226 if (__nd != nullptr)
2227 {
2228 for (__nd = __nd->__next_; __nd != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00002229 (__nd->__hash() == __hash
2230 || __constrain_hash(__nd->__hash(), __bc) == __chash);
Howard Hinnant3e519522010-05-11 19:42:16 +00002231 __nd = __nd->__next_)
2232 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002233 if ((__nd->__hash() == __hash)
2234 && key_eq()(__nd->__upcast()->__value_, __k))
Howard Hinnantb24c8022013-07-23 22:01:58 +00002235#if _LIBCPP_DEBUG_LEVEL >= 2
2236 return iterator(__nd, this);
2237#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002238 return iterator(__nd);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002239#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002240 }
2241 }
2242 }
2243 return end();
2244}
2245
2246template <class _Tp, class _Hash, class _Equal, class _Alloc>
2247template <class _Key>
2248typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
2249__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const
2250{
2251 size_t __hash = hash_function()(__k);
2252 size_type __bc = bucket_count();
2253 if (__bc != 0)
2254 {
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002255 size_t __chash = __constrain_hash(__hash, __bc);
Eric Fiselier40492ba2016-07-23 20:36:55 +00002256 __next_pointer __nd = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00002257 if (__nd != nullptr)
2258 {
2259 for (__nd = __nd->__next_; __nd != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00002260 (__hash == __nd->__hash()
2261 || __constrain_hash(__nd->__hash(), __bc) == __chash);
Howard Hinnant3e519522010-05-11 19:42:16 +00002262 __nd = __nd->__next_)
2263 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002264 if ((__nd->__hash() == __hash)
2265 && key_eq()(__nd->__upcast()->__value_, __k))
Howard Hinnantb24c8022013-07-23 22:01:58 +00002266#if _LIBCPP_DEBUG_LEVEL >= 2
2267 return const_iterator(__nd, this);
2268#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002269 return const_iterator(__nd);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002270#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002271 }
2272 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00002273
Howard Hinnant3e519522010-05-11 19:42:16 +00002274 }
2275 return end();
2276}
2277
Eric Fiselierfcd02212016-02-11 11:59:44 +00002278#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002279
2280template <class _Tp, class _Hash, class _Equal, class _Alloc>
2281template <class ..._Args>
2282typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
2283__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args)
2284{
Eric Fiselierfcd02212016-02-11 11:59:44 +00002285 static_assert(!__is_hash_value_type<_Args...>::value,
2286 "Construct cannot be called with a hash value type");
Howard Hinnant3e519522010-05-11 19:42:16 +00002287 __node_allocator& __na = __node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00002288 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Eric Fiselierfcd02212016-02-11 11:59:44 +00002289 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002290 __h.get_deleter().__value_constructed = true;
2291 __h->__hash_ = hash_function()(__h->__value_);
2292 __h->__next_ = nullptr;
2293 return __h;
2294}
2295
2296template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselierfcd02212016-02-11 11:59:44 +00002297template <class _First, class ..._Rest>
Howard Hinnant3e519522010-05-11 19:42:16 +00002298typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Eric Fiselierfcd02212016-02-11 11:59:44 +00002299__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(
2300 size_t __hash, _First&& __f, _Rest&& ...__rest)
Howard Hinnant3e519522010-05-11 19:42:16 +00002301{
Eric Fiselierfcd02212016-02-11 11:59:44 +00002302 static_assert(!__is_hash_value_type<_First, _Rest...>::value,
2303 "Construct cannot be called with a hash value type");
Howard Hinnant3e519522010-05-11 19:42:16 +00002304 __node_allocator& __na = __node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00002305 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Eric Fiselierfcd02212016-02-11 11:59:44 +00002306 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_),
2307 _VSTD::forward<_First>(__f),
2308 _VSTD::forward<_Rest>(__rest)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002309 __h.get_deleter().__value_constructed = true;
2310 __h->__hash_ = __hash;
2311 __h->__next_ = nullptr;
Howard Hinnant179b1f82013-08-22 18:29:50 +00002312 return __h;
Howard Hinnant3e519522010-05-11 19:42:16 +00002313}
2314
Eric Fiselierfcd02212016-02-11 11:59:44 +00002315#else // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002316
2317template <class _Tp, class _Hash, class _Equal, class _Alloc>
2318typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Eric Fiselierfcd02212016-02-11 11:59:44 +00002319__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const __container_value_type& __v)
Howard Hinnant3e519522010-05-11 19:42:16 +00002320{
2321 __node_allocator& __na = __node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00002322 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Eric Fiselierfcd02212016-02-11 11:59:44 +00002323 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00002324 __h.get_deleter().__value_constructed = true;
2325 __h->__hash_ = hash_function()(__h->__value_);
2326 __h->__next_ = nullptr;
Dimitry Andric251c6292015-08-19 06:43:33 +00002327 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnant3e519522010-05-11 19:42:16 +00002328}
2329
Howard Hinnant3e519522010-05-11 19:42:16 +00002330template <class _Tp, class _Hash, class _Equal, class _Alloc>
2331typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Eric Fiselierfcd02212016-02-11 11:59:44 +00002332__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash,
2333 const __container_value_type& __v)
Howard Hinnant3e519522010-05-11 19:42:16 +00002334{
2335 __node_allocator& __na = __node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00002336 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Eric Fiselierfcd02212016-02-11 11:59:44 +00002337 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00002338 __h.get_deleter().__value_constructed = true;
2339 __h->__hash_ = __hash;
2340 __h->__next_ = nullptr;
Dimitry Andric251c6292015-08-19 06:43:33 +00002341 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnant3e519522010-05-11 19:42:16 +00002342}
2343
Eric Fiselierfcd02212016-02-11 11:59:44 +00002344#endif // _LIBCPP_CXX03_LANG
2345
Howard Hinnant3e519522010-05-11 19:42:16 +00002346template <class _Tp, class _Hash, class _Equal, class _Alloc>
2347typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2348__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
2349{
Eric Fiselier40492ba2016-07-23 20:36:55 +00002350 __next_pointer __np = __p.__node_;
Howard Hinnantb24c8022013-07-23 22:01:58 +00002351#if _LIBCPP_DEBUG_LEVEL >= 2
2352 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2353 "unordered container erase(iterator) called with an iterator not"
2354 " referring to this container");
2355 _LIBCPP_ASSERT(__p != end(),
2356 "unordered container erase(iterator) called with a non-dereferenceable iterator");
2357 iterator __r(__np, this);
2358#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002359 iterator __r(__np);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002360#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002361 ++__r;
2362 remove(__p);
2363 return __r;
2364}
2365
2366template <class _Tp, class _Hash, class _Equal, class _Alloc>
2367typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2368__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
2369 const_iterator __last)
2370{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002371#if _LIBCPP_DEBUG_LEVEL >= 2
2372 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2373 "unodered container::erase(iterator, iterator) called with an iterator not"
2374 " referring to this unodered container");
2375 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
2376 "unodered container::erase(iterator, iterator) called with an iterator not"
2377 " referring to this unodered container");
2378#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002379 for (const_iterator __p = __first; __first != __last; __p = __first)
2380 {
2381 ++__first;
2382 erase(__p);
2383 }
Eric Fiselier40492ba2016-07-23 20:36:55 +00002384 __next_pointer __np = __last.__node_;
Howard Hinnantb24c8022013-07-23 22:01:58 +00002385#if _LIBCPP_DEBUG_LEVEL >= 2
2386 return iterator (__np, this);
2387#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002388 return iterator (__np);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002389#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002390}
2391
2392template <class _Tp, class _Hash, class _Equal, class _Alloc>
2393template <class _Key>
2394typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2395__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k)
2396{
2397 iterator __i = find(__k);
2398 if (__i == end())
2399 return 0;
2400 erase(__i);
2401 return 1;
2402}
2403
2404template <class _Tp, class _Hash, class _Equal, class _Alloc>
2405template <class _Key>
2406typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2407__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k)
2408{
2409 size_type __r = 0;
2410 iterator __i = find(__k);
2411 if (__i != end())
2412 {
2413 iterator __e = end();
2414 do
2415 {
2416 erase(__i++);
2417 ++__r;
2418 } while (__i != __e && key_eq()(*__i, __k));
2419 }
2420 return __r;
2421}
2422
2423template <class _Tp, class _Hash, class _Equal, class _Alloc>
2424typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Howard Hinnant37141072011-06-04 18:54:24 +00002425__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00002426{
2427 // current node
Eric Fiselier40492ba2016-07-23 20:36:55 +00002428 __next_pointer __cn = __p.__node_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002429 size_type __bc = bucket_count();
Eric Fiselier40492ba2016-07-23 20:36:55 +00002430 size_t __chash = __constrain_hash(__cn->__hash(), __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002431 // find previous node
Eric Fiselier40492ba2016-07-23 20:36:55 +00002432 __next_pointer __pn = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00002433 for (; __pn->__next_ != __cn; __pn = __pn->__next_)
2434 ;
2435 // Fix up __bucket_list_
2436 // if __pn is not in same bucket (before begin is not in same bucket) &&
2437 // if __cn->__next_ is not in same bucket (nullptr is not in same bucket)
Eric Fiselier40492ba2016-07-23 20:36:55 +00002438 if (__pn == __p1_.first().__ptr()
2439 || __constrain_hash(__pn->__hash(), __bc) != __chash)
Howard Hinnant3e519522010-05-11 19:42:16 +00002440 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002441 if (__cn->__next_ == nullptr
2442 || __constrain_hash(__cn->__next_->__hash(), __bc) != __chash)
Howard Hinnant3e519522010-05-11 19:42:16 +00002443 __bucket_list_[__chash] = nullptr;
2444 }
2445 // if __cn->__next_ is not in same bucket (nullptr is in same bucket)
2446 if (__cn->__next_ != nullptr)
2447 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002448 size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002449 if (__nhash != __chash)
2450 __bucket_list_[__nhash] = __pn;
2451 }
2452 // remove __cn
2453 __pn->__next_ = __cn->__next_;
2454 __cn->__next_ = nullptr;
2455 --size();
Howard Hinnantb24c8022013-07-23 22:01:58 +00002456#if _LIBCPP_DEBUG_LEVEL >= 2
2457 __c_node* __c = __get_db()->__find_c_and_lock(this);
Eric Fiselier780b51d2016-12-28 05:53:01 +00002458 for (__i_node** __dp = __c->end_; __dp != __c->beg_; )
Howard Hinnantb24c8022013-07-23 22:01:58 +00002459 {
Eric Fiselier780b51d2016-12-28 05:53:01 +00002460 --__dp;
2461 iterator* __i = static_cast<iterator*>((*__dp)->__i_);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002462 if (__i->__node_ == __cn)
2463 {
Eric Fiselier780b51d2016-12-28 05:53:01 +00002464 (*__dp)->__c_ = nullptr;
2465 if (--__c->end_ != __dp)
2466 memmove(__dp, __dp+1, (__c->end_ - __dp)*sizeof(__i_node*));
Howard Hinnantb24c8022013-07-23 22:01:58 +00002467 }
2468 }
2469 __get_db()->unlock();
2470#endif
Eric Fiselier40492ba2016-07-23 20:36:55 +00002471 return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true));
Howard Hinnant3e519522010-05-11 19:42:16 +00002472}
2473
2474template <class _Tp, class _Hash, class _Equal, class _Alloc>
2475template <class _Key>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00002476inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002477typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2478__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const
2479{
2480 return static_cast<size_type>(find(__k) != end());
2481}
2482
2483template <class _Tp, class _Hash, class _Equal, class _Alloc>
2484template <class _Key>
2485typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2486__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const
2487{
2488 size_type __r = 0;
2489 const_iterator __i = find(__k);
2490 if (__i != end())
2491 {
2492 const_iterator __e = end();
2493 do
2494 {
2495 ++__i;
2496 ++__r;
2497 } while (__i != __e && key_eq()(*__i, __k));
2498 }
2499 return __r;
2500}
2501
2502template <class _Tp, class _Hash, class _Equal, class _Alloc>
2503template <class _Key>
2504pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
2505 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
2506__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
2507 const _Key& __k)
2508{
2509 iterator __i = find(__k);
2510 iterator __j = __i;
2511 if (__i != end())
2512 ++__j;
2513 return pair<iterator, iterator>(__i, __j);
2514}
2515
2516template <class _Tp, class _Hash, class _Equal, class _Alloc>
2517template <class _Key>
2518pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
2519 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
2520__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
2521 const _Key& __k) const
2522{
2523 const_iterator __i = find(__k);
2524 const_iterator __j = __i;
2525 if (__i != end())
2526 ++__j;
2527 return pair<const_iterator, const_iterator>(__i, __j);
2528}
2529
2530template <class _Tp, class _Hash, class _Equal, class _Alloc>
2531template <class _Key>
2532pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
2533 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
2534__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
2535 const _Key& __k)
2536{
2537 iterator __i = find(__k);
2538 iterator __j = __i;
2539 if (__i != end())
2540 {
2541 iterator __e = end();
2542 do
2543 {
2544 ++__j;
2545 } while (__j != __e && key_eq()(*__j, __k));
2546 }
2547 return pair<iterator, iterator>(__i, __j);
2548}
2549
2550template <class _Tp, class _Hash, class _Equal, class _Alloc>
2551template <class _Key>
2552pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
2553 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
2554__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
2555 const _Key& __k) const
2556{
2557 const_iterator __i = find(__k);
2558 const_iterator __j = __i;
2559 if (__i != end())
2560 {
2561 const_iterator __e = end();
2562 do
2563 {
2564 ++__j;
2565 } while (__j != __e && key_eq()(*__j, __k));
2566 }
2567 return pair<const_iterator, const_iterator>(__i, __j);
2568}
2569
2570template <class _Tp, class _Hash, class _Equal, class _Alloc>
2571void
2572__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
Eric Fiselier87a82492015-07-18 20:40:46 +00002573#if _LIBCPP_STD_VER <= 11
Eric Fiselier780b51d2016-12-28 05:53:01 +00002574 _NOEXCEPT_DEBUG_(
Marshall Clowe3fbe142015-07-13 20:04:56 +00002575 __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
Marshall Clowe3fbe142015-07-13 20:04:56 +00002576 && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
2577 || __is_nothrow_swappable<__pointer_allocator>::value)
2578 && (!__node_traits::propagate_on_container_swap::value
2579 || __is_nothrow_swappable<__node_allocator>::value)
Marshall Clowe3fbe142015-07-13 20:04:56 +00002580 )
Eric Fiselier87a82492015-07-18 20:40:46 +00002581#else
Eric Fiselier780b51d2016-12-28 05:53:01 +00002582 _NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value)
Eric Fiselier87a82492015-07-18 20:40:46 +00002583#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002584{
Eric Fiselier780b51d2016-12-28 05:53:01 +00002585 _LIBCPP_ASSERT(__node_traits::propagate_on_container_swap::value ||
2586 this->__node_alloc() == __u.__node_alloc(),
2587 "list::swap: Either propagate_on_container_swap must be true"
2588 " or the allocators must compare equal");
Howard Hinnant3e519522010-05-11 19:42:16 +00002589 {
2590 __node_pointer_pointer __npp = __bucket_list_.release();
2591 __bucket_list_.reset(__u.__bucket_list_.release());
2592 __u.__bucket_list_.reset(__npp);
2593 }
Howard Hinnantce48a112011-06-30 21:18:19 +00002594 _VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size());
Marshall Clowe3fbe142015-07-13 20:04:56 +00002595 __swap_allocator(__bucket_list_.get_deleter().__alloc(),
Howard Hinnant3e519522010-05-11 19:42:16 +00002596 __u.__bucket_list_.get_deleter().__alloc());
Marshall Clowe3fbe142015-07-13 20:04:56 +00002597 __swap_allocator(__node_alloc(), __u.__node_alloc());
Howard Hinnantce48a112011-06-30 21:18:19 +00002598 _VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_);
Howard Hinnant3e519522010-05-11 19:42:16 +00002599 __p2_.swap(__u.__p2_);
2600 __p3_.swap(__u.__p3_);
2601 if (size() > 0)
Eric Fiselier40492ba2016-07-23 20:36:55 +00002602 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
2603 __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00002604 if (__u.size() > 0)
Eric Fiselier40492ba2016-07-23 20:36:55 +00002605 __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] =
2606 __u.__p1_.first().__ptr();
Howard Hinnantb24c8022013-07-23 22:01:58 +00002607#if _LIBCPP_DEBUG_LEVEL >= 2
2608 __get_db()->swap(this, &__u);
2609#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002610}
2611
2612template <class _Tp, class _Hash, class _Equal, class _Alloc>
2613typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2614__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const
2615{
Howard Hinnante5c13de2013-07-29 19:05:47 +00002616 _LIBCPP_ASSERT(__n < bucket_count(),
2617 "unordered container::bucket_size(n) called with n >= bucket_count()");
Eric Fiselier40492ba2016-07-23 20:36:55 +00002618 __next_pointer __np = __bucket_list_[__n];
Howard Hinnant3e519522010-05-11 19:42:16 +00002619 size_type __bc = bucket_count();
2620 size_type __r = 0;
2621 if (__np != nullptr)
2622 {
2623 for (__np = __np->__next_; __np != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00002624 __constrain_hash(__np->__hash(), __bc) == __n;
Howard Hinnant3e519522010-05-11 19:42:16 +00002625 __np = __np->__next_, ++__r)
2626 ;
2627 }
2628 return __r;
2629}
2630
Howard Hinnant37141072011-06-04 18:54:24 +00002631template <class _Tp, class _Hash, class _Equal, class _Alloc>
2632inline _LIBCPP_INLINE_VISIBILITY
2633void
2634swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x,
2635 __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y)
2636 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2637{
2638 __x.swap(__y);
2639}
2640
Howard Hinnantb24c8022013-07-23 22:01:58 +00002641#if _LIBCPP_DEBUG_LEVEL >= 2
2642
2643template <class _Tp, class _Hash, class _Equal, class _Alloc>
2644bool
2645__hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const
2646{
2647 return __i->__node_ != nullptr;
2648}
2649
2650template <class _Tp, class _Hash, class _Equal, class _Alloc>
2651bool
2652__hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const
2653{
2654 return false;
2655}
2656
2657template <class _Tp, class _Hash, class _Equal, class _Alloc>
2658bool
2659__hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
2660{
2661 return false;
2662}
2663
2664template <class _Tp, class _Hash, class _Equal, class _Alloc>
2665bool
2666__hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
2667{
2668 return false;
2669}
2670
2671#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant3e519522010-05-11 19:42:16 +00002672_LIBCPP_END_NAMESPACE_STD
2673
2674#endif // _LIBCPP__HASH_TABLE