31 #define _HASHTABLE_H 1 33 #pragma GCC system_header 36 #if __cplusplus > 201402L 40 namespace 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>>>
189 static_assert(
is_same<
typename remove_cv<_Value>::type, _Value>::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");
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)
416 const _H1&,
const _H2&,
const _Hash&,
417 const _Equal&,
const _ExtractKey&,
418 const allocator_type&);
420 template<
typename _InputIterator>
421 _Hashtable(_InputIterator __first, _InputIterator __last,
422 size_type __bucket_hint,
423 const _H1&,
const _H2&,
const _Hash&,
424 const _Equal&,
const _ExtractKey&,
425 const allocator_type&);
443 const _H1& __hf = _H1(),
444 const key_equal& __eql = key_equal(),
445 const allocator_type& __a = allocator_type())
446 :
_Hashtable(__n, __hf, _H2(), _Hash(), __eql,
447 __key_extract(), __a)
450 template<
typename _InputIterator>
451 _Hashtable(_InputIterator __f, _InputIterator __l,
453 const _H1& __hf = _H1(),
454 const key_equal& __eql = key_equal(),
455 const allocator_type& __a = allocator_type())
456 :
_Hashtable(__f, __l, __n, __hf, _H2(), _Hash(), __eql,
457 __key_extract(), __a)
462 const _H1& __hf = _H1(),
463 const key_equal& __eql = key_equal(),
464 const allocator_type& __a = allocator_type())
465 :
_Hashtable(__l.begin(), __l.end(), __n, __hf, _H2(), _Hash(), __eql,
466 __key_extract(), __a)
474 noexcept(__node_alloc_traits::_S_nothrow_move()
478 constexpr
bool __move_storage =
479 __node_alloc_traits::_S_propagate_on_move_assign()
480 || __node_alloc_traits::_S_always_equal();
488 __reuse_or_alloc_node_type __roan(_M_begin(), *
this);
489 _M_before_begin._M_nxt =
nullptr;
491 this->_M_insert_range(__l.begin(), __l.end(), __roan, __unique_keys());
499 noexcept(__and_<__is_nothrow_swappable<_H1>,
500 __is_nothrow_swappable<_Equal>>::value);
505 {
return iterator(_M_begin()); }
508 begin()
const noexcept
509 {
return const_iterator(_M_begin()); }
513 {
return iterator(
nullptr); }
517 {
return const_iterator(
nullptr); }
521 {
return const_iterator(_M_begin()); }
524 cend()
const noexcept
525 {
return const_iterator(
nullptr); }
528 size()
const noexcept
529 {
return _M_element_count; }
531 _GLIBCXX_NODISCARD
bool 532 empty()
const noexcept
533 {
return size() == 0; }
536 get_allocator()
const noexcept
537 {
return allocator_type(this->_M_node_allocator()); }
540 max_size()
const noexcept
541 {
return __node_alloc_traits::max_size(this->_M_node_allocator()); }
546 {
return this->_M_eq(); }
552 bucket_count()
const noexcept
553 {
return _M_bucket_count; }
556 max_bucket_count()
const noexcept
557 {
return max_size(); }
560 bucket_size(size_type __n)
const 564 bucket(
const key_type& __k)
const 565 {
return _M_bucket_index(__k, this->_M_hash_code(__k)); }
570 return local_iterator(*
this, _M_bucket_begin(__n),
571 __n, _M_bucket_count);
576 {
return local_iterator(*
this,
nullptr, __n, _M_bucket_count); }
579 begin(size_type __n)
const 581 return const_local_iterator(*
this, _M_bucket_begin(__n),
582 __n, _M_bucket_count);
586 end(size_type __n)
const 587 {
return const_local_iterator(*
this,
nullptr, __n, _M_bucket_count); }
591 cbegin(size_type __n)
const 593 return const_local_iterator(*
this, _M_bucket_begin(__n),
594 __n, _M_bucket_count);
598 cend(size_type __n)
const 599 {
return const_local_iterator(*
this,
nullptr, __n, _M_bucket_count); }
602 load_factor()
const noexcept
604 return static_cast<float>(size()) / static_cast<float>(bucket_count());
613 __rehash_policy()
const 614 {
return _M_rehash_policy; }
617 __rehash_policy(
const _RehashPolicy& __pol)
618 { _M_rehash_policy = __pol; }
622 find(
const key_type& __k);
625 find(
const key_type& __k)
const;
628 count(
const key_type& __k)
const;
631 equal_range(
const key_type& __k);
634 equal_range(
const key_type& __k)
const;
640 {
return __hash_code_base::_M_bucket_index(__n, _M_bucket_count); }
643 _M_bucket_index(
const key_type& __k, __hash_code __c)
const 644 {
return __hash_code_base::_M_bucket_index(__k, __c, _M_bucket_count); }
649 _M_find_before_node(size_type,
const key_type&, __hash_code)
const;
652 _M_find_node(size_type __bkt,
const key_type& __key,
653 __hash_code __c)
const 655 __node_base* __before_n = _M_find_before_node(__bkt, __key, __c);
657 return static_cast<__node_type*
>(__before_n->_M_nxt);
667 _M_remove_bucket_begin(size_type __bkt,
__node_type* __next_n,
668 size_type __next_bkt);
672 _M_get_previous_node(size_type __bkt, __node_base* __n);
678 _M_insert_unique_node(size_type __bkt, __hash_code __code,
687 template<
typename... _Args>
691 template<
typename... _Args>
694 {
return _M_emplace(
cend(), __uk, std::forward<_Args>(__args)...); }
697 template<
typename... _Args>
699 _M_emplace(const_iterator,
std::true_type __uk, _Args&&... __args)
700 {
return _M_emplace(__uk, std::forward<_Args>(__args)...).first; }
702 template<
typename... _Args>
706 template<
typename _Arg,
typename _NodeGenerator>
708 _M_insert(_Arg&&,
const _NodeGenerator&,
true_type, size_type = 1);
710 template<
typename _Arg,
typename _NodeGenerator>
712 _M_insert(_Arg&& __arg,
const _NodeGenerator& __node_gen,
715 return _M_insert(
cend(), std::forward<_Arg>(__arg), __node_gen,
720 template<
typename _Arg,
typename _NodeGenerator>
722 _M_insert(const_iterator, _Arg&& __arg,
723 const _NodeGenerator& __node_gen,
true_type __uk)
726 _M_insert(std::forward<_Arg>(__arg), __node_gen, __uk).
first;
730 template<
typename _Arg,
typename _NodeGenerator>
732 _M_insert(const_iterator, _Arg&&,
742 _M_erase(size_type __bkt, __node_base* __prev_n,
__node_type* __n);
746 template<
typename... _Args>
748 emplace(_Args&&... __args)
749 {
return _M_emplace(__unique_keys(), std::forward<_Args>(__args)...); }
751 template<
typename... _Args>
753 emplace_hint(const_iterator __hint, _Args&&... __args)
755 return _M_emplace(__hint, __unique_keys(),
756 std::forward<_Args>(__args)...);
763 erase(const_iterator);
768 {
return erase(const_iterator(__it)); }
771 erase(
const key_type& __k)
772 {
return _M_erase(__unique_keys(), __k); }
775 erase(const_iterator, const_iterator);
781 void rehash(size_type __n);
786 #if __cplusplus > 201402L 789 _M_reinsert_node(node_type&& __nh)
791 insert_return_type __ret;
793 __ret.position =
end();
796 __glibcxx_assert(get_allocator() == __nh.get_allocator());
798 const key_type& __k = __nh._M_key();
799 __hash_code __code = this->_M_hash_code(__k);
800 size_type __bkt = _M_bucket_index(__k, __code);
801 if (
__node_type* __n = _M_find_node(__bkt, __k, __code))
803 __ret.node = std::move(__nh);
804 __ret.position = iterator(__n);
805 __ret.inserted =
false;
810 = _M_insert_unique_node(__bkt, __code, __nh._M_ptr);
811 __nh._M_ptr =
nullptr;
812 __ret.inserted =
true;
820 _M_reinsert_node_multi(const_iterator __hint, node_type&& __nh)
827 __glibcxx_assert(get_allocator() == __nh.get_allocator());
829 auto __code = this->_M_hash_code(__nh._M_key());
832 __ret = _M_insert_multi_node(__hint._M_cur, __code, __node);
839 extract(const_iterator __pos)
842 size_t __bkt = _M_bucket_index(__n);
847 __node_base* __prev_n = _M_get_previous_node(__bkt, __n);
849 if (__prev_n == _M_buckets[__bkt])
850 _M_remove_bucket_begin(__bkt, __n->_M_next(),
851 __n->_M_nxt ? _M_bucket_index(__n->_M_next()) : 0);
852 else if (__n->_M_nxt)
854 size_type __next_bkt = _M_bucket_index(__n->_M_next());
855 if (__next_bkt != __bkt)
856 _M_buckets[__next_bkt] = __prev_n;
859 __prev_n->_M_nxt = __n->_M_nxt;
860 __n->_M_nxt =
nullptr;
862 return { __n, this->_M_node_allocator() };
867 extract(
const _Key& __k)
870 auto __pos = find(__k);
872 __nh = extract(const_iterator(__pos));
877 template<
typename _Compatible_Hashtable>
879 _M_merge_unique(_Compatible_Hashtable& __src) noexcept
881 static_assert(is_same_v<
typename _Compatible_Hashtable::node_type,
882 node_type>,
"Node types are compatible");
883 __glibcxx_assert(get_allocator() == __src.get_allocator());
885 auto __n_elt = __src.size();
886 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
889 const key_type& __k = this->_M_extract()(__pos._M_cur->_M_v());
890 __hash_code __code = this->_M_hash_code(__k);
891 size_type __bkt = _M_bucket_index(__k, __code);
892 if (_M_find_node(__bkt, __k, __code) ==
nullptr)
894 auto __nh = __src.extract(__pos);
895 _M_insert_unique_node(__bkt, __code, __nh._M_ptr, __n_elt);
896 __nh._M_ptr =
nullptr;
899 else if (__n_elt != 1)
905 template<
typename _Compatible_Hashtable>
907 _M_merge_multi(_Compatible_Hashtable& __src) noexcept
909 static_assert(is_same_v<
typename _Compatible_Hashtable::node_type,
910 node_type>,
"Node types are compatible");
911 __glibcxx_assert(get_allocator() == __src.get_allocator());
913 this->reserve(size() + __src.size());
914 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
915 _M_reinsert_node_multi(
cend(), __src.extract(__i++));
928 void _M_rehash(size_type __n,
const __rehash_state& __state);
933 template<
typename _Key,
typename _Value,
934 typename _Alloc,
typename _ExtractKey,
typename _Equal,
935 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
938 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
939 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
940 _M_bucket_begin(size_type __bkt)
const 943 __node_base* __n = _M_buckets[__bkt];
944 return __n ?
static_cast<__node_type*
>(__n->_M_nxt) :
nullptr;
947 template<
typename _Key,
typename _Value,
948 typename _Alloc,
typename _ExtractKey,
typename _Equal,
949 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
951 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
952 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
953 _Hashtable(size_type __bucket_hint,
954 const _H1& __h1,
const _H2& __h2,
const _Hash& __h,
955 const _Equal& __eq,
const _ExtractKey& __exk,
956 const allocator_type& __a)
957 : _Hashtable(__h1, __h2, __h, __eq, __exk, __a)
959 auto __bkt = _M_rehash_policy._M_next_bkt(__bucket_hint);
960 if (__bkt > _M_bucket_count)
962 _M_buckets = _M_allocate_buckets(__bkt);
963 _M_bucket_count = __bkt;
967 template<
typename _Key,
typename _Value,
968 typename _Alloc,
typename _ExtractKey,
typename _Equal,
969 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
971 template<
typename _InputIterator>
972 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
973 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
974 _Hashtable(_InputIterator __f, _InputIterator __l,
975 size_type __bucket_hint,
976 const _H1& __h1,
const _H2& __h2,
const _Hash& __h,
977 const _Equal& __eq,
const _ExtractKey& __exk,
978 const allocator_type& __a)
979 : _Hashtable(__h1, __h2, __h, __eq, __exk, __a)
981 auto __nb_elems = __detail::__distance_fw(__f, __l);
983 _M_rehash_policy._M_next_bkt(
984 std::max(_M_rehash_policy._M_bkt_for_elements(__nb_elems),
987 if (__bkt_count > _M_bucket_count)
989 _M_buckets = _M_allocate_buckets(__bkt_count);
990 _M_bucket_count = __bkt_count;
993 for (; __f != __l; ++__f)
997 template<
typename _Key,
typename _Value,
998 typename _Alloc,
typename _ExtractKey,
typename _Equal,
999 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1002 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1003 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1004 operator=(
const _Hashtable& __ht)
1010 if (__node_alloc_traits::_S_propagate_on_copy_assign())
1012 auto& __this_alloc = this->_M_node_allocator();
1013 auto& __that_alloc = __ht._M_node_allocator();
1014 if (!__node_alloc_traits::_S_always_equal()
1015 && __this_alloc != __that_alloc)
1018 this->_M_deallocate_nodes(_M_begin());
1019 _M_before_begin._M_nxt =
nullptr;
1020 _M_deallocate_buckets();
1021 _M_buckets =
nullptr;
1022 std::__alloc_on_copy(__this_alloc, __that_alloc);
1023 __hashtable_base::operator=(__ht);
1024 _M_bucket_count = __ht._M_bucket_count;
1025 _M_element_count = __ht._M_element_count;
1026 _M_rehash_policy = __ht._M_rehash_policy;
1030 [
this](
const __node_type* __n)
1031 {
return this->_M_allocate_node(__n->_M_v()); });
1038 __throw_exception_again;
1042 std::__alloc_on_copy(__this_alloc, __that_alloc);
1046 _M_assign_elements(__ht,
1047 [](
const __reuse_or_alloc_node_type& __roan,
const __node_type* __n)
1048 {
return __roan(__n->_M_v()); });
1052 template<
typename _Key,
typename _Value,
1053 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1054 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1056 template<
typename _Ht,
typename _NodeGenerator>
1058 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1059 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1060 _M_assign_elements(_Ht&& __ht,
const _NodeGenerator& __node_gen)
1062 __bucket_type* __former_buckets =
nullptr;
1063 std::size_t __former_bucket_count = _M_bucket_count;
1064 const __rehash_state& __former_state = _M_rehash_policy._M_state();
1066 if (_M_bucket_count != __ht._M_bucket_count)
1068 __former_buckets = _M_buckets;
1069 _M_buckets = _M_allocate_buckets(__ht._M_bucket_count);
1070 _M_bucket_count = __ht._M_bucket_count;
1073 __builtin_memset(_M_buckets, 0,
1074 _M_bucket_count *
sizeof(__bucket_type));
1078 __hashtable_base::operator=(std::forward<_Ht>(__ht));
1079 _M_element_count = __ht._M_element_count;
1080 _M_rehash_policy = __ht._M_rehash_policy;
1081 __reuse_or_alloc_node_type __roan(_M_begin(), *
this);
1082 _M_before_begin._M_nxt =
nullptr;
1084 [&__node_gen, &__roan](__node_type* __n)
1085 {
return __node_gen(__roan, __n); });
1086 if (__former_buckets)
1087 _M_deallocate_buckets(__former_buckets, __former_bucket_count);
1091 if (__former_buckets)
1094 _M_deallocate_buckets();
1095 _M_rehash_policy._M_reset(__former_state);
1096 _M_buckets = __former_buckets;
1097 _M_bucket_count = __former_bucket_count;
1099 __builtin_memset(_M_buckets, 0,
1100 _M_bucket_count *
sizeof(__bucket_type));
1101 __throw_exception_again;
1105 template<
typename _Key,
typename _Value,
1106 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1107 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1109 template<
typename _NodeGenerator>
1111 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1112 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1113 _M_assign(
const _Hashtable& __ht,
const _NodeGenerator& __node_gen)
1115 __bucket_type* __buckets =
nullptr;
1117 _M_buckets = __buckets = _M_allocate_buckets(_M_bucket_count);
1121 if (!__ht._M_before_begin._M_nxt)
1126 __node_type* __ht_n = __ht._M_begin();
1127 __node_type* __this_n = __node_gen(__ht_n);
1128 this->_M_copy_code(__this_n, __ht_n);
1129 _M_before_begin._M_nxt = __this_n;
1130 _M_buckets[_M_bucket_index(__this_n)] = &_M_before_begin;
1133 __node_base* __prev_n = __this_n;
1134 for (__ht_n = __ht_n->_M_next(); __ht_n; __ht_n = __ht_n->_M_next())
1136 __this_n = __node_gen(__ht_n);
1137 __prev_n->_M_nxt = __this_n;
1138 this->_M_copy_code(__this_n, __ht_n);
1139 size_type __bkt = _M_bucket_index(__this_n);
1140 if (!_M_buckets[__bkt])
1141 _M_buckets[__bkt] = __prev_n;
1142 __prev_n = __this_n;
1149 _M_deallocate_buckets();
1150 __throw_exception_again;
1154 template<
typename _Key,
typename _Value,
1155 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1156 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1159 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1160 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1163 _M_rehash_policy._M_reset();
1164 _M_bucket_count = 1;
1165 _M_single_bucket =
nullptr;
1166 _M_buckets = &_M_single_bucket;
1167 _M_before_begin._M_nxt =
nullptr;
1168 _M_element_count = 0;
1171 template<
typename _Key,
typename _Value,
1172 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1173 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1176 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1177 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1180 this->_M_deallocate_nodes(_M_begin());
1181 _M_deallocate_buckets();
1182 __hashtable_base::operator=(std::move(__ht));
1183 _M_rehash_policy = __ht._M_rehash_policy;
1184 if (!__ht._M_uses_single_bucket())
1185 _M_buckets = __ht._M_buckets;
1188 _M_buckets = &_M_single_bucket;
1189 _M_single_bucket = __ht._M_single_bucket;
1191 _M_bucket_count = __ht._M_bucket_count;
1192 _M_before_begin._M_nxt = __ht._M_before_begin._M_nxt;
1193 _M_element_count = __ht._M_element_count;
1194 std::__alloc_on_move(this->_M_node_allocator(), __ht._M_node_allocator());
1199 _M_buckets[_M_bucket_index(_M_begin())] = &_M_before_begin;
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 if (__ht._M_node_allocator() == this->_M_node_allocator())
1217 _M_assign_elements(std::move(__ht),
1218 [](
const __reuse_or_alloc_node_type& __roan, __node_type* __n)
1224 template<
typename _Key,
typename _Value,
1225 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1226 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1228 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1229 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1230 _Hashtable(
const _Hashtable& __ht)
1231 : __hashtable_base(__ht),
1233 __rehash_base(__ht),
1235 __node_alloc_traits::_S_select_on_copy(__ht._M_node_allocator())),
1236 _M_buckets(nullptr),
1237 _M_bucket_count(__ht._M_bucket_count),
1238 _M_element_count(__ht._M_element_count),
1239 _M_rehash_policy(__ht._M_rehash_policy)
1242 [
this](
const __node_type* __n)
1243 {
return this->_M_allocate_node(__n->_M_v()); });
1246 template<
typename _Key,
typename _Value,
1247 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1248 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1250 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1251 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1252 _Hashtable(_Hashtable&& __ht) noexcept
1253 : __hashtable_base(__ht),
1255 __rehash_base(__ht),
1256 __hashtable_alloc(std::move(__ht._M_base_alloc())),
1257 _M_buckets(__ht._M_buckets),
1258 _M_bucket_count(__ht._M_bucket_count),
1259 _M_before_begin(__ht._M_before_begin._M_nxt),
1260 _M_element_count(__ht._M_element_count),
1261 _M_rehash_policy(__ht._M_rehash_policy)
1264 if (__ht._M_uses_single_bucket())
1266 _M_buckets = &_M_single_bucket;
1267 _M_single_bucket = __ht._M_single_bucket;
1273 _M_buckets[_M_bucket_index(_M_begin())] = &_M_before_begin;
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(
const _Hashtable& __ht,
const allocator_type& __a)
1285 : __hashtable_base(__ht),
1287 __rehash_base(__ht),
1288 __hashtable_alloc(__node_alloc_type(__a)),
1290 _M_bucket_count(__ht._M_bucket_count),
1291 _M_element_count(__ht._M_element_count),
1292 _M_rehash_policy(__ht._M_rehash_policy)
1295 [
this](
const __node_type* __n)
1296 {
return this->_M_allocate_node(__n->_M_v()); });
1299 template<
typename _Key,
typename _Value,
1300 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1301 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1303 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1304 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1305 _Hashtable(_Hashtable&& __ht,
const allocator_type& __a)
1306 : __hashtable_base(__ht),
1308 __rehash_base(__ht),
1309 __hashtable_alloc(__node_alloc_type(__a)),
1310 _M_buckets(nullptr),
1311 _M_bucket_count(__ht._M_bucket_count),
1312 _M_element_count(__ht._M_element_count),
1313 _M_rehash_policy(__ht._M_rehash_policy)
1315 if (__ht._M_node_allocator() == this->_M_node_allocator())
1317 if (__ht._M_uses_single_bucket())
1319 _M_buckets = &_M_single_bucket;
1320 _M_single_bucket = __ht._M_single_bucket;
1323 _M_buckets = __ht._M_buckets;
1325 _M_before_begin._M_nxt = __ht._M_before_begin._M_nxt;
1329 _M_buckets[_M_bucket_index(_M_begin())] = &_M_before_begin;
1335 [
this](__node_type* __n)
1337 return this->_M_allocate_node(
1344 template<
typename _Key,
typename _Value,
1345 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1346 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1348 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1349 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1350 ~_Hashtable() noexcept
1353 _M_deallocate_buckets();
1356 template<
typename _Key,
typename _Value,
1357 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1358 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1361 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1362 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1363 swap(_Hashtable& __x)
1364 noexcept(__and_<__is_nothrow_swappable<_H1>,
1365 __is_nothrow_swappable<_Equal>>::value)
1372 std::__alloc_on_swap(this->_M_node_allocator(), __x._M_node_allocator());
1373 std::swap(_M_rehash_policy, __x._M_rehash_policy);
1376 if (this->_M_uses_single_bucket())
1378 if (!__x._M_uses_single_bucket())
1380 _M_buckets = __x._M_buckets;
1381 __x._M_buckets = &__x._M_single_bucket;
1384 else if (__x._M_uses_single_bucket())
1386 __x._M_buckets = _M_buckets;
1387 _M_buckets = &_M_single_bucket;
1390 std::swap(_M_buckets, __x._M_buckets);
1392 std::swap(_M_bucket_count, __x._M_bucket_count);
1393 std::swap(_M_before_begin._M_nxt, __x._M_before_begin._M_nxt);
1394 std::swap(_M_element_count, __x._M_element_count);
1395 std::swap(_M_single_bucket, __x._M_single_bucket);
1400 _M_buckets[_M_bucket_index(_M_begin())] = &_M_before_begin;
1403 __x._M_buckets[__x._M_bucket_index(__x._M_begin())]
1404 = &__x._M_before_begin;
1407 template<
typename _Key,
typename _Value,
1408 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1409 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1412 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1413 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1414 find(
const key_type& __k)
1417 __hash_code __code = this->_M_hash_code(__k);
1418 std::size_t __n = _M_bucket_index(__k, __code);
1419 __node_type* __p = _M_find_node(__n, __k, __code);
1420 return __p ? iterator(__p) :
end();
1423 template<
typename _Key,
typename _Value,
1424 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1425 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1428 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1429 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1430 find(
const key_type& __k)
const 1433 __hash_code __code = this->_M_hash_code(__k);
1434 std::size_t __n = _M_bucket_index(__k, __code);
1435 __node_type* __p = _M_find_node(__n, __k, __code);
1436 return __p ? const_iterator(__p) :
end();
1439 template<
typename _Key,
typename _Value,
1440 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1441 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1444 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1445 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1446 count(
const key_type& __k)
const 1449 __hash_code __code = this->_M_hash_code(__k);
1450 std::size_t __n = _M_bucket_index(__k, __code);
1451 __node_type* __p = _M_bucket_begin(__n);
1455 std::size_t __result = 0;
1456 for (;; __p = __p->_M_next())
1458 if (this->_M_equals(__k, __code, __p))
1465 if (!__p->_M_nxt || _M_bucket_index(__p->_M_next()) != __n)
1471 template<
typename _Key,
typename _Value,
1472 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1473 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1476 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1477 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1478 equal_range(
const key_type& __k)
1479 -> pair<iterator, iterator>
1481 __hash_code __code = this->_M_hash_code(__k);
1482 std::size_t __n = _M_bucket_index(__k, __code);
1483 __node_type* __p = _M_find_node(__n, __k, __code);
1487 __node_type* __p1 = __p->_M_next();
1488 while (__p1 && _M_bucket_index(__p1) == __n
1489 && this->_M_equals(__k, __code, __p1))
1490 __p1 = __p1->_M_next();
1498 template<
typename _Key,
typename _Value,
1499 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1500 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1503 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1504 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1505 equal_range(
const key_type& __k)
const 1506 -> pair<const_iterator, const_iterator>
1508 __hash_code __code = this->_M_hash_code(__k);
1509 std::size_t __n = _M_bucket_index(__k, __code);
1510 __node_type* __p = _M_find_node(__n, __k, __code);
1514 __node_type* __p1 = __p->_M_next();
1515 while (__p1 && _M_bucket_index(__p1) == __n
1516 && this->_M_equals(__k, __code, __p1))
1517 __p1 = __p1->_M_next();
1519 return std::make_pair(const_iterator(__p), const_iterator(__p1));
1527 template<
typename _Key,
typename _Value,
1528 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1529 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1532 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1533 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1534 _M_find_before_node(size_type __n,
const key_type& __k,
1535 __hash_code __code)
const 1538 __node_base* __prev_p = _M_buckets[__n];
1542 for (__node_type* __p = static_cast<__node_type*>(__prev_p->_M_nxt);;
1543 __p = __p->_M_next())
1545 if (this->_M_equals(__k, __code, __p))
1548 if (!__p->_M_nxt || _M_bucket_index(__p->_M_next()) != __n)
1555 template<
typename _Key,
typename _Value,
1556 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1557 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1560 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1561 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1562 _M_insert_bucket_begin(size_type __bkt, __node_type* __node)
1564 if (_M_buckets[__bkt])
1568 __node->_M_nxt = _M_buckets[__bkt]->_M_nxt;
1569 _M_buckets[__bkt]->_M_nxt = __node;
1576 __node->_M_nxt = _M_before_begin._M_nxt;
1577 _M_before_begin._M_nxt = __node;
1581 _M_buckets[_M_bucket_index(__node->_M_next())] = __node;
1582 _M_buckets[__bkt] = &_M_before_begin;
1586 template<
typename _Key,
typename _Value,
1587 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1588 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1591 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1592 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1593 _M_remove_bucket_begin(size_type __bkt, __node_type* __next,
1594 size_type __next_bkt)
1596 if (!__next || __next_bkt != __bkt)
1601 _M_buckets[__next_bkt] = _M_buckets[__bkt];
1604 if (&_M_before_begin == _M_buckets[__bkt])
1605 _M_before_begin._M_nxt = __next;
1606 _M_buckets[__bkt] =
nullptr;
1610 template<
typename _Key,
typename _Value,
1611 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1612 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1615 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1616 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1617 _M_get_previous_node(size_type __bkt, __node_base* __n)
1620 __node_base* __prev_n = _M_buckets[__bkt];
1621 while (__prev_n->_M_nxt != __n)
1622 __prev_n = __prev_n->_M_nxt;
1626 template<
typename _Key,
typename _Value,
1627 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1628 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1630 template<
typename... _Args>
1632 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1633 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1635 -> pair<iterator, bool>
1638 __node_type* __node = this->_M_allocate_node(std::forward<_Args>(__args)...);
1639 const key_type& __k = this->_M_extract()(__node->_M_v());
1643 __code = this->_M_hash_code(__k);
1647 this->_M_deallocate_node(__node);
1648 __throw_exception_again;
1651 size_type __bkt = _M_bucket_index(__k, __code);
1652 if (__node_type* __p = _M_find_node(__bkt, __k, __code))
1655 this->_M_deallocate_node(__node);
1660 return std::make_pair(_M_insert_unique_node(__bkt, __code, __node),
1664 template<
typename _Key,
typename _Value,
1665 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1666 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1668 template<
typename... _Args>
1670 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1671 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1676 __node_type* __node =
1677 this->_M_allocate_node(std::forward<_Args>(__args)...);
1682 __code = this->_M_hash_code(this->_M_extract()(__node->_M_v()));
1686 this->_M_deallocate_node(__node);
1687 __throw_exception_again;
1690 return _M_insert_multi_node(__hint._M_cur, __code, __node);
1693 template<
typename _Key,
typename _Value,
1694 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1695 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1698 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1699 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1700 _M_insert_unique_node(size_type __bkt, __hash_code __code,
1701 __node_type* __node, size_type __n_elt)
1704 const __rehash_state& __saved_state = _M_rehash_policy._M_state();
1706 = _M_rehash_policy._M_need_rehash(_M_bucket_count, _M_element_count,
1711 if (__do_rehash.
first)
1713 _M_rehash(__do_rehash.
second, __saved_state);
1714 __bkt = _M_bucket_index(this->_M_extract()(__node->_M_v()), __code);
1717 this->_M_store_code(__node, __code);
1720 _M_insert_bucket_begin(__bkt, __node);
1722 return iterator(__node);
1726 this->_M_deallocate_node(__node);
1727 __throw_exception_again;
1733 template<
typename _Key,
typename _Value,
1734 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1735 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1738 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1739 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1740 _M_insert_multi_node(__node_type* __hint, __hash_code __code,
1741 __node_type* __node)
1744 const __rehash_state& __saved_state = _M_rehash_policy._M_state();
1746 = _M_rehash_policy._M_need_rehash(_M_bucket_count, _M_element_count, 1);
1750 if (__do_rehash.
first)
1751 _M_rehash(__do_rehash.
second, __saved_state);
1753 this->_M_store_code(__node, __code);
1754 const key_type& __k = this->_M_extract()(__node->_M_v());
1755 size_type __bkt = _M_bucket_index(__k, __code);
1760 = __builtin_expect(__hint !=
nullptr,
false)
1761 && this->_M_equals(__k, __code, __hint)
1763 : _M_find_before_node(__bkt, __k, __code);
1767 __node->_M_nxt = __prev->_M_nxt;
1768 __prev->_M_nxt = __node;
1769 if (__builtin_expect(__prev == __hint,
false))
1773 && !this->_M_equals(__k, __code, __node->_M_next()))
1775 size_type __next_bkt = _M_bucket_index(__node->_M_next());
1776 if (__next_bkt != __bkt)
1777 _M_buckets[__next_bkt] = __node;
1785 _M_insert_bucket_begin(__bkt, __node);
1787 return iterator(__node);
1791 this->_M_deallocate_node(__node);
1792 __throw_exception_again;
1797 template<
typename _Key,
typename _Value,
1798 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1799 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1801 template<
typename _Arg,
typename _NodeGenerator>
1803 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1804 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1805 _M_insert(_Arg&& __v,
const _NodeGenerator& __node_gen,
true_type,
1807 -> pair<iterator, bool>
1809 const key_type& __k = this->_M_extract()(__v);
1810 __hash_code __code = this->_M_hash_code(__k);
1811 size_type __bkt = _M_bucket_index(__k, __code);
1813 __node_type* __n = _M_find_node(__bkt, __k, __code);
1817 __n = __node_gen(std::forward<_Arg>(__v));
1818 return { _M_insert_unique_node(__bkt, __code, __n, __n_elt),
true };
1822 template<
typename _Key,
typename _Value,
1823 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1824 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1826 template<
typename _Arg,
typename _NodeGenerator>
1828 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1829 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1830 _M_insert(const_iterator __hint, _Arg&& __v,
1831 const _NodeGenerator& __node_gen,
false_type)
1836 __hash_code __code = this->_M_hash_code(this->_M_extract()(__v));
1839 __node_type* __node = __node_gen(std::forward<_Arg>(__v));
1841 return _M_insert_multi_node(__hint._M_cur, __code, __node);
1844 template<
typename _Key,
typename _Value,
1845 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1846 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1849 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1850 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1851 erase(const_iterator __it)
1854 __node_type* __n = __it._M_cur;
1855 std::size_t __bkt = _M_bucket_index(__n);
1860 __node_base* __prev_n = _M_get_previous_node(__bkt, __n);
1861 return _M_erase(__bkt, __prev_n, __n);
1864 template<
typename _Key,
typename _Value,
1865 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1866 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1869 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1870 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1871 _M_erase(size_type __bkt, __node_base* __prev_n, __node_type* __n)
1874 if (__prev_n == _M_buckets[__bkt])
1875 _M_remove_bucket_begin(__bkt, __n->_M_next(),
1876 __n->_M_nxt ? _M_bucket_index(__n->_M_next()) : 0);
1877 else if (__n->_M_nxt)
1879 size_type __next_bkt = _M_bucket_index(__n->_M_next());
1880 if (__next_bkt != __bkt)
1881 _M_buckets[__next_bkt] = __prev_n;
1884 __prev_n->_M_nxt = __n->_M_nxt;
1885 iterator __result(__n->_M_next());
1886 this->_M_deallocate_node(__n);
1892 template<
typename _Key,
typename _Value,
1893 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1894 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1897 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1898 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1902 __hash_code __code = this->_M_hash_code(__k);
1903 std::size_t __bkt = _M_bucket_index(__k, __code);
1906 __node_base* __prev_n = _M_find_before_node(__bkt, __k, __code);
1911 __node_type* __n =
static_cast<__node_type*
>(__prev_n->_M_nxt);
1912 _M_erase(__bkt, __prev_n, __n);
1916 template<
typename _Key,
typename _Value,
1917 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1918 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1921 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1922 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1926 __hash_code __code = this->_M_hash_code(__k);
1927 std::size_t __bkt = _M_bucket_index(__k, __code);
1930 __node_base* __prev_n = _M_find_before_node(__bkt, __k, __code);
1940 __node_type* __n =
static_cast<__node_type*
>(__prev_n->_M_nxt);
1941 __node_type* __n_last = __n;
1942 std::size_t __n_last_bkt = __bkt;
1945 __n_last = __n_last->_M_next();
1948 __n_last_bkt = _M_bucket_index(__n_last);
1950 while (__n_last_bkt == __bkt && this->_M_equals(__k, __code, __n_last));
1953 size_type __result = 0;
1956 __node_type* __p = __n->_M_next();
1957 this->_M_deallocate_node(__n);
1962 while (__n != __n_last);
1964 if (__prev_n == _M_buckets[__bkt])
1965 _M_remove_bucket_begin(__bkt, __n_last, __n_last_bkt);
1966 else if (__n_last && __n_last_bkt != __bkt)
1967 _M_buckets[__n_last_bkt] = __prev_n;
1968 __prev_n->_M_nxt = __n_last;
1972 template<
typename _Key,
typename _Value,
1973 typename _Alloc,
typename _ExtractKey,
typename _Equal,
1974 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1977 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1978 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
1979 erase(const_iterator __first, const_iterator __last)
1982 __node_type* __n = __first._M_cur;
1983 __node_type* __last_n = __last._M_cur;
1984 if (__n == __last_n)
1985 return iterator(__n);
1987 std::size_t __bkt = _M_bucket_index(__n);
1989 __node_base* __prev_n = _M_get_previous_node(__bkt, __n);
1990 bool __is_bucket_begin = __n == _M_bucket_begin(__bkt);
1991 std::size_t __n_bkt = __bkt;
1996 __node_type* __tmp = __n;
1997 __n = __n->_M_next();
1998 this->_M_deallocate_node(__tmp);
2002 __n_bkt = _M_bucket_index(__n);
2004 while (__n != __last_n && __n_bkt == __bkt);
2005 if (__is_bucket_begin)
2006 _M_remove_bucket_begin(__bkt, __n, __n_bkt);
2007 if (__n == __last_n)
2009 __is_bucket_begin =
true;
2013 if (__n && (__n_bkt != __bkt || __is_bucket_begin))
2014 _M_buckets[__n_bkt] = __prev_n;
2015 __prev_n->_M_nxt = __n;
2016 return iterator(__n);
2019 template<
typename _Key,
typename _Value,
2020 typename _Alloc,
typename _ExtractKey,
typename _Equal,
2021 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
2024 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
2025 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
2028 this->_M_deallocate_nodes(_M_begin());
2029 __builtin_memset(_M_buckets, 0, _M_bucket_count *
sizeof(__bucket_type));
2030 _M_element_count = 0;
2031 _M_before_begin._M_nxt =
nullptr;
2034 template<
typename _Key,
typename _Value,
2035 typename _Alloc,
typename _ExtractKey,
typename _Equal,
2036 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
2039 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
2040 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
2041 rehash(size_type __n)
2043 const __rehash_state& __saved_state = _M_rehash_policy._M_state();
2044 std::size_t __buckets
2045 =
std::max(_M_rehash_policy._M_bkt_for_elements(_M_element_count + 1),
2047 __buckets = _M_rehash_policy._M_next_bkt(__buckets);
2049 if (__buckets != _M_bucket_count)
2050 _M_rehash(__buckets, __saved_state);
2053 _M_rehash_policy._M_reset(__saved_state);
2056 template<
typename _Key,
typename _Value,
2057 typename _Alloc,
typename _ExtractKey,
typename _Equal,
2058 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
2061 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
2062 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
2063 _M_rehash(size_type __n,
const __rehash_state& __state)
2067 _M_rehash_aux(__n, __unique_keys());
2073 _M_rehash_policy._M_reset(__state);
2074 __throw_exception_again;
2079 template<
typename _Key,
typename _Value,
2080 typename _Alloc,
typename _ExtractKey,
typename _Equal,
2081 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
2084 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
2085 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
2088 __bucket_type* __new_buckets = _M_allocate_buckets(__n);
2089 __node_type* __p = _M_begin();
2090 _M_before_begin._M_nxt =
nullptr;
2091 std::size_t __bbegin_bkt = 0;
2094 __node_type* __next = __p->_M_next();
2095 std::size_t __bkt = __hash_code_base::_M_bucket_index(__p, __n);
2096 if (!__new_buckets[__bkt])
2098 __p->_M_nxt = _M_before_begin._M_nxt;
2099 _M_before_begin._M_nxt = __p;
2100 __new_buckets[__bkt] = &_M_before_begin;
2102 __new_buckets[__bbegin_bkt] = __p;
2103 __bbegin_bkt = __bkt;
2107 __p->_M_nxt = __new_buckets[__bkt]->_M_nxt;
2108 __new_buckets[__bkt]->_M_nxt = __p;
2113 _M_deallocate_buckets();
2114 _M_bucket_count = __n;
2115 _M_buckets = __new_buckets;
2120 template<
typename _Key,
typename _Value,
2121 typename _Alloc,
typename _ExtractKey,
typename _Equal,
2122 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
2125 _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
2126 _H1, _H2, _Hash, _RehashPolicy, _Traits>::
2129 __bucket_type* __new_buckets = _M_allocate_buckets(__n);
2131 __node_type* __p = _M_begin();
2132 _M_before_begin._M_nxt =
nullptr;
2133 std::size_t __bbegin_bkt = 0;
2134 std::size_t __prev_bkt = 0;
2135 __node_type* __prev_p =
nullptr;
2136 bool __check_bucket =
false;
2140 __node_type* __next = __p->_M_next();
2141 std::size_t __bkt = __hash_code_base::_M_bucket_index(__p, __n);
2143 if (__prev_p && __prev_bkt == __bkt)
2148 __p->_M_nxt = __prev_p->_M_nxt;
2149 __prev_p->_M_nxt = __p;
2156 __check_bucket =
true;
2164 if (__prev_p->_M_nxt)
2166 std::size_t __next_bkt
2167 = __hash_code_base::_M_bucket_index(__prev_p->_M_next(),
2169 if (__next_bkt != __prev_bkt)
2170 __new_buckets[__next_bkt] = __prev_p;
2172 __check_bucket =
false;
2175 if (!__new_buckets[__bkt])
2177 __p->_M_nxt = _M_before_begin._M_nxt;
2178 _M_before_begin._M_nxt = __p;
2179 __new_buckets[__bkt] = &_M_before_begin;
2181 __new_buckets[__bbegin_bkt] = __p;
2182 __bbegin_bkt = __bkt;
2186 __p->_M_nxt = __new_buckets[__bkt]->_M_nxt;
2187 __new_buckets[__bkt]->_M_nxt = __p;
2195 if (__check_bucket && __prev_p->_M_nxt)
2197 std::size_t __next_bkt
2198 = __hash_code_base::_M_bucket_index(__prev_p->_M_next(), __n);
2199 if (__next_bkt != __prev_bkt)
2200 __new_buckets[__next_bkt] = __prev_p;
2203 _M_deallocate_buckets();
2204 _M_bucket_count = __n;
2205 _M_buckets = __new_buckets;
2208 #if __cplusplus > 201402L 2209 template<
typename,
typename,
typename>
class _Hash_merge_helper { };
2212 #if __cpp_deduction_guides >= 201606 2214 template<
typename _Hash>
2215 using _RequireNotAllocatorOrIntegral
2216 = __enable_if_t<!__or_<is_integral<_Hash>, __is_allocator<_Hash>>::value>;
2219 _GLIBCXX_END_NAMESPACE_VERSION
2222 #endif // _HASHTABLE_H constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
_T2 second
first is a copy of the first object
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
_Tp exchange(_Tp &__obj, _Up &&__new_val)
Assign __new_val to __obj and return its previous value.
ISO C++ entities toplevel namespace is std.
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.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
Define a member typedef type to one of two argument types.
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.
_T1 first
second_type is the second bound type
is_nothrow_move_assignable
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first 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.
Uniform interface to C++98 and C++11 allocators.
Node const_iterators, used to iterate through all the hashtable.
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.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
Struct holding two objects of arbitrary type.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
Node iterators, used to iterate through all the hashtable.