33#pragma GCC system_header
36#if __cplusplus > 201402L
40namespace std _GLIBCXX_VISIBILITY(default)
42_GLIBCXX_BEGIN_NAMESPACE_VERSION
44 template<
typename _Tp,
typename _Hash>
47 __is_fast_hash<_Hash>,
49 __is_nothrow_invocable<const _Hash&, const _Tp&>>>;
169 template<
typename _Key,
typename _Value,
typename _Alloc,
170 typename _ExtractKey,
typename _Equal,
171 typename _H1,
typename _H2,
typename _Hash,
172 typename _RehashPolicy,
typename _Traits>
175 _H1, _H2, _Hash, _Traits>,
177 _H1, _H2, _Hash, _RehashPolicy, _Traits>,
179 _H1, _H2, _Hash, _RehashPolicy, _Traits>,
181 _H1, _H2, _Hash, _RehashPolicy, _Traits>,
183 _H1, _H2, _Hash, _RehashPolicy, _Traits>,
185 __alloc_rebind<_Alloc,
186 __detail::_Hash_node<_Value,
187 _Traits::__hash_cached::value>>>
190 "unordered container must have a non-const, non-volatile value_type");
191#ifdef __STRICT_ANSI__
193 "unordered container must have the same value_type as its allocator");
196 using __traits_type = _Traits;
197 using __hash_cached =
typename __traits_type::__hash_cached;
199 using __node_alloc_type = __alloc_rebind<_Alloc, __node_type>;
203 using __value_alloc_traits =
204 typename __hashtable_alloc::__value_alloc_traits;
205 using __node_alloc_traits =
211 typedef _Key key_type;
212 typedef _Value value_type;
213 typedef _Alloc allocator_type;
214 typedef _Equal key_equal;
218 typedef typename __value_alloc_traits::pointer pointer;
219 typedef typename __value_alloc_traits::const_pointer const_pointer;
220 typedef value_type& reference;
221 typedef const value_type& const_reference;
224 using __rehash_type = _RehashPolicy;
225 using __rehash_state =
typename __rehash_type::_State;
227 using __constant_iterators =
typename __traits_type::__constant_iterators;
228 using __unique_keys =
typename __traits_type::__unique_keys;
231 __constant_iterators::value,
233 __detail::_Select1st>::type;
236 _Hashtable_base<_Key, _Value, _ExtractKey,
237 _Equal, _H1, _H2, _Hash, _Traits>;
240 using __hash_code =
typename __hashtable_base::__hash_code;
241 using __ireturn_type =
typename __hashtable_base::__ireturn_type;
244 _Equal, _H1, _H2, _Hash,
245 _RehashPolicy, _Traits>;
250 _RehashPolicy, _Traits>;
253 _Equal, _H1, _H2, _Hash,
254 _RehashPolicy, _Traits>;
256 using __reuse_or_alloc_node_type =
257 __detail::_ReuseOrAllocNode<__node_alloc_type>;
260 template<
typename _Cond>
261 using __if_hash_cached = __or_<__not_<__hash_cached>, _Cond>;
263 template<
typename _Cond>
264 using __if_hash_not_cached = __or_<__hash_cached, _Cond>;
270 struct __hash_code_base_access : __hash_code_base
271 {
using __hash_code_base::_M_bucket_index; };
275 static_assert(
noexcept(declval<const __hash_code_base_access&>()
278 "Cache the hash code or qualify your functors involved"
279 " in hash code and bucket index computation with noexcept");
286 static_assert(__if_hash_cached<is_default_constructible<_H2>>::value,
287 "Functor used to map hash code to bucket index"
288 " must be default constructible");
290 template<
typename _Keya,
typename _Valuea,
typename _Alloca,
291 typename _ExtractKeya,
typename _Equala,
292 typename _H1a,
typename _H2a,
typename _Hasha,
293 typename _RehashPolicya,
typename _Traitsa,
297 template<
typename _Keya,
typename _Valuea,
typename _Alloca,
298 typename _ExtractKeya,
typename _Equala,
299 typename _H1a,
typename _H2a,
typename _Hasha,
300 typename _RehashPolicya,
typename _Traitsa>
303 template<
typename _Keya,
typename _Valuea,
typename _Alloca,
304 typename _ExtractKeya,
typename _Equala,
305 typename _H1a,
typename _H2a,
typename _Hasha,
306 typename _RehashPolicya,
typename _Traitsa,
307 bool _Constant_iteratorsa>
311 using size_type =
typename __hashtable_base::size_type;
312 using difference_type =
typename __hashtable_base::difference_type;
318 using const_local_iterator =
typename __hashtable_base::
319 const_local_iterator;
321#if __cplusplus > 201402L
322 using node_type = _Node_handle<_Key, _Value, __node_alloc_type>;
323 using insert_return_type = _Node_insert_return<iterator, node_type>;
327 __bucket_type* _M_buckets = &_M_single_bucket;
328 size_type _M_bucket_count = 1;
329 __node_base _M_before_begin;
330 size_type _M_element_count = 0;
331 _RehashPolicy _M_rehash_policy;
339 __bucket_type _M_single_bucket =
nullptr;
342 _M_uses_single_bucket(__bucket_type* __bkts)
const
343 {
return __builtin_expect(__bkts == &_M_single_bucket,
false); }
346 _M_uses_single_bucket()
const
347 {
return _M_uses_single_bucket(_M_buckets); }
350 _M_base_alloc() {
return *
this; }
353 _M_allocate_buckets(size_type __n)
355 if (__builtin_expect(__n == 1,
false))
357 _M_single_bucket =
nullptr;
358 return &_M_single_bucket;
361 return __hashtable_alloc::_M_allocate_buckets(__n);
365 _M_deallocate_buckets(__bucket_type* __bkts, size_type __n)
367 if (_M_uses_single_bucket(__bkts))
370 __hashtable_alloc::_M_deallocate_buckets(__bkts, __n);
374 _M_deallocate_buckets()
375 { _M_deallocate_buckets(_M_buckets, _M_bucket_count); }
380 _M_bucket_begin(size_type __bkt)
const;
384 {
return static_cast<__node_type*
>(_M_before_begin._M_nxt); }
388 template<
typename _Ht,
typename _NodeGenerator>
390 _M_assign_elements(_Ht&&,
const _NodeGenerator&);
392 template<
typename _NodeGenerator>
394 _M_assign(
const _Hashtable&,
const _NodeGenerator&);
405 _Hashtable(
const _H1& __h1,
const _H2& __h2,
const _Hash& __h,
406 const _Equal& __eq,
const _ExtractKey& __exk,
407 const allocator_type& __a)
412 template<
bool _No_realloc = true>
413 static constexpr bool
416#if __cplusplus <= 201402L
417 return __and_<__bool_constant<_No_realloc>,
421 if constexpr (_No_realloc)
430 noexcept(_S_nothrow_move());
440 const _H1&,
const _H2&,
const _Hash&,
441 const _Equal&,
const _ExtractKey&,
442 const allocator_type&);
444 template<
typename _InputIterator>
445 _Hashtable(_InputIterator __first, _InputIterator __last,
446 size_type __bucket_hint,
447 const _H1&,
const _H2&,
const _Hash&,
448 const _Equal&,
const _ExtractKey&,
449 const allocator_type&);
454 noexcept(_S_nothrow_move())
455 :
_Hashtable(std::move(__ht), std::move(__ht._M_node_allocator()),
462 noexcept(_S_nothrow_move<__node_alloc_traits::_S_always_equal()>())
463 :
_Hashtable(std::move(__ht), __node_alloc_type(__a),
464 typename __node_alloc_traits::is_always_equal{})
475 const _H1& __hf = _H1(),
476 const key_equal& __eql = key_equal(),
477 const allocator_type& __a = allocator_type())
478 :
_Hashtable(__n, __hf, _H2(), _Hash(), __eql,
479 __key_extract(), __a)
482 template<
typename _InputIterator>
483 _Hashtable(_InputIterator __f, _InputIterator __l,
485 const _H1& __hf = _H1(),
486 const key_equal& __eql = key_equal(),
487 const allocator_type& __a = allocator_type())
488 :
_Hashtable(__f, __l, __n, __hf, _H2(), _Hash(), __eql,
489 __key_extract(), __a)
494 const _H1& __hf = _H1(),
495 const key_equal& __eql = key_equal(),
496 const allocator_type& __a = allocator_type())
497 :
_Hashtable(__l.begin(), __l.end(), __n, __hf, _H2(), _Hash(), __eql,
498 __key_extract(), __a)
506 noexcept(__node_alloc_traits::_S_nothrow_move()
510 constexpr bool __move_storage =
511 __node_alloc_traits::_S_propagate_on_move_assign()
512 || __node_alloc_traits::_S_always_equal();
520 __reuse_or_alloc_node_type __roan(_M_begin(), *
this);
521 _M_before_begin._M_nxt =
nullptr;
523 this->_M_insert_range(__l.begin(), __l.end(), __roan, __unique_keys());
531 noexcept(__and_<__is_nothrow_swappable<_H1>,
532 __is_nothrow_swappable<_Equal>>::value);
537 {
return iterator(_M_begin()); }
540 begin()
const noexcept
541 {
return const_iterator(_M_begin()); }
545 {
return iterator(
nullptr); }
549 {
return const_iterator(
nullptr); }
553 {
return const_iterator(_M_begin()); }
556 cend()
const noexcept
557 {
return const_iterator(
nullptr); }
560 size()
const noexcept
561 {
return _M_element_count; }
563 _GLIBCXX_NODISCARD
bool
564 empty()
const noexcept
565 {
return size() == 0; }
568 get_allocator()
const noexcept
569 {
return allocator_type(this->_M_node_allocator()); }
572 max_size()
const noexcept
573 {
return __node_alloc_traits::max_size(this->_M_node_allocator()); }
578 {
return this->_M_eq(); }
584 bucket_count()
const noexcept
585 {
return _M_bucket_count; }
588 max_bucket_count()
const noexcept
589 {
return max_size(); }
592 bucket_size(size_type __n)
const
596 bucket(
const key_type& __k)
const
597 {
return _M_bucket_index(__k, this->_M_hash_code(__k)); }
602 return local_iterator(*
this, _M_bucket_begin(__n),
603 __n, _M_bucket_count);
608 {
return local_iterator(*
this,
nullptr, __n, _M_bucket_count); }
611 begin(size_type __n)
const
613 return const_local_iterator(*
this, _M_bucket_begin(__n),
614 __n, _M_bucket_count);
618 end(size_type __n)
const
619 {
return const_local_iterator(*
this,
nullptr, __n, _M_bucket_count); }
623 cbegin(size_type __n)
const
625 return const_local_iterator(*
this, _M_bucket_begin(__n),
626 __n, _M_bucket_count);
630 cend(size_type __n)
const
631 {
return const_local_iterator(*
this,
nullptr, __n, _M_bucket_count); }
634 load_factor()
const noexcept
636 return static_cast<float>(size()) /
static_cast<float>(bucket_count());
645 __rehash_policy()
const
646 {
return _M_rehash_policy; }
649 __rehash_policy(
const _RehashPolicy& __pol)
650 { _M_rehash_policy = __pol; }
654 find(
const key_type& __k);
657 find(
const key_type& __k)
const;
660 count(
const key_type& __k)
const;
663 equal_range(
const key_type& __k);
666 equal_range(
const key_type& __k)
const;
672 {
return __hash_code_base::_M_bucket_index(__n, _M_bucket_count); }
675 _M_bucket_index(
const key_type& __k, __hash_code __c)
const
676 {
return __hash_code_base::_M_bucket_index(__k, __c, _M_bucket_count); }
681 _M_find_before_node(size_type,
const key_type&, __hash_code)
const;
684 _M_find_node(size_type __bkt,
const key_type& __key,
685 __hash_code __c)
const
687 __node_base* __before_n = _M_find_before_node(__bkt, __key, __c);
689 return static_cast<__node_type*
>(__before_n->_M_nxt);
699 _M_remove_bucket_begin(size_type __bkt,
__node_type* __next_n,
700 size_type __next_bkt);
704 _M_get_previous_node(size_type __bkt, __node_base* __n);
710 _M_insert_unique_node(size_type __bkt, __hash_code __code,
719 template<
typename... _Args>
723 template<
typename... _Args>
726 {
return _M_emplace(
cend(), __uk, std::forward<_Args>(__args)...); }
729 template<
typename... _Args>
731 _M_emplace(const_iterator,
std::true_type __uk, _Args&&... __args)
732 {
return _M_emplace(__uk, std::forward<_Args>(__args)...).first; }
734 template<
typename... _Args>
738 template<
typename _Arg,
typename _NodeGenerator>
740 _M_insert(_Arg&&,
const _NodeGenerator&,
true_type, size_type = 1);
742 template<
typename _Arg,
typename _NodeGenerator>
744 _M_insert(_Arg&& __arg,
const _NodeGenerator& __node_gen,
747 return _M_insert(
cend(), std::forward<_Arg>(__arg), __node_gen,
752 template<
typename _Arg,
typename _NodeGenerator>
754 _M_insert(const_iterator, _Arg&& __arg,
755 const _NodeGenerator& __node_gen,
true_type __uk)
758 _M_insert(std::forward<_Arg>(__arg), __node_gen, __uk).
first;
762 template<
typename _Arg,
typename _NodeGenerator>
764 _M_insert(const_iterator, _Arg&&,
774 _M_erase(size_type __bkt, __node_base* __prev_n,
__node_type* __n);
778 template<
typename... _Args>
780 emplace(_Args&&... __args)
781 {
return _M_emplace(__unique_keys(), std::forward<_Args>(__args)...); }
783 template<
typename... _Args>
785 emplace_hint(const_iterator __hint, _Args&&... __args)
787 return _M_emplace(__hint, __unique_keys(),
788 std::forward<_Args>(__args)...);
795 erase(const_iterator);
800 {
return erase(const_iterator(__it)); }
803 erase(
const key_type& __k)
804 {
return _M_erase(__unique_keys(), __k); }
807 erase(const_iterator, const_iterator);
813 void rehash(size_type __n);
818#if __cplusplus > 201402L
821 _M_reinsert_node(node_type&& __nh)
823 insert_return_type __ret;
825 __ret.position =
end();
828 __glibcxx_assert(get_allocator() == __nh.get_allocator());
830 const key_type& __k = __nh._M_key();
831 __hash_code __code = this->_M_hash_code(__k);
832 size_type __bkt = _M_bucket_index(__k, __code);
833 if (
__node_type* __n = _M_find_node(__bkt, __k, __code))
835 __ret.node = std::move(__nh);
836 __ret.position = iterator(__n);
837 __ret.inserted =
false;
842 = _M_insert_unique_node(__bkt, __code, __nh._M_ptr);
843 __nh._M_ptr =
nullptr;
844 __ret.inserted =
true;
852 _M_reinsert_node_multi(const_iterator __hint, node_type&& __nh)
859 __glibcxx_assert(get_allocator() == __nh.get_allocator());
861 auto __code = this->_M_hash_code(__nh._M_key());
864 __ret = _M_insert_multi_node(__hint._M_cur, __code, __node);
871 extract(const_iterator __pos)
874 size_t __bkt = _M_bucket_index(__n);
879 __node_base* __prev_n = _M_get_previous_node(__bkt, __n);
881 if (__prev_n == _M_buckets[__bkt])
882 _M_remove_bucket_begin(__bkt, __n->_M_next(),
883 __n->_M_nxt ? _M_bucket_index(__n->_M_next()) : 0);
884 else if (__n->_M_nxt)
886 size_type __next_bkt = _M_bucket_index(__n->_M_next());
887 if (__next_bkt != __bkt)
888 _M_buckets[__next_bkt] = __prev_n;
891 __prev_n->_M_nxt = __n->_M_nxt;
892 __n->_M_nxt =
nullptr;
894 return { __n, this->_M_node_allocator() };
899 extract(
const _Key& __k)
902 auto __pos = find(__k);
904 __nh = extract(const_iterator(__pos));
909 template<
typename _Compatible_Hashtable>
911 _M_merge_unique(_Compatible_Hashtable& __src)
noexcept
913 static_assert(is_same_v<
typename _Compatible_Hashtable::node_type,
914 node_type>,
"Node types are compatible");
915 __glibcxx_assert(get_allocator() == __src.get_allocator());
917 auto __n_elt = __src.size();
918 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
921 const key_type& __k = this->_M_extract()(__pos._M_cur->_M_v());
922 __hash_code __code = this->_M_hash_code(__k);
923 size_type __bkt = _M_bucket_index(__k, __code);
924 if (_M_find_node(__bkt, __k, __code) ==
nullptr)
926 auto __nh = __src.extract(__pos);
927 _M_insert_unique_node(__bkt, __code, __nh._M_ptr, __n_elt);
928 __nh._M_ptr =
nullptr;
931 else if (__n_elt != 1)
937 template<
typename _Compatible_Hashtable>
939 _M_merge_multi(_Compatible_Hashtable& __src)
noexcept
941 static_assert(is_same_v<
typename _Compatible_Hashtable::node_type,
942 node_type>,
"Node types are compatible");
943 __glibcxx_assert(get_allocator() == __src.get_allocator());
945 this->reserve(size() + __src.size());
946 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
947 _M_reinsert_node_multi(
cend(), __src.extract(__i++));
960 void _M_rehash(size_type __n,
const __rehash_state& __state);
965 template<
typename _Key,
typename _Value,
966 typename _Alloc,
typename _ExtractKey,
typename _Equal,
967 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
970 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
971 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
972 _M_bucket_begin(size_type __bkt)
const
975 __node_base* __n = _M_buckets[__bkt];
976 return __n ?
static_cast<__node_type*
>(__n->_M_nxt) :
nullptr;
979 template<
typename _Key,
typename _Value,
980 typename _Alloc,
typename _ExtractKey,
typename _Equal,
981 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
983 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
984 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
985 _Hashtable(size_type __bucket_hint,
986 const _H1& __h1,
const _H2& __h2,
const _Hash& __h,
987 const _Equal& __eq,
const _ExtractKey& __exk,
988 const allocator_type& __a)
989 : _Hashtable(__h1, __h2, __h, __eq, __exk, __a)
991 auto __bkt = _M_rehash_policy._M_next_bkt(__bucket_hint);
992 if (__bkt > _M_bucket_count)
994 _M_buckets = _M_allocate_buckets(__bkt);
995 _M_bucket_count = __bkt;
999 template<
typename _Key,
typename _Value,
1000 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1001 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1003 template<
typename _InputIterator>
1004 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1005 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1006 _Hashtable(_InputIterator __f, _InputIterator __l,
1007 size_type __bucket_hint,
1008 const _H1& __h1,
const _H2& __h2,
const _Hash& __h,
1009 const _Equal& __eq,
const _ExtractKey& __exk,
1010 const allocator_type& __a)
1011 : _Hashtable(__h1, __h2, __h, __eq, __exk, __a)
1013 auto __nb_elems = __detail::__distance_fw(__f, __l);
1015 _M_rehash_policy._M_next_bkt(
1016 std::max(_M_rehash_policy._M_bkt_for_elements(__nb_elems),
1019 if (__bkt_count > _M_bucket_count)
1021 _M_buckets = _M_allocate_buckets(__bkt_count);
1022 _M_bucket_count = __bkt_count;
1025 for (; __f != __l; ++__f)
1029 template<
typename _Key,
typename _Value,
1030 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1031 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1034 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1035 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1036 operator=(
const _Hashtable& __ht)
1042 if (__node_alloc_traits::_S_propagate_on_copy_assign())
1044 auto& __this_alloc = this->_M_node_allocator();
1045 auto& __that_alloc = __ht._M_node_allocator();
1046 if (!__node_alloc_traits::_S_always_equal()
1047 && __this_alloc != __that_alloc)
1050 this->_M_deallocate_nodes(_M_begin());
1051 _M_before_begin._M_nxt =
nullptr;
1052 _M_deallocate_buckets();
1053 _M_buckets =
nullptr;
1054 std::__alloc_on_copy(__this_alloc, __that_alloc);
1055 __hashtable_base::operator=(__ht);
1056 _M_bucket_count = __ht._M_bucket_count;
1057 _M_element_count = __ht._M_element_count;
1058 _M_rehash_policy = __ht._M_rehash_policy;
1062 [
this](
const __node_type* __n)
1063 {
return this->_M_allocate_node(__n->_M_v()); });
1070 __throw_exception_again;
1074 std::__alloc_on_copy(__this_alloc, __that_alloc);
1078 _M_assign_elements(__ht,
1079 [](
const __reuse_or_alloc_node_type& __roan,
const __node_type* __n)
1080 {
return __roan(__n->_M_v()); });
1084 template<
typename _Key,
typename _Value,
1085 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1086 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1088 template<
typename _Ht,
typename _NodeGenerator>
1090 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1091 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1092 _M_assign_elements(_Ht&& __ht,
const _NodeGenerator& __node_gen)
1094 __bucket_type* __former_buckets =
nullptr;
1095 std::size_t __former_bucket_count = _M_bucket_count;
1096 const __rehash_state& __former_state = _M_rehash_policy._M_state();
1098 if (_M_bucket_count != __ht._M_bucket_count)
1100 __former_buckets = _M_buckets;
1101 _M_buckets = _M_allocate_buckets(__ht._M_bucket_count);
1102 _M_bucket_count = __ht._M_bucket_count;
1105 __builtin_memset(_M_buckets, 0,
1106 _M_bucket_count *
sizeof(__bucket_type));
1110 __hashtable_base::operator=(std::forward<_Ht>(__ht));
1111 _M_element_count = __ht._M_element_count;
1112 _M_rehash_policy = __ht._M_rehash_policy;
1113 __reuse_or_alloc_node_type __roan(_M_begin(), *
this);
1114 _M_before_begin._M_nxt =
nullptr;
1116 [&__node_gen, &__roan](__node_type* __n)
1117 {
return __node_gen(__roan, __n); });
1118 if (__former_buckets)
1119 _M_deallocate_buckets(__former_buckets, __former_bucket_count);
1123 if (__former_buckets)
1126 _M_deallocate_buckets();
1127 _M_rehash_policy._M_reset(__former_state);
1128 _M_buckets = __former_buckets;
1129 _M_bucket_count = __former_bucket_count;
1131 __builtin_memset(_M_buckets, 0,
1132 _M_bucket_count *
sizeof(__bucket_type));
1133 __throw_exception_again;
1137 template<
typename _Key,
typename _Value,
1138 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1139 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1141 template<
typename _NodeGenerator>
1143 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1144 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1145 _M_assign(
const _Hashtable& __ht,
const _NodeGenerator& __node_gen)
1147 __bucket_type* __buckets =
nullptr;
1149 _M_buckets = __buckets = _M_allocate_buckets(_M_bucket_count);
1153 if (!__ht._M_before_begin._M_nxt)
1158 __node_type* __ht_n = __ht._M_begin();
1159 __node_type* __this_n = __node_gen(__ht_n);
1160 this->_M_copy_code(__this_n, __ht_n);
1161 _M_before_begin._M_nxt = __this_n;
1162 _M_buckets[_M_bucket_index(__this_n)] = &_M_before_begin;
1165 __node_base* __prev_n = __this_n;
1166 for (__ht_n = __ht_n->_M_next(); __ht_n; __ht_n = __ht_n->_M_next())
1168 __this_n = __node_gen(__ht_n);
1169 __prev_n->_M_nxt = __this_n;
1170 this->_M_copy_code(__this_n, __ht_n);
1171 size_type __bkt = _M_bucket_index(__this_n);
1172 if (!_M_buckets[__bkt])
1173 _M_buckets[__bkt] = __prev_n;
1174 __prev_n = __this_n;
1181 _M_deallocate_buckets();
1182 __throw_exception_again;
1186 template<
typename _Key,
typename _Value,
1187 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1188 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1191 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1192 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1195 _M_rehash_policy._M_reset();
1196 _M_bucket_count = 1;
1197 _M_single_bucket =
nullptr;
1198 _M_buckets = &_M_single_bucket;
1199 _M_before_begin._M_nxt =
nullptr;
1200 _M_element_count = 0;
1203 template<
typename _Key,
typename _Value,
1204 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1205 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1208 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1209 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1212 this->_M_deallocate_nodes(_M_begin());
1213 _M_deallocate_buckets();
1214 __hashtable_base::operator=(std::move(__ht));
1215 _M_rehash_policy = __ht._M_rehash_policy;
1216 if (!__ht._M_uses_single_bucket())
1217 _M_buckets = __ht._M_buckets;
1220 _M_buckets = &_M_single_bucket;
1221 _M_single_bucket = __ht._M_single_bucket;
1223 _M_bucket_count = __ht._M_bucket_count;
1224 _M_before_begin._M_nxt = __ht._M_before_begin._M_nxt;
1225 _M_element_count = __ht._M_element_count;
1226 std::__alloc_on_move(this->_M_node_allocator(), __ht._M_node_allocator());
1231 _M_buckets[_M_bucket_index(_M_begin())] = &_M_before_begin;
1235 template<
typename _Key,
typename _Value,
1236 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1237 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1240 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1241 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1244 if (__ht._M_node_allocator() == this->_M_node_allocator())
1249 _M_assign_elements(std::move(__ht),
1250 [](
const __reuse_or_alloc_node_type& __roan, __node_type* __n)
1256 template<
typename _Key,
typename _Value,
1257 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1258 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1260 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1261 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1262 _Hashtable(
const _Hashtable& __ht)
1263 : __hashtable_base(__ht),
1265 __rehash_base(__ht),
1267 __node_alloc_traits::_S_select_on_copy(__ht._M_node_allocator())),
1268 _M_buckets(nullptr),
1269 _M_bucket_count(__ht._M_bucket_count),
1270 _M_element_count(__ht._M_element_count),
1271 _M_rehash_policy(__ht._M_rehash_policy)
1274 [
this](
const __node_type* __n)
1275 {
return this->_M_allocate_node(__n->_M_v()); });
1278 template<
typename _Key,
typename _Value,
1279 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1280 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1282 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1283 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1284 _Hashtable(_Hashtable&& __ht, __node_alloc_type&& __a,
1286 noexcept(_S_nothrow_move())
1287 : __hashtable_base(__ht),
1289 __rehash_base(__ht),
1290 __hashtable_alloc(std::move(__a)),
1291 _M_buckets(__ht._M_buckets),
1292 _M_bucket_count(__ht._M_bucket_count),
1293 _M_before_begin(__ht._M_before_begin._M_nxt),
1294 _M_element_count(__ht._M_element_count),
1295 _M_rehash_policy(__ht._M_rehash_policy)
1298 if (__ht._M_uses_single_bucket())
1300 _M_buckets = &_M_single_bucket;
1301 _M_single_bucket = __ht._M_single_bucket;
1307 _M_buckets[_M_bucket_index(_M_begin())] = &_M_before_begin;
1312 template<
typename _Key,
typename _Value,
1313 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1314 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1316 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1317 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1318 _Hashtable(
const _Hashtable& __ht,
const allocator_type& __a)
1319 : __hashtable_base(__ht),
1321 __rehash_base(__ht),
1322 __hashtable_alloc(__node_alloc_type(__a)),
1324 _M_bucket_count(__ht._M_bucket_count),
1325 _M_element_count(__ht._M_element_count),
1326 _M_rehash_policy(__ht._M_rehash_policy)
1329 [
this](
const __node_type* __n)
1330 {
return this->_M_allocate_node(__n->_M_v()); });
1333 template<
typename _Key,
typename _Value,
1334 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1335 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1337 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1338 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1339 _Hashtable(_Hashtable&& __ht, __node_alloc_type&& __a,
1341 : __hashtable_base(__ht),
1343 __rehash_base(__ht),
1344 __hashtable_alloc(
std::move(__a)),
1345 _M_buckets(nullptr),
1346 _M_bucket_count(__ht._M_bucket_count),
1347 _M_element_count(__ht._M_element_count),
1348 _M_rehash_policy(__ht._M_rehash_policy)
1350 if (__ht._M_node_allocator() == this->_M_node_allocator())
1352 if (__ht._M_uses_single_bucket())
1354 _M_buckets = &_M_single_bucket;
1355 _M_single_bucket = __ht._M_single_bucket;
1358 _M_buckets = __ht._M_buckets;
1360 _M_before_begin._M_nxt = __ht._M_before_begin._M_nxt;
1364 _M_buckets[_M_bucket_index(_M_begin())] = &_M_before_begin;
1370 [
this](__node_type* __n)
1372 return this->_M_allocate_node(
1379 template<
typename _Key,
typename _Value,
1380 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1381 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1383 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1384 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1385 ~_Hashtable() noexcept
1388 _M_deallocate_buckets();
1391 template<
typename _Key,
typename _Value,
1392 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1393 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1396 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1397 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1398 swap(_Hashtable& __x)
1399 noexcept(__and_<__is_nothrow_swappable<_H1>,
1400 __is_nothrow_swappable<_Equal>>::value)
1407 std::__alloc_on_swap(this->_M_node_allocator(), __x._M_node_allocator());
1408 std::swap(_M_rehash_policy, __x._M_rehash_policy);
1411 if (this->_M_uses_single_bucket())
1413 if (!__x._M_uses_single_bucket())
1415 _M_buckets = __x._M_buckets;
1416 __x._M_buckets = &__x._M_single_bucket;
1419 else if (__x._M_uses_single_bucket())
1421 __x._M_buckets = _M_buckets;
1422 _M_buckets = &_M_single_bucket;
1425 std::swap(_M_buckets, __x._M_buckets);
1427 std::swap(_M_bucket_count, __x._M_bucket_count);
1428 std::swap(_M_before_begin._M_nxt, __x._M_before_begin._M_nxt);
1429 std::swap(_M_element_count, __x._M_element_count);
1430 std::swap(_M_single_bucket, __x._M_single_bucket);
1435 _M_buckets[_M_bucket_index(_M_begin())] = &_M_before_begin;
1438 __x._M_buckets[__x._M_bucket_index(__x._M_begin())]
1439 = &__x._M_before_begin;
1442 template<
typename _Key,
typename _Value,
1443 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1444 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1447 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1448 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1449 find(
const key_type& __k)
1452 __hash_code __code = this->_M_hash_code(__k);
1453 std::size_t __n = _M_bucket_index(__k, __code);
1454 __node_type* __p = _M_find_node(__n, __k, __code);
1455 return __p ? iterator(__p) :
end();
1458 template<
typename _Key,
typename _Value,
1459 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1460 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1463 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1464 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1465 find(
const key_type& __k)
const
1468 __hash_code __code = this->_M_hash_code(__k);
1469 std::size_t __n = _M_bucket_index(__k, __code);
1470 __node_type* __p = _M_find_node(__n, __k, __code);
1471 return __p ? const_iterator(__p) :
end();
1474 template<
typename _Key,
typename _Value,
1475 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1476 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1479 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1480 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1481 count(
const key_type& __k)
const
1484 __hash_code __code = this->_M_hash_code(__k);
1485 std::size_t __n = _M_bucket_index(__k, __code);
1486 __node_type* __p = _M_bucket_begin(__n);
1490 std::size_t __result = 0;
1491 for (;; __p = __p->_M_next())
1493 if (this->_M_equals(__k, __code, __p))
1500 if (!__p->_M_nxt || _M_bucket_index(__p->_M_next()) != __n)
1506 template<
typename _Key,
typename _Value,
1507 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1508 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1511 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1512 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1513 equal_range(
const key_type& __k)
1514 -> pair<iterator, iterator>
1516 __hash_code __code = this->_M_hash_code(__k);
1517 std::size_t __n = _M_bucket_index(__k, __code);
1518 __node_type* __p = _M_find_node(__n, __k, __code);
1522 __node_type* __p1 = __p->_M_next();
1523 while (__p1 && _M_bucket_index(__p1) == __n
1524 && this->_M_equals(__k, __code, __p1))
1525 __p1 = __p1->_M_next();
1533 template<
typename _Key,
typename _Value,
1534 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1535 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1538 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1539 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1540 equal_range(
const key_type& __k)
const
1541 -> pair<const_iterator, const_iterator>
1543 __hash_code __code = this->_M_hash_code(__k);
1544 std::size_t __n = _M_bucket_index(__k, __code);
1545 __node_type* __p = _M_find_node(__n, __k, __code);
1549 __node_type* __p1 = __p->_M_next();
1550 while (__p1 && _M_bucket_index(__p1) == __n
1551 && this->_M_equals(__k, __code, __p1))
1552 __p1 = __p1->_M_next();
1554 return std::make_pair(const_iterator(__p), const_iterator(__p1));
1562 template<
typename _Key,
typename _Value,
1563 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1564 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1567 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1568 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1569 _M_find_before_node(size_type __n,
const key_type& __k,
1570 __hash_code __code)
const
1573 __node_base* __prev_p = _M_buckets[__n];
1577 for (__node_type* __p =
static_cast<__node_type*
>(__prev_p->_M_nxt);;
1578 __p = __p->_M_next())
1580 if (this->_M_equals(__k, __code, __p))
1583 if (!__p->_M_nxt || _M_bucket_index(__p->_M_next()) != __n)
1590 template<
typename _Key,
typename _Value,
1591 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1592 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1595 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1596 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1597 _M_insert_bucket_begin(size_type __bkt, __node_type* __node)
1599 if (_M_buckets[__bkt])
1603 __node->_M_nxt = _M_buckets[__bkt]->_M_nxt;
1604 _M_buckets[__bkt]->_M_nxt = __node;
1611 __node->_M_nxt = _M_before_begin._M_nxt;
1612 _M_before_begin._M_nxt = __node;
1616 _M_buckets[_M_bucket_index(__node->_M_next())] = __node;
1617 _M_buckets[__bkt] = &_M_before_begin;
1621 template<
typename _Key,
typename _Value,
1622 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1623 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1626 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1627 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1628 _M_remove_bucket_begin(size_type __bkt, __node_type* __next,
1629 size_type __next_bkt)
1631 if (!__next || __next_bkt != __bkt)
1636 _M_buckets[__next_bkt] = _M_buckets[__bkt];
1639 if (&_M_before_begin == _M_buckets[__bkt])
1640 _M_before_begin._M_nxt = __next;
1641 _M_buckets[__bkt] =
nullptr;
1645 template<
typename _Key,
typename _Value,
1646 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1647 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1650 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1651 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1652 _M_get_previous_node(size_type __bkt, __node_base* __n)
1655 __node_base* __prev_n = _M_buckets[__bkt];
1656 while (__prev_n->_M_nxt != __n)
1657 __prev_n = __prev_n->_M_nxt;
1661 template<
typename _Key,
typename _Value,
1662 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1663 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1665 template<
typename... _Args>
1667 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1668 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1670 -> pair<iterator, bool>
1673 __node_type* __node = this->_M_allocate_node(std::forward<_Args>(__args)...);
1674 const key_type& __k = this->_M_extract()(__node->_M_v());
1678 __code = this->_M_hash_code(__k);
1682 this->_M_deallocate_node(__node);
1683 __throw_exception_again;
1686 size_type __bkt = _M_bucket_index(__k, __code);
1687 if (__node_type* __p = _M_find_node(__bkt, __k, __code))
1690 this->_M_deallocate_node(__node);
1695 return std::make_pair(_M_insert_unique_node(__bkt, __code, __node),
1699 template<
typename _Key,
typename _Value,
1700 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1701 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1703 template<
typename... _Args>
1705 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1706 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1711 __node_type* __node =
1712 this->_M_allocate_node(std::forward<_Args>(__args)...);
1717 __code = this->_M_hash_code(this->_M_extract()(__node->_M_v()));
1721 this->_M_deallocate_node(__node);
1722 __throw_exception_again;
1725 return _M_insert_multi_node(__hint._M_cur, __code, __node);
1728 template<
typename _Key,
typename _Value,
1729 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1730 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1733 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1734 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1735 _M_insert_unique_node(size_type __bkt, __hash_code __code,
1736 __node_type* __node, size_type __n_elt)
1739 const __rehash_state& __saved_state = _M_rehash_policy._M_state();
1741 = _M_rehash_policy._M_need_rehash(_M_bucket_count, _M_element_count,
1746 if (__do_rehash.
first)
1748 _M_rehash(__do_rehash.
second, __saved_state);
1749 __bkt = _M_bucket_index(this->_M_extract()(__node->_M_v()), __code);
1752 this->_M_store_code(__node, __code);
1755 _M_insert_bucket_begin(__bkt, __node);
1757 return iterator(__node);
1761 this->_M_deallocate_node(__node);
1762 __throw_exception_again;
1768 template<
typename _Key,
typename _Value,
1769 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1770 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1773 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1774 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1775 _M_insert_multi_node(__node_type* __hint, __hash_code __code,
1776 __node_type* __node)
1779 const __rehash_state& __saved_state = _M_rehash_policy._M_state();
1781 = _M_rehash_policy._M_need_rehash(_M_bucket_count, _M_element_count, 1);
1785 if (__do_rehash.
first)
1786 _M_rehash(__do_rehash.
second, __saved_state);
1788 this->_M_store_code(__node, __code);
1789 const key_type& __k = this->_M_extract()(__node->_M_v());
1790 size_type __bkt = _M_bucket_index(__k, __code);
1795 = __builtin_expect(__hint !=
nullptr,
false)
1796 && this->_M_equals(__k, __code, __hint)
1798 : _M_find_before_node(__bkt, __k, __code);
1802 __node->_M_nxt = __prev->_M_nxt;
1803 __prev->_M_nxt = __node;
1804 if (__builtin_expect(__prev == __hint,
false))
1808 && !this->_M_equals(__k, __code, __node->_M_next()))
1810 size_type __next_bkt = _M_bucket_index(__node->_M_next());
1811 if (__next_bkt != __bkt)
1812 _M_buckets[__next_bkt] = __node;
1820 _M_insert_bucket_begin(__bkt, __node);
1822 return iterator(__node);
1826 this->_M_deallocate_node(__node);
1827 __throw_exception_again;
1832 template<
typename _Key,
typename _Value,
1833 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1834 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1836 template<
typename _Arg,
typename _NodeGenerator>
1838 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1839 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1840 _M_insert(_Arg&& __v,
const _NodeGenerator& __node_gen,
true_type,
1842 -> pair<iterator, bool>
1844 const key_type& __k = this->_M_extract()(__v);
1845 __hash_code __code = this->_M_hash_code(__k);
1846 size_type __bkt = _M_bucket_index(__k, __code);
1848 __node_type* __n = _M_find_node(__bkt, __k, __code);
1852 __n = __node_gen(std::forward<_Arg>(__v));
1853 return { _M_insert_unique_node(__bkt, __code, __n, __n_elt),
true };
1857 template<
typename _Key,
typename _Value,
1858 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1859 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1861 template<
typename _Arg,
typename _NodeGenerator>
1863 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1864 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1865 _M_insert(const_iterator __hint, _Arg&& __v,
1866 const _NodeGenerator& __node_gen,
false_type)
1871 __hash_code __code = this->_M_hash_code(this->_M_extract()(__v));
1874 __node_type* __node = __node_gen(std::forward<_Arg>(__v));
1876 return _M_insert_multi_node(__hint._M_cur, __code, __node);
1879 template<
typename _Key,
typename _Value,
1880 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1881 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1884 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1885 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1886 erase(const_iterator __it)
1889 __node_type* __n = __it._M_cur;
1890 std::size_t __bkt = _M_bucket_index(__n);
1895 __node_base* __prev_n = _M_get_previous_node(__bkt, __n);
1896 return _M_erase(__bkt, __prev_n, __n);
1899 template<
typename _Key,
typename _Value,
1900 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1901 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1904 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1905 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1906 _M_erase(size_type __bkt, __node_base* __prev_n, __node_type* __n)
1909 if (__prev_n == _M_buckets[__bkt])
1910 _M_remove_bucket_begin(__bkt, __n->_M_next(),
1911 __n->_M_nxt ? _M_bucket_index(__n->_M_next()) : 0);
1912 else if (__n->_M_nxt)
1914 size_type __next_bkt = _M_bucket_index(__n->_M_next());
1915 if (__next_bkt != __bkt)
1916 _M_buckets[__next_bkt] = __prev_n;
1919 __prev_n->_M_nxt = __n->_M_nxt;
1920 iterator __result(__n->_M_next());
1921 this->_M_deallocate_node(__n);
1927 template<
typename _Key,
typename _Value,
1928 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1929 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1932 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1933 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1937 __hash_code __code = this->_M_hash_code(__k);
1938 std::size_t __bkt = _M_bucket_index(__k, __code);
1941 __node_base* __prev_n = _M_find_before_node(__bkt, __k, __code);
1946 __node_type* __n =
static_cast<__node_type*
>(__prev_n->_M_nxt);
1947 _M_erase(__bkt, __prev_n, __n);
1951 template<
typename _Key,
typename _Value,
1952 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1953 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1956 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1957 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1961 __hash_code __code = this->_M_hash_code(__k);
1962 std::size_t __bkt = _M_bucket_index(__k, __code);
1965 __node_base* __prev_n = _M_find_before_node(__bkt, __k, __code);
1975 __node_type* __n =
static_cast<__node_type*
>(__prev_n->_M_nxt);
1976 __node_type* __n_last = __n;
1977 std::size_t __n_last_bkt = __bkt;
1980 __n_last = __n_last->_M_next();
1983 __n_last_bkt = _M_bucket_index(__n_last);
1985 while (__n_last_bkt == __bkt && this->_M_equals(__k, __code, __n_last));
1988 size_type __result = 0;
1991 __node_type* __p = __n->_M_next();
1992 this->_M_deallocate_node(__n);
1997 while (__n != __n_last);
1999 if (__prev_n == _M_buckets[__bkt])
2000 _M_remove_bucket_begin(__bkt, __n_last, __n_last_bkt);
2001 else if (__n_last && __n_last_bkt != __bkt)
2002 _M_buckets[__n_last_bkt] = __prev_n;
2003 __prev_n->_M_nxt = __n_last;
2007 template<
typename _Key,
typename _Value,
2008 typename _Alloc,
typename _ExtractKey,
typename _Equal,
2009 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
2012 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
2013 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
2014 erase(const_iterator __first, const_iterator __last)
2017 __node_type* __n = __first._M_cur;
2018 __node_type* __last_n = __last._M_cur;
2019 if (__n == __last_n)
2020 return iterator(__n);
2022 std::size_t __bkt = _M_bucket_index(__n);
2024 __node_base* __prev_n = _M_get_previous_node(__bkt, __n);
2025 bool __is_bucket_begin = __n == _M_bucket_begin(__bkt);
2026 std::size_t __n_bkt = __bkt;
2031 __node_type* __tmp = __n;
2032 __n = __n->_M_next();
2033 this->_M_deallocate_node(__tmp);
2037 __n_bkt = _M_bucket_index(__n);
2039 while (__n != __last_n && __n_bkt == __bkt);
2040 if (__is_bucket_begin)
2041 _M_remove_bucket_begin(__bkt, __n, __n_bkt);
2042 if (__n == __last_n)
2044 __is_bucket_begin =
true;
2048 if (__n && (__n_bkt != __bkt || __is_bucket_begin))
2049 _M_buckets[__n_bkt] = __prev_n;
2050 __prev_n->_M_nxt = __n;
2051 return iterator(__n);
2054 template<
typename _Key,
typename _Value,
2055 typename _Alloc,
typename _ExtractKey,
typename _Equal,
2056 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
2059 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
2060 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
2063 this->_M_deallocate_nodes(_M_begin());
2064 __builtin_memset(_M_buckets, 0, _M_bucket_count *
sizeof(__bucket_type));
2065 _M_element_count = 0;
2066 _M_before_begin._M_nxt =
nullptr;
2069 template<
typename _Key,
typename _Value,
2070 typename _Alloc,
typename _ExtractKey,
typename _Equal,
2071 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
2074 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
2075 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
2076 rehash(size_type __n)
2078 const __rehash_state& __saved_state = _M_rehash_policy._M_state();
2079 std::size_t __buckets
2080 =
std::max(_M_rehash_policy._M_bkt_for_elements(_M_element_count + 1),
2082 __buckets = _M_rehash_policy._M_next_bkt(__buckets);
2084 if (__buckets != _M_bucket_count)
2085 _M_rehash(__buckets, __saved_state);
2088 _M_rehash_policy._M_reset(__saved_state);
2091 template<
typename _Key,
typename _Value,
2092 typename _Alloc,
typename _ExtractKey,
typename _Equal,
2093 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
2096 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
2097 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
2098 _M_rehash(size_type __n,
const __rehash_state& __state)
2102 _M_rehash_aux(__n, __unique_keys());
2108 _M_rehash_policy._M_reset(__state);
2109 __throw_exception_again;
2114 template<
typename _Key,
typename _Value,
2115 typename _Alloc,
typename _ExtractKey,
typename _Equal,
2116 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
2119 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
2120 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
2123 __bucket_type* __new_buckets = _M_allocate_buckets(__n);
2124 __node_type* __p = _M_begin();
2125 _M_before_begin._M_nxt =
nullptr;
2126 std::size_t __bbegin_bkt = 0;
2129 __node_type* __next = __p->_M_next();
2130 std::size_t __bkt = __hash_code_base::_M_bucket_index(__p, __n);
2131 if (!__new_buckets[__bkt])
2133 __p->_M_nxt = _M_before_begin._M_nxt;
2134 _M_before_begin._M_nxt = __p;
2135 __new_buckets[__bkt] = &_M_before_begin;
2137 __new_buckets[__bbegin_bkt] = __p;
2138 __bbegin_bkt = __bkt;
2142 __p->_M_nxt = __new_buckets[__bkt]->_M_nxt;
2143 __new_buckets[__bkt]->_M_nxt = __p;
2148 _M_deallocate_buckets();
2149 _M_bucket_count = __n;
2150 _M_buckets = __new_buckets;
2155 template<
typename _Key,
typename _Value,
2156 typename _Alloc,
typename _ExtractKey,
typename _Equal,
2157 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
2160 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
2161 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
2164 __bucket_type* __new_buckets = _M_allocate_buckets(__n);
2166 __node_type* __p = _M_begin();
2167 _M_before_begin._M_nxt =
nullptr;
2168 std::size_t __bbegin_bkt = 0;
2169 std::size_t __prev_bkt = 0;
2170 __node_type* __prev_p =
nullptr;
2171 bool __check_bucket =
false;
2175 __node_type* __next = __p->_M_next();
2176 std::size_t __bkt = __hash_code_base::_M_bucket_index(__p, __n);
2178 if (__prev_p && __prev_bkt == __bkt)
2183 __p->_M_nxt = __prev_p->_M_nxt;
2184 __prev_p->_M_nxt = __p;
2191 __check_bucket =
true;
2199 if (__prev_p->_M_nxt)
2201 std::size_t __next_bkt
2202 = __hash_code_base::_M_bucket_index(__prev_p->_M_next(),
2204 if (__next_bkt != __prev_bkt)
2205 __new_buckets[__next_bkt] = __prev_p;
2207 __check_bucket =
false;
2210 if (!__new_buckets[__bkt])
2212 __p->_M_nxt = _M_before_begin._M_nxt;
2213 _M_before_begin._M_nxt = __p;
2214 __new_buckets[__bkt] = &_M_before_begin;
2216 __new_buckets[__bbegin_bkt] = __p;
2217 __bbegin_bkt = __bkt;
2221 __p->_M_nxt = __new_buckets[__bkt]->_M_nxt;
2222 __new_buckets[__bkt]->_M_nxt = __p;
2230 if (__check_bucket && __prev_p->_M_nxt)
2232 std::size_t __next_bkt
2233 = __hash_code_base::_M_bucket_index(__prev_p->_M_next(), __n);
2234 if (__next_bkt != __prev_bkt)
2235 __new_buckets[__next_bkt] = __prev_p;
2238 _M_deallocate_buckets();
2239 _M_bucket_count = __n;
2240 _M_buckets = __new_buckets;
2243#if __cplusplus > 201402L
2244 template<
typename,
typename,
typename>
class _Hash_merge_helper { };
2247#if __cpp_deduction_guides >= 201606
2249 template<
typename _Hash>
2250 using _RequireNotAllocatorOrIntegral
2251 = __enable_if_t<!__or_<is_integral<_Hash>, __is_allocator<_Hash>>::value>;
2254_GLIBCXX_END_NAMESPACE_VERSION
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
constexpr conditional< __move_if_noexcept_cond< _Tp >::value, const_Tp &, _Tp && >::type move_if_noexcept(_Tp &__x) noexcept
Conditionally convert a value to an rvalue.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
_Tp exchange(_Tp &__obj, _Up &&__new_val)
Assign __new_val to __obj and return its previous value.
constexpr auto cend(const _Container &__cont) noexcept(noexcept(std::end(__cont))) -> decltype(std::end(__cont))
Return an iterator pointing to one past the last element of the const container.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list.
constexpr auto cbegin(const _Container &__cont) noexcept(noexcept(std::begin(__cont))) -> decltype(std::begin(__cont))
Return an iterator pointing to the first element of the const container.
Define a member typedef type to one of two argument types.
is_nothrow_copy_constructible
is_nothrow_move_assignable
Node iterators, used to iterate through all the hashtable.
Node const_iterators, used to iterate through all the hashtable.
Struct holding two objects of arbitrary type.
_T1 first
second_type is the second bound type
_T2 second
first is a copy of the first object
Uniform interface to C++98 and C++11 allocators.