blob: d089bcefc13d01dee202afb8115170f08d6c9401 [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
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000839 __hash_table()
840 _NOEXCEPT_(
841 is_nothrow_default_constructible<__bucket_list>::value &&
842 is_nothrow_default_constructible<__first_node>::value &&
843 is_nothrow_default_constructible<__node_allocator>::value &&
844 is_nothrow_default_constructible<hasher>::value &&
845 is_nothrow_default_constructible<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000846 __hash_table(const hasher& __hf, const key_equal& __eql);
847 __hash_table(const hasher& __hf, const key_equal& __eql,
848 const allocator_type& __a);
849 explicit __hash_table(const allocator_type& __a);
850 __hash_table(const __hash_table& __u);
851 __hash_table(const __hash_table& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000852#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000853 __hash_table(__hash_table&& __u)
854 _NOEXCEPT_(
855 is_nothrow_move_constructible<__bucket_list>::value &&
856 is_nothrow_move_constructible<__first_node>::value &&
857 is_nothrow_move_constructible<__node_allocator>::value &&
858 is_nothrow_move_constructible<hasher>::value &&
859 is_nothrow_move_constructible<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000860 __hash_table(__hash_table&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000861#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 ~__hash_table();
863
864 __hash_table& operator=(const __hash_table& __u);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000865#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000866 __hash_table& operator=(__hash_table&& __u)
867 _NOEXCEPT_(
868 __node_traits::propagate_on_container_move_assignment::value &&
869 is_nothrow_move_assignable<__node_allocator>::value &&
870 is_nothrow_move_assignable<hasher>::value &&
871 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000872#endif
873 template <class _InputIterator>
874 void __assign_unique(_InputIterator __first, _InputIterator __last);
875 template <class _InputIterator>
876 void __assign_multi(_InputIterator __first, _InputIterator __last);
877
Howard Hinnant99acc502010-09-21 17:32:39 +0000878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000879 size_type max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000880 {
881 return allocator_traits<__pointer_allocator>::max_size(
882 __bucket_list_.get_deleter().__alloc());
883 }
884
885 pair<iterator, bool> __node_insert_unique(__node_pointer __nd);
886 iterator __node_insert_multi(__node_pointer __nd);
887 iterator __node_insert_multi(const_iterator __p,
888 __node_pointer __nd);
889
Howard Hinnant73d21a42010-09-04 23:28:19 +0000890#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891 template <class... _Args>
892 pair<iterator, bool> __emplace_unique(_Args&&... __args);
893 template <class... _Args>
894 iterator __emplace_multi(_Args&&... __args);
895 template <class... _Args>
896 iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000897#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000898
Eric Fiselierfdae69a2015-06-13 07:18:32 +0000899#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
900 template <class _ValueTp>
901 _LIBCPP_INLINE_VISIBILITY
902 pair<iterator, bool> __insert_unique_value(_ValueTp&& __x);
903#else
904 _LIBCPP_INLINE_VISIBILITY
905 pair<iterator, bool> __insert_unique_value(const value_type& __x);
906#endif
907
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000908 pair<iterator, bool> __insert_unique(const value_type& __x);
909
Howard Hinnant73d21a42010-09-04 23:28:19 +0000910#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Eric Fiselierfdae69a2015-06-13 07:18:32 +0000911 pair<iterator, bool> __insert_unique(value_type&& __x);
Howard Hinnant99968442011-11-29 18:15:50 +0000912 template <class _Pp>
Eric Fiselierfdae69a2015-06-13 07:18:32 +0000913 pair<iterator, bool> __insert_unique(_Pp&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000914#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915
Howard Hinnant73d21a42010-09-04 23:28:19 +0000916#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000917 template <class _Pp>
918 iterator __insert_multi(_Pp&& __x);
919 template <class _Pp>
920 iterator __insert_multi(const_iterator __p, _Pp&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000921#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000922 iterator __insert_multi(const value_type& __x);
923 iterator __insert_multi(const_iterator __p, const value_type& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000924#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000926 void clear() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927 void rehash(size_type __n);
Howard Hinnant99acc502010-09-21 17:32:39 +0000928 _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000929 {rehash(static_cast<size_type>(ceil(__n / max_load_factor())));}
Howard Hinnant99acc502010-09-21 17:32:39 +0000930
931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000932 size_type bucket_count() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933 {
934 return __bucket_list_.get_deleter().size();
935 }
936
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000937 iterator begin() _NOEXCEPT;
938 iterator end() _NOEXCEPT;
939 const_iterator begin() const _NOEXCEPT;
940 const_iterator end() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000941
942 template <class _Key>
Howard Hinnant99acc502010-09-21 17:32:39 +0000943 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000944 size_type bucket(const _Key& __k) const
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +0000945 {
946 _LIBCPP_ASSERT(bucket_count() > 0,
947 "unordered container::bucket(key) called when bucket_count() == 0");
948 return __constrain_hash(hash_function()(__k), bucket_count());
949 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000950
951 template <class _Key>
952 iterator find(const _Key& __x);
953 template <class _Key>
954 const_iterator find(const _Key& __x) const;
955
Howard Hinnant99968442011-11-29 18:15:50 +0000956 typedef __hash_node_destructor<__node_allocator> _Dp;
957 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000958
959 iterator erase(const_iterator __p);
960 iterator erase(const_iterator __first, const_iterator __last);
961 template <class _Key>
962 size_type __erase_unique(const _Key& __k);
963 template <class _Key>
964 size_type __erase_multi(const _Key& __k);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000965 __node_holder remove(const_iterator __p) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000966
967 template <class _Key>
968 size_type __count_unique(const _Key& __k) const;
969 template <class _Key>
970 size_type __count_multi(const _Key& __k) const;
971
972 template <class _Key>
973 pair<iterator, iterator>
974 __equal_range_unique(const _Key& __k);
975 template <class _Key>
976 pair<const_iterator, const_iterator>
977 __equal_range_unique(const _Key& __k) const;
978
979 template <class _Key>
980 pair<iterator, iterator>
981 __equal_range_multi(const _Key& __k);
982 template <class _Key>
983 pair<const_iterator, const_iterator>
984 __equal_range_multi(const _Key& __k) const;
985
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000986 void swap(__hash_table& __u)
987 _NOEXCEPT_(
988 (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value ||
989 __is_nothrow_swappable<__pointer_allocator>::value) &&
990 (!__node_traits::propagate_on_container_swap::value ||
991 __is_nothrow_swappable<__node_allocator>::value) &&
992 __is_nothrow_swappable<hasher>::value &&
993 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000994
Howard Hinnant99acc502010-09-21 17:32:39 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000996 size_type max_bucket_count() const _NOEXCEPT
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000997 {return __pointer_alloc_traits::max_size(__bucket_list_.get_deleter().__alloc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000998 size_type bucket_size(size_type __n) const;
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000999 _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001000 {
1001 size_type __bc = bucket_count();
1002 return __bc != 0 ? (float)size() / __bc : 0.f;
1003 }
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001004 _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001005 {
1006 _LIBCPP_ASSERT(__mlf > 0,
1007 "unordered container::max_load_factor(lf) called with lf <= 0");
1008 max_load_factor() = _VSTD::max(__mlf, load_factor());
1009 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010
Howard Hinnant39213642013-07-23 22:01:58 +00001011 _LIBCPP_INLINE_VISIBILITY
1012 local_iterator
1013 begin(size_type __n)
1014 {
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001015 _LIBCPP_ASSERT(__n < bucket_count(),
1016 "unordered container::begin(n) called with n >= bucket_count()");
Howard Hinnant39213642013-07-23 22:01:58 +00001017#if _LIBCPP_DEBUG_LEVEL >= 2
1018 return local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
1019#else
1020 return local_iterator(__bucket_list_[__n], __n, bucket_count());
1021#endif
1022 }
1023
1024 _LIBCPP_INLINE_VISIBILITY
1025 local_iterator
1026 end(size_type __n)
1027 {
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001028 _LIBCPP_ASSERT(__n < bucket_count(),
1029 "unordered container::end(n) called with n >= bucket_count()");
Howard Hinnant39213642013-07-23 22:01:58 +00001030#if _LIBCPP_DEBUG_LEVEL >= 2
1031 return local_iterator(nullptr, __n, bucket_count(), this);
1032#else
1033 return local_iterator(nullptr, __n, bucket_count());
1034#endif
1035 }
1036
1037 _LIBCPP_INLINE_VISIBILITY
1038 const_local_iterator
1039 cbegin(size_type __n) const
1040 {
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001041 _LIBCPP_ASSERT(__n < bucket_count(),
1042 "unordered container::cbegin(n) called with n >= bucket_count()");
Howard Hinnant39213642013-07-23 22:01:58 +00001043#if _LIBCPP_DEBUG_LEVEL >= 2
1044 return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
1045#else
1046 return const_local_iterator(__bucket_list_[__n], __n, bucket_count());
1047#endif
1048 }
1049
1050 _LIBCPP_INLINE_VISIBILITY
1051 const_local_iterator
1052 cend(size_type __n) const
1053 {
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001054 _LIBCPP_ASSERT(__n < bucket_count(),
1055 "unordered container::cend(n) called with n >= bucket_count()");
Howard Hinnant39213642013-07-23 22:01:58 +00001056#if _LIBCPP_DEBUG_LEVEL >= 2
1057 return const_local_iterator(nullptr, __n, bucket_count(), this);
1058#else
1059 return const_local_iterator(nullptr, __n, bucket_count());
1060#endif
1061 }
1062
1063#if _LIBCPP_DEBUG_LEVEL >= 2
1064
1065 bool __dereferenceable(const const_iterator* __i) const;
1066 bool __decrementable(const const_iterator* __i) const;
1067 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1068 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1069
1070#endif // _LIBCPP_DEBUG_LEVEL >= 2
1071
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072private:
1073 void __rehash(size_type __n);
1074
Howard Hinnant73d21a42010-09-04 23:28:19 +00001075#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1076#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001077 template <class ..._Args>
1078 __node_holder __construct_node(_Args&& ...__args);
Howard Hinnantbfd55302010-09-04 23:46:48 +00001079#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080 __node_holder __construct_node(value_type&& __v, size_t __hash);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001081#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001082 __node_holder __construct_node(const value_type& __v);
1083#endif
1084 __node_holder __construct_node(const value_type& __v, size_t __hash);
1085
Howard Hinnant99acc502010-09-21 17:32:39 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001087 void __copy_assign_alloc(const __hash_table& __u)
1088 {__copy_assign_alloc(__u, integral_constant<bool,
1089 __node_traits::propagate_on_container_copy_assignment::value>());}
1090 void __copy_assign_alloc(const __hash_table& __u, true_type);
Howard Hinnant99acc502010-09-21 17:32:39 +00001091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001092 void __copy_assign_alloc(const __hash_table&, false_type) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001093
1094 void __move_assign(__hash_table& __u, false_type);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001095 void __move_assign(__hash_table& __u, true_type)
1096 _NOEXCEPT_(
1097 is_nothrow_move_assignable<__node_allocator>::value &&
1098 is_nothrow_move_assignable<hasher>::value &&
1099 is_nothrow_move_assignable<key_equal>::value);
1100 _LIBCPP_INLINE_VISIBILITY
1101 void __move_assign_alloc(__hash_table& __u)
1102 _NOEXCEPT_(
1103 !__node_traits::propagate_on_container_move_assignment::value ||
1104 (is_nothrow_move_assignable<__pointer_allocator>::value &&
1105 is_nothrow_move_assignable<__node_allocator>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106 {__move_assign_alloc(__u, integral_constant<bool,
1107 __node_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnant99acc502010-09-21 17:32:39 +00001108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001109 void __move_assign_alloc(__hash_table& __u, true_type)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001110 _NOEXCEPT_(
1111 is_nothrow_move_assignable<__pointer_allocator>::value &&
1112 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001113 {
1114 __bucket_list_.get_deleter().__alloc() =
Howard Hinnant0949eed2011-06-30 21:18:19 +00001115 _VSTD::move(__u.__bucket_list_.get_deleter().__alloc());
1116 __node_alloc() = _VSTD::move(__u.__node_alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001117 }
Howard Hinnant99acc502010-09-21 17:32:39 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001119 void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120
Howard Hinnant99968442011-11-29 18:15:50 +00001121 template <class _Ap>
Howard Hinnant99acc502010-09-21 17:32:39 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123 static
1124 void
Howard Hinnant99968442011-11-29 18:15:50 +00001125 __swap_alloc(_Ap& __x, _Ap& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001126 _NOEXCEPT_(
Howard Hinnant99968442011-11-29 18:15:50 +00001127 !allocator_traits<_Ap>::propagate_on_container_swap::value ||
1128 __is_nothrow_swappable<_Ap>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001129 {
1130 __swap_alloc(__x, __y,
1131 integral_constant<bool,
Howard Hinnant99968442011-11-29 18:15:50 +00001132 allocator_traits<_Ap>::propagate_on_container_swap::value
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001133 >());
1134 }
1135
Howard Hinnant99968442011-11-29 18:15:50 +00001136 template <class _Ap>
Howard Hinnant99acc502010-09-21 17:32:39 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001138 static
1139 void
Howard Hinnant99968442011-11-29 18:15:50 +00001140 __swap_alloc(_Ap& __x, _Ap& __y, true_type)
1141 _NOEXCEPT_(__is_nothrow_swappable<_Ap>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001142 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001143 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144 swap(__x, __y);
1145 }
1146
Howard Hinnant99968442011-11-29 18:15:50 +00001147 template <class _Ap>
Howard Hinnant99acc502010-09-21 17:32:39 +00001148 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149 static
1150 void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001151 __swap_alloc(_Ap&, _Ap&, false_type) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001153 void __deallocate(__node_pointer __np) _NOEXCEPT;
1154 __node_pointer __detach() _NOEXCEPT;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001155
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001156 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
1157 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001158};
1159
1160template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99acc502010-09-21 17:32:39 +00001161inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001162__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table()
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001163 _NOEXCEPT_(
1164 is_nothrow_default_constructible<__bucket_list>::value &&
1165 is_nothrow_default_constructible<__first_node>::value &&
1166 is_nothrow_default_constructible<hasher>::value &&
1167 is_nothrow_default_constructible<key_equal>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001168 : __p2_(0),
1169 __p3_(1.0f)
1170{
1171}
1172
1173template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99acc502010-09-21 17:32:39 +00001174inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001175__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
1176 const key_equal& __eql)
1177 : __bucket_list_(nullptr, __bucket_list_deleter()),
1178 __p1_(),
1179 __p2_(0, __hf),
1180 __p3_(1.0f, __eql)
1181{
1182}
1183
1184template <class _Tp, class _Hash, class _Equal, class _Alloc>
1185__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
1186 const key_equal& __eql,
1187 const allocator_type& __a)
1188 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1189 __p1_(__node_allocator(__a)),
1190 __p2_(0, __hf),
1191 __p3_(1.0f, __eql)
1192{
1193}
1194
1195template <class _Tp, class _Hash, class _Equal, class _Alloc>
1196__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a)
1197 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1198 __p1_(__node_allocator(__a)),
1199 __p2_(0),
1200 __p3_(1.0f)
1201{
1202}
1203
1204template <class _Tp, class _Hash, class _Equal, class _Alloc>
1205__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u)
1206 : __bucket_list_(nullptr,
1207 __bucket_list_deleter(allocator_traits<__pointer_allocator>::
1208 select_on_container_copy_construction(
1209 __u.__bucket_list_.get_deleter().__alloc()), 0)),
1210 __p1_(allocator_traits<__node_allocator>::
1211 select_on_container_copy_construction(__u.__node_alloc())),
1212 __p2_(0, __u.hash_function()),
1213 __p3_(__u.__p3_)
1214{
1215}
1216
1217template <class _Tp, class _Hash, class _Equal, class _Alloc>
1218__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u,
1219 const allocator_type& __a)
1220 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1221 __p1_(__node_allocator(__a)),
1222 __p2_(0, __u.hash_function()),
1223 __p3_(__u.__p3_)
1224{
1225}
1226
Howard Hinnant73d21a42010-09-04 23:28:19 +00001227#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001228
1229template <class _Tp, class _Hash, class _Equal, class _Alloc>
1230__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001231 _NOEXCEPT_(
1232 is_nothrow_move_constructible<__bucket_list>::value &&
1233 is_nothrow_move_constructible<__first_node>::value &&
1234 is_nothrow_move_constructible<hasher>::value &&
1235 is_nothrow_move_constructible<key_equal>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001236 : __bucket_list_(_VSTD::move(__u.__bucket_list_)),
1237 __p1_(_VSTD::move(__u.__p1_)),
1238 __p2_(_VSTD::move(__u.__p2_)),
1239 __p3_(_VSTD::move(__u.__p3_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001240{
1241 if (size() > 0)
1242 {
Howard Hinnant7a445152012-07-06 17:31:14 +00001243 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001244 static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001245 __u.__p1_.first().__next_ = nullptr;
1246 __u.size() = 0;
1247 }
1248}
1249
1250template <class _Tp, class _Hash, class _Equal, class _Alloc>
1251__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u,
1252 const allocator_type& __a)
1253 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1254 __p1_(__node_allocator(__a)),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001255 __p2_(0, _VSTD::move(__u.hash_function())),
1256 __p3_(_VSTD::move(__u.__p3_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001257{
1258 if (__a == allocator_type(__u.__node_alloc()))
1259 {
1260 __bucket_list_.reset(__u.__bucket_list_.release());
1261 __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
1262 __u.__bucket_list_.get_deleter().size() = 0;
1263 if (__u.size() > 0)
1264 {
1265 __p1_.first().__next_ = __u.__p1_.first().__next_;
1266 __u.__p1_.first().__next_ = nullptr;
Howard Hinnant7a445152012-07-06 17:31:14 +00001267 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001268 static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269 size() = __u.size();
1270 __u.size() = 0;
1271 }
1272 }
1273}
1274
Howard Hinnant73d21a42010-09-04 23:28:19 +00001275#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001276
1277template <class _Tp, class _Hash, class _Equal, class _Alloc>
1278__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
1279{
1280 __deallocate(__p1_.first().__next_);
Howard Hinnant39213642013-07-23 22:01:58 +00001281#if _LIBCPP_DEBUG_LEVEL >= 2
1282 __get_db()->__erase_c(this);
1283#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001284}
1285
1286template <class _Tp, class _Hash, class _Equal, class _Alloc>
1287void
1288__hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc(
1289 const __hash_table& __u, true_type)
1290{
1291 if (__node_alloc() != __u.__node_alloc())
1292 {
1293 clear();
1294 __bucket_list_.reset();
1295 __bucket_list_.get_deleter().size() = 0;
1296 }
1297 __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc();
1298 __node_alloc() = __u.__node_alloc();
1299}
1300
1301template <class _Tp, class _Hash, class _Equal, class _Alloc>
1302__hash_table<_Tp, _Hash, _Equal, _Alloc>&
1303__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u)
1304{
1305 if (this != &__u)
1306 {
1307 __copy_assign_alloc(__u);
1308 hash_function() = __u.hash_function();
1309 key_eq() = __u.key_eq();
1310 max_load_factor() = __u.max_load_factor();
1311 __assign_multi(__u.begin(), __u.end());
1312 }
1313 return *this;
1314}
1315
1316template <class _Tp, class _Hash, class _Equal, class _Alloc>
1317void
1318__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate(__node_pointer __np)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001319 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001320{
1321 __node_allocator& __na = __node_alloc();
1322 while (__np != nullptr)
1323 {
1324 __node_pointer __next = __np->__next_;
Howard Hinnant39213642013-07-23 22:01:58 +00001325#if _LIBCPP_DEBUG_LEVEL >= 2
1326 __c_node* __c = __get_db()->__find_c_and_lock(this);
1327 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1328 {
1329 --__p;
1330 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1331 if (__i->__node_ == __np)
1332 {
1333 (*__p)->__c_ = nullptr;
1334 if (--__c->end_ != __p)
1335 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1336 }
1337 }
1338 __get_db()->unlock();
1339#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001340 __node_traits::destroy(__na, _VSTD::addressof(__np->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001341 __node_traits::deallocate(__na, __np, 1);
1342 __np = __next;
1343 }
1344}
1345
1346template <class _Tp, class _Hash, class _Equal, class _Alloc>
1347typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_pointer
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001348__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349{
1350 size_type __bc = bucket_count();
1351 for (size_type __i = 0; __i < __bc; ++__i)
1352 __bucket_list_[__i] = nullptr;
1353 size() = 0;
1354 __node_pointer __cache = __p1_.first().__next_;
1355 __p1_.first().__next_ = nullptr;
1356 return __cache;
1357}
1358
Howard Hinnant73d21a42010-09-04 23:28:19 +00001359#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001360
1361template <class _Tp, class _Hash, class _Equal, class _Alloc>
1362void
1363__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
1364 __hash_table& __u, true_type)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001365 _NOEXCEPT_(
1366 is_nothrow_move_assignable<__node_allocator>::value &&
1367 is_nothrow_move_assignable<hasher>::value &&
1368 is_nothrow_move_assignable<key_equal>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001369{
1370 clear();
1371 __bucket_list_.reset(__u.__bucket_list_.release());
1372 __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
1373 __u.__bucket_list_.get_deleter().size() = 0;
1374 __move_assign_alloc(__u);
1375 size() = __u.size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001376 hash_function() = _VSTD::move(__u.hash_function());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001377 max_load_factor() = __u.max_load_factor();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001378 key_eq() = _VSTD::move(__u.key_eq());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379 __p1_.first().__next_ = __u.__p1_.first().__next_;
1380 if (size() > 0)
1381 {
Howard Hinnant7a445152012-07-06 17:31:14 +00001382 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001383 static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001384 __u.__p1_.first().__next_ = nullptr;
1385 __u.size() = 0;
1386 }
Howard Hinnant39213642013-07-23 22:01:58 +00001387#if _LIBCPP_DEBUG_LEVEL >= 2
1388 __get_db()->swap(this, &__u);
1389#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001390}
1391
1392template <class _Tp, class _Hash, class _Equal, class _Alloc>
1393void
1394__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
1395 __hash_table& __u, false_type)
1396{
1397 if (__node_alloc() == __u.__node_alloc())
1398 __move_assign(__u, true_type());
1399 else
1400 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001401 hash_function() = _VSTD::move(__u.hash_function());
1402 key_eq() = _VSTD::move(__u.key_eq());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403 max_load_factor() = __u.max_load_factor();
1404 if (bucket_count() != 0)
1405 {
1406 __node_pointer __cache = __detach();
1407#ifndef _LIBCPP_NO_EXCEPTIONS
1408 try
1409 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001410#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411 const_iterator __i = __u.begin();
1412 while (__cache != nullptr && __u.size() != 0)
1413 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001414 __cache->__value_ = _VSTD::move(__u.remove(__i++)->__value_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001415 __node_pointer __next = __cache->__next_;
1416 __node_insert_multi(__cache);
1417 __cache = __next;
1418 }
1419#ifndef _LIBCPP_NO_EXCEPTIONS
1420 }
1421 catch (...)
1422 {
1423 __deallocate(__cache);
1424 throw;
1425 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001426#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427 __deallocate(__cache);
1428 }
1429 const_iterator __i = __u.begin();
1430 while (__u.size() != 0)
1431 {
1432 __node_holder __h =
Howard Hinnant0949eed2011-06-30 21:18:19 +00001433 __construct_node(_VSTD::move(__u.remove(__i++)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434 __node_insert_multi(__h.get());
1435 __h.release();
1436 }
1437 }
1438}
1439
1440template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99acc502010-09-21 17:32:39 +00001441inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442__hash_table<_Tp, _Hash, _Equal, _Alloc>&
1443__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001444 _NOEXCEPT_(
1445 __node_traits::propagate_on_container_move_assignment::value &&
1446 is_nothrow_move_assignable<__node_allocator>::value &&
1447 is_nothrow_move_assignable<hasher>::value &&
1448 is_nothrow_move_assignable<key_equal>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001449{
1450 __move_assign(__u, integral_constant<bool,
1451 __node_traits::propagate_on_container_move_assignment::value>());
1452 return *this;
1453}
1454
Howard Hinnant73d21a42010-09-04 23:28:19 +00001455#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001456
1457template <class _Tp, class _Hash, class _Equal, class _Alloc>
1458template <class _InputIterator>
1459void
1460__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first,
1461 _InputIterator __last)
1462{
1463 if (bucket_count() != 0)
1464 {
1465 __node_pointer __cache = __detach();
1466#ifndef _LIBCPP_NO_EXCEPTIONS
1467 try
1468 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001469#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001470 for (; __cache != nullptr && __first != __last; ++__first)
1471 {
1472 __cache->__value_ = *__first;
1473 __node_pointer __next = __cache->__next_;
1474 __node_insert_unique(__cache);
1475 __cache = __next;
1476 }
1477#ifndef _LIBCPP_NO_EXCEPTIONS
1478 }
1479 catch (...)
1480 {
1481 __deallocate(__cache);
1482 throw;
1483 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001484#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001485 __deallocate(__cache);
1486 }
1487 for (; __first != __last; ++__first)
1488 __insert_unique(*__first);
1489}
1490
1491template <class _Tp, class _Hash, class _Equal, class _Alloc>
1492template <class _InputIterator>
1493void
1494__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first,
1495 _InputIterator __last)
1496{
1497 if (bucket_count() != 0)
1498 {
1499 __node_pointer __cache = __detach();
1500#ifndef _LIBCPP_NO_EXCEPTIONS
1501 try
1502 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001503#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001504 for (; __cache != nullptr && __first != __last; ++__first)
1505 {
1506 __cache->__value_ = *__first;
1507 __node_pointer __next = __cache->__next_;
1508 __node_insert_multi(__cache);
1509 __cache = __next;
1510 }
1511#ifndef _LIBCPP_NO_EXCEPTIONS
1512 }
1513 catch (...)
1514 {
1515 __deallocate(__cache);
1516 throw;
1517 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001518#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001519 __deallocate(__cache);
1520 }
1521 for (; __first != __last; ++__first)
1522 __insert_multi(*__first);
1523}
1524
1525template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99acc502010-09-21 17:32:39 +00001526inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001527typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001528__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001529{
Howard Hinnant39213642013-07-23 22:01:58 +00001530#if _LIBCPP_DEBUG_LEVEL >= 2
1531 return iterator(__p1_.first().__next_, this);
1532#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001533 return iterator(__p1_.first().__next_);
Howard Hinnant39213642013-07-23 22:01:58 +00001534#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001535}
1536
1537template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99acc502010-09-21 17:32:39 +00001538inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001539typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001540__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001541{
Howard Hinnant39213642013-07-23 22:01:58 +00001542#if _LIBCPP_DEBUG_LEVEL >= 2
1543 return iterator(nullptr, this);
1544#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545 return iterator(nullptr);
Howard Hinnant39213642013-07-23 22:01:58 +00001546#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001547}
1548
1549template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99acc502010-09-21 17:32:39 +00001550inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001551typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001552__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001553{
Howard Hinnant39213642013-07-23 22:01:58 +00001554#if _LIBCPP_DEBUG_LEVEL >= 2
1555 return const_iterator(__p1_.first().__next_, this);
1556#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001557 return const_iterator(__p1_.first().__next_);
Howard Hinnant39213642013-07-23 22:01:58 +00001558#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001559}
1560
1561template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99acc502010-09-21 17:32:39 +00001562inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001563typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001564__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001565{
Howard Hinnant39213642013-07-23 22:01:58 +00001566#if _LIBCPP_DEBUG_LEVEL >= 2
1567 return const_iterator(nullptr, this);
1568#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001569 return const_iterator(nullptr);
Howard Hinnant39213642013-07-23 22:01:58 +00001570#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571}
1572
1573template <class _Tp, class _Hash, class _Equal, class _Alloc>
1574void
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001575__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001576{
1577 if (size() > 0)
1578 {
1579 __deallocate(__p1_.first().__next_);
1580 __p1_.first().__next_ = nullptr;
1581 size_type __bc = bucket_count();
Howard Hinnant9f66bff2011-07-05 14:14:17 +00001582 for (size_type __i = 0; __i < __bc; ++__i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001583 __bucket_list_[__i] = nullptr;
1584 size() = 0;
1585 }
1586}
1587
1588template <class _Tp, class _Hash, class _Equal, class _Alloc>
1589pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1590__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd)
1591{
1592 __nd->__hash_ = hash_function()(__nd->__value_);
1593 size_type __bc = bucket_count();
1594 bool __inserted = false;
1595 __node_pointer __ndptr;
1596 size_t __chash;
1597 if (__bc != 0)
1598 {
Howard Hinnant7a445152012-07-06 17:31:14 +00001599 __chash = __constrain_hash(__nd->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001600 __ndptr = __bucket_list_[__chash];
1601 if (__ndptr != nullptr)
1602 {
1603 for (__ndptr = __ndptr->__next_; __ndptr != nullptr &&
Howard Hinnant7a445152012-07-06 17:31:14 +00001604 __constrain_hash(__ndptr->__hash_, __bc) == __chash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001605 __ndptr = __ndptr->__next_)
1606 {
1607 if (key_eq()(__ndptr->__value_, __nd->__value_))
1608 goto __done;
1609 }
1610 }
1611 }
1612 {
1613 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1614 {
Eric Fiselier57947ca2015-02-02 21:31:48 +00001615 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616 size_type(ceil(float(size() + 1) / max_load_factor()))));
1617 __bc = bucket_count();
Howard Hinnant7a445152012-07-06 17:31:14 +00001618 __chash = __constrain_hash(__nd->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001619 }
1620 // insert_after __bucket_list_[__chash], or __first_node if bucket is null
1621 __node_pointer __pn = __bucket_list_[__chash];
1622 if (__pn == nullptr)
1623 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001624 __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001625 __nd->__next_ = __pn->__next_;
1626 __pn->__next_ = __nd;
1627 // fix up __bucket_list_
1628 __bucket_list_[__chash] = __pn;
1629 if (__nd->__next_ != nullptr)
Howard Hinnant7a445152012-07-06 17:31:14 +00001630 __bucket_list_[__constrain_hash(__nd->__next_->__hash_, __bc)] = __nd;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001631 }
1632 else
1633 {
1634 __nd->__next_ = __pn->__next_;
1635 __pn->__next_ = __nd;
1636 }
1637 __ndptr = __nd;
1638 // increment size
1639 ++size();
1640 __inserted = true;
1641 }
1642__done:
Howard Hinnant39213642013-07-23 22:01:58 +00001643#if _LIBCPP_DEBUG_LEVEL >= 2
1644 return pair<iterator, bool>(iterator(__ndptr, this), __inserted);
1645#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646 return pair<iterator, bool>(iterator(__ndptr), __inserted);
Howard Hinnant39213642013-07-23 22:01:58 +00001647#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001648}
1649
1650template <class _Tp, class _Hash, class _Equal, class _Alloc>
1651typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1652__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp)
1653{
1654 __cp->__hash_ = hash_function()(__cp->__value_);
1655 size_type __bc = bucket_count();
1656 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1657 {
Eric Fiselier57947ca2015-02-02 21:31:48 +00001658 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001659 size_type(ceil(float(size() + 1) / max_load_factor()))));
1660 __bc = bucket_count();
1661 }
Howard Hinnant7a445152012-07-06 17:31:14 +00001662 size_t __chash = __constrain_hash(__cp->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001663 __node_pointer __pn = __bucket_list_[__chash];
1664 if (__pn == nullptr)
1665 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001666 __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001667 __cp->__next_ = __pn->__next_;
1668 __pn->__next_ = __cp;
1669 // fix up __bucket_list_
1670 __bucket_list_[__chash] = __pn;
1671 if (__cp->__next_ != nullptr)
Howard Hinnant7a445152012-07-06 17:31:14 +00001672 __bucket_list_[__constrain_hash(__cp->__next_->__hash_, __bc)] = __cp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001673 }
1674 else
1675 {
1676 for (bool __found = false; __pn->__next_ != nullptr &&
Howard Hinnant7a445152012-07-06 17:31:14 +00001677 __constrain_hash(__pn->__next_->__hash_, __bc) == __chash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001678 __pn = __pn->__next_)
Howard Hinnant324bb032010-08-22 00:02:43 +00001679 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001680 // __found key_eq() action
1681 // false false loop
1682 // true true loop
1683 // false true set __found to true
1684 // true false break
1685 if (__found != (__pn->__next_->__hash_ == __cp->__hash_ &&
1686 key_eq()(__pn->__next_->__value_, __cp->__value_)))
1687 {
1688 if (!__found)
1689 __found = true;
1690 else
1691 break;
1692 }
1693 }
1694 __cp->__next_ = __pn->__next_;
1695 __pn->__next_ = __cp;
1696 if (__cp->__next_ != nullptr)
1697 {
Howard Hinnant7a445152012-07-06 17:31:14 +00001698 size_t __nhash = __constrain_hash(__cp->__next_->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001699 if (__nhash != __chash)
1700 __bucket_list_[__nhash] = __cp;
1701 }
1702 }
1703 ++size();
Howard Hinnant39213642013-07-23 22:01:58 +00001704#if _LIBCPP_DEBUG_LEVEL >= 2
1705 return iterator(__cp, this);
1706#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001707 return iterator(__cp);
Howard Hinnant39213642013-07-23 22:01:58 +00001708#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709}
1710
1711template <class _Tp, class _Hash, class _Equal, class _Alloc>
1712typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1713__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
1714 const_iterator __p, __node_pointer __cp)
1715{
Howard Hinnant824c1992013-08-02 17:50:49 +00001716#if _LIBCPP_DEBUG_LEVEL >= 2
1717 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1718 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
1719 " referring to this unordered container");
1720#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001721 if (__p != end() && key_eq()(*__p, __cp->__value_))
1722 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001723 __node_pointer __np = __p.__node_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001724 __cp->__hash_ = __np->__hash_;
1725 size_type __bc = bucket_count();
1726 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1727 {
Eric Fiselier57947ca2015-02-02 21:31:48 +00001728 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001729 size_type(ceil(float(size() + 1) / max_load_factor()))));
1730 __bc = bucket_count();
1731 }
Howard Hinnant7a445152012-07-06 17:31:14 +00001732 size_t __chash = __constrain_hash(__cp->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001733 __node_pointer __pp = __bucket_list_[__chash];
1734 while (__pp->__next_ != __np)
1735 __pp = __pp->__next_;
1736 __cp->__next_ = __np;
1737 __pp->__next_ = __cp;
1738 ++size();
Howard Hinnant39213642013-07-23 22:01:58 +00001739#if _LIBCPP_DEBUG_LEVEL >= 2
1740 return iterator(__cp, this);
1741#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742 return iterator(__cp);
Howard Hinnant39213642013-07-23 22:01:58 +00001743#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001744 }
1745 return __node_insert_multi(__cp);
1746}
1747
1748template <class _Tp, class _Hash, class _Equal, class _Alloc>
1749pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1750__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(const value_type& __x)
1751{
Eric Fiselierfdae69a2015-06-13 07:18:32 +00001752 return __insert_unique_value(__x);
1753}
1754
1755
1756#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1757template <class _Tp, class _Hash, class _Equal, class _Alloc>
1758template <class _ValueTp>
1759_LIBCPP_INLINE_VISIBILITY
1760pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1761__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique_value(_ValueTp&& __x)
1762#else
1763template <class _Tp, class _Hash, class _Equal, class _Alloc>
1764_LIBCPP_INLINE_VISIBILITY
1765pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1766__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique_value(const value_type& __x)
1767#endif
1768{
1769#if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1770 typedef const value_type& _ValueTp;
1771#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001772 size_t __hash = hash_function()(__x);
1773 size_type __bc = bucket_count();
1774 bool __inserted = false;
1775 __node_pointer __nd;
1776 size_t __chash;
1777 if (__bc != 0)
1778 {
Howard Hinnant7a445152012-07-06 17:31:14 +00001779 __chash = __constrain_hash(__hash, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001780 __nd = __bucket_list_[__chash];
1781 if (__nd != nullptr)
1782 {
1783 for (__nd = __nd->__next_; __nd != nullptr &&
Howard Hinnant7a445152012-07-06 17:31:14 +00001784 __constrain_hash(__nd->__hash_, __bc) == __chash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001785 __nd = __nd->__next_)
1786 {
1787 if (key_eq()(__nd->__value_, __x))
1788 goto __done;
1789 }
1790 }
1791 }
1792 {
Eric Fiselierfdae69a2015-06-13 07:18:32 +00001793 __node_holder __h = __construct_node(_VSTD::forward<_ValueTp>(__x), __hash);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001794 if (size()+1 > __bc * max_load_factor() || __bc == 0)
1795 {
Eric Fiselier57947ca2015-02-02 21:31:48 +00001796 rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797 size_type(ceil(float(size() + 1) / max_load_factor()))));
1798 __bc = bucket_count();
Howard Hinnant7a445152012-07-06 17:31:14 +00001799 __chash = __constrain_hash(__hash, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001800 }
1801 // insert_after __bucket_list_[__chash], or __first_node if bucket is null
1802 __node_pointer __pn = __bucket_list_[__chash];
1803 if (__pn == nullptr)
1804 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001805 __pn = static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806 __h->__next_ = __pn->__next_;
1807 __pn->__next_ = __h.get();
1808 // fix up __bucket_list_
1809 __bucket_list_[__chash] = __pn;
1810 if (__h->__next_ != nullptr)
Howard Hinnant7a445152012-07-06 17:31:14 +00001811 __bucket_list_[__constrain_hash(__h->__next_->__hash_, __bc)] = __h.get();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001812 }
1813 else
1814 {
1815 __h->__next_ = __pn->__next_;
1816 __pn->__next_ = __h.get();
1817 }
1818 __nd = __h.release();
1819 // increment size
1820 ++size();
1821 __inserted = true;
1822 }
1823__done:
Howard Hinnant39213642013-07-23 22:01:58 +00001824#if _LIBCPP_DEBUG_LEVEL >= 2
1825 return pair<iterator, bool>(iterator(__nd, this), __inserted);
1826#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001827 return pair<iterator, bool>(iterator(__nd), __inserted);
Howard Hinnant39213642013-07-23 22:01:58 +00001828#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001829}
1830
Howard Hinnant73d21a42010-09-04 23:28:19 +00001831#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1832#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833
1834template <class _Tp, class _Hash, class _Equal, class _Alloc>
1835template <class... _Args>
1836pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1837__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique(_Args&&... __args)
1838{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001839 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001840 pair<iterator, bool> __r = __node_insert_unique(__h.get());
1841 if (__r.second)
1842 __h.release();
1843 return __r;
1844}
1845
1846template <class _Tp, class _Hash, class _Equal, class _Alloc>
1847template <class... _Args>
1848typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1849__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args)
1850{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001851 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852 iterator __r = __node_insert_multi(__h.get());
1853 __h.release();
1854 return __r;
1855}
1856
1857template <class _Tp, class _Hash, class _Equal, class _Alloc>
1858template <class... _Args>
1859typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1860__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(
1861 const_iterator __p, _Args&&... __args)
1862{
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001863#if _LIBCPP_DEBUG_LEVEL >= 2
1864 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1865 "unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
1866 " referring to this unordered container");
1867#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001868 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869 iterator __r = __node_insert_multi(__p, __h.get());
1870 __h.release();
1871 return __r;
1872}
1873
Howard Hinnant73d21a42010-09-04 23:28:19 +00001874#endif // _LIBCPP_HAS_NO_VARIADICS
1875
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001876template <class _Tp, class _Hash, class _Equal, class _Alloc>
Eric Fiselierfdae69a2015-06-13 07:18:32 +00001877pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
1878__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(value_type&& __x)
1879{
1880 return __insert_unique_value(_VSTD::move(__x));
1881}
1882
1883template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001884template <class _Pp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001885pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
Howard Hinnant99968442011-11-29 18:15:50 +00001886__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_unique(_Pp&& __x)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001887{
Howard Hinnant99968442011-11-29 18:15:50 +00001888 __node_holder __h = __construct_node(_VSTD::forward<_Pp>(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889 pair<iterator, bool> __r = __node_insert_unique(__h.get());
1890 if (__r.second)
1891 __h.release();
1892 return __r;
1893}
1894
Howard Hinnant73d21a42010-09-04 23:28:19 +00001895#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001896
Howard Hinnant73d21a42010-09-04 23:28:19 +00001897#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001898
1899template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001900template <class _Pp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001901typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
Howard Hinnant99968442011-11-29 18:15:50 +00001902__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(_Pp&& __x)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001903{
Howard Hinnant99968442011-11-29 18:15:50 +00001904 __node_holder __h = __construct_node(_VSTD::forward<_Pp>(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001905 iterator __r = __node_insert_multi(__h.get());
1906 __h.release();
1907 return __r;
1908}
1909
1910template <class _Tp, class _Hash, class _Equal, class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001911template <class _Pp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001912typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1913__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
Howard Hinnant99968442011-11-29 18:15:50 +00001914 _Pp&& __x)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001915{
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001916#if _LIBCPP_DEBUG_LEVEL >= 2
1917 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1918 "unordered container::insert(const_iterator, rvalue) called with an iterator not"
1919 " referring to this unordered container");
1920#endif
Howard Hinnant99968442011-11-29 18:15:50 +00001921 __node_holder __h = __construct_node(_VSTD::forward<_Pp>(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001922 iterator __r = __node_insert_multi(__p, __h.get());
1923 __h.release();
1924 return __r;
1925}
1926
Howard Hinnant73d21a42010-09-04 23:28:19 +00001927#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928
1929template <class _Tp, class _Hash, class _Equal, class _Alloc>
1930typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1931__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const value_type& __x)
1932{
1933 __node_holder __h = __construct_node(__x);
1934 iterator __r = __node_insert_multi(__h.get());
1935 __h.release();
1936 return __r;
1937}
1938
1939template <class _Tp, class _Hash, class _Equal, class _Alloc>
1940typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
1941__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
1942 const value_type& __x)
1943{
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00001944#if _LIBCPP_DEBUG_LEVEL >= 2
1945 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1946 "unordered container::insert(const_iterator, lvalue) called with an iterator not"
1947 " referring to this unordered container");
1948#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001949 __node_holder __h = __construct_node(__x);
1950 iterator __r = __node_insert_multi(__p, __h.get());
1951 __h.release();
1952 return __r;
1953}
1954
Howard Hinnant73d21a42010-09-04 23:28:19 +00001955#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001956
1957template <class _Tp, class _Hash, class _Equal, class _Alloc>
1958void
1959__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
1960{
Howard Hinnant7a445152012-07-06 17:31:14 +00001961 if (__n == 1)
1962 __n = 2;
1963 else if (__n & (__n - 1))
1964 __n = __next_prime(__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001965 size_type __bc = bucket_count();
1966 if (__n > __bc)
1967 __rehash(__n);
Howard Hinnant7a445152012-07-06 17:31:14 +00001968 else if (__n < __bc)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001969 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001970 __n = _VSTD::max<size_type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001971 (
1972 __n,
Eric Fiselier57947ca2015-02-02 21:31:48 +00001973 __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) :
1974 __next_prime(size_t(ceil(float(size()) / max_load_factor())))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001975 );
1976 if (__n < __bc)
1977 __rehash(__n);
1978 }
1979}
1980
1981template <class _Tp, class _Hash, class _Equal, class _Alloc>
1982void
1983__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
1984{
Howard Hinnant39213642013-07-23 22:01:58 +00001985#if _LIBCPP_DEBUG_LEVEL >= 2
1986 __get_db()->__invalidate_all(this);
1987#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001988 __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc();
1989 __bucket_list_.reset(__nbc > 0 ?
1990 __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr);
1991 __bucket_list_.get_deleter().size() = __nbc;
1992 if (__nbc > 0)
1993 {
1994 for (size_type __i = 0; __i < __nbc; ++__i)
1995 __bucket_list_[__i] = nullptr;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001996 __node_pointer __pp(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first())));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001997 __node_pointer __cp = __pp->__next_;
1998 if (__cp != nullptr)
1999 {
Howard Hinnant7a445152012-07-06 17:31:14 +00002000 size_type __chash = __constrain_hash(__cp->__hash_, __nbc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002001 __bucket_list_[__chash] = __pp;
2002 size_type __phash = __chash;
2003 for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
2004 __cp = __pp->__next_)
2005 {
Howard Hinnant7a445152012-07-06 17:31:14 +00002006 __chash = __constrain_hash(__cp->__hash_, __nbc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002007 if (__chash == __phash)
2008 __pp = __cp;
2009 else
2010 {
2011 if (__bucket_list_[__chash] == nullptr)
2012 {
2013 __bucket_list_[__chash] = __pp;
2014 __pp = __cp;
2015 __phash = __chash;
2016 }
2017 else
2018 {
2019 __node_pointer __np = __cp;
2020 for (; __np->__next_ != nullptr &&
2021 key_eq()(__cp->__value_, __np->__next_->__value_);
2022 __np = __np->__next_)
2023 ;
2024 __pp->__next_ = __np->__next_;
2025 __np->__next_ = __bucket_list_[__chash]->__next_;
2026 __bucket_list_[__chash]->__next_ = __cp;
Howard Hinnant324bb032010-08-22 00:02:43 +00002027
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002028 }
2029 }
2030 }
2031 }
2032 }
2033}
2034
2035template <class _Tp, class _Hash, class _Equal, class _Alloc>
2036template <class _Key>
2037typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2038__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k)
2039{
2040 size_t __hash = hash_function()(__k);
2041 size_type __bc = bucket_count();
2042 if (__bc != 0)
2043 {
Howard Hinnant7a445152012-07-06 17:31:14 +00002044 size_t __chash = __constrain_hash(__hash, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002045 __node_pointer __nd = __bucket_list_[__chash];
2046 if (__nd != nullptr)
2047 {
2048 for (__nd = __nd->__next_; __nd != nullptr &&
Howard Hinnant7a445152012-07-06 17:31:14 +00002049 __constrain_hash(__nd->__hash_, __bc) == __chash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002050 __nd = __nd->__next_)
2051 {
2052 if (key_eq()(__nd->__value_, __k))
Howard Hinnant39213642013-07-23 22:01:58 +00002053#if _LIBCPP_DEBUG_LEVEL >= 2
2054 return iterator(__nd, this);
2055#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002056 return iterator(__nd);
Howard Hinnant39213642013-07-23 22:01:58 +00002057#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002058 }
2059 }
2060 }
2061 return end();
2062}
2063
2064template <class _Tp, class _Hash, class _Equal, class _Alloc>
2065template <class _Key>
2066typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
2067__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const
2068{
2069 size_t __hash = hash_function()(__k);
2070 size_type __bc = bucket_count();
2071 if (__bc != 0)
2072 {
Howard Hinnant7a445152012-07-06 17:31:14 +00002073 size_t __chash = __constrain_hash(__hash, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002074 __node_const_pointer __nd = __bucket_list_[__chash];
2075 if (__nd != nullptr)
2076 {
2077 for (__nd = __nd->__next_; __nd != nullptr &&
Howard Hinnant7a445152012-07-06 17:31:14 +00002078 __constrain_hash(__nd->__hash_, __bc) == __chash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002079 __nd = __nd->__next_)
2080 {
2081 if (key_eq()(__nd->__value_, __k))
Howard Hinnant39213642013-07-23 22:01:58 +00002082#if _LIBCPP_DEBUG_LEVEL >= 2
2083 return const_iterator(__nd, this);
2084#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002085 return const_iterator(__nd);
Howard Hinnant39213642013-07-23 22:01:58 +00002086#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002087 }
2088 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002089
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090 }
2091 return end();
2092}
2093
Howard Hinnant73d21a42010-09-04 23:28:19 +00002094#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2095#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002096
2097template <class _Tp, class _Hash, class _Equal, class _Alloc>
2098template <class ..._Args>
2099typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
2100__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args)
2101{
2102 __node_allocator& __na = __node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002103 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00002104 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002105 __h.get_deleter().__value_constructed = true;
2106 __h->__hash_ = hash_function()(__h->__value_);
2107 __h->__next_ = nullptr;
2108 return __h;
2109}
2110
Howard Hinnant73d21a42010-09-04 23:28:19 +00002111#endif // _LIBCPP_HAS_NO_VARIADICS
2112
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002113template <class _Tp, class _Hash, class _Equal, class _Alloc>
2114typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
2115__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(value_type&& __v,
2116 size_t __hash)
2117{
2118 __node_allocator& __na = __node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002119 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00002120 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002121 __h.get_deleter().__value_constructed = true;
2122 __h->__hash_ = __hash;
2123 __h->__next_ = nullptr;
Howard Hinnant9a894d92013-08-22 18:29:50 +00002124 return __h;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002125}
2126
Howard Hinnant73d21a42010-09-04 23:28:19 +00002127#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002128
2129template <class _Tp, class _Hash, class _Equal, class _Alloc>
2130typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
2131__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const value_type& __v)
2132{
2133 __node_allocator& __na = __node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002134 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00002135 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002136 __h.get_deleter().__value_constructed = true;
2137 __h->__hash_ = hash_function()(__h->__value_);
2138 __h->__next_ = nullptr;
Howard Hinnant9a894d92013-08-22 18:29:50 +00002139 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002140}
2141
Howard Hinnant73d21a42010-09-04 23:28:19 +00002142#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002143
2144template <class _Tp, class _Hash, class _Equal, class _Alloc>
2145typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
2146__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const value_type& __v,
2147 size_t __hash)
2148{
2149 __node_allocator& __na = __node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002150 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00002151 __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002152 __h.get_deleter().__value_constructed = true;
2153 __h->__hash_ = __hash;
2154 __h->__next_ = nullptr;
Howard Hinnant9a894d92013-08-22 18:29:50 +00002155 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002156}
2157
2158template <class _Tp, class _Hash, class _Equal, class _Alloc>
2159typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2160__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
2161{
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00002162 __node_pointer __np = __p.__node_;
Howard Hinnant39213642013-07-23 22:01:58 +00002163#if _LIBCPP_DEBUG_LEVEL >= 2
2164 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2165 "unordered container erase(iterator) called with an iterator not"
2166 " referring to this container");
2167 _LIBCPP_ASSERT(__p != end(),
2168 "unordered container erase(iterator) called with a non-dereferenceable iterator");
2169 iterator __r(__np, this);
2170#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002171 iterator __r(__np);
Howard Hinnant39213642013-07-23 22:01:58 +00002172#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002173 ++__r;
2174 remove(__p);
2175 return __r;
2176}
2177
2178template <class _Tp, class _Hash, class _Equal, class _Alloc>
2179typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
2180__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
2181 const_iterator __last)
2182{
Howard Hinnant39213642013-07-23 22:01:58 +00002183#if _LIBCPP_DEBUG_LEVEL >= 2
2184 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2185 "unodered container::erase(iterator, iterator) called with an iterator not"
2186 " referring to this unodered container");
2187 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
2188 "unodered container::erase(iterator, iterator) called with an iterator not"
2189 " referring to this unodered container");
2190#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002191 for (const_iterator __p = __first; __first != __last; __p = __first)
2192 {
2193 ++__first;
2194 erase(__p);
2195 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00002196 __node_pointer __np = __last.__node_;
Howard Hinnant39213642013-07-23 22:01:58 +00002197#if _LIBCPP_DEBUG_LEVEL >= 2
2198 return iterator (__np, this);
2199#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002200 return iterator (__np);
Howard Hinnant39213642013-07-23 22:01:58 +00002201#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002202}
2203
2204template <class _Tp, class _Hash, class _Equal, class _Alloc>
2205template <class _Key>
2206typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2207__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k)
2208{
2209 iterator __i = find(__k);
2210 if (__i == end())
2211 return 0;
2212 erase(__i);
2213 return 1;
2214}
2215
2216template <class _Tp, class _Hash, class _Equal, class _Alloc>
2217template <class _Key>
2218typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2219__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k)
2220{
2221 size_type __r = 0;
2222 iterator __i = find(__k);
2223 if (__i != end())
2224 {
2225 iterator __e = end();
2226 do
2227 {
2228 erase(__i++);
2229 ++__r;
2230 } while (__i != __e && key_eq()(*__i, __k));
2231 }
2232 return __r;
2233}
2234
2235template <class _Tp, class _Hash, class _Equal, class _Alloc>
2236typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002237__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002238{
2239 // current node
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00002240 __node_pointer __cn = __p.__node_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002241 size_type __bc = bucket_count();
Howard Hinnant7a445152012-07-06 17:31:14 +00002242 size_t __chash = __constrain_hash(__cn->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002243 // find previous node
2244 __node_pointer __pn = __bucket_list_[__chash];
2245 for (; __pn->__next_ != __cn; __pn = __pn->__next_)
2246 ;
2247 // Fix up __bucket_list_
2248 // if __pn is not in same bucket (before begin is not in same bucket) &&
2249 // if __cn->__next_ is not in same bucket (nullptr is not in same bucket)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00002250 if (__pn == static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()))
2251 || __constrain_hash(__pn->__hash_, __bc) != __chash)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002252 {
Howard Hinnant7a445152012-07-06 17:31:14 +00002253 if (__cn->__next_ == nullptr || __constrain_hash(__cn->__next_->__hash_, __bc) != __chash)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002254 __bucket_list_[__chash] = nullptr;
2255 }
2256 // if __cn->__next_ is not in same bucket (nullptr is in same bucket)
2257 if (__cn->__next_ != nullptr)
2258 {
Howard Hinnant7a445152012-07-06 17:31:14 +00002259 size_t __nhash = __constrain_hash(__cn->__next_->__hash_, __bc);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002260 if (__nhash != __chash)
2261 __bucket_list_[__nhash] = __pn;
2262 }
2263 // remove __cn
2264 __pn->__next_ = __cn->__next_;
2265 __cn->__next_ = nullptr;
2266 --size();
Howard Hinnant39213642013-07-23 22:01:58 +00002267#if _LIBCPP_DEBUG_LEVEL >= 2
2268 __c_node* __c = __get_db()->__find_c_and_lock(this);
2269 for (__i_node** __p = __c->end_; __p != __c->beg_; )
2270 {
2271 --__p;
2272 iterator* __i = static_cast<iterator*>((*__p)->__i_);
2273 if (__i->__node_ == __cn)
2274 {
2275 (*__p)->__c_ = nullptr;
2276 if (--__c->end_ != __p)
2277 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
2278 }
2279 }
2280 __get_db()->unlock();
2281#endif
Howard Hinnant99968442011-11-29 18:15:50 +00002282 return __node_holder(__cn, _Dp(__node_alloc(), true));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002283}
2284
2285template <class _Tp, class _Hash, class _Equal, class _Alloc>
2286template <class _Key>
Howard Hinnant99acc502010-09-21 17:32:39 +00002287inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002288typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2289__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const
2290{
2291 return static_cast<size_type>(find(__k) != end());
2292}
2293
2294template <class _Tp, class _Hash, class _Equal, class _Alloc>
2295template <class _Key>
2296typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2297__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const
2298{
2299 size_type __r = 0;
2300 const_iterator __i = find(__k);
2301 if (__i != end())
2302 {
2303 const_iterator __e = end();
2304 do
2305 {
2306 ++__i;
2307 ++__r;
2308 } while (__i != __e && key_eq()(*__i, __k));
2309 }
2310 return __r;
2311}
2312
2313template <class _Tp, class _Hash, class _Equal, class _Alloc>
2314template <class _Key>
2315pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
2316 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
2317__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
2318 const _Key& __k)
2319{
2320 iterator __i = find(__k);
2321 iterator __j = __i;
2322 if (__i != end())
2323 ++__j;
2324 return pair<iterator, iterator>(__i, __j);
2325}
2326
2327template <class _Tp, class _Hash, class _Equal, class _Alloc>
2328template <class _Key>
2329pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
2330 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
2331__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
2332 const _Key& __k) const
2333{
2334 const_iterator __i = find(__k);
2335 const_iterator __j = __i;
2336 if (__i != end())
2337 ++__j;
2338 return pair<const_iterator, const_iterator>(__i, __j);
2339}
2340
2341template <class _Tp, class _Hash, class _Equal, class _Alloc>
2342template <class _Key>
2343pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
2344 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
2345__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
2346 const _Key& __k)
2347{
2348 iterator __i = find(__k);
2349 iterator __j = __i;
2350 if (__i != end())
2351 {
2352 iterator __e = end();
2353 do
2354 {
2355 ++__j;
2356 } while (__j != __e && key_eq()(*__j, __k));
2357 }
2358 return pair<iterator, iterator>(__i, __j);
2359}
2360
2361template <class _Tp, class _Hash, class _Equal, class _Alloc>
2362template <class _Key>
2363pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
2364 typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
2365__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
2366 const _Key& __k) const
2367{
2368 const_iterator __i = find(__k);
2369 const_iterator __j = __i;
2370 if (__i != end())
2371 {
2372 const_iterator __e = end();
2373 do
2374 {
2375 ++__j;
2376 } while (__j != __e && key_eq()(*__j, __k));
2377 }
2378 return pair<const_iterator, const_iterator>(__i, __j);
2379}
2380
2381template <class _Tp, class _Hash, class _Equal, class _Alloc>
2382void
2383__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002384 _NOEXCEPT_(
2385 (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value ||
2386 __is_nothrow_swappable<__pointer_allocator>::value) &&
2387 (!__node_traits::propagate_on_container_swap::value ||
2388 __is_nothrow_swappable<__node_allocator>::value) &&
2389 __is_nothrow_swappable<hasher>::value &&
2390 __is_nothrow_swappable<key_equal>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002391{
2392 {
2393 __node_pointer_pointer __npp = __bucket_list_.release();
2394 __bucket_list_.reset(__u.__bucket_list_.release());
2395 __u.__bucket_list_.reset(__npp);
2396 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002397 _VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002398 __swap_alloc(__bucket_list_.get_deleter().__alloc(),
2399 __u.__bucket_list_.get_deleter().__alloc());
2400 __swap_alloc(__node_alloc(), __u.__node_alloc());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002401 _VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002402 __p2_.swap(__u.__p2_);
2403 __p3_.swap(__u.__p3_);
2404 if (size() > 0)
Howard Hinnant7a445152012-07-06 17:31:14 +00002405 __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash_, bucket_count())] =
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00002406 static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__p1_.first()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002407 if (__u.size() > 0)
Howard Hinnant7a445152012-07-06 17:31:14 +00002408 __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash_, __u.bucket_count())] =
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00002409 static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(__u.__p1_.first()));
Howard Hinnant39213642013-07-23 22:01:58 +00002410#if _LIBCPP_DEBUG_LEVEL >= 2
2411 __get_db()->swap(this, &__u);
2412#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002413}
2414
2415template <class _Tp, class _Hash, class _Equal, class _Alloc>
2416typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
2417__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const
2418{
Howard Hinnant0bb0a7c2013-07-29 19:05:47 +00002419 _LIBCPP_ASSERT(__n < bucket_count(),
2420 "unordered container::bucket_size(n) called with n >= bucket_count()");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002421 __node_const_pointer __np = __bucket_list_[__n];
2422 size_type __bc = bucket_count();
2423 size_type __r = 0;
2424 if (__np != nullptr)
2425 {
2426 for (__np = __np->__next_; __np != nullptr &&
Howard Hinnant7a445152012-07-06 17:31:14 +00002427 __constrain_hash(__np->__hash_, __bc) == __n;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002428 __np = __np->__next_, ++__r)
2429 ;
2430 }
2431 return __r;
2432}
2433
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002434template <class _Tp, class _Hash, class _Equal, class _Alloc>
2435inline _LIBCPP_INLINE_VISIBILITY
2436void
2437swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x,
2438 __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y)
2439 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2440{
2441 __x.swap(__y);
2442}
2443
Howard Hinnant39213642013-07-23 22:01:58 +00002444#if _LIBCPP_DEBUG_LEVEL >= 2
2445
2446template <class _Tp, class _Hash, class _Equal, class _Alloc>
2447bool
2448__hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const
2449{
2450 return __i->__node_ != nullptr;
2451}
2452
2453template <class _Tp, class _Hash, class _Equal, class _Alloc>
2454bool
2455__hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const
2456{
2457 return false;
2458}
2459
2460template <class _Tp, class _Hash, class _Equal, class _Alloc>
2461bool
2462__hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
2463{
2464 return false;
2465}
2466
2467template <class _Tp, class _Hash, class _Equal, class _Alloc>
2468bool
2469__hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
2470{
2471 return false;
2472}
2473
2474#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002475_LIBCPP_END_NAMESPACE_STD
2476
2477#endif // _LIBCPP__HASH_TABLE