blob: cfa763ab217ac79ffa88c29fb55d11204a229189 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-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 Hinnantbc8d3f92010-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>
20
Howard Hinnant66c6f972011-11-29 16:45:27 +000021#include <__undef_min_max>
Saleem Abdulrasoolf1b30c42015-02-13 22:15:32 +000022#include <__undef___deallocate>
Howard Hinnant66c6f972011-11-29 16:45:27 +000023
Eric Fiselierb9536102014-08-10 23:53:08 +000024#include <__debug>
Howard Hinnant8b00e6c2013-08-02 00:26:35 +000025
Howard Hinnant08e17472011-10-17 20:05:10 +000026#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000027#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +000028#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000029
30_LIBCPP_BEGIN_NAMESPACE_STD
31
Howard Hinnant83eade62013-03-06 23:30:19 +000032_LIBCPP_FUNC_VIS
Howard Hinnant2b1b2d42011-06-14 19:58:17 +000033size_t __next_prime(size_t __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000034
35template <class _NodePtr>
36struct __hash_node_base
37{
38 typedef __hash_node_base __first_node;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000039
Howard Hinnantdf85e572011-02-27 18:02:02 +000040 _NodePtr __next_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000041
Howard Hinnant5f2f14c2011-06-04 18:54:24 +000042 _LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043};
44
45template <class _Tp, class _VoidPtr>
46struct __hash_node
47 : public __hash_node_base
48 <
49 typename pointer_traits<_VoidPtr>::template
50#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
51 rebind<__hash_node<_Tp, _VoidPtr> >
52#else
53 rebind<__hash_node<_Tp, _VoidPtr> >::other
54#endif
55 >
56{
57 typedef _Tp value_type;
58
59 size_t __hash_;
60 value_type __value_;
61};
62
Howard Hinnant7a445152012-07-06 17:31:14 +000063inline _LIBCPP_INLINE_VISIBILITY
64bool
Eric Fiselier57947ca2015-02-02 21:31:48 +000065__is_hash_power2(size_t __bc)
Howard Hinnant7a445152012-07-06 17:31:14 +000066{
67 return __bc > 2 && !(__bc & (__bc - 1));
68}
69
70inline _LIBCPP_INLINE_VISIBILITY
71size_t
72__constrain_hash(size_t __h, size_t __bc)
73{
74 return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : __h % __bc;
75}
76
77inline _LIBCPP_INLINE_VISIBILITY
78size_t
Eric Fiselier57947ca2015-02-02 21:31:48 +000079__next_hash_pow2(size_t __n)
Howard Hinnant7a445152012-07-06 17:31:14 +000080{
81 return size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1));
82}
83
Howard Hinnant2b1b2d42011-06-14 19:58:17 +000084template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table;
Howard Hinnant0f678bd2013-08-12 18:38:34 +000085template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
86template <class _HashIterator> class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator;
87template <class _HashIterator> class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000088
89template <class _NodePtr>
Howard Hinnant0f678bd2013-08-12 18:38:34 +000090class _LIBCPP_TYPE_VIS_ONLY __hash_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000091{
92 typedef _NodePtr __node_pointer;
93
94 __node_pointer __node_;
95
96public:
97 typedef forward_iterator_tag iterator_category;
98 typedef typename pointer_traits<__node_pointer>::element_type::value_type value_type;
99 typedef typename pointer_traits<__node_pointer>::difference_type difference_type;
100 typedef value_type& reference;
101 typedef typename pointer_traits<__node_pointer>::template
102#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
103 rebind<value_type>
104#else
105 rebind<value_type>::other
106#endif
107 pointer;
108
Howard Hinnant39213642013-07-23 22:01:58 +0000109 _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT
Marshall Clow193ef032013-08-07 21:30:44 +0000110#if _LIBCPP_STD_VER > 11
111 : __node_(nullptr)
112#endif
Howard Hinnant39213642013-07-23 22:01:58 +0000113 {
114#if _LIBCPP_DEBUG_LEVEL >= 2
115 __get_db()->__insert_i(this);
116#endif
117 }
118
119#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120
Howard Hinnant99acc502010-09-21 17:32:39 +0000121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000122 __hash_iterator(const __hash_iterator& __i)
123 : __node_(__i.__node_)
124 {
125 __get_db()->__iterator_copy(this, &__i);
126 }
127
Howard Hinnant99acc502010-09-21 17:32:39 +0000128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000129 ~__hash_iterator()
130 {
131 __get_db()->__erase_i(this);
132 }
133
134 _LIBCPP_INLINE_VISIBILITY
135 __hash_iterator& operator=(const __hash_iterator& __i)
136 {
137 if (this != &__i)
138 {
139 __get_db()->__iterator_copy(this, &__i);
140 __node_ = __i.__node_;
141 }
142 return *this;
143 }
144
145#endif // _LIBCPP_DEBUG_LEVEL >= 2
146
147 _LIBCPP_INLINE_VISIBILITY
148 reference operator*() const
149 {
150#if _LIBCPP_DEBUG_LEVEL >= 2
151 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
152 "Attempted to dereference a non-dereferenceable unordered container iterator");
153#endif
154 return __node_->__value_;
155 }
156 _LIBCPP_INLINE_VISIBILITY
157 pointer operator->() const
158 {
159#if _LIBCPP_DEBUG_LEVEL >= 2
160 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
161 "Attempted to dereference a non-dereferenceable unordered container iterator");
162#endif
163 return pointer_traits<pointer>::pointer_to(__node_->__value_);
164 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000165
Howard Hinnant99acc502010-09-21 17:32:39 +0000166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000167 __hash_iterator& operator++()
168 {
Howard Hinnant39213642013-07-23 22:01:58 +0000169#if _LIBCPP_DEBUG_LEVEL >= 2
170 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
171 "Attempted to increment non-incrementable unordered container iterator");
172#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000173 __node_ = __node_->__next_;
174 return *this;
175 }
176
Howard Hinnant99acc502010-09-21 17:32:39 +0000177 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000178 __hash_iterator operator++(int)
179 {
180 __hash_iterator __t(*this);
181 ++(*this);
182 return __t;
183 }
184
Howard Hinnant99acc502010-09-21 17:32:39 +0000185 friend _LIBCPP_INLINE_VISIBILITY
186 bool operator==(const __hash_iterator& __x, const __hash_iterator& __y)
Howard Hinnant39213642013-07-23 22:01:58 +0000187 {
Howard Hinnant39213642013-07-23 22:01:58 +0000188 return __x.__node_ == __y.__node_;
189 }
Howard Hinnant99acc502010-09-21 17:32:39 +0000190 friend _LIBCPP_INLINE_VISIBILITY
191 bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y)
Howard Hinnant39213642013-07-23 22:01:58 +0000192 {return !(__x == __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000193
194private:
Howard Hinnant39213642013-07-23 22:01:58 +0000195#if _LIBCPP_DEBUG_LEVEL >= 2
196 _LIBCPP_INLINE_VISIBILITY
197 __hash_iterator(__node_pointer __node, const void* __c) _NOEXCEPT
198 : __node_(__node)
199 {
200 __get_db()->__insert_ic(this, __c);
201 }
202#else
Howard Hinnant99acc502010-09-21 17:32:39 +0000203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000204 __hash_iterator(__node_pointer __node) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000205 : __node_(__node)
206 {}
Howard Hinnant39213642013-07-23 22:01:58 +0000207#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000208
209 template <class, class, class, class> friend class __hash_table;
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000210 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
211 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator;
212 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
213 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000214};
215
216template <class _ConstNodePtr>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000217class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000218{
219 typedef _ConstNodePtr __node_pointer;
220
221 __node_pointer __node_;
222
223 typedef typename remove_const<
224 typename pointer_traits<__node_pointer>::element_type
225 >::type __node;
226
227public:
228 typedef forward_iterator_tag iterator_category;
229 typedef typename __node::value_type value_type;
230 typedef typename pointer_traits<__node_pointer>::difference_type difference_type;
231 typedef const value_type& reference;
232 typedef typename pointer_traits<__node_pointer>::template
233#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
234 rebind<const value_type>
235#else
236 rebind<const value_type>::other
237#endif
238 pointer;
239 typedef typename pointer_traits<__node_pointer>::template
240#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
241 rebind<__node>
242#else
243 rebind<__node>::other
244#endif
245 __non_const_node_pointer;
246 typedef __hash_iterator<__non_const_node_pointer> __non_const_iterator;
247
Howard Hinnant39213642013-07-23 22:01:58 +0000248 _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT
Marshall Clow193ef032013-08-07 21:30:44 +0000249#if _LIBCPP_STD_VER > 11
250 : __node_(nullptr)
251#endif
Howard Hinnant39213642013-07-23 22:01:58 +0000252 {
253#if _LIBCPP_DEBUG_LEVEL >= 2
254 __get_db()->__insert_i(this);
255#endif
256 }
Howard Hinnant99acc502010-09-21 17:32:39 +0000257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000258 __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000259 : __node_(__x.__node_)
Howard Hinnant39213642013-07-23 22:01:58 +0000260 {
261#if _LIBCPP_DEBUG_LEVEL >= 2
262 __get_db()->__iterator_copy(this, &__x);
263#endif
264 }
265
266#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000267
Howard Hinnant99acc502010-09-21 17:32:39 +0000268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000269 __hash_const_iterator(const __hash_const_iterator& __i)
270 : __node_(__i.__node_)
271 {
272 __get_db()->__iterator_copy(this, &__i);
273 }
274
Howard Hinnant99acc502010-09-21 17:32:39 +0000275 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000276 ~__hash_const_iterator()
277 {
278 __get_db()->__erase_i(this);
279 }
280
281 _LIBCPP_INLINE_VISIBILITY
282 __hash_const_iterator& operator=(const __hash_const_iterator& __i)
283 {
284 if (this != &__i)
285 {
286 __get_db()->__iterator_copy(this, &__i);
287 __node_ = __i.__node_;
288 }
289 return *this;
290 }
291
292#endif // _LIBCPP_DEBUG_LEVEL >= 2
293
294 _LIBCPP_INLINE_VISIBILITY
295 reference operator*() const
296 {
297#if _LIBCPP_DEBUG_LEVEL >= 2
298 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
299 "Attempted to dereference a non-dereferenceable unordered container const_iterator");
300#endif
301 return __node_->__value_;
302 }
303 _LIBCPP_INLINE_VISIBILITY
304 pointer operator->() const
305 {
306#if _LIBCPP_DEBUG_LEVEL >= 2
307 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
308 "Attempted to dereference a non-dereferenceable unordered container const_iterator");
309#endif
310 return pointer_traits<pointer>::pointer_to(__node_->__value_);
311 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312
Howard Hinnant99acc502010-09-21 17:32:39 +0000313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000314 __hash_const_iterator& operator++()
315 {
Howard Hinnant39213642013-07-23 22:01:58 +0000316#if _LIBCPP_DEBUG_LEVEL >= 2
317 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
318 "Attempted to increment non-incrementable unordered container const_iterator");
319#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000320 __node_ = __node_->__next_;
321 return *this;
322 }
323
Howard Hinnant99acc502010-09-21 17:32:39 +0000324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325 __hash_const_iterator operator++(int)
326 {
327 __hash_const_iterator __t(*this);
328 ++(*this);
329 return __t;
330 }
331
Howard Hinnant99acc502010-09-21 17:32:39 +0000332 friend _LIBCPP_INLINE_VISIBILITY
333 bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
Howard Hinnant39213642013-07-23 22:01:58 +0000334 {
Howard Hinnant39213642013-07-23 22:01:58 +0000335 return __x.__node_ == __y.__node_;
336 }
Howard Hinnant99acc502010-09-21 17:32:39 +0000337 friend _LIBCPP_INLINE_VISIBILITY
338 bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
Howard Hinnant39213642013-07-23 22:01:58 +0000339 {return !(__x == __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000340
341private:
Howard Hinnant39213642013-07-23 22:01:58 +0000342#if _LIBCPP_DEBUG_LEVEL >= 2
343 _LIBCPP_INLINE_VISIBILITY
344 __hash_const_iterator(__node_pointer __node, const void* __c) _NOEXCEPT
345 : __node_(__node)
346 {
347 __get_db()->__insert_ic(this, __c);
348 }
349#else
Howard Hinnant99acc502010-09-21 17:32:39 +0000350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000351 __hash_const_iterator(__node_pointer __node) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352 : __node_(__node)
353 {}
Howard Hinnant39213642013-07-23 22:01:58 +0000354#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355
356 template <class, class, class, class> friend class __hash_table;
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000357 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
358 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
359 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000360};
361
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000362template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000363
364template <class _NodePtr>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000365class _LIBCPP_TYPE_VIS_ONLY __hash_local_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000366{
367 typedef _NodePtr __node_pointer;
368
369 __node_pointer __node_;
370 size_t __bucket_;
371 size_t __bucket_count_;
372
373 typedef pointer_traits<__node_pointer> __pointer_traits;
374public:
375 typedef forward_iterator_tag iterator_category;
376 typedef typename __pointer_traits::element_type::value_type value_type;
377 typedef typename __pointer_traits::difference_type difference_type;
378 typedef value_type& reference;
379 typedef typename __pointer_traits::template
380#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
381 rebind<value_type>
382#else
383 rebind<value_type>::other
384#endif
385 pointer;
386
Howard Hinnant39213642013-07-23 22:01:58 +0000387 _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT
388 {
389#if _LIBCPP_DEBUG_LEVEL >= 2
390 __get_db()->__insert_i(this);
391#endif
392 }
393
394#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000395
Howard Hinnant99acc502010-09-21 17:32:39 +0000396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000397 __hash_local_iterator(const __hash_local_iterator& __i)
398 : __node_(__i.__node_),
399 __bucket_(__i.__bucket_),
400 __bucket_count_(__i.__bucket_count_)
401 {
402 __get_db()->__iterator_copy(this, &__i);
403 }
404
Howard Hinnant99acc502010-09-21 17:32:39 +0000405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000406 ~__hash_local_iterator()
407 {
408 __get_db()->__erase_i(this);
409 }
410
411 _LIBCPP_INLINE_VISIBILITY
412 __hash_local_iterator& operator=(const __hash_local_iterator& __i)
413 {
414 if (this != &__i)
415 {
416 __get_db()->__iterator_copy(this, &__i);
417 __node_ = __i.__node_;
418 __bucket_ = __i.__bucket_;
419 __bucket_count_ = __i.__bucket_count_;
420 }
421 return *this;
422 }
423
424#endif // _LIBCPP_DEBUG_LEVEL >= 2
425
426 _LIBCPP_INLINE_VISIBILITY
427 reference operator*() const
428 {
429#if _LIBCPP_DEBUG_LEVEL >= 2
430 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
431 "Attempted to dereference a non-dereferenceable unordered container local_iterator");
432#endif
433 return __node_->__value_;
434 }
435 _LIBCPP_INLINE_VISIBILITY
436 pointer operator->() const
437 {
438#if _LIBCPP_DEBUG_LEVEL >= 2
439 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
440 "Attempted to dereference a non-dereferenceable unordered container local_iterator");
441#endif
442 return pointer_traits<pointer>::pointer_to(__node_->__value_);
443 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000444
Howard Hinnant99acc502010-09-21 17:32:39 +0000445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446 __hash_local_iterator& operator++()
447 {
Howard Hinnant39213642013-07-23 22:01:58 +0000448#if _LIBCPP_DEBUG_LEVEL >= 2
449 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
450 "Attempted to increment non-incrementable unordered container local_iterator");
451#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452 __node_ = __node_->__next_;
Howard Hinnant7a445152012-07-06 17:31:14 +0000453 if (__node_ != nullptr && __constrain_hash(__node_->__hash_, __bucket_count_) != __bucket_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000454 __node_ = nullptr;
455 return *this;
456 }
457
Howard Hinnant99acc502010-09-21 17:32:39 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459 __hash_local_iterator operator++(int)
460 {
461 __hash_local_iterator __t(*this);
462 ++(*this);
463 return __t;
464 }
465
Howard Hinnant99acc502010-09-21 17:32:39 +0000466 friend _LIBCPP_INLINE_VISIBILITY
467 bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
Howard Hinnant39213642013-07-23 22:01:58 +0000468 {
Howard Hinnant39213642013-07-23 22:01:58 +0000469 return __x.__node_ == __y.__node_;
470 }
Howard Hinnant99acc502010-09-21 17:32:39 +0000471 friend _LIBCPP_INLINE_VISIBILITY
472 bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
Howard Hinnant39213642013-07-23 22:01:58 +0000473 {return !(__x == __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474
475private:
Howard Hinnant39213642013-07-23 22:01:58 +0000476#if _LIBCPP_DEBUG_LEVEL >= 2
477 _LIBCPP_INLINE_VISIBILITY
478 __hash_local_iterator(__node_pointer __node, size_t __bucket,
479 size_t __bucket_count, const void* __c) _NOEXCEPT
480 : __node_(__node),
481 __bucket_(__bucket),
482 __bucket_count_(__bucket_count)
483 {
484 __get_db()->__insert_ic(this, __c);
485 if (__node_ != nullptr)
486 __node_ = __node_->__next_;
487 }
488#else
Howard Hinnant99acc502010-09-21 17:32:39 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490 __hash_local_iterator(__node_pointer __node, size_t __bucket,
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000491 size_t __bucket_count) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000492 : __node_(__node),
493 __bucket_(__bucket),
494 __bucket_count_(__bucket_count)
495 {
496 if (__node_ != nullptr)
497 __node_ = __node_->__next_;
498 }
Howard Hinnant39213642013-07-23 22:01:58 +0000499#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500 template <class, class, class, class> friend class __hash_table;
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000501 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
502 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000503};
504
505template <class _ConstNodePtr>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000506class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000507{
508 typedef _ConstNodePtr __node_pointer;
509
510 __node_pointer __node_;
511 size_t __bucket_;
512 size_t __bucket_count_;
513
514 typedef pointer_traits<__node_pointer> __pointer_traits;
515 typedef typename __pointer_traits::element_type __node;
516 typedef typename remove_const<__node>::type __non_const_node;
517 typedef typename pointer_traits<__node_pointer>::template
518#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
519 rebind<__non_const_node>
520#else
521 rebind<__non_const_node>::other
522#endif
523 __non_const_node_pointer;
524 typedef __hash_local_iterator<__non_const_node_pointer>
525 __non_const_iterator;
526public:
527 typedef forward_iterator_tag iterator_category;
528 typedef typename remove_const<
529 typename __pointer_traits::element_type::value_type
530 >::type value_type;
531 typedef typename __pointer_traits::difference_type difference_type;
532 typedef const value_type& reference;
533 typedef typename __pointer_traits::template
534#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
535 rebind<const value_type>
536#else
537 rebind<const value_type>::other
538#endif
539 pointer;
540
Howard Hinnant39213642013-07-23 22:01:58 +0000541 _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT
542 {
543#if _LIBCPP_DEBUG_LEVEL >= 2
544 __get_db()->__insert_i(this);
545#endif
546 }
547
Howard Hinnant99acc502010-09-21 17:32:39 +0000548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000549 __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000550 : __node_(__x.__node_),
551 __bucket_(__x.__bucket_),
552 __bucket_count_(__x.__bucket_count_)
Howard Hinnant39213642013-07-23 22:01:58 +0000553 {
554#if _LIBCPP_DEBUG_LEVEL >= 2
555 __get_db()->__iterator_copy(this, &__x);
556#endif
557 }
558
559#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560
Howard Hinnant99acc502010-09-21 17:32:39 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000562 __hash_const_local_iterator(const __hash_const_local_iterator& __i)
563 : __node_(__i.__node_),
564 __bucket_(__i.__bucket_),
565 __bucket_count_(__i.__bucket_count_)
566 {
567 __get_db()->__iterator_copy(this, &__i);
568 }
569
Howard Hinnant99acc502010-09-21 17:32:39 +0000570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000571 ~__hash_const_local_iterator()
572 {
573 __get_db()->__erase_i(this);
574 }
575
576 _LIBCPP_INLINE_VISIBILITY
577 __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i)
578 {
579 if (this != &__i)
580 {
581 __get_db()->__iterator_copy(this, &__i);
582 __node_ = __i.__node_;
583 __bucket_ = __i.__bucket_;
584 __bucket_count_ = __i.__bucket_count_;
585 }
586 return *this;
587 }
588
589#endif // _LIBCPP_DEBUG_LEVEL >= 2
590
591 _LIBCPP_INLINE_VISIBILITY
592 reference operator*() const
593 {
594#if _LIBCPP_DEBUG_LEVEL >= 2
595 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
596 "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
597#endif
598 return __node_->__value_;
599 }
600 _LIBCPP_INLINE_VISIBILITY
601 pointer operator->() const
602 {
603#if _LIBCPP_DEBUG_LEVEL >= 2
604 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
605 "Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
606#endif
607 return pointer_traits<pointer>::pointer_to(__node_->__value_);
608 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000609
Howard Hinnant99acc502010-09-21 17:32:39 +0000610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000611 __hash_const_local_iterator& operator++()
612 {
Howard Hinnant39213642013-07-23 22:01:58 +0000613#if _LIBCPP_DEBUG_LEVEL >= 2
614 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
615 "Attempted to increment non-incrementable unordered container const_local_iterator");
616#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617 __node_ = __node_->__next_;
Howard Hinnant7a445152012-07-06 17:31:14 +0000618 if (__node_ != nullptr && __constrain_hash(__node_->__hash_, __bucket_count_) != __bucket_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619 __node_ = nullptr;
620 return *this;
621 }
622
Howard Hinnant99acc502010-09-21 17:32:39 +0000623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624 __hash_const_local_iterator operator++(int)
625 {
626 __hash_const_local_iterator __t(*this);
627 ++(*this);
628 return __t;
629 }
630
Howard Hinnant99acc502010-09-21 17:32:39 +0000631 friend _LIBCPP_INLINE_VISIBILITY
632 bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
Howard Hinnant39213642013-07-23 22:01:58 +0000633 {
Howard Hinnant39213642013-07-23 22:01:58 +0000634 return __x.__node_ == __y.__node_;
635 }
Howard Hinnant99acc502010-09-21 17:32:39 +0000636 friend _LIBCPP_INLINE_VISIBILITY
637 bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
Howard Hinnant39213642013-07-23 22:01:58 +0000638 {return !(__x == __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639
640private:
Howard Hinnant39213642013-07-23 22:01:58 +0000641#if _LIBCPP_DEBUG_LEVEL >= 2
642 _LIBCPP_INLINE_VISIBILITY
643 __hash_const_local_iterator(__node_pointer __node, size_t __bucket,
644 size_t __bucket_count, const void* __c) _NOEXCEPT
645 : __node_(__node),
646 __bucket_(__bucket),
647 __bucket_count_(__bucket_count)
648 {
649 __get_db()->__insert_ic(this, __c);
650 if (__node_ != nullptr)
651 __node_ = __node_->__next_;
652 }
653#else
Howard Hinnant99acc502010-09-21 17:32:39 +0000654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655 __hash_const_local_iterator(__node_pointer __node, size_t __bucket,
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000656 size_t __bucket_count) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657 : __node_(__node),
658 __bucket_(__bucket),
659 __bucket_count_(__bucket_count)
660 {
661 if (__node_ != nullptr)
662 __node_ = __node_->__next_;
663 }
Howard Hinnant39213642013-07-23 22:01:58 +0000664#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665 template <class, class, class, class> friend class __hash_table;
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000666 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667};
668
669template <class _Alloc>
670class __bucket_list_deallocator
671{
672 typedef _Alloc allocator_type;
673 typedef allocator_traits<allocator_type> __alloc_traits;
674 typedef typename __alloc_traits::size_type size_type;
675
676 __compressed_pair<size_type, allocator_type> __data_;
677public:
678 typedef typename __alloc_traits::pointer pointer;
679
Howard Hinnant99acc502010-09-21 17:32:39 +0000680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000681 __bucket_list_deallocator()
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000682 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000683 : __data_(0) {}
Howard Hinnant99acc502010-09-21 17:32:39 +0000684
685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686 __bucket_list_deallocator(const allocator_type& __a, size_type __size)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000687 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688 : __data_(__size, __a) {}
689
Howard Hinnant73d21a42010-09-04 23:28:19 +0000690#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000691
Howard Hinnant99acc502010-09-21 17:32:39 +0000692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693 __bucket_list_deallocator(__bucket_list_deallocator&& __x)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000694 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000695 : __data_(_VSTD::move(__x.__data_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000696 {
697 __x.size() = 0;
698 }
699
Howard Hinnant73d21a42010-09-04 23:28:19 +0000700#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000701
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000702 _LIBCPP_INLINE_VISIBILITY
703 size_type& size() _NOEXCEPT {return __data_.first();}
704 _LIBCPP_INLINE_VISIBILITY
705 size_type size() const _NOEXCEPT {return __data_.first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000706
Howard Hinnant99acc502010-09-21 17:32:39 +0000707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000708 allocator_type& __alloc() _NOEXCEPT {return __data_.second();}
709 _LIBCPP_INLINE_VISIBILITY
710 const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();}
711
712 _LIBCPP_INLINE_VISIBILITY
713 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 {
715 __alloc_traits::deallocate(__alloc(), __p, size());
716 }
717};
718
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000719template <class _Alloc> class __hash_map_node_destructor;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000720
721template <class _Alloc>
722class __hash_node_destructor
723{
724 typedef _Alloc allocator_type;
725 typedef allocator_traits<allocator_type> __alloc_traits;
726 typedef typename __alloc_traits::value_type::value_type value_type;
727public:
728 typedef typename __alloc_traits::pointer pointer;
729private:
730
731 allocator_type& __na_;
732
733 __hash_node_destructor& operator=(const __hash_node_destructor&);
734
735public:
736 bool __value_constructed;
737
Howard Hinnant99acc502010-09-21 17:32:39 +0000738 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant199d0ae2011-07-31 17:04:30 +0000739 explicit __hash_node_destructor(allocator_type& __na,
740 bool __constructed = false) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741 : __na_(__na),
Howard Hinnant199d0ae2011-07-31 17:04:30 +0000742 __value_constructed(__constructed)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743 {}
744
Howard Hinnant99acc502010-09-21 17:32:39 +0000745 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000746 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747 {
748 if (__value_constructed)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000749 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000750 if (__p)
751 __alloc_traits::deallocate(__na_, __p, 1);
752 }
753
754 template <class> friend class __hash_map_node_destructor;
755};
756
757template <class _Tp, class _Hash, class _Equal, class _Alloc>
758class __hash_table
759{
760public:
761 typedef _Tp value_type;
762 typedef _Hash hasher;
763 typedef _Equal key_equal;
764 typedef _Alloc allocator_type;
765
766private:
767 typedef allocator_traits<allocator_type> __alloc_traits;
768public:
769 typedef value_type& reference;
770 typedef const value_type& const_reference;
771 typedef typename __alloc_traits::pointer pointer;
772 typedef typename __alloc_traits::const_pointer const_pointer;
773 typedef typename __alloc_traits::size_type size_type;
774 typedef typename __alloc_traits::difference_type difference_type;
775public:
776 // Create __node
777 typedef __hash_node<value_type, typename __alloc_traits::void_pointer> __node;
Marshall Clow66302c62015-04-07 05:21:38 +0000778 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779 typedef allocator_traits<__node_allocator> __node_traits;
780 typedef typename __node_traits::pointer __node_pointer;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000781 typedef typename __node_traits::pointer __node_const_pointer;
Howard Hinnantf8880d02011-12-12 17:26:24 +0000782 typedef __hash_node_base<__node_pointer> __first_node;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000783 typedef typename pointer_traits<__node_pointer>::template
784#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
785 rebind<__first_node>
786#else
787 rebind<__first_node>::other
788#endif
789 __node_base_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000790
791private:
792
Marshall Clow66302c62015-04-07 05:21:38 +0000793 typedef typename __rebind_alloc_helper<__node_traits, __node_pointer>::type __pointer_allocator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000794 typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter;
795 typedef unique_ptr<__node_pointer[], __bucket_list_deleter> __bucket_list;
796 typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits;
797 typedef typename __bucket_list_deleter::pointer __node_pointer_pointer;
798
799 // --- Member data begin ---
800 __bucket_list __bucket_list_;
801 __compressed_pair<__first_node, __node_allocator> __p1_;
802 __compressed_pair<size_type, hasher> __p2_;
803 __compressed_pair<float, key_equal> __p3_;
804 // --- Member data end ---
805
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000806 _LIBCPP_INLINE_VISIBILITY
807 size_type& size() _NOEXCEPT {return __p2_.first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000808public:
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000809 _LIBCPP_INLINE_VISIBILITY
810 size_type size() const _NOEXCEPT {return __p2_.first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000811
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000812 _LIBCPP_INLINE_VISIBILITY
813 hasher& hash_function() _NOEXCEPT {return __p2_.second();}
814 _LIBCPP_INLINE_VISIBILITY
815 const hasher& hash_function() const _NOEXCEPT {return __p2_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000816
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000817 _LIBCPP_INLINE_VISIBILITY
818 float& max_load_factor() _NOEXCEPT {return __p3_.first();}
819 _LIBCPP_INLINE_VISIBILITY
820 float max_load_factor() const _NOEXCEPT {return __p3_.first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000821
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000822 _LIBCPP_INLINE_VISIBILITY
823 key_equal& key_eq() _NOEXCEPT {return __p3_.second();}
824 _LIBCPP_INLINE_VISIBILITY
825 const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000826
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000827 _LIBCPP_INLINE_VISIBILITY
828 __node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();}
829 _LIBCPP_INLINE_VISIBILITY
830 const __node_allocator& __node_alloc() const _NOEXCEPT
831 {return __p1_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000832
833public:
834 typedef __hash_iterator<__node_pointer> iterator;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000835 typedef __hash_const_iterator<__node_pointer> const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000836 typedef __hash_local_iterator<__node_pointer> local_iterator;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000837 typedef __hash_const_local_iterator<__node_pointer> const_local_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000840 __hash_table()
841 _NOEXCEPT_(
842 is_nothrow_default_constructible<__bucket_list>::value &&
843 is_nothrow_default_constructible<__first_node>::value &&
844 is_nothrow_default_constructible<__node_allocator>::value &&
845 is_nothrow_default_constructible<hasher>::value &&
846 is_nothrow_default_constructible<key_equal>::value);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000848 __hash_table(const hasher& __hf, const key_equal& __eql);
849 __hash_table(const hasher& __hf, const key_equal& __eql,
850 const allocator_type& __a);
851 explicit __hash_table(const allocator_type& __a);
852 __hash_table(const __hash_table& __u);
853 __hash_table(const __hash_table& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000854#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000855 __hash_table(__hash_table&& __u)
856 _NOEXCEPT_(
857 is_nothrow_move_constructible<__bucket_list>::value &&
858 is_nothrow_move_constructible<__first_node>::value &&
859 is_nothrow_move_constructible<__node_allocator>::value &&
860 is_nothrow_move_constructible<hasher>::value &&
861 is_nothrow_move_constructible<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 __hash_table(__hash_table&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000863#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864 ~__hash_table();
865
866 __hash_table& operator=(const __hash_table& __u);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000867#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000869 __hash_table& operator=(__hash_table&& __u)
870 _NOEXCEPT_(
871 __node_traits::propagate_on_container_move_assignment::value &&
872 is_nothrow_move_assignable<__node_allocator>::value &&
873 is_nothrow_move_assignable<hasher>::value &&
874 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875#endif
876 template <class _InputIterator>
877 void __assign_unique(_InputIterator __first, _InputIterator __last);
878 template <class _InputIterator>
879 void __assign_multi(_InputIterator __first, _InputIterator __last);
880
Howard Hinnant99acc502010-09-21 17:32:39 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000882 size_type max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883 {
884 return allocator_traits<__pointer_allocator>::max_size(
885 __bucket_list_.get_deleter().__alloc());
886 }
887
888 pair<iterator, bool> __node_insert_unique(__node_pointer __nd);
889 iterator __node_insert_multi(__node_pointer __nd);
890 iterator __node_insert_multi(const_iterator __p,
891 __node_pointer __nd);
892
Howard Hinnant73d21a42010-09-04 23:28:19 +0000893#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894 template <class... _Args>
895 pair<iterator, bool> __emplace_unique(_Args&&... __args);
896 template <class... _Args>
897 iterator __emplace_multi(_Args&&... __args);
898 template <class... _Args>
899 iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000900#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901
Eric Fiselierfdae69a2015-06-13 07:18:32 +0000902#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
903 template <class _ValueTp>
904 _LIBCPP_INLINE_VISIBILITY
905 pair<iterator, bool> __insert_unique_value(_ValueTp&& __x);
906#else
907 _LIBCPP_INLINE_VISIBILITY
908 pair<iterator, bool> __insert_unique_value(const value_type& __x);
909#endif
910
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000911 pair<iterator, bool> __insert_unique(const value_type& __x);
912
Howard Hinnant73d21a42010-09-04 23:28:19 +0000913#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Eric Fiselierfdae69a2015-06-13 07:18:32 +0000914 pair<iterator, bool> __insert_unique(value_type&& __x);
Howard Hinnant99968442011-11-29 18:15:50 +0000915 template <class _Pp>
Eric Fiselierfdae69a2015-06-13 07:18:32 +0000916 pair<iterator, bool> __insert_unique(_Pp&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000917#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918
Howard Hinnant73d21a42010-09-04 23:28:19 +0000919#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000920 template <class _Pp>
921 iterator __insert_multi(_Pp&& __x);
922 template <class _Pp>
923 iterator __insert_multi(const_iterator __p, _Pp&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000924#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925 iterator __insert_multi(const value_type& __x);
926 iterator __insert_multi(const_iterator __p, const value_type& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000927#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000928
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000929 void clear() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000930 void rehash(size_type __n);
Howard Hinnant99acc502010-09-21 17:32:39 +0000931 _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000932 {rehash(static_cast<size_type>(ceil(__n / max_load_factor())));}
Howard Hinnant99acc502010-09-21 17:32:39 +0000933
934 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000935 size_type bucket_count() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936 {
937 return __bucket_list_.get_deleter().size();
938 }
939
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000941 iterator begin() _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000943 iterator end() _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000945 const_iterator begin() const _NOEXCEPT;
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000947 const_iterator end() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000948
949 template <class _Key>
Howard Hinnant99acc502010-09-21 17:32:39 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951 size_type bucket(const _Key& __k) const
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +0000952 {
953 _LIBCPP_ASSERT(bucket_count() > 0,
954 "unordered container::bucket(key) called when bucket_count() == 0");
955 return __constrain_hash(hash_function()(__k), bucket_count());
956 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000957
958 template <class _Key>
959 iterator find(const _Key& __x);
960 template <class _Key>
961 const_iterator find(const _Key& __x) const;
962
Howard Hinnant99968442011-11-29 18:15:50 +0000963 typedef __hash_node_destructor<__node_allocator> _Dp;
964 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000965
966 iterator erase(const_iterator __p);
967 iterator erase(const_iterator __first, const_iterator __last);
968 template <class _Key>
969 size_type __erase_unique(const _Key& __k);
970 template <class _Key>
971 size_type __erase_multi(const _Key& __k);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000972 __node_holder remove(const_iterator __p) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973
974 template <class _Key>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976 size_type __count_unique(const _Key& __k) const;
977 template <class _Key>
978 size_type __count_multi(const _Key& __k) const;
979
980 template <class _Key>
981 pair<iterator, iterator>
982 __equal_range_unique(const _Key& __k);
983 template <class _Key>
984 pair<const_iterator, const_iterator>
985 __equal_range_unique(const _Key& __k) const;
986
987 template <class _Key>
988 pair<iterator, iterator>
989 __equal_range_multi(const _Key& __k);
990 template <class _Key>
991 pair<const_iterator, const_iterator>
992 __equal_range_multi(const _Key& __k) const;
993
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000994 void swap(__hash_table& __u)
Eric Fiselier692177d2015-07-18 20:40:46 +0000995#if _LIBCPP_STD_VER <= 11
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000996 _NOEXCEPT_(
Marshall Clow7d914d12015-07-13 20:04:56 +0000997 __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
Marshall Clow7d914d12015-07-13 20:04:56 +0000998 && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
999 || __is_nothrow_swappable<__pointer_allocator>::value)
1000 && (!__node_traits::propagate_on_container_swap::value
1001 || __is_nothrow_swappable<__node_allocator>::value)
Marshall Clow7d914d12015-07-13 20:04:56 +00001002 );
Eric Fiselier692177d2015-07-18 20:40:46 +00001003#else
1004 _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value);
1005#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001006
Howard Hinnant99acc502010-09-21 17:32:39 +00001007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001008 size_type max_bucket_count() const _NOEXCEPT
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001009 {return __pointer_alloc_traits::max_size(__bucket_list_.get_deleter().__alloc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010 size_type bucket_size(size_type __n) const;
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001011 _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001012 {
1013 size_type __bc = bucket_count();
1014 return __bc != 0 ? (float)size() / __bc : 0.f;
1015 }
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001016 _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001017 {
1018 _LIBCPP_ASSERT(__mlf > 0,
1019 "unordered container::max_load_factor(lf) called with lf <= 0");
1020 max_load_factor() = _VSTD::max(__mlf, load_factor());
1021 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001022
Howard Hinnant39213642013-07-23 22:01:58 +00001023 _LIBCPP_INLINE_VISIBILITY
1024 local_iterator
1025 begin(size_type __n)
1026 {
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001027 _LIBCPP_ASSERT(__n < bucket_count(),
1028 "unordered container::begin(n) called with n >= bucket_count()");
Howard Hinnant39213642013-07-23 22:01:58 +00001029#if _LIBCPP_DEBUG_LEVEL >= 2
1030 return local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
1031#else
1032 return local_iterator(__bucket_list_[__n], __n, bucket_count());
1033#endif
1034 }
1035
1036 _LIBCPP_INLINE_VISIBILITY
1037 local_iterator
1038 end(size_type __n)
1039 {
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001040 _LIBCPP_ASSERT(__n < bucket_count(),
1041 "unordered container::end(n) called with n >= bucket_count()");
Howard Hinnant39213642013-07-23 22:01:58 +00001042#if _LIBCPP_DEBUG_LEVEL >= 2
1043 return local_iterator(nullptr, __n, bucket_count(), this);
1044#else
1045 return local_iterator(nullptr, __n, bucket_count());
1046#endif
1047 }
1048
1049 _LIBCPP_INLINE_VISIBILITY
1050 const_local_iterator
1051 cbegin(size_type __n) const
1052 {
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001053 _LIBCPP_ASSERT(__n < bucket_count(),
1054 "unordered container::cbegin(n) called with n >= bucket_count()");
Howard Hinnant39213642013-07-23 22:01:58 +00001055#if _LIBCPP_DEBUG_LEVEL >= 2
1056 return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
1057#else
1058 return const_local_iterator(__bucket_list_[__n], __n, bucket_count());
1059#endif
1060 }
1061
1062 _LIBCPP_INLINE_VISIBILITY
1063 const_local_iterator
1064 cend(size_type __n) const
1065 {
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001066 _LIBCPP_ASSERT(__n < bucket_count(),
1067 "unordered container::cend(n) called with n >= bucket_count()");
Howard Hinnant39213642013-07-23 22:01:58 +00001068#if _LIBCPP_DEBUG_LEVEL >= 2
1069 return const_local_iterator(nullptr, __n, bucket_count(), this);
1070#else
1071 return const_local_iterator(nullptr, __n, bucket_count());
1072#endif
1073 }
1074
1075#if _LIBCPP_DEBUG_LEVEL >= 2
1076
1077 bool __dereferenceable(const const_iterator* __i) const;
1078 bool __decrementable(const const_iterator* __i) const;
1079 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1080 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1081
1082#endif // _LIBCPP_DEBUG_LEVEL >= 2
1083
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001084private:
1085 void __rehash(size_type __n);
1086
Howard Hinnant73d21a42010-09-04 23:28:19 +00001087#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1088#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089 template <class ..._Args>
1090 __node_holder __construct_node(_Args&& ...__args);
Howard Hinnantbfd55302010-09-04 23:46:48 +00001091#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001092 __node_holder __construct_node(value_type&& __v, size_t __hash);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001093#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094 __node_holder __construct_node(const value_type& __v);
1095#endif
1096 __node_holder __construct_node(const value_type& __v, size_t __hash);
1097
Howard Hinnant99acc502010-09-21 17:32:39 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001099 void __copy_assign_alloc(const __hash_table& __u)
1100 {__copy_assign_alloc(__u, integral_constant<bool,
1101 __node_traits::propagate_on_container_copy_assignment::value>());}
1102 void __copy_assign_alloc(const __hash_table& __u, true_type);
Howard Hinnant99acc502010-09-21 17:32:39 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001104 void __copy_assign_alloc(const __hash_table&, false_type) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105
1106 void __move_assign(__hash_table& __u, false_type);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001107 void __move_assign(__hash_table& __u, true_type)
1108 _NOEXCEPT_(
1109 is_nothrow_move_assignable<__node_allocator>::value &&
1110 is_nothrow_move_assignable<hasher>::value &&
1111 is_nothrow_move_assignable<key_equal>::value);
1112 _LIBCPP_INLINE_VISIBILITY
1113 void __move_assign_alloc(__hash_table& __u)
1114 _NOEXCEPT_(
1115 !__node_traits::propagate_on_container_move_assignment::value ||
1116 (is_nothrow_move_assignable<__pointer_allocator>::value &&
1117 is_nothrow_move_assignable<__node_allocator>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001118 {__move_assign_alloc(__u, integral_constant<bool,
1119 __node_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnant99acc502010-09-21 17:32:39 +00001120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001121 void __move_assign_alloc(__hash_table& __u, true_type)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001122 _NOEXCEPT_(
1123 is_nothrow_move_assignable<__pointer_allocator>::value &&
1124 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001125 {
1126 __bucket_list_.get_deleter().__alloc() =
Howard Hinnant0949eed2011-06-30 21:18:19 +00001127 _VSTD::move(__u.__bucket_list_.get_deleter().__alloc());
1128 __node_alloc() = _VSTD::move(__u.__node_alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001129 }
Howard Hinnant99acc502010-09-21 17:32:39 +00001130 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001131 void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001132
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001133 void __deallocate(__node_pointer __np) _NOEXCEPT;
1134 __node_pointer __detach() _NOEXCEPT;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001135
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001136 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
1137 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001138};
1139
1140template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001141inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001142__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table()
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001143 _NOEXCEPT_(
1144 is_nothrow_default_constructible<__bucket_list>::value &&
1145 is_nothrow_default_constructible<__first_node>::value &&
Eric Fiselierc8f54c22015-12-16 00:53:04 +00001146 is_nothrow_default_constructible<__node_allocator>::value &&
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001147 is_nothrow_default_constructible<hasher>::value &&
1148 is_nothrow_default_constructible<key_equal>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149 : __p2_(0),
1150 __p3_(1.0f)
1151{
1152}
1153
1154template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001155inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001156__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
1157 const key_equal& __eql)
1158 : __bucket_list_(nullptr, __bucket_list_deleter()),
1159 __p1_(),
1160 __p2_(0, __hf),
1161 __p3_(1.0f, __eql)
1162{
1163}
1164
1165template <class _Tp, class _Hash, class _Equal, class _Alloc>
1166__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
1167 const key_equal& __eql,
1168 const allocator_type& __a)
1169 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1170 __p1_(__node_allocator(__a)),
1171 __p2_(0, __hf),
1172 __p3_(1.0f, __eql)
1173{
1174}
1175
1176template <class _Tp, class _Hash, class _Equal, class _Alloc>
1177__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a)
1178 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1179 __p1_(__node_allocator(__a)),
1180 __p2_(0),
1181 __p3_(1.0f)
1182{
1183}
1184
1185template <class _Tp, class _Hash, class _Equal, class _Alloc>
1186__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u)
1187 : __bucket_list_(nullptr,
1188 __bucket_list_deleter(allocator_traits<__pointer_allocator>::
1189 select_on_container_copy_construction(
1190 __u.__bucket_list_.get_deleter().__alloc()), 0)),
1191 __p1_(allocator_traits<__node_allocator>::
1192 select_on_container_copy_construction(__u.__node_alloc())),
1193 __p2_(0, __u.hash_function()),
1194 __p3_(__u.__p3_)
1195{
1196}
1197
1198template <class _Tp, class _Hash, class _Equal, class _Alloc>
1199__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u,
1200 const allocator_type& __a)
1201 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1202 __p1_(__node_allocator(__a)),
1203 __p2_(0, __u.hash_function()),
1204 __p3_(__u.__p3_)
1205{
1206}
1207
Howard Hinnant73d21a42010-09-04 23:28:19 +00001208#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001209
1210template <class _Tp, class _Hash, class _Equal, class _Alloc>
1211__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001212 _NOEXCEPT_(
1213 is_nothrow_move_constructible<__bucket_list>::value &&
1214 is_nothrow_move_constructible<__first_node>::value &&
Eric Fiselierc8f54c22015-12-16 00:53:04 +00001215 is_nothrow_move_constructible<__node_allocator>::value &&
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001216 is_nothrow_move_constructible<hasher>::value &&
1217 is_nothrow_move_constructible<key_equal>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001218 : __bucket_list_(_VSTD::move(__u.__bucket_list_)),
1219 __p1_(_VSTD::move(__u.__p1_)),
1220 __p2_(_VSTD::move(__u.__p2_)),
1221 __p3_(_VSTD::move(__u.__p3_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222{
1223 if (size() > 0)
1224 {
Howard Hinnant7a445152012-07-06 17:31:14 +00001225 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001226 static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227 __u.__p1_.first().__next_ = nullptr;
1228 __u.size() = 0;
1229 }
1230}
1231
1232template <class _Tp, class _Hash, class _Equal, class _Alloc>
1233__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u,
1234 const allocator_type& __a)
1235 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1236 __p1_(__node_allocator(__a)),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001237 __p2_(0, _VSTD::move(__u.hash_function())),
1238 __p3_(_VSTD::move(__u.__p3_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001239{
1240 if (__a == allocator_type(__u.__node_alloc()))
1241 {
1242 __bucket_list_.reset(__u.__bucket_list_.release());
1243 __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
1244 __u.__bucket_list_.get_deleter().size() = 0;
1245 if (__u.size() > 0)
1246 {
1247 __p1_.first().__next_ = __u.__p1_.first().__next_;
1248 __u.__p1_.first().__next_ = nullptr;
Howard Hinnant7a445152012-07-06 17:31:14 +00001249 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001250 static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001251 size() = __u.size();
1252 __u.size() = 0;
1253 }
1254 }
1255}
1256
Howard Hinnant73d21a42010-09-04 23:28:19 +00001257#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258
1259template <class _Tp, class _Hash, class _Equal, class _Alloc>
1260__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
1261{
1262 __deallocate(__p1_.first().__next_);
Howard Hinnant39213642013-07-23 22:01:58 +00001263#if _LIBCPP_DEBUG_LEVEL >= 2
1264 __get_db()->__erase_c(this);
1265#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001266}
1267
1268template <class _Tp, class _Hash, class _Equal, class _Alloc>
1269void
1270__hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc(
1271 const __hash_table& __u, true_type)
1272{
1273 if (__node_alloc() != __u.__node_alloc())
1274 {
1275 clear();
1276 __bucket_list_.reset();
1277 __bucket_list_.get_deleter().size() = 0;
1278 }
1279 __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc();
1280 __node_alloc() = __u.__node_alloc();
1281}
1282
1283template <class _Tp, class _Hash, class _Equal, class _Alloc>
1284__hash_table<_Tp, _Hash, _Equal, _Alloc>&
1285__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u)
1286{
1287 if (this != &__u)
1288 {
1289 __copy_assign_alloc(__u);
1290 hash_function() = __u.hash_function();
1291 key_eq() = __u.key_eq();
1292 max_load_factor() = __u.max_load_factor();
1293 __assign_multi(__u.begin(), __u.end());
1294 }
1295 return *this;
1296}
1297
1298template <class _Tp, class _Hash, class _Equal, class _Alloc>
1299void
1300__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate(__node_pointer __np)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001301 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001302{
1303 __node_allocator& __na = __node_alloc();
1304 while (__np != nullptr)
1305 {
1306 __node_pointer __next = __np->__next_;
Howard Hinnant39213642013-07-23 22:01:58 +00001307#if _LIBCPP_DEBUG_LEVEL >= 2
1308 __c_node* __c = __get_db()->__find_c_and_lock(this);
1309 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1310 {
1311 --__p;
1312 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1313 if (__i->__node_ == __np)
1314 {
1315 (*__p)->__c_ = nullptr;
1316 if (--__c->end_ != __p)
1317 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1318 }
1319 }
1320 __get_db()->unlock();
1321#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001322 __node_traits::destroy(__na, _VSTD::addressof(__np->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323 __node_traits::deallocate(__na, __np, 1);
1324 __np = __next;
1325 }
1326}
1327
1328template <class _Tp, class _Hash, class _Equal, class _Alloc>
1329typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_pointer
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001330__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001331{
1332 size_type __bc = bucket_count();
1333 for (size_type __i = 0; __i < __bc; ++__i)
1334 __bucket_list_[__i] = nullptr;
1335 size() = 0;
1336 __node_pointer __cache = __p1_.first().__next_;
1337 __p1_.first().__next_ = nullptr;
1338 return __cache;
1339}
1340
Howard Hinnant73d21a42010-09-04 23:28:19 +00001341#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001342
1343template <class _Tp, class _Hash, class _Equal, class _Alloc>
1344void
1345__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
1346 __hash_table& __u, true_type)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001347 _NOEXCEPT_(
1348 is_nothrow_move_assignable<__node_allocator>::value &&
1349 is_nothrow_move_assignable<hasher>::value &&
1350 is_nothrow_move_assignable<key_equal>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001351{
1352 clear();
1353 __bucket_list_.reset(__u.__bucket_list_.release());
1354 __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
1355 __u.__bucket_list_.get_deleter().size() = 0;
1356 __move_assign_alloc(__u);
1357 size() = __u.size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001358 hash_function() = _VSTD::move(__u.hash_function());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001359 max_load_factor() = __u.max_load_factor();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001360 key_eq() = _VSTD::move(__u.key_eq());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001361 __p1_.first().__next_ = __u.__p1_.first().__next_;
1362 if (size() > 0)
1363 {
Howard Hinnant7a445152012-07-06 17:31:14 +00001364 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001365 static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001366 __u.__p1_.first().__next_ = nullptr;
1367 __u.size() = 0;
1368 }
Howard Hinnant39213642013-07-23 22:01:58 +00001369#if _LIBCPP_DEBUG_LEVEL >= 2
1370 __get_db()->swap(this, &__u);
1371#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001372}
1373
1374template <class _Tp, class _Hash, class _Equal, class _Alloc>
1375void
1376__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
1377 __hash_table& __u, false_type)
1378{
1379 if (__node_alloc() == __u.__node_alloc())
1380 __move_assign(__u, true_type());
1381 else
1382 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001383 hash_function() = _VSTD::move(__u.hash_function());
1384 key_eq() = _VSTD::move(__u.key_eq());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001385 max_load_factor() = __u.max_load_factor();
1386 if (bucket_count() != 0)
1387 {
1388 __node_pointer __cache = __detach();
1389#ifndef _LIBCPP_NO_EXCEPTIONS
1390 try
1391 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001392#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393 const_iterator __i = __u.begin();
1394 while (__cache != nullptr && __u.size() != 0)
1395 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001396 __cache->__value_ = _VSTD::move(__u.remove(__i++)->__value_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001397 __node_pointer __next = __cache->__next_;
1398 __node_insert_multi(__cache);
1399 __cache = __next;
1400 }
1401#ifndef _LIBCPP_NO_EXCEPTIONS
1402 }
1403 catch (...)
1404 {
1405 __deallocate(__cache);
1406 throw;
1407 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001408#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409 __deallocate(__cache);
1410 }
1411 const_iterator __i = __u.begin();
1412 while (__u.size() != 0)
1413 {
1414 __node_holder __h =
Howard Hinnant0949eed2011-06-30 21:18:19 +00001415 __construct_node(_VSTD::move(__u.remove(__i++)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001416 __node_insert_multi(__h.get());
1417 __h.release();
1418 }
1419 }
1420}
1421
1422template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001423inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001424__hash_table<_Tp, _Hash, _Equal, _Alloc>&
1425__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001426 _NOEXCEPT_(
1427 __node_traits::propagate_on_container_move_assignment::value &&
1428 is_nothrow_move_assignable<__node_allocator>::value &&
1429 is_nothrow_move_assignable<hasher>::value &&
1430 is_nothrow_move_assignable<key_equal>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001431{
1432 __move_assign(__u, integral_constant<bool,
1433 __node_traits::propagate_on_container_move_assignment::value>());
1434 return *this;
1435}
1436
Howard Hinnant73d21a42010-09-04 23:28:19 +00001437#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438
1439template <class _Tp, class _Hash, class _Equal, class _Alloc>
1440template <class _InputIterator>
1441void
1442__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first,
1443 _InputIterator __last)
1444{
1445 if (bucket_count() != 0)
1446 {
1447 __node_pointer __cache = __detach();
1448#ifndef _LIBCPP_NO_EXCEPTIONS
1449 try
1450 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001451#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452 for (; __cache != nullptr && __first != __last; ++__first)
1453 {
1454 __cache->__value_ = *__first;
1455 __node_pointer __next = __cache->__next_;
1456 __node_insert_unique(__cache);
1457 __cache = __next;
1458 }
1459#ifndef _LIBCPP_NO_EXCEPTIONS
1460 }
1461 catch (...)
1462 {
1463 __deallocate(__cache);
1464 throw;
1465 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001466#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001467 __deallocate(__cache);
1468 }
1469 for (; __first != __last; ++__first)
1470 __insert_unique(*__first);
1471}
1472
1473template <class _Tp, class _Hash, class _Equal, class _Alloc>
1474template <class _InputIterator>
1475void
1476__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first,
1477 _InputIterator __last)
1478{
1479 if (bucket_count() != 0)
1480 {
1481 __node_pointer __cache = __detach();
1482#ifndef _LIBCPP_NO_EXCEPTIONS
1483 try
1484 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001485#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486 for (; __cache != nullptr && __first != __last; ++__first)
1487 {
1488 __cache->__value_ = *__first;
1489 __node_pointer __next = __cache->__next_;
1490 __node_insert_multi(__cache);
1491 __cache = __next;
1492 }
1493#ifndef _LIBCPP_NO_EXCEPTIONS
1494 }
1495 catch (...)
1496 {
1497 __deallocate(__cache);
1498 throw;
1499 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001500#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001501 __deallocate(__cache);
1502 }
1503 for (; __first != __last; ++__first)
1504 __insert_multi(*__first);
1505}
1506
1507template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001508inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001509typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001510__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511{
Howard Hinnant39213642013-07-23 22:01:58 +00001512#if _LIBCPP_DEBUG_LEVEL >= 2
1513 return iterator(__p1_.first().__next_, this);
1514#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515 return iterator(__p1_.first().__next_);
Howard Hinnant39213642013-07-23 22:01:58 +00001516#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001517}
1518
1519template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001520inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001521typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001522__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001523{
Howard Hinnant39213642013-07-23 22:01:58 +00001524#if _LIBCPP_DEBUG_LEVEL >= 2
1525 return iterator(nullptr, this);
1526#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001527 return iterator(nullptr);
Howard Hinnant39213642013-07-23 22:01:58 +00001528#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001529}
1530
1531template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001532inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001533typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001534__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001535{
Howard Hinnant39213642013-07-23 22:01:58 +00001536#if _LIBCPP_DEBUG_LEVEL >= 2
1537 return const_iterator(__p1_.first().__next_, this);
1538#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001539 return const_iterator(__p1_.first().__next_);
Howard Hinnant39213642013-07-23 22:01:58 +00001540#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001541}
1542
1543template <class _Tp, class _Hash, class _Equal, class _Alloc>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001544inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001546__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001547{
Howard Hinnant39213642013-07-23 22:01:58 +00001548#if _LIBCPP_DEBUG_LEVEL >= 2
1549 return const_iterator(nullptr, this);
1550#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001551 return const_iterator(nullptr);
Howard Hinnant39213642013-07-23 22:01:58 +00001552#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001553}
1554
1555template <class _Tp, class _Hash, class _Equal, class _Alloc>
1556void
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001557__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001558{
1559 if (size() > 0)
1560 {
1561 __deallocate(__p1_.first().__next_);
1562 __p1_.first().__next_ = nullptr;
1563 size_type __bc = bucket_count();
Howard Hinnant9f66bff2011-07-05 14:14:17 +00001564 for (size_type __i = 0; __i < __bc; ++__i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001565 __bucket_list_[__i] = nullptr;
1566 size() = 0;
1567 }
1568}
1569
1570template <class _Tp, class _Hash, class _Equal, class _Alloc>
1571pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1572__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd)
1573{
1574 __nd->__hash_ = hash_function()(__nd->__value_);
1575 size_type __bc = bucket_count();
1576 bool __inserted = false;
1577 __node_pointer __ndptr;
1578 size_t __chash;
1579 if (__bc != 0)
1580 {
Howard Hinnant7a445152012-07-06 17:31:14 +00001581 __chash = __constrain_hash(__nd->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001582 __ndptr = __bucket_list_[__chash];
1583 if (__ndptr != nullptr)
1584 {
1585 for (__ndptr = __ndptr->__next_; __ndptr != nullptr &&
Howard Hinnant7a445152012-07-06 17:31:14 +00001586 __constrain_hash(__ndptr->__hash_, __bc) == __chash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001587 __ndptr = __ndptr->__next_)
1588 {
1589 if (key_eq()(__ndptr->__value_, __nd->__value_))
1590 goto __done;
1591 }
1592 }
1593 }
1594 {
1595 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1596 {
Eric Fiselier57947ca2015-02-02 21:31:48 +00001597 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001598 size_type(ceil(float(size() + 1) / max_load_factor()))));
1599 __bc = bucket_count();
Howard Hinnant7a445152012-07-06 17:31:14 +00001600 __chash = __constrain_hash(__nd->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601 }
1602 // insert_after __bucket_list_[__chash], or __first_node if bucket is null
1603 __node_pointer __pn = __bucket_list_[__chash];
1604 if (__pn == nullptr)
1605 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001606 __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001607 __nd->__next_ = __pn->__next_;
1608 __pn->__next_ = __nd;
1609 // fix up __bucket_list_
1610 __bucket_list_[__chash] = __pn;
1611 if (__nd->__next_ != nullptr)
Howard Hinnant7a445152012-07-06 17:31:14 +00001612 __bucket_list_[__constrain_hash(__nd->__next_->__hash_, __bc)] = __nd;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001613 }
1614 else
1615 {
1616 __nd->__next_ = __pn->__next_;
1617 __pn->__next_ = __nd;
1618 }
1619 __ndptr = __nd;
1620 // increment size
1621 ++size();
1622 __inserted = true;
1623 }
1624__done:
Howard Hinnant39213642013-07-23 22:01:58 +00001625#if _LIBCPP_DEBUG_LEVEL >= 2
1626 return pair<iterator, bool>(iterator(__ndptr, this), __inserted);
1627#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001628 return pair<iterator, bool>(iterator(__ndptr), __inserted);
Howard Hinnant39213642013-07-23 22:01:58 +00001629#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001630}
1631
1632template <class _Tp, class _Hash, class _Equal, class _Alloc>
1633typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1634__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp)
1635{
1636 __cp->__hash_ = hash_function()(__cp->__value_);
1637 size_type __bc = bucket_count();
1638 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1639 {
Eric Fiselier57947ca2015-02-02 21:31:48 +00001640 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001641 size_type(ceil(float(size() + 1) / max_load_factor()))));
1642 __bc = bucket_count();
1643 }
Howard Hinnant7a445152012-07-06 17:31:14 +00001644 size_t __chash = __constrain_hash(__cp->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001645 __node_pointer __pn = __bucket_list_[__chash];
1646 if (__pn == nullptr)
1647 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001648 __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649 __cp->__next_ = __pn->__next_;
1650 __pn->__next_ = __cp;
1651 // fix up __bucket_list_
1652 __bucket_list_[__chash] = __pn;
1653 if (__cp->__next_ != nullptr)
Howard Hinnant7a445152012-07-06 17:31:14 +00001654 __bucket_list_[__constrain_hash(__cp->__next_->__hash_, __bc)] = __cp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655 }
1656 else
1657 {
1658 for (bool __found = false; __pn->__next_ != nullptr &&
Howard Hinnant7a445152012-07-06 17:31:14 +00001659 __constrain_hash(__pn->__next_->__hash_, __bc) == __chash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001660 __pn = __pn->__next_)
Howard Hinnant324bb032010-08-22 00:02:43 +00001661 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001662 // __found key_eq() action
1663 // false false loop
1664 // true true loop
1665 // false true set __found to true
1666 // true false break
1667 if (__found != (__pn->__next_->__hash_ == __cp->__hash_ &&
1668 key_eq()(__pn->__next_->__value_, __cp->__value_)))
1669 {
1670 if (!__found)
1671 __found = true;
1672 else
1673 break;
1674 }
1675 }
1676 __cp->__next_ = __pn->__next_;
1677 __pn->__next_ = __cp;
1678 if (__cp->__next_ != nullptr)
1679 {
Howard Hinnant7a445152012-07-06 17:31:14 +00001680 size_t __nhash = __constrain_hash(__cp->__next_->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001681 if (__nhash != __chash)
1682 __bucket_list_[__nhash] = __cp;
1683 }
1684 }
1685 ++size();
Howard Hinnant39213642013-07-23 22:01:58 +00001686#if _LIBCPP_DEBUG_LEVEL >= 2
1687 return iterator(__cp, this);
1688#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001689 return iterator(__cp);
Howard Hinnant39213642013-07-23 22:01:58 +00001690#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001691}
1692
1693template <class _Tp, class _Hash, class _Equal, class _Alloc>
1694typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1695__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
1696 const_iterator __p, __node_pointer __cp)
1697{
Howard Hinnant824c1992013-08-02 17:50:49 +00001698#if _LIBCPP_DEBUG_LEVEL >= 2
1699 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1700 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
1701 " referring to this unordered container");
1702#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001703 if (__p != end() && key_eq()(*__p, __cp->__value_))
1704 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001705 __node_pointer __np = __p.__node_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001706 __cp->__hash_ = __np->__hash_;
1707 size_type __bc = bucket_count();
1708 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1709 {
Eric Fiselier57947ca2015-02-02 21:31:48 +00001710 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001711 size_type(ceil(float(size() + 1) / max_load_factor()))));
1712 __bc = bucket_count();
1713 }
Howard Hinnant7a445152012-07-06 17:31:14 +00001714 size_t __chash = __constrain_hash(__cp->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001715 __node_pointer __pp = __bucket_list_[__chash];
1716 while (__pp->__next_ != __np)
1717 __pp = __pp->__next_;
1718 __cp->__next_ = __np;
1719 __pp->__next_ = __cp;
1720 ++size();
Howard Hinnant39213642013-07-23 22:01:58 +00001721#if _LIBCPP_DEBUG_LEVEL >= 2
1722 return iterator(__cp, this);
1723#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001724 return iterator(__cp);
Howard Hinnant39213642013-07-23 22:01:58 +00001725#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001726 }
1727 return __node_insert_multi(__cp);
1728}
1729
1730template <class _Tp, class _Hash, class _Equal, class _Alloc>
1731pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1732__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(const value_type& __x)
1733{
Eric Fiselierfdae69a2015-06-13 07:18:32 +00001734 return __insert_unique_value(__x);
1735}
1736
1737
1738#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1739template <class _Tp, class _Hash, class _Equal, class _Alloc>
1740template <class _ValueTp>
1741_LIBCPP_INLINE_VISIBILITY
1742pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1743__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique_value(_ValueTp&& __x)
1744#else
1745template <class _Tp, class _Hash, class _Equal, class _Alloc>
1746_LIBCPP_INLINE_VISIBILITY
1747pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1748__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique_value(const value_type& __x)
1749#endif
1750{
1751#if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1752 typedef const value_type& _ValueTp;
1753#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001754 size_t __hash = hash_function()(__x);
1755 size_type __bc = bucket_count();
1756 bool __inserted = false;
1757 __node_pointer __nd;
1758 size_t __chash;
1759 if (__bc != 0)
1760 {
Howard Hinnant7a445152012-07-06 17:31:14 +00001761 __chash = __constrain_hash(__hash, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001762 __nd = __bucket_list_[__chash];
1763 if (__nd != nullptr)
1764 {
1765 for (__nd = __nd->__next_; __nd != nullptr &&
Howard Hinnant7a445152012-07-06 17:31:14 +00001766 __constrain_hash(__nd->__hash_, __bc) == __chash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001767 __nd = __nd->__next_)
1768 {
1769 if (key_eq()(__nd->__value_, __x))
1770 goto __done;
1771 }
1772 }
1773 }
1774 {
Eric Fiselierfdae69a2015-06-13 07:18:32 +00001775 __node_holder __h = __construct_node(_VSTD::forward<_ValueTp>(__x), __hash);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001776 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1777 {
Eric Fiselier57947ca2015-02-02 21:31:48 +00001778 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001779 size_type(ceil(float(size() + 1) / max_load_factor()))));
1780 __bc = bucket_count();
Howard Hinnant7a445152012-07-06 17:31:14 +00001781 __chash = __constrain_hash(__hash, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782 }
1783 // insert_after __bucket_list_[__chash], or __first_node if bucket is null
1784 __node_pointer __pn = __bucket_list_[__chash];
1785 if (__pn == nullptr)
1786 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001787 __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001788 __h->__next_ = __pn->__next_;
1789 __pn->__next_ = __h.get();
1790 // fix up __bucket_list_
1791 __bucket_list_[__chash] = __pn;
1792 if (__h->__next_ != nullptr)
Howard Hinnant7a445152012-07-06 17:31:14 +00001793 __bucket_list_[__constrain_hash(__h->__next_->__hash_, __bc)] = __h.get();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001794 }
1795 else
1796 {
1797 __h->__next_ = __pn->__next_;
1798 __pn->__next_ = __h.get();
1799 }
1800 __nd = __h.release();
1801 // increment size
1802 ++size();
1803 __inserted = true;
1804 }
1805__done:
Howard Hinnant39213642013-07-23 22:01:58 +00001806#if _LIBCPP_DEBUG_LEVEL >= 2
1807 return pair<iterator, bool>(iterator(__nd, this), __inserted);
1808#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001809 return pair<iterator, bool>(iterator(__nd), __inserted);
Howard Hinnant39213642013-07-23 22:01:58 +00001810#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001811}
1812
Howard Hinnant73d21a42010-09-04 23:28:19 +00001813#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1814#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001815
1816template <class _Tp, class _Hash, class _Equal, class _Alloc>
1817template <class... _Args>
1818pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1819__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique(_Args&&... __args)
1820{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001821 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001822 pair<iterator, bool> __r = __node_insert_unique(__h.get());
1823 if (__r.second)
1824 __h.release();
1825 return __r;
1826}
1827
1828template <class _Tp, class _Hash, class _Equal, class _Alloc>
1829template <class... _Args>
1830typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1831__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args)
1832{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001833 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001834 iterator __r = __node_insert_multi(__h.get());
1835 __h.release();
1836 return __r;
1837}
1838
1839template <class _Tp, class _Hash, class _Equal, class _Alloc>
1840template <class... _Args>
1841typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1842__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(
1843 const_iterator __p, _Args&&... __args)
1844{
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001845#if _LIBCPP_DEBUG_LEVEL >= 2
1846 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1847 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
1848 " referring to this unordered container");
1849#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001850 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001851 iterator __r = __node_insert_multi(__p, __h.get());
1852 __h.release();
1853 return __r;
1854}
1855
Howard Hinnant73d21a42010-09-04 23:28:19 +00001856#endif // _LIBCPP_HAS_NO_VARIADICS
1857
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001858template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselierfdae69a2015-06-13 07:18:32 +00001859pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1860__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(value_type&& __x)
1861{
1862 return __insert_unique_value(_VSTD::move(__x));
1863}
1864
1865template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001866template <class _Pp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001867pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
Howard Hinnant99968442011-11-29 18:15:50 +00001868__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(_Pp&& __x)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869{
Howard Hinnant99968442011-11-29 18:15:50 +00001870 __node_holder __h = __construct_node(_VSTD::forward<_Pp>(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001871 pair<iterator, bool> __r = __node_insert_unique(__h.get());
1872 if (__r.second)
1873 __h.release();
1874 return __r;
1875}
1876
Howard Hinnant73d21a42010-09-04 23:28:19 +00001877#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001878
Howard Hinnant73d21a42010-09-04 23:28:19 +00001879#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001880
1881template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001882template <class _Pp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001883typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Howard Hinnant99968442011-11-29 18:15:50 +00001884__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(_Pp&& __x)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001885{
Howard Hinnant99968442011-11-29 18:15:50 +00001886 __node_holder __h = __construct_node(_VSTD::forward<_Pp>(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001887 iterator __r = __node_insert_multi(__h.get());
1888 __h.release();
1889 return __r;
1890}
1891
1892template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001893template <class _Pp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001894typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1895__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
Howard Hinnant99968442011-11-29 18:15:50 +00001896 _Pp&& __x)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001897{
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001898#if _LIBCPP_DEBUG_LEVEL >= 2
1899 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1900 "unordered container::insert(const_iterator, rvalue) called with an iterator not"
1901 " referring to this unordered container");
1902#endif
Howard Hinnant99968442011-11-29 18:15:50 +00001903 __node_holder __h = __construct_node(_VSTD::forward<_Pp>(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001904 iterator __r = __node_insert_multi(__p, __h.get());
1905 __h.release();
1906 return __r;
1907}
1908
Howard Hinnant73d21a42010-09-04 23:28:19 +00001909#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001910
1911template <class _Tp, class _Hash, class _Equal, class _Alloc>
1912typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1913__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const value_type& __x)
1914{
1915 __node_holder __h = __construct_node(__x);
1916 iterator __r = __node_insert_multi(__h.get());
1917 __h.release();
1918 return __r;
1919}
1920
1921template <class _Tp, class _Hash, class _Equal, class _Alloc>
1922typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1923__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
1924 const value_type& __x)
1925{
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001926#if _LIBCPP_DEBUG_LEVEL >= 2
1927 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1928 "unordered container::insert(const_iterator, lvalue) called with an iterator not"
1929 " referring to this unordered container");
1930#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001931 __node_holder __h = __construct_node(__x);
1932 iterator __r = __node_insert_multi(__p, __h.get());
1933 __h.release();
1934 return __r;
1935}
1936
Howard Hinnant73d21a42010-09-04 23:28:19 +00001937#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001938
1939template <class _Tp, class _Hash, class _Equal, class _Alloc>
1940void
1941__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
1942{
Howard Hinnant7a445152012-07-06 17:31:14 +00001943 if (__n == 1)
1944 __n = 2;
1945 else if (__n & (__n - 1))
1946 __n = __next_prime(__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001947 size_type __bc = bucket_count();
1948 if (__n > __bc)
1949 __rehash(__n);
Howard Hinnant7a445152012-07-06 17:31:14 +00001950 else if (__n < __bc)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001951 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001952 __n = _VSTD::max<size_type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001953 (
1954 __n,
Eric Fiselier57947ca2015-02-02 21:31:48 +00001955 __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) :
1956 __next_prime(size_t(ceil(float(size()) / max_load_factor())))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001957 );
1958 if (__n < __bc)
1959 __rehash(__n);
1960 }
1961}
1962
1963template <class _Tp, class _Hash, class _Equal, class _Alloc>
1964void
1965__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
1966{
Howard Hinnant39213642013-07-23 22:01:58 +00001967#if _LIBCPP_DEBUG_LEVEL >= 2
1968 __get_db()->__invalidate_all(this);
1969#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970 __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc();
1971 __bucket_list_.reset(__nbc > 0 ?
1972 __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr);
1973 __bucket_list_.get_deleter().size() = __nbc;
1974 if (__nbc > 0)
1975 {
1976 for (size_type __i = 0; __i < __nbc; ++__i)
1977 __bucket_list_[__i] = nullptr;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001978 __node_pointer __pp(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001979 __node_pointer __cp = __pp->__next_;
1980 if (__cp != nullptr)
1981 {
Howard Hinnant7a445152012-07-06 17:31:14 +00001982 size_type __chash = __constrain_hash(__cp->__hash_, __nbc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001983 __bucket_list_[__chash] = __pp;
1984 size_type __phash = __chash;
1985 for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
1986 __cp = __pp->__next_)
1987 {
Howard Hinnant7a445152012-07-06 17:31:14 +00001988 __chash = __constrain_hash(__cp->__hash_, __nbc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001989 if (__chash == __phash)
1990 __pp = __cp;
1991 else
1992 {
1993 if (__bucket_list_[__chash] == nullptr)
1994 {
1995 __bucket_list_[__chash] = __pp;
1996 __pp = __cp;
1997 __phash = __chash;
1998 }
1999 else
2000 {
2001 __node_pointer __np = __cp;
2002 for (; __np->__next_ != nullptr &&
2003 key_eq()(__cp->__value_, __np->__next_->__value_);
2004 __np = __np->__next_)
2005 ;
2006 __pp->__next_ = __np->__next_;
2007 __np->__next_ = __bucket_list_[__chash]->__next_;
2008 __bucket_list_[__chash]->__next_ = __cp;
Howard Hinnant324bb032010-08-22 00:02:43 +00002009
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002010 }
2011 }
2012 }
2013 }
2014 }
2015}
2016
2017template <class _Tp, class _Hash, class _Equal, class _Alloc>
2018template <class _Key>
2019typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2020__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k)
2021{
2022 size_t __hash = hash_function()(__k);
2023 size_type __bc = bucket_count();
2024 if (__bc != 0)
2025 {
Howard Hinnant7a445152012-07-06 17:31:14 +00002026 size_t __chash = __constrain_hash(__hash, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002027 __node_pointer __nd = __bucket_list_[__chash];
2028 if (__nd != nullptr)
2029 {
2030 for (__nd = __nd->__next_; __nd != nullptr &&
Howard Hinnant7a445152012-07-06 17:31:14 +00002031 __constrain_hash(__nd->__hash_, __bc) == __chash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002032 __nd = __nd->__next_)
2033 {
2034 if (key_eq()(__nd->__value_, __k))
Howard Hinnant39213642013-07-23 22:01:58 +00002035#if _LIBCPP_DEBUG_LEVEL >= 2
2036 return iterator(__nd, this);
2037#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002038 return iterator(__nd);
Howard Hinnant39213642013-07-23 22:01:58 +00002039#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002040 }
2041 }
2042 }
2043 return end();
2044}
2045
2046template <class _Tp, class _Hash, class _Equal, class _Alloc>
2047template <class _Key>
2048typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
2049__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const
2050{
2051 size_t __hash = hash_function()(__k);
2052 size_type __bc = bucket_count();
2053 if (__bc != 0)
2054 {
Howard Hinnant7a445152012-07-06 17:31:14 +00002055 size_t __chash = __constrain_hash(__hash, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002056 __node_const_pointer __nd = __bucket_list_[__chash];
2057 if (__nd != nullptr)
2058 {
2059 for (__nd = __nd->__next_; __nd != nullptr &&
Howard Hinnant7a445152012-07-06 17:31:14 +00002060 __constrain_hash(__nd->__hash_, __bc) == __chash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002061 __nd = __nd->__next_)
2062 {
2063 if (key_eq()(__nd->__value_, __k))
Howard Hinnant39213642013-07-23 22:01:58 +00002064#if _LIBCPP_DEBUG_LEVEL >= 2
2065 return const_iterator(__nd, this);
2066#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002067 return const_iterator(__nd);
Howard Hinnant39213642013-07-23 22:01:58 +00002068#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069 }
2070 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002071
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072 }
2073 return end();
2074}
2075
Howard Hinnant73d21a42010-09-04 23:28:19 +00002076#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2077#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002078
2079template <class _Tp, class _Hash, class _Equal, class _Alloc>
2080template <class ..._Args>
2081typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
2082__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args)
2083{
2084 __node_allocator& __na = __node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002085 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00002086 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002087 __h.get_deleter().__value_constructed = true;
2088 __h->__hash_ = hash_function()(__h->__value_);
2089 __h->__next_ = nullptr;
2090 return __h;
2091}
2092
Howard Hinnant73d21a42010-09-04 23:28:19 +00002093#endif // _LIBCPP_HAS_NO_VARIADICS
2094
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095template <class _Tp, class _Hash, class _Equal, class _Alloc>
2096typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
2097__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(value_type&& __v,
2098 size_t __hash)
2099{
2100 __node_allocator& __na = __node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002101 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00002102 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002103 __h.get_deleter().__value_constructed = true;
2104 __h->__hash_ = __hash;
2105 __h->__next_ = nullptr;
Howard Hinnant9a894d92013-08-22 18:29:50 +00002106 return __h;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002107}
2108
Howard Hinnant73d21a42010-09-04 23:28:19 +00002109#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002110
2111template <class _Tp, class _Hash, class _Equal, class _Alloc>
2112typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
2113__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const value_type& __v)
2114{
2115 __node_allocator& __na = __node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002116 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00002117 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002118 __h.get_deleter().__value_constructed = true;
2119 __h->__hash_ = hash_function()(__h->__value_);
2120 __h->__next_ = nullptr;
Dimitry Andric89663502015-08-19 06:43:33 +00002121 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002122}
2123
Howard Hinnant73d21a42010-09-04 23:28:19 +00002124#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002125
2126template <class _Tp, class _Hash, class _Equal, class _Alloc>
2127typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
2128__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const value_type& __v,
2129 size_t __hash)
2130{
2131 __node_allocator& __na = __node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002132 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00002133 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002134 __h.get_deleter().__value_constructed = true;
2135 __h->__hash_ = __hash;
2136 __h->__next_ = nullptr;
Dimitry Andric89663502015-08-19 06:43:33 +00002137 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002138}
2139
2140template <class _Tp, class _Hash, class _Equal, class _Alloc>
2141typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2142__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
2143{
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00002144 __node_pointer __np = __p.__node_;
Howard Hinnant39213642013-07-23 22:01:58 +00002145#if _LIBCPP_DEBUG_LEVEL >= 2
2146 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2147 "unordered container erase(iterator) called with an iterator not"
2148 " referring to this container");
2149 _LIBCPP_ASSERT(__p != end(),
2150 "unordered container erase(iterator) called with a non-dereferenceable iterator");
2151 iterator __r(__np, this);
2152#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002153 iterator __r(__np);
Howard Hinnant39213642013-07-23 22:01:58 +00002154#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002155 ++__r;
2156 remove(__p);
2157 return __r;
2158}
2159
2160template <class _Tp, class _Hash, class _Equal, class _Alloc>
2161typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2162__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
2163 const_iterator __last)
2164{
Howard Hinnant39213642013-07-23 22:01:58 +00002165#if _LIBCPP_DEBUG_LEVEL >= 2
2166 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2167 "unodered container::erase(iterator, iterator) called with an iterator not"
2168 " referring to this unodered container");
2169 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
2170 "unodered container::erase(iterator, iterator) called with an iterator not"
2171 " referring to this unodered container");
2172#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002173 for (const_iterator __p = __first; __first != __last; __p = __first)
2174 {
2175 ++__first;
2176 erase(__p);
2177 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00002178 __node_pointer __np = __last.__node_;
Howard Hinnant39213642013-07-23 22:01:58 +00002179#if _LIBCPP_DEBUG_LEVEL >= 2
2180 return iterator (__np, this);
2181#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002182 return iterator (__np);
Howard Hinnant39213642013-07-23 22:01:58 +00002183#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002184}
2185
2186template <class _Tp, class _Hash, class _Equal, class _Alloc>
2187template <class _Key>
2188typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2189__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k)
2190{
2191 iterator __i = find(__k);
2192 if (__i == end())
2193 return 0;
2194 erase(__i);
2195 return 1;
2196}
2197
2198template <class _Tp, class _Hash, class _Equal, class _Alloc>
2199template <class _Key>
2200typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2201__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k)
2202{
2203 size_type __r = 0;
2204 iterator __i = find(__k);
2205 if (__i != end())
2206 {
2207 iterator __e = end();
2208 do
2209 {
2210 erase(__i++);
2211 ++__r;
2212 } while (__i != __e && key_eq()(*__i, __k));
2213 }
2214 return __r;
2215}
2216
2217template <class _Tp, class _Hash, class _Equal, class _Alloc>
2218typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002219__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002220{
2221 // current node
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00002222 __node_pointer __cn = __p.__node_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002223 size_type __bc = bucket_count();
Howard Hinnant7a445152012-07-06 17:31:14 +00002224 size_t __chash = __constrain_hash(__cn->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002225 // find previous node
2226 __node_pointer __pn = __bucket_list_[__chash];
2227 for (; __pn->__next_ != __cn; __pn = __pn->__next_)
2228 ;
2229 // Fix up __bucket_list_
2230 // if __pn is not in same bucket (before begin is not in same bucket) &&
2231 // if __cn->__next_ is not in same bucket (nullptr is not in same bucket)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00002232 if (__pn == static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()))
2233 || __constrain_hash(__pn->__hash_, __bc) != __chash)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002234 {
Howard Hinnant7a445152012-07-06 17:31:14 +00002235 if (__cn->__next_ == nullptr || __constrain_hash(__cn->__next_->__hash_, __bc) != __chash)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002236 __bucket_list_[__chash] = nullptr;
2237 }
2238 // if __cn->__next_ is not in same bucket (nullptr is in same bucket)
2239 if (__cn->__next_ != nullptr)
2240 {
Howard Hinnant7a445152012-07-06 17:31:14 +00002241 size_t __nhash = __constrain_hash(__cn->__next_->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002242 if (__nhash != __chash)
2243 __bucket_list_[__nhash] = __pn;
2244 }
2245 // remove __cn
2246 __pn->__next_ = __cn->__next_;
2247 __cn->__next_ = nullptr;
2248 --size();
Howard Hinnant39213642013-07-23 22:01:58 +00002249#if _LIBCPP_DEBUG_LEVEL >= 2
2250 __c_node* __c = __get_db()->__find_c_and_lock(this);
2251 for (__i_node** __p = __c->end_; __p != __c->beg_; )
2252 {
2253 --__p;
2254 iterator* __i = static_cast<iterator*>((*__p)->__i_);
2255 if (__i->__node_ == __cn)
2256 {
2257 (*__p)->__c_ = nullptr;
2258 if (--__c->end_ != __p)
2259 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
2260 }
2261 }
2262 __get_db()->unlock();
2263#endif
Howard Hinnant99968442011-11-29 18:15:50 +00002264 return __node_holder(__cn, _Dp(__node_alloc(), true));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002265}
2266
2267template <class _Tp, class _Hash, class _Equal, class _Alloc>
2268template <class _Key>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00002269inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002270typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2271__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const
2272{
2273 return static_cast<size_type>(find(__k) != end());
2274}
2275
2276template <class _Tp, class _Hash, class _Equal, class _Alloc>
2277template <class _Key>
2278typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2279__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const
2280{
2281 size_type __r = 0;
2282 const_iterator __i = find(__k);
2283 if (__i != end())
2284 {
2285 const_iterator __e = end();
2286 do
2287 {
2288 ++__i;
2289 ++__r;
2290 } while (__i != __e && key_eq()(*__i, __k));
2291 }
2292 return __r;
2293}
2294
2295template <class _Tp, class _Hash, class _Equal, class _Alloc>
2296template <class _Key>
2297pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
2298 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
2299__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
2300 const _Key& __k)
2301{
2302 iterator __i = find(__k);
2303 iterator __j = __i;
2304 if (__i != end())
2305 ++__j;
2306 return pair<iterator, iterator>(__i, __j);
2307}
2308
2309template <class _Tp, class _Hash, class _Equal, class _Alloc>
2310template <class _Key>
2311pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
2312 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
2313__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
2314 const _Key& __k) const
2315{
2316 const_iterator __i = find(__k);
2317 const_iterator __j = __i;
2318 if (__i != end())
2319 ++__j;
2320 return pair<const_iterator, const_iterator>(__i, __j);
2321}
2322
2323template <class _Tp, class _Hash, class _Equal, class _Alloc>
2324template <class _Key>
2325pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
2326 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
2327__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
2328 const _Key& __k)
2329{
2330 iterator __i = find(__k);
2331 iterator __j = __i;
2332 if (__i != end())
2333 {
2334 iterator __e = end();
2335 do
2336 {
2337 ++__j;
2338 } while (__j != __e && key_eq()(*__j, __k));
2339 }
2340 return pair<iterator, iterator>(__i, __j);
2341}
2342
2343template <class _Tp, class _Hash, class _Equal, class _Alloc>
2344template <class _Key>
2345pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
2346 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
2347__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
2348 const _Key& __k) const
2349{
2350 const_iterator __i = find(__k);
2351 const_iterator __j = __i;
2352 if (__i != end())
2353 {
2354 const_iterator __e = end();
2355 do
2356 {
2357 ++__j;
2358 } while (__j != __e && key_eq()(*__j, __k));
2359 }
2360 return pair<const_iterator, const_iterator>(__i, __j);
2361}
2362
2363template <class _Tp, class _Hash, class _Equal, class _Alloc>
2364void
2365__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
Eric Fiselier692177d2015-07-18 20:40:46 +00002366#if _LIBCPP_STD_VER <= 11
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002367 _NOEXCEPT_(
Marshall Clow7d914d12015-07-13 20:04:56 +00002368 __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
Marshall Clow7d914d12015-07-13 20:04:56 +00002369 && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
2370 || __is_nothrow_swappable<__pointer_allocator>::value)
2371 && (!__node_traits::propagate_on_container_swap::value
2372 || __is_nothrow_swappable<__node_allocator>::value)
Marshall Clow7d914d12015-07-13 20:04:56 +00002373 )
Eric Fiselier692177d2015-07-18 20:40:46 +00002374#else
2375 _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value)
2376#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002377{
2378 {
2379 __node_pointer_pointer __npp = __bucket_list_.release();
2380 __bucket_list_.reset(__u.__bucket_list_.release());
2381 __u.__bucket_list_.reset(__npp);
2382 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002383 _VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size());
Marshall Clow7d914d12015-07-13 20:04:56 +00002384 __swap_allocator(__bucket_list_.get_deleter().__alloc(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002385 __u.__bucket_list_.get_deleter().__alloc());
Marshall Clow7d914d12015-07-13 20:04:56 +00002386 __swap_allocator(__node_alloc(), __u.__node_alloc());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002387 _VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002388 __p2_.swap(__u.__p2_);
2389 __p3_.swap(__u.__p3_);
2390 if (size() > 0)
Howard Hinnant7a445152012-07-06 17:31:14 +00002391 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00002392 static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002393 if (__u.size() > 0)
Howard Hinnant7a445152012-07-06 17:31:14 +00002394 __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash_, __u.bucket_count())] =
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00002395 static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__u.__p1_.first()));
Howard Hinnant39213642013-07-23 22:01:58 +00002396#if _LIBCPP_DEBUG_LEVEL >= 2
2397 __get_db()->swap(this, &__u);
2398#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002399}
2400
2401template <class _Tp, class _Hash, class _Equal, class _Alloc>
2402typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2403__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const
2404{
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00002405 _LIBCPP_ASSERT(__n < bucket_count(),
2406 "unordered container::bucket_size(n) called with n >= bucket_count()");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002407 __node_const_pointer __np = __bucket_list_[__n];
2408 size_type __bc = bucket_count();
2409 size_type __r = 0;
2410 if (__np != nullptr)
2411 {
2412 for (__np = __np->__next_; __np != nullptr &&
Howard Hinnant7a445152012-07-06 17:31:14 +00002413 __constrain_hash(__np->__hash_, __bc) == __n;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002414 __np = __np->__next_, ++__r)
2415 ;
2416 }
2417 return __r;
2418}
2419
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002420template <class _Tp, class _Hash, class _Equal, class _Alloc>
2421inline _LIBCPP_INLINE_VISIBILITY
2422void
2423swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x,
2424 __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y)
2425 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2426{
2427 __x.swap(__y);
2428}
2429
Howard Hinnant39213642013-07-23 22:01:58 +00002430#if _LIBCPP_DEBUG_LEVEL >= 2
2431
2432template <class _Tp, class _Hash, class _Equal, class _Alloc>
2433bool
2434__hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const
2435{
2436 return __i->__node_ != nullptr;
2437}
2438
2439template <class _Tp, class _Hash, class _Equal, class _Alloc>
2440bool
2441__hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const
2442{
2443 return false;
2444}
2445
2446template <class _Tp, class _Hash, class _Equal, class _Alloc>
2447bool
2448__hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
2449{
2450 return false;
2451}
2452
2453template <class _Tp, class _Hash, class _Equal, class _Alloc>
2454bool
2455__hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
2456{
2457 return false;
2458}
2459
2460#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002461_LIBCPP_END_NAMESPACE_STD
2462
2463#endif // _LIBCPP__HASH_TABLE