blob: 44ba268a0ec819db8d076aa14dd356f8e09a8c20 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00005//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP__HASH_TABLE
12#define _LIBCPP__HASH_TABLE
13
14#include <__config>
15#include <initializer_list>
16#include <memory>
17#include <iterator>
18#include <algorithm>
19#include <cmath>
Eric Fiselier75d0dcf2016-02-10 20:46:23 +000020#include <utility>
Eric Fiselier04333f92017-01-13 22:42:53 +000021#include <type_traits>
Howard Hinnant3e519522010-05-11 19:42:16 +000022
Eric Fiselierc1bd9192014-08-10 23:53:08 +000023#include <__debug>
Howard Hinnant42a30462013-08-02 00:26:35 +000024
Howard Hinnant073458b2011-10-17 20:05:10 +000025#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +000026#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +000027#endif
Howard Hinnant3e519522010-05-11 19:42:16 +000028
Eric Fiseliera016efb2017-05-31 22:07:49 +000029_LIBCPP_PUSH_MACROS
30#include <__undef_macros>
Howard Hinnant3e519522010-05-11 19:42:16 +000031
Eric Fiselierfcd02212016-02-11 11:59:44 +000032
Eric Fiseliera016efb2017-05-31 22:07:49 +000033_LIBCPP_BEGIN_NAMESPACE_STD
34
Eric Fiselierfcd02212016-02-11 11:59:44 +000035template <class _Key, class _Tp>
36struct __hash_value_type;
Eric Fiselierfcd02212016-02-11 11:59:44 +000037
Eric Fiselier04333f92017-01-13 22:42:53 +000038template <class _Key, class _Cp, class _Hash,
39 bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value>
40class __unordered_map_hasher;
41
42template <class _Key, class _Cp, class _Pred,
43 bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value
44 >
45class __unordered_map_equal;
46
Eric Fiselierfcd02212016-02-11 11:59:44 +000047#ifndef _LIBCPP_CXX03_LANG
48template <class _Tp>
49struct __is_hash_value_type_imp : false_type {};
50
51template <class _Key, class _Value>
52struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {};
53
54template <class ..._Args>
55struct __is_hash_value_type : false_type {};
56
57template <class _One>
58struct __is_hash_value_type<_One> : __is_hash_value_type_imp<typename __uncvref<_One>::type> {};
59#endif
60
Howard Hinnant6e412562013-03-06 23:30:19 +000061_LIBCPP_FUNC_VIS
Howard Hinnantce534202011-06-14 19:58:17 +000062size_t __next_prime(size_t __n);
Howard Hinnant3e519522010-05-11 19:42:16 +000063
64template <class _NodePtr>
65struct __hash_node_base
66{
Eric Fiselier40492ba2016-07-23 20:36:55 +000067 typedef typename pointer_traits<_NodePtr>::element_type __node_type;
Howard Hinnant3e519522010-05-11 19:42:16 +000068 typedef __hash_node_base __first_node;
Eric Fiselier40492ba2016-07-23 20:36:55 +000069 typedef typename __rebind_pointer<_NodePtr, __first_node>::type __node_base_pointer;
70 typedef _NodePtr __node_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +000071
Eric Fiselier40492ba2016-07-23 20:36:55 +000072#if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB)
73 typedef __node_base_pointer __next_pointer;
74#else
75 typedef typename conditional<
76 is_pointer<__node_pointer>::value,
77 __node_base_pointer,
78 __node_pointer>::type __next_pointer;
79#endif
80
81 __next_pointer __next_;
82
83 _LIBCPP_INLINE_VISIBILITY
84 __next_pointer __ptr() _NOEXCEPT {
85 return static_cast<__next_pointer>(
86 pointer_traits<__node_base_pointer>::pointer_to(*this));
87 }
88
89 _LIBCPP_INLINE_VISIBILITY
90 __node_pointer __upcast() _NOEXCEPT {
91 return static_cast<__node_pointer>(
92 pointer_traits<__node_base_pointer>::pointer_to(*this));
93 }
94
95 _LIBCPP_INLINE_VISIBILITY
96 size_t __hash() const _NOEXCEPT {
97 return static_cast<__node_type const&>(*this).__hash_;
98 }
Howard Hinnant3e519522010-05-11 19:42:16 +000099
Howard Hinnant37141072011-06-04 18:54:24 +0000100 _LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000101};
102
103template <class _Tp, class _VoidPtr>
104struct __hash_node
105 : public __hash_node_base
106 <
Eric Fiselier934b0922015-12-30 21:52:00 +0000107 typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type
Howard Hinnant3e519522010-05-11 19:42:16 +0000108 >
109{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000110 typedef _Tp __node_value_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000111
Eric Fiselier40492ba2016-07-23 20:36:55 +0000112 size_t __hash_;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000113 __node_value_type __value_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000114};
115
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000116inline _LIBCPP_INLINE_VISIBILITY
117bool
Eric Fiselier9ba5c112015-02-02 21:31:48 +0000118__is_hash_power2(size_t __bc)
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000119{
120 return __bc > 2 && !(__bc & (__bc - 1));
121}
122
123inline _LIBCPP_INLINE_VISIBILITY
124size_t
125__constrain_hash(size_t __h, size_t __bc)
126{
Eric Fiselier118cb412016-07-11 22:02:02 +0000127 return !(__bc & (__bc - 1)) ? __h & (__bc - 1) :
128 (__h < __bc ? __h : __h % __bc);
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000129}
130
131inline _LIBCPP_INLINE_VISIBILITY
132size_t
Eric Fiselier9ba5c112015-02-02 21:31:48 +0000133__next_hash_pow2(size_t __n)
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000134{
Marshall Clow87af6462017-06-03 00:08:32 +0000135 return __n < 2 ? __n : (size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1)));
Howard Hinnant4cb38a82012-07-06 17:31:14 +0000136}
137
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +0000138
Howard Hinnantce534202011-06-14 19:58:17 +0000139template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000140
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000141template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_iterator;
142template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
143template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_local_iterator;
144template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
145template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
146template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000147
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000148template <class _Tp>
Eric Fiselier43b121d2016-02-20 07:59:16 +0000149struct __hash_key_value_types {
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000150 static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, "");
151 typedef _Tp key_type;
152 typedef _Tp __node_value_type;
153 typedef _Tp __container_value_type;
154 static const bool __is_map = false;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000155
156 _LIBCPP_INLINE_VISIBILITY
157 static key_type const& __get_key(_Tp const& __v) {
158 return __v;
159 }
160 _LIBCPP_INLINE_VISIBILITY
161 static __container_value_type const& __get_value(__node_value_type const& __v) {
162 return __v;
163 }
164 _LIBCPP_INLINE_VISIBILITY
165 static __container_value_type* __get_ptr(__node_value_type& __n) {
166 return _VSTD::addressof(__n);
167 }
168#ifndef _LIBCPP_CXX03_LANG
169 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000170 static __container_value_type&& __move(__node_value_type& __v) {
Eric Fiselierfcd02212016-02-11 11:59:44 +0000171 return _VSTD::move(__v);
172 }
173#endif
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000174};
175
176template <class _Key, class _Tp>
Eric Fiselier43b121d2016-02-20 07:59:16 +0000177struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > {
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000178 typedef _Key key_type;
179 typedef _Tp mapped_type;
180 typedef __hash_value_type<_Key, _Tp> __node_value_type;
181 typedef pair<const _Key, _Tp> __container_value_type;
182 typedef __container_value_type __map_value_type;
183 static const bool __is_map = true;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000184
185 _LIBCPP_INLINE_VISIBILITY
186 static key_type const& __get_key(__container_value_type const& __v) {
187 return __v.first;
188 }
189
190 template <class _Up>
191 _LIBCPP_INLINE_VISIBILITY
192 static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value,
193 __container_value_type const&>::type
194 __get_value(_Up& __t) {
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000195 return __t.__get_value();
Eric Fiselierfcd02212016-02-11 11:59:44 +0000196 }
197
198 template <class _Up>
199 _LIBCPP_INLINE_VISIBILITY
200 static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value,
201 __container_value_type const&>::type
202 __get_value(_Up& __t) {
203 return __t;
204 }
205
206 _LIBCPP_INLINE_VISIBILITY
207 static __container_value_type* __get_ptr(__node_value_type& __n) {
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000208 return _VSTD::addressof(__n.__get_value());
Eric Fiselierfcd02212016-02-11 11:59:44 +0000209 }
210#ifndef _LIBCPP_CXX03_LANG
211 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000212 static pair<key_type&&, mapped_type&&> __move(__node_value_type& __v) {
213 return __v.__move();
Eric Fiselierfcd02212016-02-11 11:59:44 +0000214 }
215#endif
216
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000217};
218
Eric Fiselier43b121d2016-02-20 07:59:16 +0000219template <class _Tp, class _AllocPtr, class _KVTypes = __hash_key_value_types<_Tp>,
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000220 bool = _KVTypes::__is_map>
Eric Fiselier43b121d2016-02-20 07:59:16 +0000221struct __hash_map_pointer_types {};
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000222
223template <class _Tp, class _AllocPtr, class _KVTypes>
Eric Fiselier43b121d2016-02-20 07:59:16 +0000224struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> {
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000225 typedef typename _KVTypes::__map_value_type _Mv;
226 typedef typename __rebind_pointer<_AllocPtr, _Mv>::type
227 __map_value_type_pointer;
228 typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type
229 __const_map_value_type_pointer;
230};
231
232template <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type>
233struct __hash_node_types;
234
235template <class _NodePtr, class _Tp, class _VoidPtr>
236struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> >
Eric Fiselier43b121d2016-02-20 07:59:16 +0000237 : public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr>
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000238
239{
Eric Fiselier43b121d2016-02-20 07:59:16 +0000240 typedef __hash_key_value_types<_Tp> __base;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000241
242public:
243 typedef ptrdiff_t difference_type;
244 typedef size_t size_type;
245
246 typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer;
247
248 typedef typename pointer_traits<_NodePtr>::element_type __node_type;
249 typedef _NodePtr __node_pointer;
250
251 typedef __hash_node_base<__node_pointer> __node_base_type;
252 typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type
253 __node_base_pointer;
254
Eric Fiselier40492ba2016-07-23 20:36:55 +0000255 typedef typename __node_base_type::__next_pointer __next_pointer;
256
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000257 typedef _Tp __node_value_type;
258 typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type
259 __node_value_type_pointer;
260 typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type
261 __const_node_value_type_pointer;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000262
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000263private:
264 static_assert(!is_const<__node_type>::value,
265 "_NodePtr should never be a pointer to const");
266 static_assert((is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value),
267 "_VoidPtr does not point to unqualified void type");
268 static_assert((is_same<typename __rebind_pointer<_VoidPtr, __node_type>::type,
269 _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr.");
270};
271
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000272template <class _HashIterator>
273struct __hash_node_types_from_iterator;
274template <class _NodePtr>
275struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
276template <class _NodePtr>
277struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
278template <class _NodePtr>
279struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
280template <class _NodePtr>
281struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
282
283
284template <class _NodeValueTp, class _VoidPtr>
285struct __make_hash_node_types {
286 typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp;
287 typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr;
288 typedef __hash_node_types<_NodePtr> type;
289};
290
Howard Hinnant3e519522010-05-11 19:42:16 +0000291template <class _NodePtr>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000292class _LIBCPP_TEMPLATE_VIS __hash_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000293{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000294 typedef __hash_node_types<_NodePtr> _NodeTypes;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000295 typedef _NodePtr __node_pointer;
296 typedef typename _NodeTypes::__next_pointer __next_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000297
Eric Fiselier40492ba2016-07-23 20:36:55 +0000298 __next_pointer __node_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000299
300public:
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000301 typedef forward_iterator_tag iterator_category;
302 typedef typename _NodeTypes::__node_value_type value_type;
303 typedef typename _NodeTypes::difference_type difference_type;
304 typedef value_type& reference;
305 typedef typename _NodeTypes::__node_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000306
Eric Fiselier40492ba2016-07-23 20:36:55 +0000307 _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT : __node_(nullptr) {
308 _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000309 }
310
311#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant43d99232010-09-21 17:32:39 +0000312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000313 __hash_iterator(const __hash_iterator& __i)
314 : __node_(__i.__node_)
315 {
316 __get_db()->__iterator_copy(this, &__i);
317 }
318
Howard Hinnant43d99232010-09-21 17:32:39 +0000319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000320 ~__hash_iterator()
321 {
322 __get_db()->__erase_i(this);
323 }
324
325 _LIBCPP_INLINE_VISIBILITY
326 __hash_iterator& operator=(const __hash_iterator& __i)
327 {
328 if (this != &__i)
329 {
330 __get_db()->__iterator_copy(this, &__i);
331 __node_ = __i.__node_;
332 }
333 return *this;
334 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000335#endif // _LIBCPP_DEBUG_LEVEL >= 2
336
337 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000338 reference operator*() const {
339 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
340 "Attempted to dereference a non-dereferenceable unordered container iterator");
341 return __node_->__upcast()->__value_;
342 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000343
Howard Hinnant43d99232010-09-21 17:32:39 +0000344 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000345 pointer operator->() const {
346 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
347 "Attempted to dereference a non-dereferenceable unordered container iterator");
348 return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
349 }
350
351 _LIBCPP_INLINE_VISIBILITY
352 __hash_iterator& operator++() {
353 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000354 "Attempted to increment non-incrementable unordered container iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +0000355 __node_ = __node_->__next_;
356 return *this;
357 }
358
Howard Hinnant43d99232010-09-21 17:32:39 +0000359 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000360 __hash_iterator operator++(int)
361 {
362 __hash_iterator __t(*this);
363 ++(*this);
364 return __t;
365 }
366
Howard Hinnant43d99232010-09-21 17:32:39 +0000367 friend _LIBCPP_INLINE_VISIBILITY
368 bool operator==(const __hash_iterator& __x, const __hash_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000369 {
Howard Hinnantb24c8022013-07-23 22:01:58 +0000370 return __x.__node_ == __y.__node_;
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 {return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000375
376private:
Howard Hinnantb24c8022013-07-23 22:01:58 +0000377#if _LIBCPP_DEBUG_LEVEL >= 2
378 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000379 __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
Howard Hinnantb24c8022013-07-23 22:01:58 +0000380 : __node_(__node)
381 {
382 __get_db()->__insert_ic(this, __c);
383 }
384#else
Howard Hinnant43d99232010-09-21 17:32:39 +0000385 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000386 __hash_iterator(__next_pointer __node) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000387 : __node_(__node)
388 {}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000389#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000390 template <class, class, class, class> friend class __hash_table;
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000391 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
392 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
393 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
394 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000395};
396
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000397template <class _NodePtr>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000398class _LIBCPP_TEMPLATE_VIS __hash_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000399{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000400 static_assert(!is_const<typename pointer_traits<_NodePtr>::element_type>::value, "");
401 typedef __hash_node_types<_NodePtr> _NodeTypes;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000402 typedef _NodePtr __node_pointer;
403 typedef typename _NodeTypes::__next_pointer __next_pointer;
Eric Fiselier757373e2016-02-18 00:20:34 +0000404
Eric Fiselier40492ba2016-07-23 20:36:55 +0000405 __next_pointer __node_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000406
407public:
Eric Fiselier757373e2016-02-18 00:20:34 +0000408 typedef __hash_iterator<_NodePtr> __non_const_iterator;
409
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000410 typedef forward_iterator_tag iterator_category;
411 typedef typename _NodeTypes::__node_value_type value_type;
412 typedef typename _NodeTypes::difference_type difference_type;
413 typedef const value_type& reference;
414 typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
415
Howard Hinnant3e519522010-05-11 19:42:16 +0000416
Eric Fiselier40492ba2016-07-23 20:36:55 +0000417 _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT : __node_(nullptr) {
418 _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000419 }
Eric Fiselier40492ba2016-07-23 20:36:55 +0000420
Howard Hinnant43d99232010-09-21 17:32:39 +0000421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000422 __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000423 : __node_(__x.__node_)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000424 {
Eric Fiselier40492ba2016-07-23 20:36:55 +0000425 _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000426 }
427
428#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant43d99232010-09-21 17:32:39 +0000429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000430 __hash_const_iterator(const __hash_const_iterator& __i)
431 : __node_(__i.__node_)
432 {
433 __get_db()->__iterator_copy(this, &__i);
434 }
435
Howard Hinnant43d99232010-09-21 17:32:39 +0000436 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000437 ~__hash_const_iterator()
438 {
439 __get_db()->__erase_i(this);
440 }
441
442 _LIBCPP_INLINE_VISIBILITY
443 __hash_const_iterator& operator=(const __hash_const_iterator& __i)
444 {
445 if (this != &__i)
446 {
447 __get_db()->__iterator_copy(this, &__i);
448 __node_ = __i.__node_;
449 }
450 return *this;
451 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000452#endif // _LIBCPP_DEBUG_LEVEL >= 2
453
454 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000455 reference operator*() const {
456 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000457 "Attempted to dereference a non-dereferenceable unordered container const_iterator");
Eric Fiselier40492ba2016-07-23 20:36:55 +0000458 return __node_->__upcast()->__value_;
459 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000460 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000461 pointer operator->() const {
462 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000463 "Attempted to dereference a non-dereferenceable unordered container const_iterator");
Eric Fiselier40492ba2016-07-23 20:36:55 +0000464 return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
465 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000466
Howard Hinnant43d99232010-09-21 17:32:39 +0000467 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000468 __hash_const_iterator& operator++() {
469 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
470 "Attempted to increment non-incrementable unordered container const_iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +0000471 __node_ = __node_->__next_;
472 return *this;
473 }
474
Howard Hinnant43d99232010-09-21 17:32:39 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000476 __hash_const_iterator operator++(int)
477 {
478 __hash_const_iterator __t(*this);
479 ++(*this);
480 return __t;
481 }
482
Howard Hinnant43d99232010-09-21 17:32:39 +0000483 friend _LIBCPP_INLINE_VISIBILITY
484 bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000485 {
Howard Hinnantb24c8022013-07-23 22:01:58 +0000486 return __x.__node_ == __y.__node_;
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 {return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000491
492private:
Howard Hinnantb24c8022013-07-23 22:01:58 +0000493#if _LIBCPP_DEBUG_LEVEL >= 2
494 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000495 __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
Howard Hinnantb24c8022013-07-23 22:01:58 +0000496 : __node_(__node)
497 {
498 __get_db()->__insert_ic(this, __c);
499 }
500#else
Howard Hinnant43d99232010-09-21 17:32:39 +0000501 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000502 __hash_const_iterator(__next_pointer __node) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000503 : __node_(__node)
504 {}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000505#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000506 template <class, class, class, class> friend class __hash_table;
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000507 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
508 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
509 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000510};
511
Howard Hinnant3e519522010-05-11 19:42:16 +0000512template <class _NodePtr>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000513class _LIBCPP_TEMPLATE_VIS __hash_local_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000514{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000515 typedef __hash_node_types<_NodePtr> _NodeTypes;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000516 typedef _NodePtr __node_pointer;
517 typedef typename _NodeTypes::__next_pointer __next_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000518
Eric Fiselier40492ba2016-07-23 20:36:55 +0000519 __next_pointer __node_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000520 size_t __bucket_;
521 size_t __bucket_count_;
522
Howard Hinnant3e519522010-05-11 19:42:16 +0000523public:
524 typedef forward_iterator_tag iterator_category;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000525 typedef typename _NodeTypes::__node_value_type value_type;
526 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000527 typedef value_type& reference;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000528 typedef typename _NodeTypes::__node_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000529
Eric Fiselier40492ba2016-07-23 20:36:55 +0000530 _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT : __node_(nullptr) {
531 _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000532 }
533
534#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant43d99232010-09-21 17:32:39 +0000535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000536 __hash_local_iterator(const __hash_local_iterator& __i)
537 : __node_(__i.__node_),
538 __bucket_(__i.__bucket_),
539 __bucket_count_(__i.__bucket_count_)
540 {
541 __get_db()->__iterator_copy(this, &__i);
542 }
543
Howard Hinnant43d99232010-09-21 17:32:39 +0000544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000545 ~__hash_local_iterator()
546 {
547 __get_db()->__erase_i(this);
548 }
549
550 _LIBCPP_INLINE_VISIBILITY
551 __hash_local_iterator& operator=(const __hash_local_iterator& __i)
552 {
553 if (this != &__i)
554 {
555 __get_db()->__iterator_copy(this, &__i);
556 __node_ = __i.__node_;
557 __bucket_ = __i.__bucket_;
558 __bucket_count_ = __i.__bucket_count_;
559 }
560 return *this;
561 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000562#endif // _LIBCPP_DEBUG_LEVEL >= 2
563
564 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000565 reference operator*() const {
566 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000567 "Attempted to dereference a non-dereferenceable unordered container local_iterator");
Eric Fiselier40492ba2016-07-23 20:36:55 +0000568 return __node_->__upcast()->__value_;
569 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000570
Howard Hinnant43d99232010-09-21 17:32:39 +0000571 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000572 pointer operator->() const {
573 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
574 "Attempted to dereference a non-dereferenceable unordered container local_iterator");
575 return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
576 }
577
578 _LIBCPP_INLINE_VISIBILITY
579 __hash_local_iterator& operator++() {
580 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000581 "Attempted to increment non-incrementable unordered container local_iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +0000582 __node_ = __node_->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000583 if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_)
Howard Hinnant3e519522010-05-11 19:42:16 +0000584 __node_ = nullptr;
585 return *this;
586 }
587
Howard Hinnant43d99232010-09-21 17:32:39 +0000588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000589 __hash_local_iterator operator++(int)
590 {
591 __hash_local_iterator __t(*this);
592 ++(*this);
593 return __t;
594 }
595
Howard Hinnant43d99232010-09-21 17:32:39 +0000596 friend _LIBCPP_INLINE_VISIBILITY
597 bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000598 {
Howard Hinnantb24c8022013-07-23 22:01:58 +0000599 return __x.__node_ == __y.__node_;
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 {return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000604
605private:
Howard Hinnantb24c8022013-07-23 22:01:58 +0000606#if _LIBCPP_DEBUG_LEVEL >= 2
607 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000608 __hash_local_iterator(__next_pointer __node, size_t __bucket,
Howard Hinnantb24c8022013-07-23 22:01:58 +0000609 size_t __bucket_count, const void* __c) _NOEXCEPT
610 : __node_(__node),
611 __bucket_(__bucket),
612 __bucket_count_(__bucket_count)
613 {
614 __get_db()->__insert_ic(this, __c);
615 if (__node_ != nullptr)
616 __node_ = __node_->__next_;
617 }
618#else
Howard Hinnant43d99232010-09-21 17:32:39 +0000619 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000620 __hash_local_iterator(__next_pointer __node, size_t __bucket,
Howard Hinnant37141072011-06-04 18:54:24 +0000621 size_t __bucket_count) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000622 : __node_(__node),
623 __bucket_(__bucket),
624 __bucket_count_(__bucket_count)
625 {
626 if (__node_ != nullptr)
627 __node_ = __node_->__next_;
628 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000629#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000630 template <class, class, class, class> friend class __hash_table;
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000631 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
632 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000633};
634
635template <class _ConstNodePtr>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000636class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000637{
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000638 typedef __hash_node_types<_ConstNodePtr> _NodeTypes;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000639 typedef _ConstNodePtr __node_pointer;
640 typedef typename _NodeTypes::__next_pointer __next_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000641
Eric Fiselier40492ba2016-07-23 20:36:55 +0000642 __next_pointer __node_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000643 size_t __bucket_;
644 size_t __bucket_count_;
645
646 typedef pointer_traits<__node_pointer> __pointer_traits;
647 typedef typename __pointer_traits::element_type __node;
648 typedef typename remove_const<__node>::type __non_const_node;
Eric Fiselier934b0922015-12-30 21:52:00 +0000649 typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type
650 __non_const_node_pointer;
Eric Fiselier757373e2016-02-18 00:20:34 +0000651public:
Howard Hinnant3e519522010-05-11 19:42:16 +0000652 typedef __hash_local_iterator<__non_const_node_pointer>
653 __non_const_iterator;
Eric Fiselier757373e2016-02-18 00:20:34 +0000654
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000655 typedef forward_iterator_tag iterator_category;
656 typedef typename _NodeTypes::__node_value_type value_type;
657 typedef typename _NodeTypes::difference_type difference_type;
658 typedef const value_type& reference;
659 typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
Eric Fiselier934b0922015-12-30 21:52:00 +0000660
Howard Hinnant3e519522010-05-11 19:42:16 +0000661
Eric Fiselier40492ba2016-07-23 20:36:55 +0000662 _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) {
663 _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000664 }
665
Howard Hinnant43d99232010-09-21 17:32:39 +0000666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000667 __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000668 : __node_(__x.__node_),
669 __bucket_(__x.__bucket_),
670 __bucket_count_(__x.__bucket_count_)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000671 {
Eric Fiselier40492ba2016-07-23 20:36:55 +0000672 _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x));
Howard Hinnantb24c8022013-07-23 22:01:58 +0000673 }
674
675#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant43d99232010-09-21 17:32:39 +0000676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000677 __hash_const_local_iterator(const __hash_const_local_iterator& __i)
678 : __node_(__i.__node_),
679 __bucket_(__i.__bucket_),
680 __bucket_count_(__i.__bucket_count_)
681 {
682 __get_db()->__iterator_copy(this, &__i);
683 }
684
Howard Hinnant43d99232010-09-21 17:32:39 +0000685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000686 ~__hash_const_local_iterator()
687 {
688 __get_db()->__erase_i(this);
689 }
690
691 _LIBCPP_INLINE_VISIBILITY
692 __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i)
693 {
694 if (this != &__i)
695 {
696 __get_db()->__iterator_copy(this, &__i);
697 __node_ = __i.__node_;
698 __bucket_ = __i.__bucket_;
699 __bucket_count_ = __i.__bucket_count_;
700 }
701 return *this;
702 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000703#endif // _LIBCPP_DEBUG_LEVEL >= 2
704
705 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000706 reference operator*() const {
707 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000708 "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
Eric Fiselier40492ba2016-07-23 20:36:55 +0000709 return __node_->__upcast()->__value_;
710 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000711
Howard Hinnant43d99232010-09-21 17:32:39 +0000712 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000713 pointer operator->() const {
714 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
715 "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
716 return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
717 }
718
719 _LIBCPP_INLINE_VISIBILITY
720 __hash_const_local_iterator& operator++() {
721 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
Howard Hinnantb24c8022013-07-23 22:01:58 +0000722 "Attempted to increment non-incrementable unordered container const_local_iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +0000723 __node_ = __node_->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000724 if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_)
Howard Hinnant3e519522010-05-11 19:42:16 +0000725 __node_ = nullptr;
726 return *this;
727 }
728
Howard Hinnant43d99232010-09-21 17:32:39 +0000729 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000730 __hash_const_local_iterator operator++(int)
731 {
732 __hash_const_local_iterator __t(*this);
733 ++(*this);
734 return __t;
735 }
736
Howard Hinnant43d99232010-09-21 17:32:39 +0000737 friend _LIBCPP_INLINE_VISIBILITY
738 bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000739 {
Howard Hinnantb24c8022013-07-23 22:01:58 +0000740 return __x.__node_ == __y.__node_;
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 {return !(__x == __y);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000745
746private:
Howard Hinnantb24c8022013-07-23 22:01:58 +0000747#if _LIBCPP_DEBUG_LEVEL >= 2
748 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000749 __hash_const_local_iterator(__next_pointer __node, size_t __bucket,
Howard Hinnantb24c8022013-07-23 22:01:58 +0000750 size_t __bucket_count, const void* __c) _NOEXCEPT
751 : __node_(__node),
752 __bucket_(__bucket),
753 __bucket_count_(__bucket_count)
754 {
755 __get_db()->__insert_ic(this, __c);
756 if (__node_ != nullptr)
757 __node_ = __node_->__next_;
758 }
759#else
Howard Hinnant43d99232010-09-21 17:32:39 +0000760 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier40492ba2016-07-23 20:36:55 +0000761 __hash_const_local_iterator(__next_pointer __node, size_t __bucket,
Howard Hinnant37141072011-06-04 18:54:24 +0000762 size_t __bucket_count) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000763 : __node_(__node),
764 __bucket_(__bucket),
765 __bucket_count_(__bucket_count)
766 {
767 if (__node_ != nullptr)
768 __node_ = __node_->__next_;
769 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000770#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000771 template <class, class, class, class> friend class __hash_table;
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000772 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000773};
774
775template <class _Alloc>
776class __bucket_list_deallocator
777{
778 typedef _Alloc allocator_type;
779 typedef allocator_traits<allocator_type> __alloc_traits;
780 typedef typename __alloc_traits::size_type size_type;
781
782 __compressed_pair<size_type, allocator_type> __data_;
783public:
784 typedef typename __alloc_traits::pointer pointer;
785
Howard Hinnant43d99232010-09-21 17:32:39 +0000786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000787 __bucket_list_deallocator()
Howard Hinnant37141072011-06-04 18:54:24 +0000788 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000789 : __data_(0) {}
Howard Hinnant43d99232010-09-21 17:32:39 +0000790
791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000792 __bucket_list_deallocator(const allocator_type& __a, size_type __size)
Howard Hinnant37141072011-06-04 18:54:24 +0000793 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000794 : __data_(__size, __a) {}
795
Eric Fiselierafa7a952017-04-19 01:23:04 +0000796#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant43d99232010-09-21 17:32:39 +0000797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000798 __bucket_list_deallocator(__bucket_list_deallocator&& __x)
Howard Hinnant37141072011-06-04 18:54:24 +0000799 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000800 : __data_(_VSTD::move(__x.__data_))
Howard Hinnant3e519522010-05-11 19:42:16 +0000801 {
802 __x.size() = 0;
803 }
Eric Fiselierafa7a952017-04-19 01:23:04 +0000804#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000805
Howard Hinnant37141072011-06-04 18:54:24 +0000806 _LIBCPP_INLINE_VISIBILITY
807 size_type& size() _NOEXCEPT {return __data_.first();}
808 _LIBCPP_INLINE_VISIBILITY
809 size_type size() const _NOEXCEPT {return __data_.first();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000810
Howard Hinnant43d99232010-09-21 17:32:39 +0000811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000812 allocator_type& __alloc() _NOEXCEPT {return __data_.second();}
813 _LIBCPP_INLINE_VISIBILITY
814 const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();}
815
816 _LIBCPP_INLINE_VISIBILITY
817 void operator()(pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000818 {
819 __alloc_traits::deallocate(__alloc(), __p, size());
820 }
821};
822
Howard Hinnantce534202011-06-14 19:58:17 +0000823template <class _Alloc> class __hash_map_node_destructor;
Howard Hinnant3e519522010-05-11 19:42:16 +0000824
825template <class _Alloc>
826class __hash_node_destructor
827{
828 typedef _Alloc allocator_type;
829 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000830
Howard Hinnant3e519522010-05-11 19:42:16 +0000831public:
832 typedef typename __alloc_traits::pointer pointer;
833private:
Eric Fiselierfcd02212016-02-11 11:59:44 +0000834 typedef __hash_node_types<pointer> _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +0000835
836 allocator_type& __na_;
837
838 __hash_node_destructor& operator=(const __hash_node_destructor&);
839
840public:
841 bool __value_constructed;
842
Howard Hinnant43d99232010-09-21 17:32:39 +0000843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf622b582011-07-31 17:04:30 +0000844 explicit __hash_node_destructor(allocator_type& __na,
845 bool __constructed = false) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000846 : __na_(__na),
Howard Hinnantf622b582011-07-31 17:04:30 +0000847 __value_constructed(__constructed)
Howard Hinnant3e519522010-05-11 19:42:16 +0000848 {}
849
Howard Hinnant43d99232010-09-21 17:32:39 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000851 void operator()(pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000852 {
853 if (__value_constructed)
Eric Fiselierfcd02212016-02-11 11:59:44 +0000854 __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000855 if (__p)
856 __alloc_traits::deallocate(__na_, __p, 1);
857 }
858
859 template <class> friend class __hash_map_node_destructor;
860};
861
Eric Fiselier04333f92017-01-13 22:42:53 +0000862
863#ifndef _LIBCPP_CXX03_LANG
864template <class _Key, class _Hash, class _Equal, class _Alloc>
865struct __diagnose_hash_table_helper {
866 static constexpr bool __trigger_diagnostics()
Eric Fiselierbd6a2d82017-03-03 22:35:58 +0000867 _LIBCPP_DIAGNOSE_WARNING(__check_hash_requirements<_Key, _Hash>::value
Eric Fiselieracb21582017-03-01 02:02:28 +0000868 && !__invokable<_Hash const&, _Key const&>::value,
869 "the specified hash functor does not provide a const call operator")
870 _LIBCPP_DIAGNOSE_WARNING(is_copy_constructible<_Equal>::value
871 && !__invokable<_Equal const&, _Key const&, _Key const&>::value,
872 "the specified comparator type does not provide a const call operator")
873 {
Eric Fiselierbd6a2d82017-03-03 22:35:58 +0000874 static_assert(__check_hash_requirements<_Key, _Hash>::value,
875 "the specified hash does not meet the Hash requirements");
Eric Fiselieracb21582017-03-01 02:02:28 +0000876 static_assert(is_copy_constructible<_Equal>::value,
877 "the specified comparator is required to be copy constructible");
878 return true;
879 }
Eric Fiselier04333f92017-01-13 22:42:53 +0000880};
881
882template <class _Key, class _Value, class _Hash, class _Equal, class _Alloc>
883struct __diagnose_hash_table_helper<
884 __hash_value_type<_Key, _Value>,
885 __unordered_map_hasher<_Key, __hash_value_type<_Key, _Value>, _Hash>,
886 __unordered_map_equal<_Key, __hash_value_type<_Key, _Value>, _Equal>,
887 _Alloc>
888: __diagnose_hash_table_helper<_Key, _Hash, _Equal, _Alloc>
889{
890};
891#endif // _LIBCPP_CXX03_LANG
892
Howard Hinnant3e519522010-05-11 19:42:16 +0000893template <class _Tp, class _Hash, class _Equal, class _Alloc>
894class __hash_table
895{
896public:
897 typedef _Tp value_type;
898 typedef _Hash hasher;
899 typedef _Equal key_equal;
900 typedef _Alloc allocator_type;
901
902private:
903 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000904 typedef typename
905 __make_hash_node_types<value_type, typename __alloc_traits::void_pointer>::type
906 _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +0000907public:
Eric Fiselierfcd02212016-02-11 11:59:44 +0000908
909 typedef typename _NodeTypes::__node_value_type __node_value_type;
910 typedef typename _NodeTypes::__container_value_type __container_value_type;
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +0000911 typedef typename _NodeTypes::key_type key_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000912 typedef value_type& reference;
913 typedef const value_type& const_reference;
914 typedef typename __alloc_traits::pointer pointer;
915 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000916#ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
Howard Hinnant3e519522010-05-11 19:42:16 +0000917 typedef typename __alloc_traits::size_type size_type;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000918#else
919 typedef typename _NodeTypes::size_type size_type;
920#endif
921 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000922public:
923 // Create __node
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000924
925 typedef typename _NodeTypes::__node_type __node;
Marshall Clow1f508012015-04-07 05:21:38 +0000926 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000927 typedef allocator_traits<__node_allocator> __node_traits;
Eric Fiselier8e397682016-02-11 15:22:37 +0000928 typedef typename _NodeTypes::__void_pointer __void_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000929 typedef typename _NodeTypes::__node_pointer __node_pointer;
930 typedef typename _NodeTypes::__node_pointer __node_const_pointer;
931 typedef typename _NodeTypes::__node_base_type __first_node;
932 typedef typename _NodeTypes::__node_base_pointer __node_base_pointer;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000933 typedef typename _NodeTypes::__next_pointer __next_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000934
935private:
936 // check for sane allocator pointer rebinding semantics. Rebinding the
937 // allocator for a new pointer type should be exactly the same as rebinding
938 // the pointer using 'pointer_traits'.
939 static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value),
940 "Allocator does not rebind pointers in a sane manner.");
941 typedef typename __rebind_alloc_helper<__node_traits, __first_node>::type
942 __node_base_allocator;
943 typedef allocator_traits<__node_base_allocator> __node_base_traits;
944 static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value),
945 "Allocator does not rebind pointers in a sane manner.");
Howard Hinnant3e519522010-05-11 19:42:16 +0000946
947private:
948
Eric Fiselier40492ba2016-07-23 20:36:55 +0000949 typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000950 typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000951 typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list;
Howard Hinnant3e519522010-05-11 19:42:16 +0000952 typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits;
Eric Fiselier40492ba2016-07-23 20:36:55 +0000953 typedef typename __bucket_list_deleter::pointer __node_pointer_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000954
Eric Fiselieracb21582017-03-01 02:02:28 +0000955#ifndef _LIBCPP_CXX03_LANG
956 static_assert(__diagnose_hash_table_helper<_Tp, _Hash, _Equal, _Alloc>::__trigger_diagnostics(), "");
957#endif
958
Howard Hinnant3e519522010-05-11 19:42:16 +0000959 // --- Member data begin ---
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000960 __bucket_list __bucket_list_;
961 __compressed_pair<__first_node, __node_allocator> __p1_;
962 __compressed_pair<size_type, hasher> __p2_;
963 __compressed_pair<float, key_equal> __p3_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000964 // --- Member data end ---
965
Howard Hinnant37141072011-06-04 18:54:24 +0000966 _LIBCPP_INLINE_VISIBILITY
967 size_type& size() _NOEXCEPT {return __p2_.first();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000968public:
Howard Hinnant37141072011-06-04 18:54:24 +0000969 _LIBCPP_INLINE_VISIBILITY
970 size_type size() const _NOEXCEPT {return __p2_.first();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000971
Howard Hinnant37141072011-06-04 18:54:24 +0000972 _LIBCPP_INLINE_VISIBILITY
973 hasher& hash_function() _NOEXCEPT {return __p2_.second();}
974 _LIBCPP_INLINE_VISIBILITY
975 const hasher& hash_function() const _NOEXCEPT {return __p2_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000976
Howard Hinnant37141072011-06-04 18:54:24 +0000977 _LIBCPP_INLINE_VISIBILITY
978 float& max_load_factor() _NOEXCEPT {return __p3_.first();}
979 _LIBCPP_INLINE_VISIBILITY
980 float max_load_factor() const _NOEXCEPT {return __p3_.first();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000981
Howard Hinnant37141072011-06-04 18:54:24 +0000982 _LIBCPP_INLINE_VISIBILITY
983 key_equal& key_eq() _NOEXCEPT {return __p3_.second();}
984 _LIBCPP_INLINE_VISIBILITY
985 const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000986
Howard Hinnant37141072011-06-04 18:54:24 +0000987 _LIBCPP_INLINE_VISIBILITY
988 __node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();}
989 _LIBCPP_INLINE_VISIBILITY
990 const __node_allocator& __node_alloc() const _NOEXCEPT
991 {return __p1_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000992
993public:
994 typedef __hash_iterator<__node_pointer> iterator;
Howard Hinnant307f8142013-06-22 15:21:29 +0000995 typedef __hash_const_iterator<__node_pointer> const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000996 typedef __hash_local_iterator<__node_pointer> local_iterator;
Howard Hinnant307f8142013-06-22 15:21:29 +0000997 typedef __hash_const_local_iterator<__node_pointer> const_local_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000998
Evgeniy Stepanov906c8722015-11-07 01:22:13 +0000999 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001000 __hash_table()
1001 _NOEXCEPT_(
1002 is_nothrow_default_constructible<__bucket_list>::value &&
1003 is_nothrow_default_constructible<__first_node>::value &&
1004 is_nothrow_default_constructible<__node_allocator>::value &&
1005 is_nothrow_default_constructible<hasher>::value &&
1006 is_nothrow_default_constructible<key_equal>::value);
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001008 __hash_table(const hasher& __hf, const key_equal& __eql);
1009 __hash_table(const hasher& __hf, const key_equal& __eql,
1010 const allocator_type& __a);
1011 explicit __hash_table(const allocator_type& __a);
1012 __hash_table(const __hash_table& __u);
1013 __hash_table(const __hash_table& __u, const allocator_type& __a);
Eric Fiselierfcd02212016-02-11 11:59:44 +00001014#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant37141072011-06-04 18:54:24 +00001015 __hash_table(__hash_table&& __u)
1016 _NOEXCEPT_(
1017 is_nothrow_move_constructible<__bucket_list>::value &&
1018 is_nothrow_move_constructible<__first_node>::value &&
1019 is_nothrow_move_constructible<__node_allocator>::value &&
1020 is_nothrow_move_constructible<hasher>::value &&
1021 is_nothrow_move_constructible<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001022 __hash_table(__hash_table&& __u, const allocator_type& __a);
Eric Fiselierfcd02212016-02-11 11:59:44 +00001023#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001024 ~__hash_table();
1025
1026 __hash_table& operator=(const __hash_table& __u);
Eric Fiselierfcd02212016-02-11 11:59:44 +00001027#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001028 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001029 __hash_table& operator=(__hash_table&& __u)
1030 _NOEXCEPT_(
1031 __node_traits::propagate_on_container_move_assignment::value &&
1032 is_nothrow_move_assignable<__node_allocator>::value &&
1033 is_nothrow_move_assignable<hasher>::value &&
1034 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001035#endif
1036 template <class _InputIterator>
1037 void __assign_unique(_InputIterator __first, _InputIterator __last);
1038 template <class _InputIterator>
1039 void __assign_multi(_InputIterator __first, _InputIterator __last);
1040
Howard Hinnant43d99232010-09-21 17:32:39 +00001041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001042 size_type max_size() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001043 {
Eric Fiselier55b31b4e2016-11-23 01:18:56 +00001044 return std::min<size_type>(
Eric Fiselier341c9dd2016-11-23 09:16:12 +00001045 __node_traits::max_size(__node_alloc()),
Eric Fiselier55b31b4e2016-11-23 01:18:56 +00001046 numeric_limits<difference_type >::max()
1047 );
Howard Hinnant3e519522010-05-11 19:42:16 +00001048 }
1049
1050 pair<iterator, bool> __node_insert_unique(__node_pointer __nd);
1051 iterator __node_insert_multi(__node_pointer __nd);
1052 iterator __node_insert_multi(const_iterator __p,
1053 __node_pointer __nd);
1054
Eric Fiselierfcd02212016-02-11 11:59:44 +00001055#ifndef _LIBCPP_CXX03_LANG
1056 template <class _Key, class ..._Args>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00001057 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001058 pair<iterator, bool> __emplace_unique_key_args(_Key const& __k, _Args&&... __args);
Howard Hinnant3e519522010-05-11 19:42:16 +00001059
Eric Fiselierfcd02212016-02-11 11:59:44 +00001060 template <class... _Args>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00001061 _LIBCPP_INLINE_VISIBILITY
1062 pair<iterator, bool> __emplace_unique_impl(_Args&&... __args);
1063
1064 template <class _Pp>
1065 _LIBCPP_INLINE_VISIBILITY
1066 pair<iterator, bool> __emplace_unique(_Pp&& __x) {
1067 return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x),
1068 __can_extract_key<_Pp, key_type>());
1069 }
Eric Fiselier50088682016-04-16 00:23:12 +00001070
1071 template <class _First, class _Second>
1072 _LIBCPP_INLINE_VISIBILITY
1073 typename enable_if<
1074 __can_extract_map_key<_First, key_type, __container_value_type>::value,
1075 pair<iterator, bool>
1076 >::type __emplace_unique(_First&& __f, _Second&& __s) {
1077 return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f),
1078 _VSTD::forward<_Second>(__s));
1079 }
1080
Eric Fiselierfcd02212016-02-11 11:59:44 +00001081 template <class... _Args>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00001082 _LIBCPP_INLINE_VISIBILITY
1083 pair<iterator, bool> __emplace_unique(_Args&&... __args) {
1084 return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...);
1085 }
1086
1087 template <class _Pp>
1088 _LIBCPP_INLINE_VISIBILITY
1089 pair<iterator, bool>
1090 __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) {
1091 return __emplace_unique_impl(_VSTD::forward<_Pp>(__x));
1092 }
1093 template <class _Pp>
1094 _LIBCPP_INLINE_VISIBILITY
1095 pair<iterator, bool>
1096 __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) {
1097 return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x));
1098 }
1099 template <class _Pp>
1100 _LIBCPP_INLINE_VISIBILITY
1101 pair<iterator, bool>
1102 __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) {
1103 return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x));
1104 }
1105
1106 template <class... _Args>
1107 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001108 iterator __emplace_multi(_Args&&... __args);
1109 template <class... _Args>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00001110 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001111 iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
1112
1113
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001114 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001115 pair<iterator, bool>
1116 __insert_unique(__container_value_type&& __x) {
1117 return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _VSTD::move(__x));
1118 }
1119
1120 template <class _Pp, class = typename enable_if<
1121 !__is_same_uncvref<_Pp, __container_value_type>::value
1122 >::type>
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001123 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001124 pair<iterator, bool> __insert_unique(_Pp&& __x) {
1125 return __emplace_unique(_VSTD::forward<_Pp>(__x));
1126 }
1127
1128 template <class _Pp>
1129 _LIBCPP_INLINE_VISIBILITY
1130 iterator __insert_multi(_Pp&& __x) {
1131 return __emplace_multi(_VSTD::forward<_Pp>(__x));
1132 }
1133
1134 template <class _Pp>
1135 _LIBCPP_INLINE_VISIBILITY
1136 iterator __insert_multi(const_iterator __p, _Pp&& __x) {
1137 return __emplace_hint_multi(__p, _VSTD::forward<_Pp>(__x));
1138 }
1139
1140#else // !defined(_LIBCPP_CXX03_LANG)
1141 template <class _Key, class _Args>
Eric Fiselier4271d012016-09-25 04:05:46 +00001142 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +00001143 pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args);
1144
1145 iterator __insert_multi(const __container_value_type& __x);
1146 iterator __insert_multi(const_iterator __p, const __container_value_type& __x);
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001147#endif
1148
Eric Fiselierfcd02212016-02-11 11:59:44 +00001149 _LIBCPP_INLINE_VISIBILITY
1150 pair<iterator, bool> __insert_unique(const __container_value_type& __x) {
1151 return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x);
1152 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001153
Howard Hinnant37141072011-06-04 18:54:24 +00001154 void clear() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +00001155 void rehash(size_type __n);
Howard Hinnant43d99232010-09-21 17:32:39 +00001156 _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n)
Howard Hinnant3e519522010-05-11 19:42:16 +00001157 {rehash(static_cast<size_type>(ceil(__n / max_load_factor())));}
Howard Hinnant43d99232010-09-21 17:32:39 +00001158
1159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001160 size_type bucket_count() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001161 {
1162 return __bucket_list_.get_deleter().size();
1163 }
1164
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001166 iterator begin() _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001168 iterator end() _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001170 const_iterator begin() const _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001172 const_iterator end() const _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +00001173
1174 template <class _Key>
Howard Hinnant43d99232010-09-21 17:32:39 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001176 size_type bucket(const _Key& __k) const
Howard Hinnante5c13de2013-07-29 19:05:47 +00001177 {
1178 _LIBCPP_ASSERT(bucket_count() > 0,
1179 "unordered container::bucket(key) called when bucket_count() == 0");
1180 return __constrain_hash(hash_function()(__k), bucket_count());
1181 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001182
1183 template <class _Key>
1184 iterator find(const _Key& __x);
1185 template <class _Key>
1186 const_iterator find(const _Key& __x) const;
1187
Howard Hinnantc003db12011-11-29 18:15:50 +00001188 typedef __hash_node_destructor<__node_allocator> _Dp;
1189 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +00001190
1191 iterator erase(const_iterator __p);
1192 iterator erase(const_iterator __first, const_iterator __last);
1193 template <class _Key>
1194 size_type __erase_unique(const _Key& __k);
1195 template <class _Key>
1196 size_type __erase_multi(const _Key& __k);
Howard Hinnant37141072011-06-04 18:54:24 +00001197 __node_holder remove(const_iterator __p) _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +00001198
1199 template <class _Key>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001200 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001201 size_type __count_unique(const _Key& __k) const;
1202 template <class _Key>
1203 size_type __count_multi(const _Key& __k) const;
1204
1205 template <class _Key>
1206 pair<iterator, iterator>
1207 __equal_range_unique(const _Key& __k);
1208 template <class _Key>
1209 pair<const_iterator, const_iterator>
1210 __equal_range_unique(const _Key& __k) const;
1211
1212 template <class _Key>
1213 pair<iterator, iterator>
1214 __equal_range_multi(const _Key& __k);
1215 template <class _Key>
1216 pair<const_iterator, const_iterator>
1217 __equal_range_multi(const _Key& __k) const;
1218
Howard Hinnant37141072011-06-04 18:54:24 +00001219 void swap(__hash_table& __u)
Eric Fiselier87a82492015-07-18 20:40:46 +00001220#if _LIBCPP_STD_VER <= 11
Eric Fiselier780b51d2016-12-28 05:53:01 +00001221 _NOEXCEPT_DEBUG_(
Marshall Clowe3fbe142015-07-13 20:04:56 +00001222 __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
Marshall Clowe3fbe142015-07-13 20:04:56 +00001223 && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
1224 || __is_nothrow_swappable<__pointer_allocator>::value)
1225 && (!__node_traits::propagate_on_container_swap::value
1226 || __is_nothrow_swappable<__node_allocator>::value)
Marshall Clowe3fbe142015-07-13 20:04:56 +00001227 );
Eric Fiselier87a82492015-07-18 20:40:46 +00001228#else
Eric Fiselier780b51d2016-12-28 05:53:01 +00001229 _NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value);
Eric Fiselier87a82492015-07-18 20:40:46 +00001230#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001231
Howard Hinnant43d99232010-09-21 17:32:39 +00001232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001233 size_type max_bucket_count() const _NOEXCEPT
Eric Fiselier55b31b4e2016-11-23 01:18:56 +00001234 {return max_size(); }
Howard Hinnant3e519522010-05-11 19:42:16 +00001235 size_type bucket_size(size_type __n) const;
Howard Hinnant37141072011-06-04 18:54:24 +00001236 _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001237 {
1238 size_type __bc = bucket_count();
1239 return __bc != 0 ? (float)size() / __bc : 0.f;
1240 }
Howard Hinnant37141072011-06-04 18:54:24 +00001241 _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT
Howard Hinnante5c13de2013-07-29 19:05:47 +00001242 {
1243 _LIBCPP_ASSERT(__mlf > 0,
1244 "unordered container::max_load_factor(lf) called with lf <= 0");
1245 max_load_factor() = _VSTD::max(__mlf, load_factor());
1246 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001247
Howard Hinnantb24c8022013-07-23 22:01:58 +00001248 _LIBCPP_INLINE_VISIBILITY
1249 local_iterator
1250 begin(size_type __n)
1251 {
Howard Hinnante5c13de2013-07-29 19:05:47 +00001252 _LIBCPP_ASSERT(__n < bucket_count(),
1253 "unordered container::begin(n) called with n >= bucket_count()");
Howard Hinnantb24c8022013-07-23 22:01:58 +00001254#if _LIBCPP_DEBUG_LEVEL >= 2
1255 return local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
1256#else
1257 return local_iterator(__bucket_list_[__n], __n, bucket_count());
1258#endif
1259 }
1260
1261 _LIBCPP_INLINE_VISIBILITY
1262 local_iterator
1263 end(size_type __n)
1264 {
Howard Hinnante5c13de2013-07-29 19:05:47 +00001265 _LIBCPP_ASSERT(__n < bucket_count(),
1266 "unordered container::end(n) called with n >= bucket_count()");
Howard Hinnantb24c8022013-07-23 22:01:58 +00001267#if _LIBCPP_DEBUG_LEVEL >= 2
1268 return local_iterator(nullptr, __n, bucket_count(), this);
1269#else
1270 return local_iterator(nullptr, __n, bucket_count());
1271#endif
1272 }
1273
1274 _LIBCPP_INLINE_VISIBILITY
1275 const_local_iterator
1276 cbegin(size_type __n) const
1277 {
Howard Hinnante5c13de2013-07-29 19:05:47 +00001278 _LIBCPP_ASSERT(__n < bucket_count(),
1279 "unordered container::cbegin(n) called with n >= bucket_count()");
Howard Hinnantb24c8022013-07-23 22:01:58 +00001280#if _LIBCPP_DEBUG_LEVEL >= 2
1281 return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
1282#else
1283 return const_local_iterator(__bucket_list_[__n], __n, bucket_count());
1284#endif
1285 }
1286
1287 _LIBCPP_INLINE_VISIBILITY
1288 const_local_iterator
1289 cend(size_type __n) const
1290 {
Howard Hinnante5c13de2013-07-29 19:05:47 +00001291 _LIBCPP_ASSERT(__n < bucket_count(),
1292 "unordered container::cend(n) called with n >= bucket_count()");
Howard Hinnantb24c8022013-07-23 22:01:58 +00001293#if _LIBCPP_DEBUG_LEVEL >= 2
1294 return const_local_iterator(nullptr, __n, bucket_count(), this);
1295#else
1296 return const_local_iterator(nullptr, __n, bucket_count());
1297#endif
1298 }
1299
1300#if _LIBCPP_DEBUG_LEVEL >= 2
1301
1302 bool __dereferenceable(const const_iterator* __i) const;
1303 bool __decrementable(const const_iterator* __i) const;
1304 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1305 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1306
1307#endif // _LIBCPP_DEBUG_LEVEL >= 2
1308
Howard Hinnant3e519522010-05-11 19:42:16 +00001309private:
1310 void __rehash(size_type __n);
1311
Eric Fiselierfcd02212016-02-11 11:59:44 +00001312#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001313 template <class ..._Args>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001314 __node_holder __construct_node(_Args&& ...__args);
1315
1316 template <class _First, class ..._Rest>
1317 __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest);
1318#else // _LIBCPP_CXX03_LANG
1319 __node_holder __construct_node(const __container_value_type& __v);
1320 __node_holder __construct_node_hash(size_t __hash, const __container_value_type& __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001321#endif
Eric Fiselierfcd02212016-02-11 11:59:44 +00001322
Howard Hinnant3e519522010-05-11 19:42:16 +00001323
Howard Hinnant43d99232010-09-21 17:32:39 +00001324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001325 void __copy_assign_alloc(const __hash_table& __u)
1326 {__copy_assign_alloc(__u, integral_constant<bool,
1327 __node_traits::propagate_on_container_copy_assignment::value>());}
1328 void __copy_assign_alloc(const __hash_table& __u, true_type);
Howard Hinnant43d99232010-09-21 17:32:39 +00001329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc2063662011-12-01 20:21:04 +00001330 void __copy_assign_alloc(const __hash_table&, false_type) {}
Howard Hinnant3e519522010-05-11 19:42:16 +00001331
Eric Fiselierfcd02212016-02-11 11:59:44 +00001332#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001333 void __move_assign(__hash_table& __u, false_type);
Howard Hinnant37141072011-06-04 18:54:24 +00001334 void __move_assign(__hash_table& __u, true_type)
1335 _NOEXCEPT_(
1336 is_nothrow_move_assignable<__node_allocator>::value &&
1337 is_nothrow_move_assignable<hasher>::value &&
1338 is_nothrow_move_assignable<key_equal>::value);
1339 _LIBCPP_INLINE_VISIBILITY
1340 void __move_assign_alloc(__hash_table& __u)
1341 _NOEXCEPT_(
1342 !__node_traits::propagate_on_container_move_assignment::value ||
1343 (is_nothrow_move_assignable<__pointer_allocator>::value &&
1344 is_nothrow_move_assignable<__node_allocator>::value))
Howard Hinnant3e519522010-05-11 19:42:16 +00001345 {__move_assign_alloc(__u, integral_constant<bool,
1346 __node_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnant43d99232010-09-21 17:32:39 +00001347 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001348 void __move_assign_alloc(__hash_table& __u, true_type)
Howard Hinnant37141072011-06-04 18:54:24 +00001349 _NOEXCEPT_(
1350 is_nothrow_move_assignable<__pointer_allocator>::value &&
1351 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001352 {
1353 __bucket_list_.get_deleter().__alloc() =
Howard Hinnantce48a112011-06-30 21:18:19 +00001354 _VSTD::move(__u.__bucket_list_.get_deleter().__alloc());
1355 __node_alloc() = _VSTD::move(__u.__node_alloc());
Howard Hinnant3e519522010-05-11 19:42:16 +00001356 }
Howard Hinnant43d99232010-09-21 17:32:39 +00001357 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001358 void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {}
Eric Fiselierfcd02212016-02-11 11:59:44 +00001359#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001360
Eric Fiseliercd71f442017-01-07 03:01:24 +00001361 void __deallocate_node(__next_pointer __np) _NOEXCEPT;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001362 __next_pointer __detach() _NOEXCEPT;
Howard Hinnant307f8142013-06-22 15:21:29 +00001363
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +00001364 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
1365 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
Howard Hinnant3e519522010-05-11 19:42:16 +00001366};
1367
1368template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001369inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001370__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table()
Howard Hinnant37141072011-06-04 18:54:24 +00001371 _NOEXCEPT_(
1372 is_nothrow_default_constructible<__bucket_list>::value &&
1373 is_nothrow_default_constructible<__first_node>::value &&
Eric Fiseliere2e332a2015-12-16 00:53:04 +00001374 is_nothrow_default_constructible<__node_allocator>::value &&
Howard Hinnant37141072011-06-04 18:54:24 +00001375 is_nothrow_default_constructible<hasher>::value &&
1376 is_nothrow_default_constructible<key_equal>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001377 : __p2_(0),
1378 __p3_(1.0f)
1379{
1380}
1381
1382template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001383inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001384__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
1385 const key_equal& __eql)
1386 : __bucket_list_(nullptr, __bucket_list_deleter()),
1387 __p1_(),
1388 __p2_(0, __hf),
1389 __p3_(1.0f, __eql)
1390{
1391}
1392
1393template <class _Tp, class _Hash, class _Equal, class _Alloc>
1394__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
1395 const key_equal& __eql,
1396 const allocator_type& __a)
1397 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
Eric Fiselierc88580c2017-04-12 23:45:53 +00001398 __p1_(__second_tag(), __node_allocator(__a)),
Howard Hinnant3e519522010-05-11 19:42:16 +00001399 __p2_(0, __hf),
1400 __p3_(1.0f, __eql)
1401{
1402}
1403
1404template <class _Tp, class _Hash, class _Equal, class _Alloc>
1405__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a)
1406 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
Eric Fiselierc88580c2017-04-12 23:45:53 +00001407 __p1_(__second_tag(), __node_allocator(__a)),
Howard Hinnant3e519522010-05-11 19:42:16 +00001408 __p2_(0),
1409 __p3_(1.0f)
1410{
1411}
1412
1413template <class _Tp, class _Hash, class _Equal, class _Alloc>
1414__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u)
1415 : __bucket_list_(nullptr,
1416 __bucket_list_deleter(allocator_traits<__pointer_allocator>::
1417 select_on_container_copy_construction(
1418 __u.__bucket_list_.get_deleter().__alloc()), 0)),
Eric Fiselierc88580c2017-04-12 23:45:53 +00001419 __p1_(__second_tag(), allocator_traits<__node_allocator>::
Howard Hinnant3e519522010-05-11 19:42:16 +00001420 select_on_container_copy_construction(__u.__node_alloc())),
1421 __p2_(0, __u.hash_function()),
1422 __p3_(__u.__p3_)
1423{
1424}
1425
1426template <class _Tp, class _Hash, class _Equal, class _Alloc>
1427__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u,
1428 const allocator_type& __a)
1429 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
Eric Fiselierc88580c2017-04-12 23:45:53 +00001430 __p1_(__second_tag(), __node_allocator(__a)),
Howard Hinnant3e519522010-05-11 19:42:16 +00001431 __p2_(0, __u.hash_function()),
1432 __p3_(__u.__p3_)
1433{
1434}
1435
Eric Fiselierfcd02212016-02-11 11:59:44 +00001436#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001437
1438template <class _Tp, class _Hash, class _Equal, class _Alloc>
1439__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001440 _NOEXCEPT_(
1441 is_nothrow_move_constructible<__bucket_list>::value &&
1442 is_nothrow_move_constructible<__first_node>::value &&
Eric Fiseliere2e332a2015-12-16 00:53:04 +00001443 is_nothrow_move_constructible<__node_allocator>::value &&
Howard Hinnant37141072011-06-04 18:54:24 +00001444 is_nothrow_move_constructible<hasher>::value &&
1445 is_nothrow_move_constructible<key_equal>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001446 : __bucket_list_(_VSTD::move(__u.__bucket_list_)),
1447 __p1_(_VSTD::move(__u.__p1_)),
1448 __p2_(_VSTD::move(__u.__p2_)),
1449 __p3_(_VSTD::move(__u.__p3_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001450{
1451 if (size() > 0)
1452 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001453 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
1454 __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001455 __u.__p1_.first().__next_ = nullptr;
1456 __u.size() = 0;
1457 }
1458}
1459
1460template <class _Tp, class _Hash, class _Equal, class _Alloc>
1461__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u,
1462 const allocator_type& __a)
1463 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
Eric Fiselierc88580c2017-04-12 23:45:53 +00001464 __p1_(__second_tag(), __node_allocator(__a)),
Howard Hinnantce48a112011-06-30 21:18:19 +00001465 __p2_(0, _VSTD::move(__u.hash_function())),
1466 __p3_(_VSTD::move(__u.__p3_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001467{
1468 if (__a == allocator_type(__u.__node_alloc()))
1469 {
1470 __bucket_list_.reset(__u.__bucket_list_.release());
1471 __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
1472 __u.__bucket_list_.get_deleter().size() = 0;
1473 if (__u.size() > 0)
1474 {
1475 __p1_.first().__next_ = __u.__p1_.first().__next_;
1476 __u.__p1_.first().__next_ = nullptr;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001477 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
1478 __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001479 size() = __u.size();
1480 __u.size() = 0;
1481 }
1482 }
1483}
1484
Eric Fiselierfcd02212016-02-11 11:59:44 +00001485#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001486
1487template <class _Tp, class _Hash, class _Equal, class _Alloc>
1488__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
1489{
Eric Fiselieracb21582017-03-01 02:02:28 +00001490#if defined(_LIBCPP_CXX03_LANG)
Marshall Clow3b8669e2016-06-30 22:05:45 +00001491 static_assert((is_copy_constructible<key_equal>::value),
1492 "Predicate must be copy-constructible.");
1493 static_assert((is_copy_constructible<hasher>::value),
1494 "Hasher must be copy-constructible.");
Eric Fiselier04333f92017-01-13 22:42:53 +00001495#endif
Eric Fiselieracb21582017-03-01 02:02:28 +00001496
Eric Fiseliercd71f442017-01-07 03:01:24 +00001497 __deallocate_node(__p1_.first().__next_);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001498#if _LIBCPP_DEBUG_LEVEL >= 2
1499 __get_db()->__erase_c(this);
1500#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001501}
1502
1503template <class _Tp, class _Hash, class _Equal, class _Alloc>
1504void
1505__hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc(
1506 const __hash_table& __u, true_type)
1507{
1508 if (__node_alloc() != __u.__node_alloc())
1509 {
1510 clear();
1511 __bucket_list_.reset();
1512 __bucket_list_.get_deleter().size() = 0;
1513 }
1514 __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc();
1515 __node_alloc() = __u.__node_alloc();
1516}
1517
1518template <class _Tp, class _Hash, class _Equal, class _Alloc>
1519__hash_table<_Tp, _Hash, _Equal, _Alloc>&
1520__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u)
1521{
1522 if (this != &__u)
1523 {
1524 __copy_assign_alloc(__u);
1525 hash_function() = __u.hash_function();
1526 key_eq() = __u.key_eq();
1527 max_load_factor() = __u.max_load_factor();
1528 __assign_multi(__u.begin(), __u.end());
1529 }
1530 return *this;
1531}
1532
1533template <class _Tp, class _Hash, class _Equal, class _Alloc>
1534void
Eric Fiseliercd71f442017-01-07 03:01:24 +00001535__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np)
Howard Hinnant37141072011-06-04 18:54:24 +00001536 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001537{
1538 __node_allocator& __na = __node_alloc();
1539 while (__np != nullptr)
1540 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001541 __next_pointer __next = __np->__next_;
Howard Hinnantb24c8022013-07-23 22:01:58 +00001542#if _LIBCPP_DEBUG_LEVEL >= 2
1543 __c_node* __c = __get_db()->__find_c_and_lock(this);
1544 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1545 {
1546 --__p;
1547 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1548 if (__i->__node_ == __np)
1549 {
1550 (*__p)->__c_ = nullptr;
1551 if (--__c->end_ != __p)
1552 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1553 }
1554 }
1555 __get_db()->unlock();
1556#endif
Eric Fiselier40492ba2016-07-23 20:36:55 +00001557 __node_pointer __real_np = __np->__upcast();
1558 __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__value_));
1559 __node_traits::deallocate(__na, __real_np, 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001560 __np = __next;
1561 }
1562}
1563
1564template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselier40492ba2016-07-23 20:36:55 +00001565typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer
Howard Hinnant37141072011-06-04 18:54:24 +00001566__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001567{
1568 size_type __bc = bucket_count();
1569 for (size_type __i = 0; __i < __bc; ++__i)
1570 __bucket_list_[__i] = nullptr;
1571 size() = 0;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001572 __next_pointer __cache = __p1_.first().__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001573 __p1_.first().__next_ = nullptr;
1574 return __cache;
1575}
1576
Eric Fiselierfcd02212016-02-11 11:59:44 +00001577#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001578
1579template <class _Tp, class _Hash, class _Equal, class _Alloc>
1580void
1581__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
1582 __hash_table& __u, true_type)
Howard Hinnant37141072011-06-04 18:54:24 +00001583 _NOEXCEPT_(
1584 is_nothrow_move_assignable<__node_allocator>::value &&
1585 is_nothrow_move_assignable<hasher>::value &&
1586 is_nothrow_move_assignable<key_equal>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001587{
1588 clear();
1589 __bucket_list_.reset(__u.__bucket_list_.release());
1590 __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
1591 __u.__bucket_list_.get_deleter().size() = 0;
1592 __move_assign_alloc(__u);
1593 size() = __u.size();
Howard Hinnantce48a112011-06-30 21:18:19 +00001594 hash_function() = _VSTD::move(__u.hash_function());
Howard Hinnant3e519522010-05-11 19:42:16 +00001595 max_load_factor() = __u.max_load_factor();
Howard Hinnantce48a112011-06-30 21:18:19 +00001596 key_eq() = _VSTD::move(__u.key_eq());
Howard Hinnant3e519522010-05-11 19:42:16 +00001597 __p1_.first().__next_ = __u.__p1_.first().__next_;
1598 if (size() > 0)
1599 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001600 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
1601 __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001602 __u.__p1_.first().__next_ = nullptr;
1603 __u.size() = 0;
1604 }
Howard Hinnantb24c8022013-07-23 22:01:58 +00001605#if _LIBCPP_DEBUG_LEVEL >= 2
1606 __get_db()->swap(this, &__u);
1607#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001608}
1609
1610template <class _Tp, class _Hash, class _Equal, class _Alloc>
1611void
1612__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
1613 __hash_table& __u, false_type)
1614{
1615 if (__node_alloc() == __u.__node_alloc())
1616 __move_assign(__u, true_type());
1617 else
1618 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001619 hash_function() = _VSTD::move(__u.hash_function());
1620 key_eq() = _VSTD::move(__u.key_eq());
Howard Hinnant3e519522010-05-11 19:42:16 +00001621 max_load_factor() = __u.max_load_factor();
1622 if (bucket_count() != 0)
1623 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001624 __next_pointer __cache = __detach();
Howard Hinnant3e519522010-05-11 19:42:16 +00001625#ifndef _LIBCPP_NO_EXCEPTIONS
1626 try
1627 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001628#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001629 const_iterator __i = __u.begin();
1630 while (__cache != nullptr && __u.size() != 0)
1631 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001632 __cache->__upcast()->__value_ =
1633 _VSTD::move(__u.remove(__i++)->__value_);
1634 __next_pointer __next = __cache->__next_;
1635 __node_insert_multi(__cache->__upcast());
Howard Hinnant3e519522010-05-11 19:42:16 +00001636 __cache = __next;
1637 }
1638#ifndef _LIBCPP_NO_EXCEPTIONS
1639 }
1640 catch (...)
1641 {
Eric Fiseliercd71f442017-01-07 03:01:24 +00001642 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001643 throw;
1644 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001645#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiseliercd71f442017-01-07 03:01:24 +00001646 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001647 }
1648 const_iterator __i = __u.begin();
1649 while (__u.size() != 0)
1650 {
Eric Fiselierfcd02212016-02-11 11:59:44 +00001651 __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001652 __node_insert_multi(__h.get());
1653 __h.release();
1654 }
1655 }
1656}
1657
1658template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001659inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001660__hash_table<_Tp, _Hash, _Equal, _Alloc>&
1661__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001662 _NOEXCEPT_(
1663 __node_traits::propagate_on_container_move_assignment::value &&
1664 is_nothrow_move_assignable<__node_allocator>::value &&
1665 is_nothrow_move_assignable<hasher>::value &&
1666 is_nothrow_move_assignable<key_equal>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001667{
1668 __move_assign(__u, integral_constant<bool,
1669 __node_traits::propagate_on_container_move_assignment::value>());
1670 return *this;
1671}
1672
Eric Fiselierfcd02212016-02-11 11:59:44 +00001673#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001674
1675template <class _Tp, class _Hash, class _Equal, class _Alloc>
1676template <class _InputIterator>
1677void
1678__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first,
1679 _InputIterator __last)
1680{
Eric Fiselierfcd02212016-02-11 11:59:44 +00001681 typedef iterator_traits<_InputIterator> _ITraits;
1682 typedef typename _ITraits::value_type _ItValueType;
1683 static_assert((is_same<_ItValueType, __container_value_type>::value),
1684 "__assign_unique may only be called with the containers value type");
1685
Howard Hinnant3e519522010-05-11 19:42:16 +00001686 if (bucket_count() != 0)
1687 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001688 __next_pointer __cache = __detach();
Howard Hinnant3e519522010-05-11 19:42:16 +00001689#ifndef _LIBCPP_NO_EXCEPTIONS
1690 try
1691 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001692#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001693 for (; __cache != nullptr && __first != __last; ++__first)
1694 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001695 __cache->__upcast()->__value_ = *__first;
1696 __next_pointer __next = __cache->__next_;
1697 __node_insert_unique(__cache->__upcast());
Howard Hinnant3e519522010-05-11 19:42:16 +00001698 __cache = __next;
1699 }
1700#ifndef _LIBCPP_NO_EXCEPTIONS
1701 }
1702 catch (...)
1703 {
Eric Fiseliercd71f442017-01-07 03:01:24 +00001704 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001705 throw;
1706 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001707#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiseliercd71f442017-01-07 03:01:24 +00001708 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001709 }
1710 for (; __first != __last; ++__first)
1711 __insert_unique(*__first);
1712}
1713
1714template <class _Tp, class _Hash, class _Equal, class _Alloc>
1715template <class _InputIterator>
1716void
1717__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first,
1718 _InputIterator __last)
1719{
Eric Fiselierfcd02212016-02-11 11:59:44 +00001720 typedef iterator_traits<_InputIterator> _ITraits;
1721 typedef typename _ITraits::value_type _ItValueType;
1722 static_assert((is_same<_ItValueType, __container_value_type>::value ||
1723 is_same<_ItValueType, __node_value_type>::value),
1724 "__assign_multi may only be called with the containers value type"
1725 " or the nodes value type");
Howard Hinnant3e519522010-05-11 19:42:16 +00001726 if (bucket_count() != 0)
1727 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001728 __next_pointer __cache = __detach();
Howard Hinnant3e519522010-05-11 19:42:16 +00001729#ifndef _LIBCPP_NO_EXCEPTIONS
1730 try
1731 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001732#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001733 for (; __cache != nullptr && __first != __last; ++__first)
1734 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001735 __cache->__upcast()->__value_ = *__first;
1736 __next_pointer __next = __cache->__next_;
1737 __node_insert_multi(__cache->__upcast());
Howard Hinnant3e519522010-05-11 19:42:16 +00001738 __cache = __next;
1739 }
1740#ifndef _LIBCPP_NO_EXCEPTIONS
1741 }
1742 catch (...)
1743 {
Eric Fiseliercd71f442017-01-07 03:01:24 +00001744 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001745 throw;
1746 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001747#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiseliercd71f442017-01-07 03:01:24 +00001748 __deallocate_node(__cache);
Howard Hinnant3e519522010-05-11 19:42:16 +00001749 }
1750 for (; __first != __last; ++__first)
Eric Fiselierfcd02212016-02-11 11:59:44 +00001751 __insert_multi(_NodeTypes::__get_value(*__first));
Howard Hinnant3e519522010-05-11 19:42:16 +00001752}
1753
1754template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001755inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001756typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Howard Hinnant37141072011-06-04 18:54:24 +00001757__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001758{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001759#if _LIBCPP_DEBUG_LEVEL >= 2
1760 return iterator(__p1_.first().__next_, this);
1761#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001762 return iterator(__p1_.first().__next_);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001763#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001764}
1765
1766template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001767inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001768typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Howard Hinnant37141072011-06-04 18:54:24 +00001769__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001770{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001771#if _LIBCPP_DEBUG_LEVEL >= 2
1772 return iterator(nullptr, this);
1773#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001774 return iterator(nullptr);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001775#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001776}
1777
1778template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001779inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001780typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
Howard Hinnant37141072011-06-04 18:54:24 +00001781__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001782{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001783#if _LIBCPP_DEBUG_LEVEL >= 2
1784 return const_iterator(__p1_.first().__next_, this);
1785#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001786 return const_iterator(__p1_.first().__next_);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001787#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001788}
1789
1790template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00001791inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001792typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
Howard Hinnant37141072011-06-04 18:54:24 +00001793__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001794{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001795#if _LIBCPP_DEBUG_LEVEL >= 2
1796 return const_iterator(nullptr, this);
1797#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001798 return const_iterator(nullptr);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001799#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001800}
1801
1802template <class _Tp, class _Hash, class _Equal, class _Alloc>
1803void
Howard Hinnant37141072011-06-04 18:54:24 +00001804__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001805{
1806 if (size() > 0)
1807 {
Eric Fiseliercd71f442017-01-07 03:01:24 +00001808 __deallocate_node(__p1_.first().__next_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001809 __p1_.first().__next_ = nullptr;
1810 size_type __bc = bucket_count();
Howard Hinnant1f8da842011-07-05 14:14:17 +00001811 for (size_type __i = 0; __i < __bc; ++__i)
Howard Hinnant3e519522010-05-11 19:42:16 +00001812 __bucket_list_[__i] = nullptr;
1813 size() = 0;
1814 }
1815}
1816
1817template <class _Tp, class _Hash, class _Equal, class _Alloc>
1818pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1819__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd)
1820{
1821 __nd->__hash_ = hash_function()(__nd->__value_);
1822 size_type __bc = bucket_count();
1823 bool __inserted = false;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001824 __next_pointer __ndptr;
Howard Hinnant3e519522010-05-11 19:42:16 +00001825 size_t __chash;
1826 if (__bc != 0)
1827 {
Howard Hinnant4cb38a82012-07-06 17:31:14 +00001828 __chash = __constrain_hash(__nd->__hash_, __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00001829 __ndptr = __bucket_list_[__chash];
1830 if (__ndptr != nullptr)
1831 {
1832 for (__ndptr = __ndptr->__next_; __ndptr != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00001833 __constrain_hash(__ndptr->__hash(), __bc) == __chash;
Howard Hinnant3e519522010-05-11 19:42:16 +00001834 __ndptr = __ndptr->__next_)
1835 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001836 if (key_eq()(__ndptr->__upcast()->__value_, __nd->__value_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001837 goto __done;
1838 }
1839 }
1840 }
1841 {
1842 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1843 {
Eric Fiselier9ba5c112015-02-02 21:31:48 +00001844 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnant3e519522010-05-11 19:42:16 +00001845 size_type(ceil(float(size() + 1) / max_load_factor()))));
1846 __bc = bucket_count();
Howard Hinnant4cb38a82012-07-06 17:31:14 +00001847 __chash = __constrain_hash(__nd->__hash_, __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00001848 }
1849 // insert_after __bucket_list_[__chash], or __first_node if bucket is null
Eric Fiselier40492ba2016-07-23 20:36:55 +00001850 __next_pointer __pn = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00001851 if (__pn == nullptr)
1852 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001853 __pn =__p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001854 __nd->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001855 __pn->__next_ = __nd->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001856 // fix up __bucket_list_
1857 __bucket_list_[__chash] = __pn;
1858 if (__nd->__next_ != nullptr)
Eric Fiselier40492ba2016-07-23 20:36:55 +00001859 __bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001860 }
1861 else
1862 {
1863 __nd->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001864 __pn->__next_ = __nd->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001865 }
Eric Fiselier40492ba2016-07-23 20:36:55 +00001866 __ndptr = __nd->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001867 // increment size
1868 ++size();
1869 __inserted = true;
1870 }
1871__done:
Howard Hinnantb24c8022013-07-23 22:01:58 +00001872#if _LIBCPP_DEBUG_LEVEL >= 2
1873 return pair<iterator, bool>(iterator(__ndptr, this), __inserted);
1874#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001875 return pair<iterator, bool>(iterator(__ndptr), __inserted);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001876#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001877}
1878
1879template <class _Tp, class _Hash, class _Equal, class _Alloc>
1880typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1881__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp)
1882{
1883 __cp->__hash_ = hash_function()(__cp->__value_);
1884 size_type __bc = bucket_count();
1885 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1886 {
Eric Fiselier9ba5c112015-02-02 21:31:48 +00001887 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnant3e519522010-05-11 19:42:16 +00001888 size_type(ceil(float(size() + 1) / max_load_factor()))));
1889 __bc = bucket_count();
1890 }
Howard Hinnant4cb38a82012-07-06 17:31:14 +00001891 size_t __chash = __constrain_hash(__cp->__hash_, __bc);
Eric Fiselier40492ba2016-07-23 20:36:55 +00001892 __next_pointer __pn = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00001893 if (__pn == nullptr)
1894 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001895 __pn =__p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001896 __cp->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001897 __pn->__next_ = __cp->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001898 // fix up __bucket_list_
1899 __bucket_list_[__chash] = __pn;
1900 if (__cp->__next_ != nullptr)
Eric Fiselier40492ba2016-07-23 20:36:55 +00001901 __bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)]
1902 = __cp->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001903 }
1904 else
1905 {
1906 for (bool __found = false; __pn->__next_ != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00001907 __constrain_hash(__pn->__next_->__hash(), __bc) == __chash;
Howard Hinnant3e519522010-05-11 19:42:16 +00001908 __pn = __pn->__next_)
Howard Hinnantb3371f62010-08-22 00:02:43 +00001909 {
Howard Hinnant3e519522010-05-11 19:42:16 +00001910 // __found key_eq() action
1911 // false false loop
1912 // true true loop
1913 // false true set __found to true
1914 // true false break
Eric Fiselier40492ba2016-07-23 20:36:55 +00001915 if (__found != (__pn->__next_->__hash() == __cp->__hash_ &&
1916 key_eq()(__pn->__next_->__upcast()->__value_, __cp->__value_)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001917 {
1918 if (!__found)
1919 __found = true;
1920 else
1921 break;
1922 }
1923 }
1924 __cp->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001925 __pn->__next_ = __cp->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001926 if (__cp->__next_ != nullptr)
1927 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001928 size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00001929 if (__nhash != __chash)
Eric Fiselier40492ba2016-07-23 20:36:55 +00001930 __bucket_list_[__nhash] = __cp->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00001931 }
1932 }
1933 ++size();
Howard Hinnantb24c8022013-07-23 22:01:58 +00001934#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier40492ba2016-07-23 20:36:55 +00001935 return iterator(__cp->__ptr(), this);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001936#else
Eric Fiselier40492ba2016-07-23 20:36:55 +00001937 return iterator(__cp->__ptr());
Howard Hinnantb24c8022013-07-23 22:01:58 +00001938#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001939}
1940
1941template <class _Tp, class _Hash, class _Equal, class _Alloc>
1942typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1943__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
1944 const_iterator __p, __node_pointer __cp)
1945{
Howard Hinnant2f51de52013-08-02 17:50:49 +00001946#if _LIBCPP_DEBUG_LEVEL >= 2
1947 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1948 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
1949 " referring to this unordered container");
1950#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001951 if (__p != end() && key_eq()(*__p, __cp->__value_))
1952 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00001953 __next_pointer __np = __p.__node_;
1954 __cp->__hash_ = __np->__hash();
Howard Hinnant3e519522010-05-11 19:42:16 +00001955 size_type __bc = bucket_count();
1956 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1957 {
Eric Fiselier9ba5c112015-02-02 21:31:48 +00001958 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnant3e519522010-05-11 19:42:16 +00001959 size_type(ceil(float(size() + 1) / max_load_factor()))));
1960 __bc = bucket_count();
1961 }
Howard Hinnant4cb38a82012-07-06 17:31:14 +00001962 size_t __chash = __constrain_hash(__cp->__hash_, __bc);
Eric Fiselier40492ba2016-07-23 20:36:55 +00001963 __next_pointer __pp = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00001964 while (__pp->__next_ != __np)
1965 __pp = __pp->__next_;
1966 __cp->__next_ = __np;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001967 __pp->__next_ = static_cast<__next_pointer>(__cp);
Howard Hinnant3e519522010-05-11 19:42:16 +00001968 ++size();
Howard Hinnantb24c8022013-07-23 22:01:58 +00001969#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier40492ba2016-07-23 20:36:55 +00001970 return iterator(static_cast<__next_pointer>(__cp), this);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001971#else
Eric Fiselier40492ba2016-07-23 20:36:55 +00001972 return iterator(static_cast<__next_pointer>(__cp));
Howard Hinnantb24c8022013-07-23 22:01:58 +00001973#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001974 }
1975 return __node_insert_multi(__cp);
1976}
1977
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001978
1979
Eric Fiselierfcd02212016-02-11 11:59:44 +00001980#ifndef _LIBCPP_CXX03_LANG
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001981template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001982template <class _Key, class ..._Args>
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001983pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001984__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args)
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001985#else
1986template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001987template <class _Key, class _Args>
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001988pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001989__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args)
Eric Fiselierde3f2b32015-06-13 07:18:32 +00001990#endif
1991{
Eric Fiselierfcd02212016-02-11 11:59:44 +00001992
1993 size_t __hash = hash_function()(__k);
Howard Hinnant3e519522010-05-11 19:42:16 +00001994 size_type __bc = bucket_count();
1995 bool __inserted = false;
Eric Fiselier40492ba2016-07-23 20:36:55 +00001996 __next_pointer __nd;
Howard Hinnant3e519522010-05-11 19:42:16 +00001997 size_t __chash;
1998 if (__bc != 0)
1999 {
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002000 __chash = __constrain_hash(__hash, __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002001 __nd = __bucket_list_[__chash];
2002 if (__nd != nullptr)
2003 {
2004 for (__nd = __nd->__next_; __nd != nullptr &&
Eric Fiselier1a06fe52016-07-24 06:22:25 +00002005 (__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash);
Howard Hinnant3e519522010-05-11 19:42:16 +00002006 __nd = __nd->__next_)
2007 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002008 if (key_eq()(__nd->__upcast()->__value_, __k))
Howard Hinnant3e519522010-05-11 19:42:16 +00002009 goto __done;
2010 }
2011 }
2012 }
2013 {
Eric Fiselierfcd02212016-02-11 11:59:44 +00002014#ifndef _LIBCPP_CXX03_LANG
2015 __node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...);
2016#else
2017 __node_holder __h = __construct_node_hash(__hash, __args);
2018#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002019 if (size()+1 > __bc * max_load_factor() || __bc == 0)
2020 {
Eric Fiselier9ba5c112015-02-02 21:31:48 +00002021 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnant3e519522010-05-11 19:42:16 +00002022 size_type(ceil(float(size() + 1) / max_load_factor()))));
2023 __bc = bucket_count();
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002024 __chash = __constrain_hash(__hash, __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002025 }
2026 // insert_after __bucket_list_[__chash], or __first_node if bucket is null
Eric Fiselier40492ba2016-07-23 20:36:55 +00002027 __next_pointer __pn = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00002028 if (__pn == nullptr)
2029 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002030 __pn = __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00002031 __h->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00002032 __pn->__next_ = __h.get()->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00002033 // fix up __bucket_list_
2034 __bucket_list_[__chash] = __pn;
2035 if (__h->__next_ != nullptr)
Eric Fiselier40492ba2016-07-23 20:36:55 +00002036 __bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)]
2037 = __h.get()->__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00002038 }
2039 else
2040 {
2041 __h->__next_ = __pn->__next_;
Eric Fiselier40492ba2016-07-23 20:36:55 +00002042 __pn->__next_ = static_cast<__next_pointer>(__h.get());
Howard Hinnant3e519522010-05-11 19:42:16 +00002043 }
Eric Fiselier40492ba2016-07-23 20:36:55 +00002044 __nd = static_cast<__next_pointer>(__h.release());
Howard Hinnant3e519522010-05-11 19:42:16 +00002045 // increment size
2046 ++size();
2047 __inserted = true;
2048 }
2049__done:
Howard Hinnantb24c8022013-07-23 22:01:58 +00002050#if _LIBCPP_DEBUG_LEVEL >= 2
2051 return pair<iterator, bool>(iterator(__nd, this), __inserted);
2052#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002053 return pair<iterator, bool>(iterator(__nd), __inserted);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002054#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002055}
2056
Eric Fiselierfcd02212016-02-11 11:59:44 +00002057#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002058
2059template <class _Tp, class _Hash, class _Equal, class _Alloc>
2060template <class... _Args>
2061pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
Duncan P. N. Exon Smithfde79b42016-03-17 20:45:20 +00002062__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args)
Howard Hinnant3e519522010-05-11 19:42:16 +00002063{
Howard Hinnantce48a112011-06-30 21:18:19 +00002064 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002065 pair<iterator, bool> __r = __node_insert_unique(__h.get());
2066 if (__r.second)
2067 __h.release();
2068 return __r;
2069}
2070
2071template <class _Tp, class _Hash, class _Equal, class _Alloc>
2072template <class... _Args>
2073typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2074__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args)
2075{
Howard Hinnantce48a112011-06-30 21:18:19 +00002076 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002077 iterator __r = __node_insert_multi(__h.get());
2078 __h.release();
2079 return __r;
2080}
2081
2082template <class _Tp, class _Hash, class _Equal, class _Alloc>
2083template <class... _Args>
2084typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2085__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(
2086 const_iterator __p, _Args&&... __args)
2087{
Howard Hinnante5c13de2013-07-29 19:05:47 +00002088#if _LIBCPP_DEBUG_LEVEL >= 2
2089 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2090 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
2091 " referring to this unordered container");
2092#endif
Howard Hinnantce48a112011-06-30 21:18:19 +00002093 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002094 iterator __r = __node_insert_multi(__p, __h.get());
2095 __h.release();
2096 return __r;
2097}
2098
Eric Fiselierfcd02212016-02-11 11:59:44 +00002099#else // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002100
2101template <class _Tp, class _Hash, class _Equal, class _Alloc>
2102typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Eric Fiselierfcd02212016-02-11 11:59:44 +00002103__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const __container_value_type& __x)
Howard Hinnant3e519522010-05-11 19:42:16 +00002104{
2105 __node_holder __h = __construct_node(__x);
2106 iterator __r = __node_insert_multi(__h.get());
2107 __h.release();
2108 return __r;
2109}
2110
2111template <class _Tp, class _Hash, class _Equal, class _Alloc>
2112typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2113__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
Eric Fiselierfcd02212016-02-11 11:59:44 +00002114 const __container_value_type& __x)
Howard Hinnant3e519522010-05-11 19:42:16 +00002115{
Howard Hinnante5c13de2013-07-29 19:05:47 +00002116#if _LIBCPP_DEBUG_LEVEL >= 2
2117 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2118 "unordered container::insert(const_iterator, lvalue) called with an iterator not"
2119 " referring to this unordered container");
2120#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002121 __node_holder __h = __construct_node(__x);
2122 iterator __r = __node_insert_multi(__p, __h.get());
2123 __h.release();
2124 return __r;
2125}
2126
Eric Fiselierfcd02212016-02-11 11:59:44 +00002127#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002128
2129template <class _Tp, class _Hash, class _Equal, class _Alloc>
2130void
2131__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
2132{
Dan Albert553b09b2018-01-08 22:57:12 +00002133 if (__n == 1)
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002134 __n = 2;
2135 else if (__n & (__n - 1))
2136 __n = __next_prime(__n);
Howard Hinnant3e519522010-05-11 19:42:16 +00002137 size_type __bc = bucket_count();
2138 if (__n > __bc)
2139 __rehash(__n);
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002140 else if (__n < __bc)
Howard Hinnant3e519522010-05-11 19:42:16 +00002141 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002142 __n = _VSTD::max<size_type>
Howard Hinnant3e519522010-05-11 19:42:16 +00002143 (
2144 __n,
Eric Fiselier9ba5c112015-02-02 21:31:48 +00002145 __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) :
2146 __next_prime(size_t(ceil(float(size()) / max_load_factor())))
Howard Hinnant3e519522010-05-11 19:42:16 +00002147 );
2148 if (__n < __bc)
2149 __rehash(__n);
2150 }
2151}
2152
2153template <class _Tp, class _Hash, class _Equal, class _Alloc>
2154void
2155__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
2156{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002157#if _LIBCPP_DEBUG_LEVEL >= 2
2158 __get_db()->__invalidate_all(this);
2159#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant3e519522010-05-11 19:42:16 +00002160 __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc();
2161 __bucket_list_.reset(__nbc > 0 ?
2162 __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr);
2163 __bucket_list_.get_deleter().size() = __nbc;
2164 if (__nbc > 0)
2165 {
2166 for (size_type __i = 0; __i < __nbc; ++__i)
2167 __bucket_list_[__i] = nullptr;
Eric Fiselier40492ba2016-07-23 20:36:55 +00002168 __next_pointer __pp = __p1_.first().__ptr();
2169 __next_pointer __cp = __pp->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002170 if (__cp != nullptr)
2171 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002172 size_type __chash = __constrain_hash(__cp->__hash(), __nbc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002173 __bucket_list_[__chash] = __pp;
2174 size_type __phash = __chash;
2175 for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
2176 __cp = __pp->__next_)
2177 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002178 __chash = __constrain_hash(__cp->__hash(), __nbc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002179 if (__chash == __phash)
2180 __pp = __cp;
2181 else
2182 {
2183 if (__bucket_list_[__chash] == nullptr)
2184 {
2185 __bucket_list_[__chash] = __pp;
2186 __pp = __cp;
2187 __phash = __chash;
2188 }
2189 else
2190 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002191 __next_pointer __np = __cp;
Howard Hinnant3e519522010-05-11 19:42:16 +00002192 for (; __np->__next_ != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00002193 key_eq()(__cp->__upcast()->__value_,
2194 __np->__next_->__upcast()->__value_);
Howard Hinnant3e519522010-05-11 19:42:16 +00002195 __np = __np->__next_)
2196 ;
2197 __pp->__next_ = __np->__next_;
2198 __np->__next_ = __bucket_list_[__chash]->__next_;
2199 __bucket_list_[__chash]->__next_ = __cp;
Howard Hinnantb3371f62010-08-22 00:02:43 +00002200
Howard Hinnant3e519522010-05-11 19:42:16 +00002201 }
2202 }
2203 }
2204 }
2205 }
2206}
2207
2208template <class _Tp, class _Hash, class _Equal, class _Alloc>
2209template <class _Key>
2210typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2211__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k)
2212{
2213 size_t __hash = hash_function()(__k);
2214 size_type __bc = bucket_count();
2215 if (__bc != 0)
2216 {
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002217 size_t __chash = __constrain_hash(__hash, __bc);
Eric Fiselier40492ba2016-07-23 20:36:55 +00002218 __next_pointer __nd = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00002219 if (__nd != nullptr)
2220 {
2221 for (__nd = __nd->__next_; __nd != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00002222 (__nd->__hash() == __hash
2223 || __constrain_hash(__nd->__hash(), __bc) == __chash);
Howard Hinnant3e519522010-05-11 19:42:16 +00002224 __nd = __nd->__next_)
2225 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002226 if ((__nd->__hash() == __hash)
2227 && key_eq()(__nd->__upcast()->__value_, __k))
Howard Hinnantb24c8022013-07-23 22:01:58 +00002228#if _LIBCPP_DEBUG_LEVEL >= 2
2229 return iterator(__nd, this);
2230#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002231 return iterator(__nd);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002232#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002233 }
2234 }
2235 }
2236 return end();
2237}
2238
2239template <class _Tp, class _Hash, class _Equal, class _Alloc>
2240template <class _Key>
2241typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
2242__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const
2243{
2244 size_t __hash = hash_function()(__k);
2245 size_type __bc = bucket_count();
2246 if (__bc != 0)
2247 {
Howard Hinnant4cb38a82012-07-06 17:31:14 +00002248 size_t __chash = __constrain_hash(__hash, __bc);
Eric Fiselier40492ba2016-07-23 20:36:55 +00002249 __next_pointer __nd = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00002250 if (__nd != nullptr)
2251 {
2252 for (__nd = __nd->__next_; __nd != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00002253 (__hash == __nd->__hash()
2254 || __constrain_hash(__nd->__hash(), __bc) == __chash);
Howard Hinnant3e519522010-05-11 19:42:16 +00002255 __nd = __nd->__next_)
2256 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002257 if ((__nd->__hash() == __hash)
2258 && key_eq()(__nd->__upcast()->__value_, __k))
Howard Hinnantb24c8022013-07-23 22:01:58 +00002259#if _LIBCPP_DEBUG_LEVEL >= 2
2260 return const_iterator(__nd, this);
2261#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002262 return const_iterator(__nd);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002263#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002264 }
2265 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00002266
Howard Hinnant3e519522010-05-11 19:42:16 +00002267 }
2268 return end();
2269}
2270
Eric Fiselierfcd02212016-02-11 11:59:44 +00002271#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002272
2273template <class _Tp, class _Hash, class _Equal, class _Alloc>
2274template <class ..._Args>
2275typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
2276__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args)
2277{
Eric Fiselierfcd02212016-02-11 11:59:44 +00002278 static_assert(!__is_hash_value_type<_Args...>::value,
2279 "Construct cannot be called with a hash value type");
Howard Hinnant3e519522010-05-11 19:42:16 +00002280 __node_allocator& __na = __node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00002281 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Eric Fiselierfcd02212016-02-11 11:59:44 +00002282 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002283 __h.get_deleter().__value_constructed = true;
2284 __h->__hash_ = hash_function()(__h->__value_);
2285 __h->__next_ = nullptr;
2286 return __h;
2287}
2288
2289template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselierfcd02212016-02-11 11:59:44 +00002290template <class _First, class ..._Rest>
Howard Hinnant3e519522010-05-11 19:42:16 +00002291typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Eric Fiselierfcd02212016-02-11 11:59:44 +00002292__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(
2293 size_t __hash, _First&& __f, _Rest&& ...__rest)
Howard Hinnant3e519522010-05-11 19:42:16 +00002294{
Eric Fiselierfcd02212016-02-11 11:59:44 +00002295 static_assert(!__is_hash_value_type<_First, _Rest...>::value,
2296 "Construct cannot be called with a hash value type");
Howard Hinnant3e519522010-05-11 19:42:16 +00002297 __node_allocator& __na = __node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00002298 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Eric Fiselierfcd02212016-02-11 11:59:44 +00002299 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_),
2300 _VSTD::forward<_First>(__f),
2301 _VSTD::forward<_Rest>(__rest)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00002302 __h.get_deleter().__value_constructed = true;
2303 __h->__hash_ = __hash;
2304 __h->__next_ = nullptr;
Howard Hinnant179b1f82013-08-22 18:29:50 +00002305 return __h;
Howard Hinnant3e519522010-05-11 19:42:16 +00002306}
2307
Eric Fiselierfcd02212016-02-11 11:59:44 +00002308#else // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002309
2310template <class _Tp, class _Hash, class _Equal, class _Alloc>
2311typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Eric Fiselierfcd02212016-02-11 11:59:44 +00002312__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const __container_value_type& __v)
Howard Hinnant3e519522010-05-11 19:42:16 +00002313{
2314 __node_allocator& __na = __node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00002315 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Eric Fiselierfcd02212016-02-11 11:59:44 +00002316 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00002317 __h.get_deleter().__value_constructed = true;
2318 __h->__hash_ = hash_function()(__h->__value_);
2319 __h->__next_ = nullptr;
Dimitry Andric251c6292015-08-19 06:43:33 +00002320 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnant3e519522010-05-11 19:42:16 +00002321}
2322
Howard Hinnant3e519522010-05-11 19:42:16 +00002323template <class _Tp, class _Hash, class _Equal, class _Alloc>
2324typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Eric Fiselierfcd02212016-02-11 11:59:44 +00002325__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash,
2326 const __container_value_type& __v)
Howard Hinnant3e519522010-05-11 19:42:16 +00002327{
2328 __node_allocator& __na = __node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00002329 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Eric Fiselierfcd02212016-02-11 11:59:44 +00002330 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00002331 __h.get_deleter().__value_constructed = true;
2332 __h->__hash_ = __hash;
2333 __h->__next_ = nullptr;
Dimitry Andric251c6292015-08-19 06:43:33 +00002334 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnant3e519522010-05-11 19:42:16 +00002335}
2336
Eric Fiselierfcd02212016-02-11 11:59:44 +00002337#endif // _LIBCPP_CXX03_LANG
2338
Howard Hinnant3e519522010-05-11 19:42:16 +00002339template <class _Tp, class _Hash, class _Equal, class _Alloc>
2340typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2341__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
2342{
Eric Fiselier40492ba2016-07-23 20:36:55 +00002343 __next_pointer __np = __p.__node_;
Howard Hinnantb24c8022013-07-23 22:01:58 +00002344#if _LIBCPP_DEBUG_LEVEL >= 2
2345 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2346 "unordered container erase(iterator) called with an iterator not"
2347 " referring to this container");
2348 _LIBCPP_ASSERT(__p != end(),
2349 "unordered container erase(iterator) called with a non-dereferenceable iterator");
2350 iterator __r(__np, this);
2351#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002352 iterator __r(__np);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002353#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002354 ++__r;
2355 remove(__p);
2356 return __r;
2357}
2358
2359template <class _Tp, class _Hash, class _Equal, class _Alloc>
2360typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2361__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
2362 const_iterator __last)
2363{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002364#if _LIBCPP_DEBUG_LEVEL >= 2
2365 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2366 "unodered container::erase(iterator, iterator) called with an iterator not"
2367 " referring to this unodered container");
2368 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
2369 "unodered container::erase(iterator, iterator) called with an iterator not"
2370 " referring to this unodered container");
2371#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002372 for (const_iterator __p = __first; __first != __last; __p = __first)
2373 {
2374 ++__first;
2375 erase(__p);
2376 }
Eric Fiselier40492ba2016-07-23 20:36:55 +00002377 __next_pointer __np = __last.__node_;
Howard Hinnantb24c8022013-07-23 22:01:58 +00002378#if _LIBCPP_DEBUG_LEVEL >= 2
2379 return iterator (__np, this);
2380#else
Howard Hinnant3e519522010-05-11 19:42:16 +00002381 return iterator (__np);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002382#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002383}
2384
2385template <class _Tp, class _Hash, class _Equal, class _Alloc>
2386template <class _Key>
2387typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2388__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k)
2389{
2390 iterator __i = find(__k);
2391 if (__i == end())
2392 return 0;
2393 erase(__i);
2394 return 1;
2395}
2396
2397template <class _Tp, class _Hash, class _Equal, class _Alloc>
2398template <class _Key>
2399typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2400__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k)
2401{
2402 size_type __r = 0;
2403 iterator __i = find(__k);
2404 if (__i != end())
2405 {
2406 iterator __e = end();
2407 do
2408 {
2409 erase(__i++);
2410 ++__r;
2411 } while (__i != __e && key_eq()(*__i, __k));
2412 }
2413 return __r;
2414}
2415
2416template <class _Tp, class _Hash, class _Equal, class _Alloc>
2417typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Howard Hinnant37141072011-06-04 18:54:24 +00002418__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00002419{
2420 // current node
Eric Fiselier40492ba2016-07-23 20:36:55 +00002421 __next_pointer __cn = __p.__node_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002422 size_type __bc = bucket_count();
Eric Fiselier40492ba2016-07-23 20:36:55 +00002423 size_t __chash = __constrain_hash(__cn->__hash(), __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002424 // find previous node
Eric Fiselier40492ba2016-07-23 20:36:55 +00002425 __next_pointer __pn = __bucket_list_[__chash];
Howard Hinnant3e519522010-05-11 19:42:16 +00002426 for (; __pn->__next_ != __cn; __pn = __pn->__next_)
2427 ;
2428 // Fix up __bucket_list_
2429 // if __pn is not in same bucket (before begin is not in same bucket) &&
2430 // if __cn->__next_ is not in same bucket (nullptr is not in same bucket)
Eric Fiselier40492ba2016-07-23 20:36:55 +00002431 if (__pn == __p1_.first().__ptr()
2432 || __constrain_hash(__pn->__hash(), __bc) != __chash)
Howard Hinnant3e519522010-05-11 19:42:16 +00002433 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002434 if (__cn->__next_ == nullptr
2435 || __constrain_hash(__cn->__next_->__hash(), __bc) != __chash)
Howard Hinnant3e519522010-05-11 19:42:16 +00002436 __bucket_list_[__chash] = nullptr;
2437 }
2438 // if __cn->__next_ is not in same bucket (nullptr is in same bucket)
2439 if (__cn->__next_ != nullptr)
2440 {
Eric Fiselier40492ba2016-07-23 20:36:55 +00002441 size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc);
Howard Hinnant3e519522010-05-11 19:42:16 +00002442 if (__nhash != __chash)
2443 __bucket_list_[__nhash] = __pn;
2444 }
2445 // remove __cn
2446 __pn->__next_ = __cn->__next_;
2447 __cn->__next_ = nullptr;
2448 --size();
Howard Hinnantb24c8022013-07-23 22:01:58 +00002449#if _LIBCPP_DEBUG_LEVEL >= 2
2450 __c_node* __c = __get_db()->__find_c_and_lock(this);
Eric Fiselier780b51d2016-12-28 05:53:01 +00002451 for (__i_node** __dp = __c->end_; __dp != __c->beg_; )
Howard Hinnantb24c8022013-07-23 22:01:58 +00002452 {
Eric Fiselier780b51d2016-12-28 05:53:01 +00002453 --__dp;
2454 iterator* __i = static_cast<iterator*>((*__dp)->__i_);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002455 if (__i->__node_ == __cn)
2456 {
Eric Fiselier780b51d2016-12-28 05:53:01 +00002457 (*__dp)->__c_ = nullptr;
2458 if (--__c->end_ != __dp)
2459 memmove(__dp, __dp+1, (__c->end_ - __dp)*sizeof(__i_node*));
Howard Hinnantb24c8022013-07-23 22:01:58 +00002460 }
2461 }
2462 __get_db()->unlock();
2463#endif
Eric Fiselier40492ba2016-07-23 20:36:55 +00002464 return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true));
Howard Hinnant3e519522010-05-11 19:42:16 +00002465}
2466
2467template <class _Tp, class _Hash, class _Equal, class _Alloc>
2468template <class _Key>
Evgeniy Stepanov906c8722015-11-07 01:22:13 +00002469inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002470typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2471__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const
2472{
2473 return static_cast<size_type>(find(__k) != end());
2474}
2475
2476template <class _Tp, class _Hash, class _Equal, class _Alloc>
2477template <class _Key>
2478typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2479__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const
2480{
2481 size_type __r = 0;
2482 const_iterator __i = find(__k);
2483 if (__i != end())
2484 {
2485 const_iterator __e = end();
2486 do
2487 {
2488 ++__i;
2489 ++__r;
2490 } while (__i != __e && key_eq()(*__i, __k));
2491 }
2492 return __r;
2493}
2494
2495template <class _Tp, class _Hash, class _Equal, class _Alloc>
2496template <class _Key>
2497pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
2498 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
2499__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
2500 const _Key& __k)
2501{
2502 iterator __i = find(__k);
2503 iterator __j = __i;
2504 if (__i != end())
2505 ++__j;
2506 return pair<iterator, iterator>(__i, __j);
2507}
2508
2509template <class _Tp, class _Hash, class _Equal, class _Alloc>
2510template <class _Key>
2511pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
2512 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
2513__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
2514 const _Key& __k) const
2515{
2516 const_iterator __i = find(__k);
2517 const_iterator __j = __i;
2518 if (__i != end())
2519 ++__j;
2520 return pair<const_iterator, const_iterator>(__i, __j);
2521}
2522
2523template <class _Tp, class _Hash, class _Equal, class _Alloc>
2524template <class _Key>
2525pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
2526 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
2527__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
2528 const _Key& __k)
2529{
2530 iterator __i = find(__k);
2531 iterator __j = __i;
2532 if (__i != end())
2533 {
2534 iterator __e = end();
2535 do
2536 {
2537 ++__j;
2538 } while (__j != __e && key_eq()(*__j, __k));
2539 }
2540 return pair<iterator, iterator>(__i, __j);
2541}
2542
2543template <class _Tp, class _Hash, class _Equal, class _Alloc>
2544template <class _Key>
2545pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
2546 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
2547__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
2548 const _Key& __k) const
2549{
2550 const_iterator __i = find(__k);
2551 const_iterator __j = __i;
2552 if (__i != end())
2553 {
2554 const_iterator __e = end();
2555 do
2556 {
2557 ++__j;
2558 } while (__j != __e && key_eq()(*__j, __k));
2559 }
2560 return pair<const_iterator, const_iterator>(__i, __j);
2561}
2562
2563template <class _Tp, class _Hash, class _Equal, class _Alloc>
2564void
2565__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
Eric Fiselier87a82492015-07-18 20:40:46 +00002566#if _LIBCPP_STD_VER <= 11
Eric Fiselier780b51d2016-12-28 05:53:01 +00002567 _NOEXCEPT_DEBUG_(
Marshall Clowe3fbe142015-07-13 20:04:56 +00002568 __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
Marshall Clowe3fbe142015-07-13 20:04:56 +00002569 && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
2570 || __is_nothrow_swappable<__pointer_allocator>::value)
2571 && (!__node_traits::propagate_on_container_swap::value
2572 || __is_nothrow_swappable<__node_allocator>::value)
Marshall Clowe3fbe142015-07-13 20:04:56 +00002573 )
Eric Fiselier87a82492015-07-18 20:40:46 +00002574#else
Eric Fiselier780b51d2016-12-28 05:53:01 +00002575 _NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value)
Eric Fiselier87a82492015-07-18 20:40:46 +00002576#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002577{
Eric Fiselier780b51d2016-12-28 05:53:01 +00002578 _LIBCPP_ASSERT(__node_traits::propagate_on_container_swap::value ||
2579 this->__node_alloc() == __u.__node_alloc(),
2580 "list::swap: Either propagate_on_container_swap must be true"
2581 " or the allocators must compare equal");
Howard Hinnant3e519522010-05-11 19:42:16 +00002582 {
2583 __node_pointer_pointer __npp = __bucket_list_.release();
2584 __bucket_list_.reset(__u.__bucket_list_.release());
2585 __u.__bucket_list_.reset(__npp);
2586 }
Howard Hinnantce48a112011-06-30 21:18:19 +00002587 _VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size());
Marshall Clowe3fbe142015-07-13 20:04:56 +00002588 __swap_allocator(__bucket_list_.get_deleter().__alloc(),
Howard Hinnant3e519522010-05-11 19:42:16 +00002589 __u.__bucket_list_.get_deleter().__alloc());
Marshall Clowe3fbe142015-07-13 20:04:56 +00002590 __swap_allocator(__node_alloc(), __u.__node_alloc());
Howard Hinnantce48a112011-06-30 21:18:19 +00002591 _VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_);
Howard Hinnant3e519522010-05-11 19:42:16 +00002592 __p2_.swap(__u.__p2_);
2593 __p3_.swap(__u.__p3_);
2594 if (size() > 0)
Eric Fiselier40492ba2016-07-23 20:36:55 +00002595 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
2596 __p1_.first().__ptr();
Howard Hinnant3e519522010-05-11 19:42:16 +00002597 if (__u.size() > 0)
Eric Fiselier40492ba2016-07-23 20:36:55 +00002598 __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] =
2599 __u.__p1_.first().__ptr();
Howard Hinnantb24c8022013-07-23 22:01:58 +00002600#if _LIBCPP_DEBUG_LEVEL >= 2
2601 __get_db()->swap(this, &__u);
2602#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002603}
2604
2605template <class _Tp, class _Hash, class _Equal, class _Alloc>
2606typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2607__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const
2608{
Howard Hinnante5c13de2013-07-29 19:05:47 +00002609 _LIBCPP_ASSERT(__n < bucket_count(),
2610 "unordered container::bucket_size(n) called with n >= bucket_count()");
Eric Fiselier40492ba2016-07-23 20:36:55 +00002611 __next_pointer __np = __bucket_list_[__n];
Howard Hinnant3e519522010-05-11 19:42:16 +00002612 size_type __bc = bucket_count();
2613 size_type __r = 0;
2614 if (__np != nullptr)
2615 {
2616 for (__np = __np->__next_; __np != nullptr &&
Eric Fiselier40492ba2016-07-23 20:36:55 +00002617 __constrain_hash(__np->__hash(), __bc) == __n;
Howard Hinnant3e519522010-05-11 19:42:16 +00002618 __np = __np->__next_, ++__r)
2619 ;
2620 }
2621 return __r;
2622}
2623
Howard Hinnant37141072011-06-04 18:54:24 +00002624template <class _Tp, class _Hash, class _Equal, class _Alloc>
2625inline _LIBCPP_INLINE_VISIBILITY
2626void
2627swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x,
2628 __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y)
2629 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2630{
2631 __x.swap(__y);
2632}
2633
Howard Hinnantb24c8022013-07-23 22:01:58 +00002634#if _LIBCPP_DEBUG_LEVEL >= 2
2635
2636template <class _Tp, class _Hash, class _Equal, class _Alloc>
2637bool
2638__hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const
2639{
2640 return __i->__node_ != nullptr;
2641}
2642
2643template <class _Tp, class _Hash, class _Equal, class _Alloc>
2644bool
2645__hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const
2646{
2647 return false;
2648}
2649
2650template <class _Tp, class _Hash, class _Equal, class _Alloc>
2651bool
2652__hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
2653{
2654 return false;
2655}
2656
2657template <class _Tp, class _Hash, class _Equal, class _Alloc>
2658bool
2659__hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
2660{
2661 return false;
2662}
2663
2664#endif // _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiseliera016efb2017-05-31 22:07:49 +00002665
Howard Hinnant3e519522010-05-11 19:42:16 +00002666_LIBCPP_END_NAMESPACE_STD
2667
Eric Fiseliera016efb2017-05-31 22:07:49 +00002668_LIBCPP_POP_MACROS
2669
Howard Hinnant3e519522010-05-11 19:42:16 +00002670#endif // _LIBCPP__HASH_TABLE