31#ifndef _HASHTABLE_POLICY_H
32#define _HASHTABLE_POLICY_H 1
42namespace std _GLIBCXX_VISIBILITY(default)
44_GLIBCXX_BEGIN_NAMESPACE_VERSION
47 template<
typename _Key,
typename _Value,
typename _Alloc,
48 typename _ExtractKey,
typename _Equal,
49 typename _Hash,
typename _RangeHash,
typename _Unused,
50 typename _RehashPolicy,
typename _Traits>
60 template<
typename _Key,
typename _Value,
typename _ExtractKey,
61 typename _Equal,
typename _Hash,
typename _RangeHash,
62 typename _Unused,
typename _Traits>
63 struct _Hashtable_base;
67 template<
typename _Iterator>
69 __distance_fw(_Iterator __first, _Iterator __last,
71 {
return __first != __last ? 1 : 0; }
73 template<
typename _Iterator>
75 __distance_fw(_Iterator __first, _Iterator __last,
79 template<
typename _Iterator>
81 __distance_fw(_Iterator __first, _Iterator __last)
82 {
return __distance_fw(__first, __last,
87 template<
typename _Tp>
89 operator()(_Tp&& __x)
const noexcept
95 template<
typename _Pair>
98 template<
typename _Tp,
typename _Up>
99 struct __1st_type<
pair<_Tp, _Up>>
100 {
using type = _Tp; };
102 template<
typename _Tp,
typename _Up>
103 struct __1st_type<const
pair<_Tp, _Up>>
104 {
using type =
const _Tp; };
106 template<
typename _Pair>
107 struct __1st_type<_Pair&>
108 {
using type =
typename __1st_type<_Pair>::type&; };
110 template<
typename _Tp>
111 typename __1st_type<_Tp>::type&&
112 operator()(_Tp&& __x)
const noexcept
116 template<
typename _ExKey>
120 struct _NodeBuilder<_Select1st>
122 template<
typename _Kt,
typename _Arg,
typename _NodeGenerator>
124 _S_build(_Kt&& __k, _Arg&& __arg,
const _NodeGenerator& __node_gen)
125 ->
typename _NodeGenerator::__node_ptr
133 struct _NodeBuilder<_Identity>
135 template<
typename _Kt,
typename _Arg,
typename _NodeGenerator>
137 _S_build(_Kt&& __k, _Arg&&,
const _NodeGenerator& __node_gen)
138 ->
typename _NodeGenerator::__node_ptr
142 template<
typename _HashtableAlloc,
typename _NodePtr>
145 _HashtableAlloc& _M_h;
151 _M_h._M_deallocate_node_ptr(_M_ptr);
155 template<
typename _NodeAlloc>
156 struct _Hashtable_alloc;
160 template<
typename _NodeAlloc>
161 struct _ReuseOrAllocNode
164 using __node_alloc_type = _NodeAlloc;
165 using __hashtable_alloc = _Hashtable_alloc<__node_alloc_type>;
166 using __node_alloc_traits =
167 typename __hashtable_alloc::__node_alloc_traits;
170 using __node_ptr =
typename __hashtable_alloc::__node_ptr;
172 _ReuseOrAllocNode(__node_ptr __nodes, __hashtable_alloc& __h)
173 : _M_nodes(__nodes), _M_h(__h) { }
174 _ReuseOrAllocNode(
const _ReuseOrAllocNode&) =
delete;
177 { _M_h._M_deallocate_nodes(_M_nodes); }
179 template<
typename... _Args>
181 operator()(_Args&&... __args)
const
186 __node_ptr __node = _M_nodes;
187 _M_nodes = _M_nodes->_M_next();
188 __node->_M_nxt =
nullptr;
189 auto& __a = _M_h._M_node_allocator();
190 __node_alloc_traits::destroy(__a, __node->_M_valptr());
191 _NodePtrGuard<__hashtable_alloc, __node_ptr> __guard { _M_h, __node };
192 __node_alloc_traits::construct(__a, __node->_M_valptr(),
194 __guard._M_ptr =
nullptr;
199 mutable __node_ptr _M_nodes;
200 __hashtable_alloc& _M_h;
205 template<
typename _NodeAlloc>
209 using __hashtable_alloc = _Hashtable_alloc<_NodeAlloc>;
212 using __node_ptr =
typename __hashtable_alloc::__node_ptr;
214 _AllocNode(__hashtable_alloc& __h)
217 template<
typename... _Args>
219 operator()(_Args&&... __args)
const
223 __hashtable_alloc& _M_h;
251 template<
bool _Cache_hash_code,
bool _Constant_iterators,
bool _Unique_keys>
252 struct _Hashtable_traits
254 using __hash_cached = __bool_constant<_Cache_hash_code>;
255 using __constant_iterators = __bool_constant<_Constant_iterators>;
256 using __unique_keys = __bool_constant<_Unique_keys>;
265 template<
typename _Hash>
266 struct _Hashtable_hash_traits
268 static constexpr std::size_t
269 __small_size_threshold() noexcept
281 struct _Hash_node_base
283 _Hash_node_base* _M_nxt;
285 _Hash_node_base() noexcept : _M_nxt() { }
287 _Hash_node_base(_Hash_node_base* __next) noexcept : _M_nxt(__next) { }
295 template<
typename _Value>
296 struct _Hash_node_value_base
298 typedef _Value value_type;
300 __gnu_cxx::__aligned_buffer<_Value> _M_storage;
302 [[__gnu__::__always_inline__]]
305 {
return _M_storage._M_ptr(); }
307 [[__gnu__::__always_inline__]]
309 _M_valptr() const noexcept
310 {
return _M_storage._M_ptr(); }
312 [[__gnu__::__always_inline__]]
315 {
return *_M_valptr(); }
317 [[__gnu__::__always_inline__]]
319 _M_v() const noexcept
320 {
return *_M_valptr(); }
326 template<
bool _Cache_hash_code>
327 struct _Hash_node_code_cache
334 struct _Hash_node_code_cache<true>
335 { std::size_t _M_hash_code; };
337 template<
typename _Value,
bool _Cache_hash_code>
338 struct _Hash_node_value
339 : _Hash_node_value_base<_Value>
340 , _Hash_node_code_cache<_Cache_hash_code>
346 template<
typename _Value,
bool _Cache_hash_code>
349 , _Hash_node_value<_Value, _Cache_hash_code>
352 _M_next() const noexcept
353 {
return static_cast<_Hash_node*
>(this->_M_nxt); }
357 template<
typename _Value,
bool _Cache_hash_code>
358 struct _Node_iterator_base
360 using __node_type = _Hash_node<_Value, _Cache_hash_code>;
364 _Node_iterator_base() : _M_cur(nullptr) { }
365 _Node_iterator_base(__node_type* __p) noexcept
370 { _M_cur = _M_cur->_M_next(); }
373 operator==(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
375 {
return __x._M_cur == __y._M_cur; }
377#if __cpp_impl_three_way_comparison < 201907L
379 operator!=(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
381 {
return __x._M_cur != __y._M_cur; }
386 template<
typename _Value,
bool __constant_iterators,
bool __cache>
387 struct _Node_iterator
388 :
public _Node_iterator_base<_Value, __cache>
391 using __base_type = _Node_iterator_base<_Value, __cache>;
392 using __node_type =
typename __base_type::__node_type;
395 using value_type = _Value;
396 using difference_type = std::ptrdiff_t;
399 using pointer = __conditional_t<__constant_iterators,
400 const value_type*, value_type*>;
402 using reference = __conditional_t<__constant_iterators,
403 const value_type&, value_type&>;
405 _Node_iterator() =
default;
408 _Node_iterator(__node_type* __p) noexcept
409 : __base_type(__p) { }
413 {
return this->_M_cur->_M_v(); }
416 operator->() const noexcept
417 {
return this->_M_cur->_M_valptr(); }
420 operator++() noexcept
427 operator++(
int)
noexcept
429 _Node_iterator __tmp(*
this);
434#if __cpp_impl_three_way_comparison >= 201907L
436 operator==(
const _Node_iterator&,
const _Node_iterator&) =
default;
439 operator==(
const _Node_iterator& __x,
const _Node_iterator& __y)
noexcept
441 const __base_type& __bx = __x;
442 const __base_type& __by = __y;
447 operator!=(
const _Node_iterator& __x,
const _Node_iterator& __y)
noexcept
448 {
return !(__x == __y); }
453 template<
typename _Value,
bool __constant_iterators,
bool __cache>
454 struct _Node_const_iterator
455 :
public _Node_iterator_base<_Value, __cache>
458 using __base_type = _Node_iterator_base<_Value, __cache>;
459 using __node_type =
typename __base_type::__node_type;
463 = _Node_iterator<_Value, __constant_iterators, __cache>;
466 typedef _Value value_type;
467 typedef std::ptrdiff_t difference_type;
470 typedef const value_type* pointer;
471 typedef const value_type& reference;
473 _Node_const_iterator() =
default;
476 _Node_const_iterator(__node_type* __p) noexcept
477 : __base_type(__p) { }
479 _Node_const_iterator(
const __iterator& __x) noexcept
480 : __base_type(__x._M_cur) { }
484 {
return this->_M_cur->_M_v(); }
487 operator->() const noexcept
488 {
return this->_M_cur->_M_valptr(); }
490 _Node_const_iterator&
491 operator++() noexcept
498 operator++(
int)
noexcept
500 _Node_const_iterator __tmp(*
this);
505#if __cpp_impl_three_way_comparison >= 201907L
507 operator==(
const _Node_const_iterator&,
508 const _Node_const_iterator&) =
default;
511 operator==(
const _Node_const_iterator& __x,
const __iterator& __y)
513 const __base_type& __bx = __x;
514 const __base_type& __by = __y;
519 operator==(
const _Node_const_iterator& __x,
520 const _Node_const_iterator& __y)
noexcept
522 const __base_type& __bx = __x;
523 const __base_type& __by = __y;
528 operator!=(
const _Node_const_iterator& __x,
529 const _Node_const_iterator& __y)
noexcept
530 {
return !(__x == __y); }
533 operator==(
const _Node_const_iterator& __x,
534 const __iterator& __y)
noexcept
536 const __base_type& __bx = __x;
537 const __base_type& __by = __y;
542 operator!=(
const _Node_const_iterator& __x,
543 const __iterator& __y)
noexcept
544 {
return !(__x == __y); }
547 operator==(
const __iterator& __x,
548 const _Node_const_iterator& __y)
noexcept
550 const __base_type& __bx = __x;
551 const __base_type& __by = __y;
556 operator!=(
const __iterator& __x,
557 const _Node_const_iterator& __y)
noexcept
558 {
return !(__x == __y); }
567 struct _Mod_range_hashing
569 typedef std::size_t first_argument_type;
570 typedef std::size_t second_argument_type;
571 typedef std::size_t result_type;
574 operator()(first_argument_type __num,
575 second_argument_type __den)
const noexcept
576 {
return __num % __den; }
584 struct _Default_ranged_hash { };
588 struct _Prime_rehash_policy
590 using __has_load_factor = true_type;
592 _Prime_rehash_policy(
float __z = 1.0) noexcept
593 : _M_max_load_factor(__z), _M_next_resize(0) { }
596 max_load_factor() const noexcept
597 {
return _M_max_load_factor; }
601 _M_next_bkt(std::size_t __n)
const;
605 _M_bkt_for_elements(std::size_t __n)
const
606 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
613 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
614 std::size_t __n_ins)
const;
616 typedef std::size_t _State;
620 {
return _M_next_resize; }
624 { _M_next_resize = 0; }
627 _M_reset(_State __state)
628 { _M_next_resize = __state; }
630 static const std::size_t _S_growth_factor = 2;
632 float _M_max_load_factor;
633 mutable std::size_t _M_next_resize;
637 struct _Mask_range_hashing
639 typedef std::size_t first_argument_type;
640 typedef std::size_t second_argument_type;
641 typedef std::size_t result_type;
644 operator()(first_argument_type __num,
645 second_argument_type __den)
const noexcept
646 {
return __num & (__den - 1); }
651 __clp2(std::size_t __n)
noexcept
657 const unsigned __lz =
sizeof(size_t) >
sizeof(
long)
658 ? __builtin_clzll(__n - 1ull)
659 : __builtin_clzl(__n - 1ul);
661 return (
size_t(1) << (__int_traits<size_t>::__digits - __lz - 1)) << 1;
666 struct _Power2_rehash_policy
668 using __has_load_factor = true_type;
670 _Power2_rehash_policy(
float __z = 1.0) noexcept
671 : _M_max_load_factor(__z), _M_next_resize(0) { }
674 max_load_factor() const noexcept
675 {
return _M_max_load_factor; }
680 _M_next_bkt(std::size_t __n)
noexcept
689 const auto __max_bkt = size_t(1) << (__max_width * __CHAR_BIT__ - 1);
690 std::size_t __res = __clp2(__n);
700 if (__res == __max_bkt)
704 _M_next_resize = size_t(-1);
707 = __builtin_floor(__res * (
double)_M_max_load_factor);
714 _M_bkt_for_elements(std::size_t __n)
const noexcept
715 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
722 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
723 std::size_t __n_ins)
noexcept
725 if (__n_elt + __n_ins > _M_next_resize)
732 / (double)_M_max_load_factor;
733 if (__min_bkts >= __n_bkt)
736 __n_bkt * _S_growth_factor)) };
739 = __builtin_floor(__n_bkt * (
double)_M_max_load_factor);
746 typedef std::size_t _State;
749 _M_state() const noexcept
750 {
return _M_next_resize; }
754 { _M_next_resize = 0; }
757 _M_reset(_State __state)
noexcept
758 { _M_next_resize = __state; }
760 static const std::size_t _S_growth_factor = 2;
762 float _M_max_load_factor;
763 std::size_t _M_next_resize;
766 template<
typename _RehashPolicy>
767 struct _RehashStateGuard
769 _RehashPolicy* _M_guarded_obj;
770 typename _RehashPolicy::_State _M_prev_state;
772 _RehashStateGuard(_RehashPolicy& __policy)
774 , _M_prev_state(__policy._M_state())
776 _RehashStateGuard(
const _RehashStateGuard&) =
delete;
781 _M_guarded_obj->_M_reset(_M_prev_state);
803 template<
typename _Key,
typename _Value,
typename _Alloc,
804 typename _ExtractKey,
typename _Equal,
805 typename _Hash,
typename _RangeHash,
typename _Unused,
806 typename _RehashPolicy,
typename _Traits,
807 bool _Unique_keys = _Traits::__unique_keys::value>
808 struct _Map_base { };
811 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
812 typename _Hash,
typename _RangeHash,
typename _Unused,
813 typename _RehashPolicy,
typename _Traits>
814 struct _Map_base<_Key,
pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
815 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
817 using mapped_type = _Val;
821 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
822 typename _Hash,
typename _RangeHash,
typename _Unused,
823 typename _RehashPolicy,
typename _Traits>
824 struct _Map_base<_Key,
pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
825 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
828 using __hashtable_base = _Hashtable_base<_Key, pair<const _Key, _Val>,
829 _Select1st, _Equal, _Hash,
833 using __hashtable = _Hashtable<_Key, pair<const _Key, _Val>, _Alloc,
834 _Select1st, _Equal, _Hash, _RangeHash,
835 _Unused, _RehashPolicy, _Traits>;
837 using __hash_code =
typename __hashtable_base::__hash_code;
840 using key_type =
typename __hashtable_base::key_type;
841 using mapped_type = _Val;
844 operator[](
const key_type& __k);
847 operator[](key_type&& __k);
852 at(
const key_type& __k)
854 auto __ite =
static_cast<__hashtable*
>(
this)->find(__k);
856 __throw_out_of_range(__N(
"unordered_map::at"));
857 return __ite->second;
861 at(
const key_type& __k)
const
863 auto __ite =
static_cast<const __hashtable*
>(
this)->find(__k);
865 __throw_out_of_range(__N(
"unordered_map::at"));
866 return __ite->second;
870 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
871 typename _Hash,
typename _RangeHash,
typename _Unused,
872 typename _RehashPolicy,
typename _Traits>
874 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
875 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
876 operator[](
const key_type& __k)
879 __hashtable* __h =
static_cast<__hashtable*
>(
this);
880 __hash_code __code = __h->_M_hash_code(__k);
881 std::size_t __bkt = __h->_M_bucket_index(__code);
882 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
883 return __node->_M_v().second;
885 typename __hashtable::_Scoped_node __node {
892 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
893 __node._M_node =
nullptr;
894 return __pos->second;
897 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
898 typename _Hash,
typename _RangeHash,
typename _Unused,
899 typename _RehashPolicy,
typename _Traits>
901 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
902 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
903 operator[](key_type&& __k)
906 __hashtable* __h =
static_cast<__hashtable*
>(
this);
907 __hash_code __code = __h->_M_hash_code(__k);
908 std::size_t __bkt = __h->_M_bucket_index(__code);
909 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
910 return __node->_M_v().second;
912 typename __hashtable::_Scoped_node __node {
919 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
920 __node._M_node =
nullptr;
921 return __pos->second;
925 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
926 typename _Hash,
typename _RangeHash,
typename _Unused,
927 typename _RehashPolicy,
typename _Traits,
bool __uniq>
928 struct _Map_base<const _Key,
pair<const _Key, _Val>,
929 _Alloc, _Select1st, _Equal, _Hash,
930 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
931 : _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal, _Hash,
932 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
940 template<
typename _Key,
typename _Value,
typename _Alloc,
941 typename _ExtractKey,
typename _Equal,
942 typename _Hash,
typename _RangeHash,
typename _Unused,
943 typename _RehashPolicy,
typename _Traits>
947 using __hashtable_base = _Hashtable_base<_Key, _Value, _ExtractKey,
948 _Equal, _Hash, _RangeHash,
951 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
953 _Unused, _RehashPolicy, _Traits>;
955 using __hash_cached =
typename _Traits::__hash_cached;
956 using __constant_iterators =
typename _Traits::__constant_iterators;
958 using __hashtable_alloc = _Hashtable_alloc<
959 __alloc_rebind<_Alloc, _Hash_node<_Value,
960 __hash_cached::value>>>;
962 using value_type =
typename __hashtable_base::value_type;
963 using size_type =
typename __hashtable_base::size_type;
965 using __unique_keys =
typename _Traits::__unique_keys;
966 using __node_alloc_type =
typename __hashtable_alloc::__node_alloc_type;
967 using __node_gen_type = _AllocNode<__node_alloc_type>;
970 _M_conjure_hashtable()
971 {
return *(
static_cast<__hashtable*
>(
this)); }
973 template<
typename _InputIterator,
typename _NodeGetter>
975 _M_insert_range(_InputIterator __first, _InputIterator __last,
976 const _NodeGetter&, true_type __uks);
978 template<
typename _InputIterator,
typename _NodeGetter>
980 _M_insert_range(_InputIterator __first, _InputIterator __last,
981 const _NodeGetter&, false_type __uks);
984 using iterator = _Node_iterator<_Value, __constant_iterators::value,
985 __hash_cached::value>;
987 using const_iterator = _Node_const_iterator<_Value,
988 __constant_iterators::value,
989 __hash_cached::value>;
991 using __ireturn_type = __conditional_t<__unique_keys::value,
996 insert(
const value_type& __v)
998 __hashtable& __h = _M_conjure_hashtable();
999 __node_gen_type __node_gen(__h);
1000 return __h._M_insert(__v, __node_gen, __unique_keys{});
1004 insert(const_iterator __hint,
const value_type& __v)
1006 __hashtable& __h = _M_conjure_hashtable();
1007 __node_gen_type __node_gen(__h);
1008 return __h._M_insert(__hint, __v, __node_gen, __unique_keys{});
1011#ifdef __glibcxx_unordered_map_try_emplace
1012 template<
typename _KType,
typename... _Args>
1014 try_emplace(const_iterator, _KType&& __k, _Args&&... __args)
1016 __hashtable& __h = _M_conjure_hashtable();
1017 auto __code = __h._M_hash_code(__k);
1018 std::size_t __bkt = __h._M_bucket_index(__code);
1019 if (
auto __node = __h._M_find_node(__bkt, __k, __code))
1020 return { iterator(__node),
false };
1022 typename __hashtable::_Scoped_node __node {
1029 = __h._M_insert_unique_node(__bkt, __code, __node._M_node);
1030 __node._M_node =
nullptr;
1031 return { __it,
true };
1036 insert(initializer_list<value_type> __l)
1037 { this->insert(__l.begin(), __l.end()); }
1039 template<
typename _InputIterator>
1041 insert(_InputIterator __first, _InputIterator __last)
1043 __hashtable& __h = _M_conjure_hashtable();
1044 __node_gen_type __node_gen(__h);
1045 return _M_insert_range(__first, __last, __node_gen, __unique_keys{});
1049 template<
typename _Key,
typename _Value,
typename _Alloc,
1050 typename _ExtractKey,
typename _Equal,
1051 typename _Hash,
typename _RangeHash,
typename _Unused,
1052 typename _RehashPolicy,
typename _Traits>
1053 template<
typename _InputIterator,
typename _NodeGetter>
1055 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1056 _Hash, _RangeHash, _Unused,
1057 _RehashPolicy, _Traits>::
1058 _M_insert_range(_InputIterator __first, _InputIterator __last,
1059 const _NodeGetter& __node_gen, true_type __uks)
1061 __hashtable& __h = _M_conjure_hashtable();
1062 for (; __first != __last; ++__first)
1063 __h._M_insert(*__first, __node_gen, __uks);
1066 template<
typename _Key,
typename _Value,
typename _Alloc,
1067 typename _ExtractKey,
typename _Equal,
1068 typename _Hash,
typename _RangeHash,
typename _Unused,
1069 typename _RehashPolicy,
typename _Traits>
1070 template<
typename _InputIterator,
typename _NodeGetter>
1072 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1073 _Hash, _RangeHash, _Unused,
1074 _RehashPolicy, _Traits>::
1075 _M_insert_range(_InputIterator __first, _InputIterator __last,
1076 const _NodeGetter& __node_gen, false_type __uks)
1078 using __rehash_guard_t =
typename __hashtable::__rehash_guard_t;
1081 size_type __n_elt = __detail::__distance_fw(__first, __last);
1085 __hashtable& __h = _M_conjure_hashtable();
1086 __rehash_guard_t __rehash_guard(__h._M_rehash_policy);
1087 __pair_type __do_rehash
1088 = __h._M_rehash_policy._M_need_rehash(__h._M_bucket_count,
1089 __h._M_element_count,
1092 if (__do_rehash.first)
1093 __h._M_rehash(__do_rehash.second, __uks);
1095 __rehash_guard._M_guarded_obj =
nullptr;
1096 for (; __first != __last; ++__first)
1097 __h._M_insert(*__first, __node_gen, __uks);
1106 template<
typename _Key,
typename _Value,
typename _Alloc,
1107 typename _ExtractKey,
typename _Equal,
1108 typename _Hash,
typename _RangeHash,
typename _Unused,
1109 typename _RehashPolicy,
typename _Traits,
1110 bool _Constant_iterators = _Traits::__constant_iterators::value>
1114 template<
typename _Key,
typename _Value,
typename _Alloc,
1115 typename _ExtractKey,
typename _Equal,
1116 typename _Hash,
typename _RangeHash,
typename _Unused,
1117 typename _RehashPolicy,
typename _Traits>
1118 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1119 _Hash, _RangeHash, _Unused,
1120 _RehashPolicy, _Traits, true>
1121 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1122 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1124 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1125 _Equal, _Hash, _RangeHash, _Unused,
1126 _RehashPolicy, _Traits>;
1128 using value_type =
typename __base_type::value_type;
1129 using iterator =
typename __base_type::iterator;
1130 using const_iterator =
typename __base_type::const_iterator;
1131 using __ireturn_type =
typename __base_type::__ireturn_type;
1133 using __unique_keys =
typename __base_type::__unique_keys;
1134 using __hashtable =
typename __base_type::__hashtable;
1135 using __node_gen_type =
typename __base_type::__node_gen_type;
1137 using __base_type::insert;
1140 insert(value_type&& __v)
1142 __hashtable& __h = this->_M_conjure_hashtable();
1143 __node_gen_type __node_gen(__h);
1144 return __h._M_insert(
std::move(__v), __node_gen, __unique_keys{});
1148 insert(const_iterator __hint, value_type&& __v)
1150 __hashtable& __h = this->_M_conjure_hashtable();
1151 __node_gen_type __node_gen(__h);
1152 return __h._M_insert(__hint,
std::move(__v), __node_gen,
1158 template<
typename _Key,
typename _Value,
typename _Alloc,
1159 typename _ExtractKey,
typename _Equal,
1160 typename _Hash,
typename _RangeHash,
typename _Unused,
1161 typename _RehashPolicy,
typename _Traits>
1162 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1163 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1164 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1165 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1167 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1168 _Equal, _Hash, _RangeHash, _Unused,
1169 _RehashPolicy, _Traits>;
1170 using value_type =
typename __base_type::value_type;
1171 using iterator =
typename __base_type::iterator;
1172 using const_iterator =
typename __base_type::const_iterator;
1174 using __unique_keys =
typename __base_type::__unique_keys;
1175 using __hashtable =
typename __base_type::__hashtable;
1176 using __ireturn_type =
typename __base_type::__ireturn_type;
1178 using __base_type::insert;
1180 template<
typename _Pair>
1183 template<
typename _Pair>
1186 template<
typename _Pair>
1187 using _IFconsp =
typename _IFcons<_Pair>::type;
1189 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1193 __hashtable& __h = this->_M_conjure_hashtable();
1197 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1199 insert(const_iterator __hint, _Pair&& __v)
1201 __hashtable& __h = this->_M_conjure_hashtable();
1202 return __h._M_emplace(__hint, __unique_keys{},
1207 template<
typename _Policy>
1208 using __has_load_factor =
typename _Policy::__has_load_factor;
1216 template<
typename _Key,
typename _Value,
typename _Alloc,
1217 typename _ExtractKey,
typename _Equal,
1218 typename _Hash,
typename _RangeHash,
typename _Unused,
1219 typename _RehashPolicy,
typename _Traits,
1221 __detected_or_t<false_type, __has_load_factor, _RehashPolicy>>
1222 struct _Rehash_base;
1225 template<
typename _Key,
typename _Value,
typename _Alloc,
1226 typename _ExtractKey,
typename _Equal,
1227 typename _Hash,
typename _RangeHash,
typename _Unused,
1228 typename _RehashPolicy,
typename _Traits>
1229 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1230 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1236 template<
typename _Key,
typename _Value,
typename _Alloc,
1237 typename _ExtractKey,
typename _Equal,
1238 typename _Hash,
typename _RangeHash,
typename _Unused,
1239 typename _RehashPolicy,
typename _Traits>
1240 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1241 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1245 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey,
1246 _Equal, _Hash, _RangeHash, _Unused,
1247 _RehashPolicy, _Traits>;
1251 max_load_factor() const noexcept
1253 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1254 return __this->__rehash_policy().max_load_factor();
1258 max_load_factor(
float __z)
1260 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1261 __this->__rehash_policy(_RehashPolicy(__z));
1265 reserve(std::size_t __n)
1267 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1268 __this->rehash(__this->__rehash_policy()._M_bkt_for_elements(__n));
1278 template<
int _Nm,
typename _Tp,
1279 bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
1280 struct _Hashtable_ebo_helper;
1283 template<
int _Nm,
typename _Tp>
1284 struct _Hashtable_ebo_helper<_Nm, _Tp, true>
1287 _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
1289 template<
typename _OtherTp>
1290 _Hashtable_ebo_helper(_OtherTp&& __tp)
1294 const _Tp& _M_cget()
const {
return static_cast<const _Tp&
>(*this); }
1295 _Tp& _M_get() {
return static_cast<_Tp&
>(*this); }
1299 template<
int _Nm,
typename _Tp>
1300 struct _Hashtable_ebo_helper<_Nm, _Tp, false>
1302 _Hashtable_ebo_helper() =
default;
1304 template<
typename _OtherTp>
1305 _Hashtable_ebo_helper(_OtherTp&& __tp)
1309 const _Tp& _M_cget()
const {
return _M_tp; }
1310 _Tp& _M_get() {
return _M_tp; }
1322 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1323 typename _Hash,
typename _RangeHash,
typename _Unused,
1324 bool __cache_hash_code>
1325 struct _Local_iterator_base;
1345 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1346 typename _Hash,
typename _RangeHash,
typename _Unused,
1347 bool __cache_hash_code>
1348 struct _Hash_code_base
1349 :
private _Hashtable_ebo_helper<1, _Hash>
1352 using __ebo_hash = _Hashtable_ebo_helper<1, _Hash>;
1355 friend struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1356 _Hash, _RangeHash, _Unused, false>;
1359 typedef _Hash hasher;
1362 hash_function()
const
1363 {
return _M_hash(); }
1366 typedef std::size_t __hash_code;
1370 _Hash_code_base() =
default;
1372 _Hash_code_base(
const _Hash& __hash) : __ebo_hash(__hash) { }
1375 _M_hash_code(
const _Key& __k)
const
1377 static_assert(__is_invocable<const _Hash&, const _Key&>{},
1378 "hash function must be invocable with an argument of key type");
1379 return _M_hash()(__k);
1382 template<
typename _Kt>
1384 _M_hash_code_tr(
const _Kt& __k)
const
1386 static_assert(__is_invocable<const _Hash&, const _Kt&>{},
1387 "hash function must be invocable with an argument of key type");
1388 return _M_hash()(__k);
1392 _M_hash_code(
const _Hash_node_value<_Value, false>& __n)
const
1393 {
return _M_hash_code(_ExtractKey{}(__n._M_v())); }
1396 _M_hash_code(
const _Hash_node_value<_Value, true>& __n)
const
1397 {
return __n._M_hash_code; }
1400 _M_bucket_index(__hash_code __c, std::size_t __bkt_count)
const
1401 {
return _RangeHash{}(__c, __bkt_count); }
1404 _M_bucket_index(
const _Hash_node_value<_Value, false>& __n,
1405 std::size_t __bkt_count)
const
1406 noexcept(
noexcept(declval<const _Hash&>()(declval<const _Key&>()))
1407 &&
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1410 return _RangeHash{}(_M_hash_code(_ExtractKey{}(__n._M_v())),
1415 _M_bucket_index(
const _Hash_node_value<_Value, true>& __n,
1416 std::size_t __bkt_count)
const
1417 noexcept(
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1419 {
return _RangeHash{}(__n._M_hash_code, __bkt_count); }
1422 _M_store_code(_Hash_node_code_cache<false>&, __hash_code)
const
1426 _M_copy_code(_Hash_node_code_cache<false>&,
1427 const _Hash_node_code_cache<false>&)
const
1431 _M_store_code(_Hash_node_code_cache<true>& __n, __hash_code __c)
const
1432 { __n._M_hash_code = __c; }
1435 _M_copy_code(_Hash_node_code_cache<true>& __to,
1436 const _Hash_node_code_cache<true>& __from)
const
1437 { __to._M_hash_code = __from._M_hash_code; }
1440 _M_swap(_Hash_code_base& __x)
1443 swap(__ebo_hash::_M_get(), __x.__ebo_hash::_M_get());
1447 _M_hash()
const {
return __ebo_hash::_M_cget(); }
1451 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1452 typename _Hash,
typename _RangeHash,
typename _Unused>
1453 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1454 _Hash, _RangeHash, _Unused, true>
1455 :
public _Node_iterator_base<_Value, true>
1458 using __base_node_iter = _Node_iterator_base<_Value, true>;
1459 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1460 _Hash, _RangeHash, _Unused,
true>;
1462 _Local_iterator_base() =
default;
1463 _Local_iterator_base(
const __hash_code_base&,
1464 _Hash_node<_Value, true>* __p,
1465 std::size_t __bkt, std::size_t __bkt_count)
1466 : __base_node_iter(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1472 __base_node_iter::_M_incr();
1476 = _RangeHash{}(this->_M_cur->_M_hash_code, _M_bucket_count);
1477 if (__bkt != _M_bucket)
1478 this->_M_cur =
nullptr;
1482 std::size_t _M_bucket;
1483 std::size_t _M_bucket_count;
1487 _M_get_bucket()
const {
return _M_bucket; }
1494 template<typename _Tp, bool _IsEmpty = std::is_empty<_Tp>::value>
1495 struct _Hash_code_storage
1497 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
1500 _M_h() {
return _M_storage._M_ptr(); }
1503 _M_h()
const {
return _M_storage._M_ptr(); }
1507 template<
typename _Tp>
1508 struct _Hash_code_storage<_Tp, true>
1515 _M_h() {
return reinterpret_cast<_Tp*
>(
this); }
1518 _M_h()
const {
return reinterpret_cast<const _Tp*
>(
this); }
1521 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1522 typename _Hash,
typename _RangeHash,
typename _Unused>
1523 using __hash_code_for_local_iter
1524 = _Hash_code_storage<_Hash_code_base<_Key, _Value, _ExtractKey,
1525 _Hash, _RangeHash, _Unused,
false>>;
1528 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1529 typename _Hash,
typename _RangeHash,
typename _Unused>
1530 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1531 _Hash, _RangeHash, _Unused, false>
1532 : __hash_code_for_local_iter<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1534 , _Node_iterator_base<_Value, false>
1537 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1538 _Hash, _RangeHash, _Unused,
false>;
1539 using __node_iter_base = _Node_iterator_base<_Value, false>;
1541 _Local_iterator_base() : _M_bucket_count(-1) { }
1543 _Local_iterator_base(
const __hash_code_base& __base,
1544 _Hash_node<_Value, false>* __p,
1545 std::size_t __bkt, std::size_t __bkt_count)
1546 : __node_iter_base(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1547 { _M_init(__base); }
1549 ~_Local_iterator_base()
1551 if (_M_bucket_count !=
size_t(-1))
1555 _Local_iterator_base(
const _Local_iterator_base& __iter)
1556 : __node_iter_base(__iter._M_cur), _M_bucket(__iter._M_bucket)
1557 , _M_bucket_count(__iter._M_bucket_count)
1559 if (_M_bucket_count !=
size_t(-1))
1560 _M_init(*__iter._M_h());
1563 _Local_iterator_base&
1564 operator=(
const _Local_iterator_base& __iter)
1566 if (_M_bucket_count != -1)
1568 this->_M_cur = __iter._M_cur;
1569 _M_bucket = __iter._M_bucket;
1570 _M_bucket_count = __iter._M_bucket_count;
1571 if (_M_bucket_count != -1)
1572 _M_init(*__iter._M_h());
1579 __node_iter_base::_M_incr();
1582 std::size_t __bkt = this->_M_h()->_M_bucket_index(*this->_M_cur,
1584 if (__bkt != _M_bucket)
1585 this->_M_cur =
nullptr;
1589 std::size_t _M_bucket;
1590 std::size_t _M_bucket_count;
1593 _M_init(
const __hash_code_base& __base)
1594 { ::new(this->_M_h()) __hash_code_base(__base); }
1597 _M_destroy() { this->_M_h()->~__hash_code_base(); }
1601 _M_get_bucket()
const {
return _M_bucket; }
1605 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1606 typename _Hash,
typename _RangeHash,
typename _Unused,
1607 bool __constant_iterators,
bool __cache>
1608 struct _Local_iterator
1609 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1610 _Hash, _RangeHash, _Unused, __cache>
1613 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1614 _Hash, _RangeHash, _Unused, __cache>;
1615 using __hash_code_base =
typename __base_type::__hash_code_base;
1618 using value_type = _Value;
1619 using pointer = __conditional_t<__constant_iterators,
1620 const value_type*, value_type*>;
1621 using reference = __conditional_t<__constant_iterators,
1622 const value_type&, value_type&>;
1623 using difference_type = ptrdiff_t;
1624 using iterator_category = forward_iterator_tag;
1626 _Local_iterator() =
default;
1628 _Local_iterator(
const __hash_code_base& __base,
1629 _Hash_node<_Value, __cache>* __n,
1630 std::size_t __bkt, std::size_t __bkt_count)
1631 : __base_type(
__base, __n, __bkt, __bkt_count)
1636 {
return this->_M_cur->_M_v(); }
1640 {
return this->_M_cur->_M_valptr(); }
1652 _Local_iterator __tmp(*
this);
1659 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1660 typename _Hash,
typename _RangeHash,
typename _Unused,
1661 bool __constant_iterators,
bool __cache>
1662 struct _Local_const_iterator
1663 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1664 _Hash, _RangeHash, _Unused, __cache>
1667 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1668 _Hash, _RangeHash, _Unused, __cache>;
1669 using __hash_code_base =
typename __base_type::__hash_code_base;
1672 typedef _Value value_type;
1673 typedef const value_type* pointer;
1674 typedef const value_type& reference;
1675 typedef std::ptrdiff_t difference_type;
1678 _Local_const_iterator() =
default;
1680 _Local_const_iterator(
const __hash_code_base& __base,
1681 _Hash_node<_Value, __cache>* __n,
1682 std::size_t __bkt, std::size_t __bkt_count)
1683 : __base_type(
__base, __n, __bkt, __bkt_count)
1686 _Local_const_iterator(
const _Local_iterator<_Key, _Value, _ExtractKey,
1687 _Hash, _RangeHash, _Unused,
1688 __constant_iterators,
1695 {
return this->_M_cur->_M_v(); }
1699 {
return this->_M_cur->_M_valptr(); }
1701 _Local_const_iterator&
1708 _Local_const_iterator
1711 _Local_const_iterator __tmp(*
this);
1727 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1728 typename _Equal,
typename _Hash,
typename _RangeHash,
1729 typename _Unused,
typename _Traits>
1730 struct _Hashtable_base
1731 :
public _Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1732 _Unused, _Traits::__hash_cached::value>,
1733 private _Hashtable_ebo_helper<0, _Equal>
1736 typedef _Key key_type;
1737 typedef _Value value_type;
1738 typedef _Equal key_equal;
1739 typedef std::size_t size_type;
1740 typedef std::ptrdiff_t difference_type;
1742 using __traits_type = _Traits;
1743 using __hash_cached =
typename __traits_type::__hash_cached;
1745 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1746 _Hash, _RangeHash, _Unused,
1747 __hash_cached::value>;
1749 using __hash_code =
typename __hash_code_base::__hash_code;
1752 using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>;
1755 _S_equals(__hash_code,
const _Hash_node_code_cache<false>&)
1759 _S_node_equals(
const _Hash_node_code_cache<false>&,
1760 const _Hash_node_code_cache<false>&)
1764 _S_equals(__hash_code __c,
const _Hash_node_code_cache<true>& __n)
1765 {
return __c == __n._M_hash_code; }
1768 _S_node_equals(
const _Hash_node_code_cache<true>& __lhn,
1769 const _Hash_node_code_cache<true>& __rhn)
1770 {
return __lhn._M_hash_code == __rhn._M_hash_code; }
1773 _Hashtable_base() =
default;
1775 _Hashtable_base(
const _Hash& __hash,
const _Equal& __eq)
1776 : __hash_code_base(__hash), _EqualEBO(__eq)
1780 _M_key_equals(
const _Key& __k,
1781 const _Hash_node_value<_Value,
1782 __hash_cached::value>& __n)
const
1784 static_assert(__is_invocable<const _Equal&, const _Key&, const _Key&>{},
1785 "key equality predicate must be invocable with two arguments of "
1787 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1790 template<
typename _Kt>
1792 _M_key_equals_tr(
const _Kt& __k,
1793 const _Hash_node_value<_Value,
1794 __hash_cached::value>& __n)
const
1797 __is_invocable<const _Equal&, const _Kt&, const _Key&>{},
1798 "key equality predicate must be invocable with two arguments of "
1800 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1804 _M_equals(
const _Key& __k, __hash_code __c,
1805 const _Hash_node_value<_Value, __hash_cached::value>& __n)
const
1806 {
return _S_equals(__c, __n) && _M_key_equals(__k, __n); }
1808 template<
typename _Kt>
1810 _M_equals_tr(
const _Kt& __k, __hash_code __c,
1811 const _Hash_node_value<_Value,
1812 __hash_cached::value>& __n)
const
1813 {
return _S_equals(__c, __n) && _M_key_equals_tr(__k, __n); }
1817 const _Hash_node_value<_Value, __hash_cached::value>& __lhn,
1818 const _Hash_node_value<_Value, __hash_cached::value>& __rhn)
const
1820 return _S_node_equals(__lhn, __rhn)
1821 && _M_key_equals(_ExtractKey{}(__lhn._M_v()), __rhn);
1825 _M_swap(_Hashtable_base& __x)
1827 __hash_code_base::_M_swap(__x);
1829 swap(_EqualEBO::_M_get(), __x._EqualEBO::_M_get());
1833 _M_eq()
const {
return _EqualEBO::_M_cget(); }
1844 template<
typename _Key,
typename _Value,
typename _Alloc,
1845 typename _ExtractKey,
typename _Equal,
1846 typename _Hash,
typename _RangeHash,
typename _Unused,
1847 typename _RehashPolicy,
typename _Traits,
1848 bool _Unique_keys = _Traits::__unique_keys::value>
1852 template<
typename _Key,
typename _Value,
typename _Alloc,
1853 typename _ExtractKey,
typename _Equal,
1854 typename _Hash,
typename _RangeHash,
typename _Unused,
1855 typename _RehashPolicy,
typename _Traits>
1856 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1857 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
1859 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1860 _Hash, _RangeHash, _Unused,
1861 _RehashPolicy, _Traits>;
1864 _M_equal(
const __hashtable&)
const;
1867 template<
typename _Key,
typename _Value,
typename _Alloc,
1868 typename _ExtractKey,
typename _Equal,
1869 typename _Hash,
typename _RangeHash,
typename _Unused,
1870 typename _RehashPolicy,
typename _Traits>
1872 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1873 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
1874 _M_equal(
const __hashtable& __other)
const
1876 using __node_ptr =
typename __hashtable::__node_ptr;
1877 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1878 if (__this->size() != __other.size())
1881 for (
auto __x_n = __this->_M_begin(); __x_n; __x_n = __x_n->_M_next())
1883 std::size_t __ybkt = __other._M_bucket_index(*__x_n);
1884 auto __prev_n = __other._M_buckets[__ybkt];
1888 for (__node_ptr __n =
static_cast<__node_ptr
>(__prev_n->_M_nxt);;
1889 __n = __n->_M_next())
1891 if (__n->_M_v() == __x_n->_M_v())
1895 || __other._M_bucket_index(*__n->_M_next()) != __ybkt)
1904 template<
typename _Key,
typename _Value,
typename _Alloc,
1905 typename _ExtractKey,
typename _Equal,
1906 typename _Hash,
typename _RangeHash,
typename _Unused,
1907 typename _RehashPolicy,
typename _Traits>
1908 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1909 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1911 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1912 _Hash, _RangeHash, _Unused,
1913 _RehashPolicy, _Traits>;
1916 _M_equal(
const __hashtable&)
const;
1919 template<
typename _Key,
typename _Value,
typename _Alloc,
1920 typename _ExtractKey,
typename _Equal,
1921 typename _Hash,
typename _RangeHash,
typename _Unused,
1922 typename _RehashPolicy,
typename _Traits>
1924 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1925 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
false>::
1926 _M_equal(
const __hashtable& __other)
const
1928 using __node_ptr =
typename __hashtable::__node_ptr;
1929 using const_iterator =
typename __hashtable::const_iterator;
1930 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1931 if (__this->size() != __other.size())
1934 for (
auto __x_n = __this->_M_begin(); __x_n;)
1936 std::size_t __x_count = 1;
1937 auto __x_n_end = __x_n->_M_next();
1939 && __this->key_eq()(_ExtractKey{}(__x_n->_M_v()),
1940 _ExtractKey{}(__x_n_end->_M_v()));
1941 __x_n_end = __x_n_end->_M_next())
1944 std::size_t __ybkt = __other._M_bucket_index(*__x_n);
1945 auto __y_prev_n = __other._M_buckets[__ybkt];
1949 __node_ptr __y_n =
static_cast<__node_ptr
>(__y_prev_n->_M_nxt);
1952 if (__this->key_eq()(_ExtractKey{}(__y_n->_M_v()),
1953 _ExtractKey{}(__x_n->_M_v())))
1956 auto __y_ref_n = __y_n;
1957 for (__y_n = __y_n->_M_next(); __y_n; __y_n = __y_n->_M_next())
1958 if (!__other._M_node_equals(*__y_ref_n, *__y_n))
1961 if (!__y_n || __other._M_bucket_index(*__y_n) != __ybkt)
1965 auto __y_n_end = __y_n;
1966 for (; __y_n_end; __y_n_end = __y_n_end->_M_next())
1967 if (--__x_count == 0)
1973 const_iterator __itx(__x_n), __itx_end(__x_n_end);
1974 const_iterator __ity(__y_n);
1975 if (!std::is_permutation(__itx, __itx_end, __ity))
1987 template<
typename _NodeAlloc>
1988 struct _Hashtable_alloc :
private _Hashtable_ebo_helper<0, _NodeAlloc>
1991 using __ebo_node_alloc = _Hashtable_ebo_helper<0, _NodeAlloc>;
1994 struct __get_value_type;
1995 template<
typename _Val,
bool _Cache_hash_code>
1996 struct __get_value_type<_Hash_node<_Val, _Cache_hash_code>>
1997 {
using type = _Val; };
2000 using __node_type =
typename _NodeAlloc::value_type;
2001 using __node_alloc_type = _NodeAlloc;
2005 using __value_alloc_traits =
typename __node_alloc_traits::template
2006 rebind_traits<typename __get_value_type<__node_type>::type>;
2008 using __node_ptr = __node_type*;
2009 using __node_base = _Hash_node_base;
2010 using __node_base_ptr = __node_base*;
2011 using __buckets_alloc_type =
2012 __alloc_rebind<__node_alloc_type, __node_base_ptr>;
2014 using __buckets_ptr = __node_base_ptr*;
2016 _Hashtable_alloc() =
default;
2017 _Hashtable_alloc(
const _Hashtable_alloc&) =
default;
2018 _Hashtable_alloc(_Hashtable_alloc&&) =
default;
2020 template<
typename _Alloc>
2021 _Hashtable_alloc(_Alloc&& __a)
2022 : __ebo_node_alloc(
std::
forward<_Alloc>(__a))
2027 {
return __ebo_node_alloc::_M_get(); }
2029 const __node_alloc_type&
2030 _M_node_allocator()
const
2031 {
return __ebo_node_alloc::_M_cget(); }
2034 template<
typename... _Args>
2036 _M_allocate_node(_Args&&... __args);
2040 _M_deallocate_node(__node_ptr __n);
2044 _M_deallocate_node_ptr(__node_ptr __n);
2049 _M_deallocate_nodes(__node_ptr __n);
2052 _M_allocate_buckets(std::size_t __bkt_count);
2055 _M_deallocate_buckets(__buckets_ptr, std::size_t __bkt_count);
2060 template<
typename _NodeAlloc>
2061 template<
typename... _Args>
2063 _Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&&... __args)
2066 auto& __alloc = _M_node_allocator();
2067 auto __nptr = __node_alloc_traits::allocate(__alloc, 1);
2068 __node_ptr __n = std::__to_address(__nptr);
2071 ::new ((
void*)__n) __node_type;
2072 __node_alloc_traits::construct(__alloc, __n->_M_valptr(),
2078 __n->~__node_type();
2079 __node_alloc_traits::deallocate(__alloc, __nptr, 1);
2080 __throw_exception_again;
2084 template<
typename _NodeAlloc>
2086 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node(__node_ptr __n)
2088 __node_alloc_traits::destroy(_M_node_allocator(), __n->_M_valptr());
2089 _M_deallocate_node_ptr(__n);
2092 template<
typename _NodeAlloc>
2094 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node_ptr(__node_ptr __n)
2096 typedef typename __node_alloc_traits::pointer _Ptr;
2098 __n->~__node_type();
2099 __node_alloc_traits::deallocate(_M_node_allocator(), __ptr, 1);
2102 template<
typename _NodeAlloc>
2104 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_nodes(__node_ptr __n)
2108 __node_ptr __tmp = __n;
2109 __n = __n->_M_next();
2110 _M_deallocate_node(__tmp);
2114 template<
typename _NodeAlloc>
2116 _Hashtable_alloc<_NodeAlloc>::_M_allocate_buckets(std::size_t __bkt_count)
2119 __buckets_alloc_type __alloc(_M_node_allocator());
2121 auto __ptr = __buckets_alloc_traits::allocate(__alloc, __bkt_count);
2122 __buckets_ptr __p = std::__to_address(__ptr);
2123 __builtin_memset(__p, 0, __bkt_count *
sizeof(__node_base_ptr));
2127 template<
typename _NodeAlloc>
2129 _Hashtable_alloc<_NodeAlloc>::
2130 _M_deallocate_buckets(__buckets_ptr __bkts,
2131 std::size_t __bkt_count)
2133 typedef typename __buckets_alloc_traits::pointer _Ptr;
2135 __buckets_alloc_type __alloc(_M_node_allocator());
2136 __buckets_alloc_traits::deallocate(__alloc, __ptr, __bkt_count);
2142_GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
pair(_T1, _T2) -> pair< _T1, _T2 >
Two pairs of the same type are equal iff their members are equal.
constexpr tuple< _Elements &&... > forward_as_tuple(_Elements &&... __args) noexcept
Create a tuple of lvalue or rvalue references to the arguments.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr piecewise_construct_t piecewise_construct
Tag for piecewise construction of std::pair objects.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.
constexpr _Iterator __base(_Iterator __it)
Primary class template, tuple.
Define a member typedef type only if a boolean constant is true.
Uniform interface to all allocator types.
Traits class for iterators.
Uniform interface to all pointer-like types.
Struct holding two objects of arbitrary type.
Forward iterators support a superset of input iterator operations.
Uniform interface to C++98 and C++11 allocators.