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,
typename _Value>
117 struct _ConvertToValueType;
119 template<
typename _Value>
120 struct _ConvertToValueType<_Identity, _Value>
122 template<
typename _Kt>
124 operator()(_Kt&& __k)
const noexcept
128 template<
typename _Value>
129 struct _ConvertToValueType<_Select1st, _Value>
132 operator()(_Value&& __x)
const noexcept
135 constexpr const _Value&
136 operator()(
const _Value& __x)
const noexcept
139 template<
typename _Kt,
typename _Val>
144 template<
typename _Kt,
typename _Val>
150 template<
typename _ExKey>
154 struct _NodeBuilder<_Select1st>
156 template<
typename _Kt,
typename _Arg,
typename _NodeGenerator>
158 _S_build(_Kt&& __k, _Arg&& __arg,
const _NodeGenerator& __node_gen)
159 ->
typename _NodeGenerator::__node_ptr
167 struct _NodeBuilder<_Identity>
169 template<
typename _Kt,
typename _Arg,
typename _NodeGenerator>
171 _S_build(_Kt&& __k, _Arg&&,
const _NodeGenerator& __node_gen)
172 ->
typename _NodeGenerator::__node_ptr
176 template<
typename _HashtableAlloc,
typename _NodePtr>
179 _HashtableAlloc& _M_h;
185 _M_h._M_deallocate_node_ptr(_M_ptr);
189 template<
typename _NodeAlloc>
190 struct _Hashtable_alloc;
194 template<
typename _NodeAlloc>
195 struct _ReuseOrAllocNode
198 using __node_alloc_type = _NodeAlloc;
199 using __hashtable_alloc = _Hashtable_alloc<__node_alloc_type>;
200 using __node_alloc_traits =
201 typename __hashtable_alloc::__node_alloc_traits;
204 using __node_ptr =
typename __hashtable_alloc::__node_ptr;
206 _ReuseOrAllocNode(__node_ptr __nodes, __hashtable_alloc& __h)
207 : _M_nodes(__nodes), _M_h(__h) { }
208 _ReuseOrAllocNode(
const _ReuseOrAllocNode&) =
delete;
211 { _M_h._M_deallocate_nodes(_M_nodes); }
213 template<
typename... _Args>
215 operator()(_Args&&... __args)
const
220 __node_ptr __node = _M_nodes;
221 _M_nodes = _M_nodes->_M_next();
222 __node->_M_nxt =
nullptr;
223 auto& __a = _M_h._M_node_allocator();
224 __node_alloc_traits::destroy(__a, __node->_M_valptr());
225 _NodePtrGuard<__hashtable_alloc, __node_ptr> __guard { _M_h, __node };
226 __node_alloc_traits::construct(__a, __node->_M_valptr(),
228 __guard._M_ptr =
nullptr;
233 mutable __node_ptr _M_nodes;
234 __hashtable_alloc& _M_h;
239 template<
typename _NodeAlloc>
243 using __hashtable_alloc = _Hashtable_alloc<_NodeAlloc>;
246 using __node_ptr =
typename __hashtable_alloc::__node_ptr;
248 _AllocNode(__hashtable_alloc& __h)
251 template<
typename... _Args>
253 operator()(_Args&&... __args)
const
257 __hashtable_alloc& _M_h;
285 template<
bool _Cache_hash_code,
bool _Constant_iterators,
bool _Unique_keys>
286 struct _Hashtable_traits
288 using __hash_cached = __bool_constant<_Cache_hash_code>;
289 using __constant_iterators = __bool_constant<_Constant_iterators>;
290 using __unique_keys = __bool_constant<_Unique_keys>;
299 template<
typename _Hash>
300 struct _Hashtable_hash_traits
302 static constexpr std::size_t
303 __small_size_threshold() noexcept
315 struct _Hash_node_base
317 _Hash_node_base* _M_nxt;
319 _Hash_node_base() noexcept : _M_nxt() { }
321 _Hash_node_base(_Hash_node_base* __next) noexcept : _M_nxt(__next) { }
329 template<
typename _Value>
330 struct _Hash_node_value_base
332 typedef _Value value_type;
334 __gnu_cxx::__aligned_buffer<_Value> _M_storage;
336 [[__gnu__::__always_inline__]]
339 {
return _M_storage._M_ptr(); }
341 [[__gnu__::__always_inline__]]
343 _M_valptr() const noexcept
344 {
return _M_storage._M_ptr(); }
346 [[__gnu__::__always_inline__]]
349 {
return *_M_valptr(); }
351 [[__gnu__::__always_inline__]]
353 _M_v() const noexcept
354 {
return *_M_valptr(); }
360 template<
bool _Cache_hash_code>
361 struct _Hash_node_code_cache
368 struct _Hash_node_code_cache<true>
369 { std::size_t _M_hash_code; };
371 template<
typename _Value,
bool _Cache_hash_code>
372 struct _Hash_node_value
373 : _Hash_node_value_base<_Value>
374 , _Hash_node_code_cache<_Cache_hash_code>
380 template<
typename _Value,
bool _Cache_hash_code>
383 , _Hash_node_value<_Value, _Cache_hash_code>
386 _M_next() const noexcept
387 {
return static_cast<_Hash_node*
>(this->_M_nxt); }
391 template<
typename _Value,
bool _Cache_hash_code>
392 struct _Node_iterator_base
394 using __node_type = _Hash_node<_Value, _Cache_hash_code>;
398 _Node_iterator_base() : _M_cur(nullptr) { }
399 _Node_iterator_base(__node_type* __p) noexcept
404 { _M_cur = _M_cur->_M_next(); }
407 operator==(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
409 {
return __x._M_cur == __y._M_cur; }
411#if __cpp_impl_three_way_comparison < 201907L
413 operator!=(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
415 {
return __x._M_cur != __y._M_cur; }
420 template<
typename _Value,
bool __constant_iterators,
bool __cache>
421 struct _Node_iterator
422 :
public _Node_iterator_base<_Value, __cache>
425 using __base_type = _Node_iterator_base<_Value, __cache>;
426 using __node_type =
typename __base_type::__node_type;
429 using value_type = _Value;
433 using pointer = __conditional_t<__constant_iterators,
434 const value_type*, value_type*>;
436 using reference = __conditional_t<__constant_iterators,
437 const value_type&, value_type&>;
439 _Node_iterator() =
default;
442 _Node_iterator(__node_type* __p) noexcept
443 : __base_type(__p) { }
447 {
return this->_M_cur->_M_v(); }
450 operator->() const noexcept
451 {
return this->_M_cur->_M_valptr(); }
454 operator++() noexcept
461 operator++(
int)
noexcept
463 _Node_iterator __tmp(*
this);
468#if __cpp_impl_three_way_comparison >= 201907L
470 operator==(
const _Node_iterator&,
const _Node_iterator&) =
default;
473 operator==(
const _Node_iterator& __x,
const _Node_iterator& __y)
noexcept
475 const __base_type& __bx = __x;
476 const __base_type& __by = __y;
481 operator!=(
const _Node_iterator& __x,
const _Node_iterator& __y)
noexcept
482 {
return !(__x == __y); }
487 template<
typename _Value,
bool __constant_iterators,
bool __cache>
488 struct _Node_const_iterator
489 :
public _Node_iterator_base<_Value, __cache>
492 using __base_type = _Node_iterator_base<_Value, __cache>;
493 using __node_type =
typename __base_type::__node_type;
497 = _Node_iterator<_Value, __constant_iterators, __cache>;
500 typedef _Value value_type;
504 typedef const value_type* pointer;
505 typedef const value_type& reference;
507 _Node_const_iterator() =
default;
510 _Node_const_iterator(__node_type* __p) noexcept
511 : __base_type(__p) { }
513 _Node_const_iterator(
const __iterator& __x) noexcept
514 : __base_type(__x._M_cur) { }
518 {
return this->_M_cur->_M_v(); }
521 operator->() const noexcept
522 {
return this->_M_cur->_M_valptr(); }
524 _Node_const_iterator&
525 operator++() noexcept
532 operator++(
int)
noexcept
534 _Node_const_iterator __tmp(*
this);
539#if __cpp_impl_three_way_comparison >= 201907L
541 operator==(
const _Node_const_iterator&,
542 const _Node_const_iterator&) =
default;
545 operator==(
const _Node_const_iterator& __x,
const __iterator& __y)
547 const __base_type& __bx = __x;
548 const __base_type& __by = __y;
553 operator==(
const _Node_const_iterator& __x,
554 const _Node_const_iterator& __y)
noexcept
556 const __base_type& __bx = __x;
557 const __base_type& __by = __y;
562 operator!=(
const _Node_const_iterator& __x,
563 const _Node_const_iterator& __y)
noexcept
564 {
return !(__x == __y); }
567 operator==(
const _Node_const_iterator& __x,
568 const __iterator& __y)
noexcept
570 const __base_type& __bx = __x;
571 const __base_type& __by = __y;
576 operator!=(
const _Node_const_iterator& __x,
577 const __iterator& __y)
noexcept
578 {
return !(__x == __y); }
581 operator==(
const __iterator& __x,
582 const _Node_const_iterator& __y)
noexcept
584 const __base_type& __bx = __x;
585 const __base_type& __by = __y;
590 operator!=(
const __iterator& __x,
591 const _Node_const_iterator& __y)
noexcept
592 {
return !(__x == __y); }
601 struct _Mod_range_hashing
603 typedef std::size_t first_argument_type;
604 typedef std::size_t second_argument_type;
605 typedef std::size_t result_type;
608 operator()(first_argument_type __num,
609 second_argument_type __den)
const noexcept
610 {
return __num % __den; }
618 struct _Default_ranged_hash { };
622 struct _Prime_rehash_policy
626 _Prime_rehash_policy(
float __z = 1.0) noexcept
627 : _M_max_load_factor(__z), _M_next_resize(0) { }
630 max_load_factor() const noexcept
631 {
return _M_max_load_factor; }
635 _M_next_bkt(std::size_t __n)
const;
639 _M_bkt_for_elements(std::size_t __n)
const
640 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
647 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
648 std::size_t __n_ins)
const;
650 typedef std::size_t _State;
654 {
return _M_next_resize; }
658 { _M_next_resize = 0; }
661 _M_reset(_State __state)
662 { _M_next_resize = __state; }
664 static const std::size_t _S_growth_factor = 2;
666 float _M_max_load_factor;
667 mutable std::size_t _M_next_resize;
671 struct _Mask_range_hashing
673 typedef std::size_t first_argument_type;
674 typedef std::size_t second_argument_type;
675 typedef std::size_t result_type;
678 operator()(first_argument_type __num,
679 second_argument_type __den)
const noexcept
680 {
return __num & (__den - 1); }
685 __clp2(std::size_t __n)
noexcept
691 const unsigned __lz =
sizeof(size_t) >
sizeof(
long)
692 ? __builtin_clzll(__n - 1ull)
693 : __builtin_clzl(__n - 1ul);
695 return (
size_t(1) << (__int_traits<size_t>::__digits - __lz - 1)) << 1;
700 struct _Power2_rehash_policy
704 _Power2_rehash_policy(
float __z = 1.0) noexcept
705 : _M_max_load_factor(__z), _M_next_resize(0) { }
708 max_load_factor() const noexcept
709 {
return _M_max_load_factor; }
714 _M_next_bkt(std::size_t __n)
noexcept
723 const auto __max_bkt = size_t(1) << (__max_width * __CHAR_BIT__ - 1);
724 std::size_t __res = __clp2(__n);
734 if (__res == __max_bkt)
738 _M_next_resize = size_t(-1);
741 = __builtin_floor(__res * (
double)_M_max_load_factor);
748 _M_bkt_for_elements(std::size_t __n)
const noexcept
749 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
756 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
757 std::size_t __n_ins)
noexcept
759 if (__n_elt + __n_ins > _M_next_resize)
766 / (double)_M_max_load_factor;
767 if (__min_bkts >= __n_bkt)
770 __n_bkt * _S_growth_factor)) };
773 = __builtin_floor(__n_bkt * (
double)_M_max_load_factor);
780 typedef std::size_t _State;
783 _M_state() const noexcept
784 {
return _M_next_resize; }
788 { _M_next_resize = 0; }
791 _M_reset(_State __state)
noexcept
792 { _M_next_resize = __state; }
794 static const std::size_t _S_growth_factor = 2;
796 float _M_max_load_factor;
797 std::size_t _M_next_resize;
800 template<
typename _RehashPolicy>
801 struct _RehashStateGuard
803 _RehashPolicy* _M_guarded_obj;
804 typename _RehashPolicy::_State _M_prev_state;
806 _RehashStateGuard(_RehashPolicy& __policy)
808 , _M_prev_state(__policy._M_state())
810 _RehashStateGuard(
const _RehashStateGuard&) =
delete;
815 _M_guarded_obj->_M_reset(_M_prev_state);
837 template<
typename _Key,
typename _Value,
typename _Alloc,
838 typename _ExtractKey,
typename _Equal,
839 typename _Hash,
typename _RangeHash,
typename _Unused,
840 typename _RehashPolicy,
typename _Traits,
841 bool _Unique_keys = _Traits::__unique_keys::value>
842 struct _Map_base { };
845 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
846 typename _Hash,
typename _RangeHash,
typename _Unused,
847 typename _RehashPolicy,
typename _Traits>
848 struct _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
849 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
851 using mapped_type = _Val;
855 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
856 typename _Hash,
typename _RangeHash,
typename _Unused,
857 typename _RehashPolicy,
typename _Traits>
858 struct _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
859 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
862 using __hashtable_base = _Hashtable_base<_Key, pair<const _Key, _Val>,
863 _Select1st, _Equal, _Hash,
867 using __hashtable = _Hashtable<_Key, pair<const _Key, _Val>, _Alloc,
868 _Select1st, _Equal, _Hash, _RangeHash,
869 _Unused, _RehashPolicy, _Traits>;
871 using __hash_code =
typename __hashtable_base::__hash_code;
874 using key_type =
typename __hashtable_base::key_type;
875 using mapped_type = _Val;
878 operator[](
const key_type& __k);
881 operator[](key_type&& __k);
886 at(
const key_type& __k)
888 auto __ite =
static_cast<__hashtable*
>(
this)->find(__k);
890 __throw_out_of_range(__N(
"unordered_map::at"));
891 return __ite->second;
895 at(
const key_type& __k)
const
897 auto __ite =
static_cast<const __hashtable*
>(
this)->find(__k);
899 __throw_out_of_range(__N(
"unordered_map::at"));
900 return __ite->second;
904 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
905 typename _Hash,
typename _RangeHash,
typename _Unused,
906 typename _RehashPolicy,
typename _Traits>
908 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
909 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
910 operator[](
const key_type& __k)
913 __hashtable* __h =
static_cast<__hashtable*
>(
this);
914 __hash_code __code = __h->_M_hash_code(__k);
915 std::size_t __bkt = __h->_M_bucket_index(__code);
916 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
917 return __node->_M_v().second;
919 typename __hashtable::_Scoped_node __node {
926 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
927 __node._M_node =
nullptr;
928 return __pos->second;
931 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
932 typename _Hash,
typename _RangeHash,
typename _Unused,
933 typename _RehashPolicy,
typename _Traits>
935 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
936 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
937 operator[](key_type&& __k)
940 __hashtable* __h =
static_cast<__hashtable*
>(
this);
941 __hash_code __code = __h->_M_hash_code(__k);
942 std::size_t __bkt = __h->_M_bucket_index(__code);
943 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
944 return __node->_M_v().second;
946 typename __hashtable::_Scoped_node __node {
953 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
954 __node._M_node =
nullptr;
955 return __pos->second;
959 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
960 typename _Hash,
typename _RangeHash,
typename _Unused,
961 typename _RehashPolicy,
typename _Traits,
bool __uniq>
962 struct _Map_base<const _Key, pair<const _Key, _Val>,
963 _Alloc, _Select1st, _Equal, _Hash,
964 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
965 : _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal, _Hash,
966 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
974 template<
typename _Key,
typename _Value,
typename _Alloc,
975 typename _ExtractKey,
typename _Equal,
976 typename _Hash,
typename _RangeHash,
typename _Unused,
977 typename _RehashPolicy,
typename _Traits>
981 using __hashtable_base = _Hashtable_base<_Key, _Value, _ExtractKey,
982 _Equal, _Hash, _RangeHash,
985 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
987 _Unused, _RehashPolicy, _Traits>;
989 using __hash_cached =
typename _Traits::__hash_cached;
990 using __constant_iterators =
typename _Traits::__constant_iterators;
992 using __hashtable_alloc = _Hashtable_alloc<
993 __alloc_rebind<_Alloc, _Hash_node<_Value,
994 __hash_cached::value>>>;
996 using value_type =
typename __hashtable_base::value_type;
997 using size_type =
typename __hashtable_base::size_type;
999 using __unique_keys =
typename _Traits::__unique_keys;
1000 using __node_alloc_type =
typename __hashtable_alloc::__node_alloc_type;
1001 using __node_gen_type = _AllocNode<__node_alloc_type>;
1004 _M_conjure_hashtable()
1005 {
return *(
static_cast<__hashtable*
>(
this)); }
1007 template<
typename _InputIterator,
typename _NodeGetter>
1009 _M_insert_range(_InputIterator __first, _InputIterator __last,
1010 const _NodeGetter&, true_type __uks);
1012 template<
typename _InputIterator,
typename _NodeGetter>
1014 _M_insert_range(_InputIterator __first, _InputIterator __last,
1015 const _NodeGetter&, false_type __uks);
1018 using iterator = _Node_iterator<_Value, __constant_iterators::value,
1019 __hash_cached::value>;
1021 using const_iterator = _Node_const_iterator<_Value,
1022 __constant_iterators::value,
1023 __hash_cached::value>;
1025 using __ireturn_type = __conditional_t<__unique_keys::value,
1030 insert(
const value_type& __v)
1032 __hashtable& __h = _M_conjure_hashtable();
1033 __node_gen_type __node_gen(__h);
1034 return __h._M_insert(__v, __node_gen, __unique_keys{});
1038 insert(const_iterator __hint,
const value_type& __v)
1040 __hashtable& __h = _M_conjure_hashtable();
1041 __node_gen_type __node_gen(__h);
1042 return __h._M_insert(__hint, __v, __node_gen, __unique_keys{});
1045#ifdef __glibcxx_unordered_map_try_emplace
1046 template<
typename _KType,
typename... _Args>
1048 try_emplace(const_iterator, _KType&& __k, _Args&&... __args)
1050 __hashtable& __h = _M_conjure_hashtable();
1051 auto __code = __h._M_hash_code(__k);
1052 std::size_t __bkt = __h._M_bucket_index(__code);
1053 if (
auto __node = __h._M_find_node(__bkt, __k, __code))
1054 return { iterator(__node),
false };
1056 typename __hashtable::_Scoped_node __node {
1063 = __h._M_insert_unique_node(__bkt, __code, __node._M_node);
1064 __node._M_node =
nullptr;
1065 return { __it,
true };
1070 insert(initializer_list<value_type> __l)
1071 { this->insert(__l.begin(), __l.end()); }
1073 template<
typename _InputIterator>
1075 insert(_InputIterator __first, _InputIterator __last)
1077 __hashtable& __h = _M_conjure_hashtable();
1078 __node_gen_type __node_gen(__h);
1079 return _M_insert_range(__first, __last, __node_gen, __unique_keys{});
1083 template<
typename _Key,
typename _Value,
typename _Alloc,
1084 typename _ExtractKey,
typename _Equal,
1085 typename _Hash,
typename _RangeHash,
typename _Unused,
1086 typename _RehashPolicy,
typename _Traits>
1087 template<
typename _InputIterator,
typename _NodeGetter>
1089 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1090 _Hash, _RangeHash, _Unused,
1091 _RehashPolicy, _Traits>::
1092 _M_insert_range(_InputIterator __first, _InputIterator __last,
1093 const _NodeGetter& __node_gen,
true_type __uks)
1095 __hashtable& __h = _M_conjure_hashtable();
1096 for (; __first != __last; ++__first)
1097 __h._M_insert(*__first, __node_gen, __uks);
1100 template<
typename _Key,
typename _Value,
typename _Alloc,
1101 typename _ExtractKey,
typename _Equal,
1102 typename _Hash,
typename _RangeHash,
typename _Unused,
1103 typename _RehashPolicy,
typename _Traits>
1104 template<
typename _InputIterator,
typename _NodeGetter>
1106 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1107 _Hash, _RangeHash, _Unused,
1108 _RehashPolicy, _Traits>::
1109 _M_insert_range(_InputIterator __first, _InputIterator __last,
1110 const _NodeGetter& __node_gen,
false_type __uks)
1112 using __rehash_guard_t =
typename __hashtable::__rehash_guard_t;
1115 size_type __n_elt = __detail::__distance_fw(__first, __last);
1119 __hashtable& __h = _M_conjure_hashtable();
1120 __rehash_guard_t __rehash_guard(__h._M_rehash_policy);
1121 __pair_type __do_rehash
1122 = __h._M_rehash_policy._M_need_rehash(__h._M_bucket_count,
1123 __h._M_element_count,
1126 if (__do_rehash.first)
1127 __h._M_rehash(__do_rehash.second, __uks);
1129 __rehash_guard._M_guarded_obj =
nullptr;
1130 for (; __first != __last; ++__first)
1131 __h._M_insert(*__first, __node_gen, __uks);
1140 template<
typename _Key,
typename _Value,
typename _Alloc,
1141 typename _ExtractKey,
typename _Equal,
1142 typename _Hash,
typename _RangeHash,
typename _Unused,
1143 typename _RehashPolicy,
typename _Traits,
1144 bool _Constant_iterators = _Traits::__constant_iterators::value>
1148 template<
typename _Key,
typename _Value,
typename _Alloc,
1149 typename _ExtractKey,
typename _Equal,
1150 typename _Hash,
typename _RangeHash,
typename _Unused,
1151 typename _RehashPolicy,
typename _Traits>
1152 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1153 _Hash, _RangeHash, _Unused,
1154 _RehashPolicy, _Traits, true>
1155 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1156 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1158 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1159 _Equal, _Hash, _RangeHash, _Unused,
1160 _RehashPolicy, _Traits>;
1162 using value_type =
typename __base_type::value_type;
1163 using iterator =
typename __base_type::iterator;
1164 using const_iterator =
typename __base_type::const_iterator;
1165 using __ireturn_type =
typename __base_type::__ireturn_type;
1167 using __unique_keys =
typename __base_type::__unique_keys;
1168 using __hashtable =
typename __base_type::__hashtable;
1169 using __node_gen_type =
typename __base_type::__node_gen_type;
1171 using __base_type::insert;
1174 insert(value_type&& __v)
1176 __hashtable& __h = this->_M_conjure_hashtable();
1177 __node_gen_type __node_gen(__h);
1178 return __h._M_insert(
std::move(__v), __node_gen, __unique_keys{});
1182 insert(const_iterator __hint, value_type&& __v)
1184 __hashtable& __h = this->_M_conjure_hashtable();
1185 __node_gen_type __node_gen(__h);
1186 return __h._M_insert(__hint,
std::move(__v), __node_gen,
1192 template<
typename _Key,
typename _Value,
typename _Alloc,
1193 typename _ExtractKey,
typename _Equal,
1194 typename _Hash,
typename _RangeHash,
typename _Unused,
1195 typename _RehashPolicy,
typename _Traits>
1196 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1197 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1198 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1199 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1201 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1202 _Equal, _Hash, _RangeHash, _Unused,
1203 _RehashPolicy, _Traits>;
1204 using value_type =
typename __base_type::value_type;
1205 using iterator =
typename __base_type::iterator;
1206 using const_iterator =
typename __base_type::const_iterator;
1208 using __unique_keys =
typename __base_type::__unique_keys;
1209 using __hashtable =
typename __base_type::__hashtable;
1210 using __ireturn_type =
typename __base_type::__ireturn_type;
1212 using __base_type::insert;
1214 template<
typename _Pair>
1217 template<
typename _Pair>
1220 template<
typename _Pair>
1221 using _IFconsp =
typename _IFcons<_Pair>::type;
1223 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1227 __hashtable& __h = this->_M_conjure_hashtable();
1231 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1233 insert(const_iterator __hint, _Pair&& __v)
1235 __hashtable& __h = this->_M_conjure_hashtable();
1236 return __h._M_emplace(__hint, __unique_keys{},
1241 template<
typename _Policy>
1242 using __has_load_factor =
typename _Policy::__has_load_factor;
1250 template<
typename _Key,
typename _Value,
typename _Alloc,
1251 typename _ExtractKey,
typename _Equal,
1252 typename _Hash,
typename _RangeHash,
typename _Unused,
1253 typename _RehashPolicy,
typename _Traits,
1255 __detected_or_t<false_type, __has_load_factor, _RehashPolicy>>
1256 struct _Rehash_base;
1259 template<
typename _Key,
typename _Value,
typename _Alloc,
1260 typename _ExtractKey,
typename _Equal,
1261 typename _Hash,
typename _RangeHash,
typename _Unused,
1262 typename _RehashPolicy,
typename _Traits>
1263 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1264 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1270 template<
typename _Key,
typename _Value,
typename _Alloc,
1271 typename _ExtractKey,
typename _Equal,
1272 typename _Hash,
typename _RangeHash,
typename _Unused,
1273 typename _RehashPolicy,
typename _Traits>
1274 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1275 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1279 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey,
1280 _Equal, _Hash, _RangeHash, _Unused,
1281 _RehashPolicy, _Traits>;
1285 max_load_factor() const noexcept
1287 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1288 return __this->__rehash_policy().max_load_factor();
1292 max_load_factor(
float __z)
1294 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1295 __this->__rehash_policy(_RehashPolicy(__z));
1299 reserve(std::size_t __n)
1301 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1302 __this->rehash(__this->__rehash_policy()._M_bkt_for_elements(__n));
1312 template<
int _Nm,
typename _Tp,
1313 bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
1314 struct _Hashtable_ebo_helper;
1317 template<
int _Nm,
typename _Tp>
1318 struct _Hashtable_ebo_helper<_Nm, _Tp, true>
1321 _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
1323 template<
typename _OtherTp>
1324 _Hashtable_ebo_helper(_OtherTp&& __tp)
1328 const _Tp& _M_cget()
const {
return static_cast<const _Tp&
>(*this); }
1329 _Tp& _M_get() {
return static_cast<_Tp&
>(*this); }
1333 template<
int _Nm,
typename _Tp>
1334 struct _Hashtable_ebo_helper<_Nm, _Tp, false>
1336 _Hashtable_ebo_helper() =
default;
1338 template<
typename _OtherTp>
1339 _Hashtable_ebo_helper(_OtherTp&& __tp)
1343 const _Tp& _M_cget()
const {
return _M_tp; }
1344 _Tp& _M_get() {
return _M_tp; }
1356 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1357 typename _Hash,
typename _RangeHash,
typename _Unused,
1358 bool __cache_hash_code>
1359 struct _Local_iterator_base;
1379 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1380 typename _Hash,
typename _RangeHash,
typename _Unused,
1381 bool __cache_hash_code>
1382 struct _Hash_code_base
1383 :
private _Hashtable_ebo_helper<1, _Hash>
1386 using __ebo_hash = _Hashtable_ebo_helper<1, _Hash>;
1389 friend struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1390 _Hash, _RangeHash, _Unused, false>;
1393 typedef _Hash hasher;
1396 hash_function()
const
1397 {
return _M_hash(); }
1400 typedef std::size_t __hash_code;
1404 _Hash_code_base() =
default;
1406 _Hash_code_base(
const _Hash& __hash) : __ebo_hash(__hash) { }
1409 _M_hash_code(
const _Key& __k)
const
1411 static_assert(__is_invocable<const _Hash&, const _Key&>{},
1412 "hash function must be invocable with an argument of key type");
1413 return _M_hash()(__k);
1416 template<
typename _Kt>
1418 _M_hash_code_tr(
const _Kt& __k)
const
1420 static_assert(__is_invocable<const _Hash&, const _Kt&>{},
1421 "hash function must be invocable with an argument of key type");
1422 return _M_hash()(__k);
1426 _M_hash_code(
const _Hash_node_value<_Value, false>& __n)
const
1427 {
return _M_hash_code(_ExtractKey{}(__n._M_v())); }
1430 _M_hash_code(
const _Hash_node_value<_Value, true>& __n)
const
1431 {
return __n._M_hash_code; }
1434 _M_bucket_index(__hash_code __c, std::size_t __bkt_count)
const
1435 {
return _RangeHash{}(__c, __bkt_count); }
1438 _M_bucket_index(
const _Hash_node_value<_Value, false>& __n,
1439 std::size_t __bkt_count)
const
1440 noexcept(
noexcept(declval<const _Hash&>()(declval<const _Key&>()))
1441 &&
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1444 return _RangeHash{}(_M_hash_code(_ExtractKey{}(__n._M_v())),
1449 _M_bucket_index(
const _Hash_node_value<_Value, true>& __n,
1450 std::size_t __bkt_count)
const
1451 noexcept(
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1453 {
return _RangeHash{}(__n._M_hash_code, __bkt_count); }
1456 _M_store_code(_Hash_node_code_cache<false>&, __hash_code)
const
1460 _M_copy_code(_Hash_node_code_cache<false>&,
1461 const _Hash_node_code_cache<false>&)
const
1465 _M_store_code(_Hash_node_code_cache<true>& __n, __hash_code __c)
const
1466 { __n._M_hash_code = __c; }
1469 _M_copy_code(_Hash_node_code_cache<true>& __to,
1470 const _Hash_node_code_cache<true>& __from)
const
1471 { __to._M_hash_code = __from._M_hash_code; }
1474 _M_swap(_Hash_code_base& __x)
1477 swap(__ebo_hash::_M_get(), __x.__ebo_hash::_M_get());
1481 _M_hash()
const {
return __ebo_hash::_M_cget(); }
1485 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1486 typename _Hash,
typename _RangeHash,
typename _Unused>
1487 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1488 _Hash, _RangeHash, _Unused, true>
1489 :
public _Node_iterator_base<_Value, true>
1492 using __base_node_iter = _Node_iterator_base<_Value, true>;
1493 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1494 _Hash, _RangeHash, _Unused,
true>;
1496 _Local_iterator_base() =
default;
1497 _Local_iterator_base(
const __hash_code_base&,
1498 _Hash_node<_Value, true>* __p,
1499 std::size_t __bkt, std::size_t __bkt_count)
1500 : __base_node_iter(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1506 __base_node_iter::_M_incr();
1510 = _RangeHash{}(this->_M_cur->_M_hash_code, _M_bucket_count);
1511 if (__bkt != _M_bucket)
1512 this->_M_cur =
nullptr;
1516 std::size_t _M_bucket;
1517 std::size_t _M_bucket_count;
1521 _M_get_bucket()
const {
return _M_bucket; }
1528 template<typename _Tp, bool _IsEmpty = std::is_empty<_Tp>::value>
1529 struct _Hash_code_storage
1531 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
1534 _M_h() {
return _M_storage._M_ptr(); }
1537 _M_h()
const {
return _M_storage._M_ptr(); }
1541 template<
typename _Tp>
1542 struct _Hash_code_storage<_Tp, true>
1549 _M_h() {
return reinterpret_cast<_Tp*
>(
this); }
1552 _M_h()
const {
return reinterpret_cast<const _Tp*
>(
this); }
1555 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1556 typename _Hash,
typename _RangeHash,
typename _Unused>
1557 using __hash_code_for_local_iter
1558 = _Hash_code_storage<_Hash_code_base<_Key, _Value, _ExtractKey,
1559 _Hash, _RangeHash, _Unused,
false>>;
1562 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1563 typename _Hash,
typename _RangeHash,
typename _Unused>
1564 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1565 _Hash, _RangeHash, _Unused, false>
1566 : __hash_code_for_local_iter<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1568 , _Node_iterator_base<_Value, false>
1571 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1572 _Hash, _RangeHash, _Unused,
false>;
1573 using __node_iter_base = _Node_iterator_base<_Value, false>;
1575 _Local_iterator_base() : _M_bucket_count(-1) { }
1577 _Local_iterator_base(
const __hash_code_base& __base,
1578 _Hash_node<_Value, false>* __p,
1579 std::size_t __bkt, std::size_t __bkt_count)
1580 : __node_iter_base(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1581 { _M_init(__base); }
1583 ~_Local_iterator_base()
1585 if (_M_bucket_count !=
size_t(-1))
1589 _Local_iterator_base(
const _Local_iterator_base& __iter)
1590 : __node_iter_base(__iter._M_cur), _M_bucket(__iter._M_bucket)
1591 , _M_bucket_count(__iter._M_bucket_count)
1593 if (_M_bucket_count !=
size_t(-1))
1594 _M_init(*__iter._M_h());
1597 _Local_iterator_base&
1598 operator=(
const _Local_iterator_base& __iter)
1600 if (_M_bucket_count != -1)
1602 this->_M_cur = __iter._M_cur;
1603 _M_bucket = __iter._M_bucket;
1604 _M_bucket_count = __iter._M_bucket_count;
1605 if (_M_bucket_count != -1)
1606 _M_init(*__iter._M_h());
1613 __node_iter_base::_M_incr();
1616 std::size_t __bkt = this->_M_h()->_M_bucket_index(*this->_M_cur,
1618 if (__bkt != _M_bucket)
1619 this->_M_cur =
nullptr;
1623 std::size_t _M_bucket;
1624 std::size_t _M_bucket_count;
1627 _M_init(
const __hash_code_base& __base)
1628 { ::new(this->_M_h()) __hash_code_base(__base); }
1631 _M_destroy() { this->_M_h()->~__hash_code_base(); }
1635 _M_get_bucket()
const {
return _M_bucket; }
1639 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1640 typename _Hash,
typename _RangeHash,
typename _Unused,
1641 bool __constant_iterators,
bool __cache>
1642 struct _Local_iterator
1643 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1644 _Hash, _RangeHash, _Unused, __cache>
1647 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1648 _Hash, _RangeHash, _Unused, __cache>;
1649 using __hash_code_base =
typename __base_type::__hash_code_base;
1652 using value_type = _Value;
1653 using pointer = __conditional_t<__constant_iterators,
1654 const value_type*, value_type*>;
1655 using reference = __conditional_t<__constant_iterators,
1656 const value_type&, value_type&>;
1657 using difference_type = ptrdiff_t;
1658 using iterator_category = forward_iterator_tag;
1660 _Local_iterator() =
default;
1662 _Local_iterator(
const __hash_code_base& __base,
1663 _Hash_node<_Value, __cache>* __n,
1664 std::size_t __bkt, std::size_t __bkt_count)
1665 : __base_type(
__base, __n, __bkt, __bkt_count)
1670 {
return this->_M_cur->_M_v(); }
1674 {
return this->_M_cur->_M_valptr(); }
1686 _Local_iterator __tmp(*
this);
1693 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1694 typename _Hash,
typename _RangeHash,
typename _Unused,
1695 bool __constant_iterators,
bool __cache>
1696 struct _Local_const_iterator
1697 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1698 _Hash, _RangeHash, _Unused, __cache>
1701 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1702 _Hash, _RangeHash, _Unused, __cache>;
1703 using __hash_code_base =
typename __base_type::__hash_code_base;
1706 typedef _Value value_type;
1707 typedef const value_type* pointer;
1708 typedef const value_type& reference;
1712 _Local_const_iterator() =
default;
1714 _Local_const_iterator(
const __hash_code_base& __base,
1715 _Hash_node<_Value, __cache>* __n,
1716 std::size_t __bkt, std::size_t __bkt_count)
1717 : __base_type(
__base, __n, __bkt, __bkt_count)
1720 _Local_const_iterator(
const _Local_iterator<_Key, _Value, _ExtractKey,
1721 _Hash, _RangeHash, _Unused,
1722 __constant_iterators,
1729 {
return this->_M_cur->_M_v(); }
1733 {
return this->_M_cur->_M_valptr(); }
1735 _Local_const_iterator&
1742 _Local_const_iterator
1745 _Local_const_iterator __tmp(*
this);
1761 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1762 typename _Equal,
typename _Hash,
typename _RangeHash,
1763 typename _Unused,
typename _Traits>
1764 struct _Hashtable_base
1765 :
public _Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1766 _Unused, _Traits::__hash_cached::value>,
1767 private _Hashtable_ebo_helper<0, _Equal>
1770 typedef _Key key_type;
1771 typedef _Value value_type;
1772 typedef _Equal key_equal;
1773 typedef std::size_t size_type;
1776 using __traits_type = _Traits;
1777 using __hash_cached =
typename __traits_type::__hash_cached;
1779 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1780 _Hash, _RangeHash, _Unused,
1781 __hash_cached::value>;
1783 using __hash_code =
typename __hash_code_base::__hash_code;
1786 using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>;
1789 _S_equals(__hash_code,
const _Hash_node_code_cache<false>&)
1793 _S_node_equals(
const _Hash_node_code_cache<false>&,
1794 const _Hash_node_code_cache<false>&)
1798 _S_equals(__hash_code __c,
const _Hash_node_code_cache<true>& __n)
1799 {
return __c == __n._M_hash_code; }
1802 _S_node_equals(
const _Hash_node_code_cache<true>& __lhn,
1803 const _Hash_node_code_cache<true>& __rhn)
1804 {
return __lhn._M_hash_code == __rhn._M_hash_code; }
1807 _Hashtable_base() =
default;
1809 _Hashtable_base(
const _Hash& __hash,
const _Equal& __eq)
1810 : __hash_code_base(__hash), _EqualEBO(__eq)
1814 _M_key_equals(
const _Key& __k,
1815 const _Hash_node_value<_Value,
1816 __hash_cached::value>& __n)
const
1818 static_assert(__is_invocable<const _Equal&, const _Key&, const _Key&>{},
1819 "key equality predicate must be invocable with two arguments of "
1821 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1824 template<
typename _Kt>
1826 _M_key_equals_tr(
const _Kt& __k,
1827 const _Hash_node_value<_Value,
1828 __hash_cached::value>& __n)
const
1831 __is_invocable<const _Equal&, const _Kt&, const _Key&>{},
1832 "key equality predicate must be invocable with two arguments of "
1834 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1838 _M_equals(
const _Key& __k, __hash_code __c,
1839 const _Hash_node_value<_Value, __hash_cached::value>& __n)
const
1840 {
return _S_equals(__c, __n) && _M_key_equals(__k, __n); }
1842 template<
typename _Kt>
1844 _M_equals_tr(
const _Kt& __k, __hash_code __c,
1845 const _Hash_node_value<_Value,
1846 __hash_cached::value>& __n)
const
1847 {
return _S_equals(__c, __n) && _M_key_equals_tr(__k, __n); }
1851 const _Hash_node_value<_Value, __hash_cached::value>& __lhn,
1852 const _Hash_node_value<_Value, __hash_cached::value>& __rhn)
const
1854 return _S_node_equals(__lhn, __rhn)
1855 && _M_key_equals(_ExtractKey{}(__lhn._M_v()), __rhn);
1859 _M_swap(_Hashtable_base& __x)
1861 __hash_code_base::_M_swap(__x);
1863 swap(_EqualEBO::_M_get(), __x._EqualEBO::_M_get());
1867 _M_eq()
const {
return _EqualEBO::_M_cget(); }
1878 template<
typename _Key,
typename _Value,
typename _Alloc,
1879 typename _ExtractKey,
typename _Equal,
1880 typename _Hash,
typename _RangeHash,
typename _Unused,
1881 typename _RehashPolicy,
typename _Traits,
1882 bool _Unique_keys = _Traits::__unique_keys::value>
1886 template<
typename _Key,
typename _Value,
typename _Alloc,
1887 typename _ExtractKey,
typename _Equal,
1888 typename _Hash,
typename _RangeHash,
typename _Unused,
1889 typename _RehashPolicy,
typename _Traits>
1890 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1891 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
1893 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1894 _Hash, _RangeHash, _Unused,
1895 _RehashPolicy, _Traits>;
1898 _M_equal(
const __hashtable&)
const;
1901 template<
typename _Key,
typename _Value,
typename _Alloc,
1902 typename _ExtractKey,
typename _Equal,
1903 typename _Hash,
typename _RangeHash,
typename _Unused,
1904 typename _RehashPolicy,
typename _Traits>
1906 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1907 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
1908 _M_equal(
const __hashtable& __other)
const
1910 using __node_ptr =
typename __hashtable::__node_ptr;
1911 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1912 if (__this->size() != __other.size())
1915 for (
auto __x_n = __this->_M_begin(); __x_n; __x_n = __x_n->_M_next())
1917 std::size_t __ybkt = __other._M_bucket_index(*__x_n);
1918 auto __prev_n = __other._M_buckets[__ybkt];
1922 for (__node_ptr __n =
static_cast<__node_ptr
>(__prev_n->_M_nxt);;
1923 __n = __n->_M_next())
1925 if (__n->_M_v() == __x_n->_M_v())
1929 || __other._M_bucket_index(*__n->_M_next()) != __ybkt)
1938 template<
typename _Key,
typename _Value,
typename _Alloc,
1939 typename _ExtractKey,
typename _Equal,
1940 typename _Hash,
typename _RangeHash,
typename _Unused,
1941 typename _RehashPolicy,
typename _Traits>
1942 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1943 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1945 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1946 _Hash, _RangeHash, _Unused,
1947 _RehashPolicy, _Traits>;
1950 _M_equal(
const __hashtable&)
const;
1953 template<
typename _Key,
typename _Value,
typename _Alloc,
1954 typename _ExtractKey,
typename _Equal,
1955 typename _Hash,
typename _RangeHash,
typename _Unused,
1956 typename _RehashPolicy,
typename _Traits>
1958 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1959 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
false>::
1960 _M_equal(
const __hashtable& __other)
const
1962 using __node_ptr =
typename __hashtable::__node_ptr;
1963 using const_iterator =
typename __hashtable::const_iterator;
1964 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1965 if (__this->size() != __other.size())
1968 for (
auto __x_n = __this->_M_begin(); __x_n;)
1970 std::size_t __x_count = 1;
1971 auto __x_n_end = __x_n->_M_next();
1973 && __this->key_eq()(_ExtractKey{}(__x_n->_M_v()),
1974 _ExtractKey{}(__x_n_end->_M_v()));
1975 __x_n_end = __x_n_end->_M_next())
1978 std::size_t __ybkt = __other._M_bucket_index(*__x_n);
1979 auto __y_prev_n = __other._M_buckets[__ybkt];
1983 __node_ptr __y_n =
static_cast<__node_ptr
>(__y_prev_n->_M_nxt);
1986 if (__this->key_eq()(_ExtractKey{}(__y_n->_M_v()),
1987 _ExtractKey{}(__x_n->_M_v())))
1990 auto __y_ref_n = __y_n;
1991 for (__y_n = __y_n->_M_next(); __y_n; __y_n = __y_n->_M_next())
1992 if (!__other._M_node_equals(*__y_ref_n, *__y_n))
1995 if (!__y_n || __other._M_bucket_index(*__y_n) != __ybkt)
1999 auto __y_n_end = __y_n;
2000 for (; __y_n_end; __y_n_end = __y_n_end->_M_next())
2001 if (--__x_count == 0)
2007 const_iterator __itx(__x_n), __itx_end(__x_n_end);
2008 const_iterator __ity(__y_n);
2009 if (!std::is_permutation(__itx, __itx_end, __ity))
2021 template<
typename _NodeAlloc>
2022 struct _Hashtable_alloc :
private _Hashtable_ebo_helper<0, _NodeAlloc>
2025 using __ebo_node_alloc = _Hashtable_ebo_helper<0, _NodeAlloc>;
2028 struct __get_value_type;
2029 template<
typename _Val,
bool _Cache_hash_code>
2030 struct __get_value_type<_Hash_node<_Val, _Cache_hash_code>>
2031 {
using type = _Val; };
2034 using __node_type =
typename _NodeAlloc::value_type;
2035 using __node_alloc_type = _NodeAlloc;
2039 using __value_alloc_traits =
typename __node_alloc_traits::template
2040 rebind_traits<typename __get_value_type<__node_type>::type>;
2042 using __node_ptr = __node_type*;
2043 using __node_base = _Hash_node_base;
2044 using __node_base_ptr = __node_base*;
2045 using __buckets_alloc_type =
2046 __alloc_rebind<__node_alloc_type, __node_base_ptr>;
2048 using __buckets_ptr = __node_base_ptr*;
2050 _Hashtable_alloc() =
default;
2051 _Hashtable_alloc(
const _Hashtable_alloc&) =
default;
2052 _Hashtable_alloc(_Hashtable_alloc&&) =
default;
2054 template<
typename _Alloc>
2055 _Hashtable_alloc(_Alloc&& __a)
2056 : __ebo_node_alloc(
std::
forward<_Alloc>(__a))
2061 {
return __ebo_node_alloc::_M_get(); }
2063 const __node_alloc_type&
2064 _M_node_allocator()
const
2065 {
return __ebo_node_alloc::_M_cget(); }
2068 template<
typename... _Args>
2070 _M_allocate_node(_Args&&... __args);
2074 _M_deallocate_node(__node_ptr __n);
2078 _M_deallocate_node_ptr(__node_ptr __n);
2083 _M_deallocate_nodes(__node_ptr __n);
2086 _M_allocate_buckets(std::size_t __bkt_count);
2089 _M_deallocate_buckets(__buckets_ptr, std::size_t __bkt_count);
2094 template<
typename _NodeAlloc>
2095 template<
typename... _Args>
2097 _Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&&... __args)
2100 auto& __alloc = _M_node_allocator();
2101 auto __nptr = __node_alloc_traits::allocate(__alloc, 1);
2102 __node_ptr __n = std::__to_address(__nptr);
2105 ::new ((
void*)__n) __node_type;
2106 __node_alloc_traits::construct(__alloc, __n->_M_valptr(),
2112 __n->~__node_type();
2113 __node_alloc_traits::deallocate(__alloc, __nptr, 1);
2114 __throw_exception_again;
2118 template<
typename _NodeAlloc>
2120 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node(__node_ptr __n)
2122 __node_alloc_traits::destroy(_M_node_allocator(), __n->_M_valptr());
2123 _M_deallocate_node_ptr(__n);
2126 template<
typename _NodeAlloc>
2128 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node_ptr(__node_ptr __n)
2130 typedef typename __node_alloc_traits::pointer _Ptr;
2132 __n->~__node_type();
2133 __node_alloc_traits::deallocate(_M_node_allocator(), __ptr, 1);
2136 template<
typename _NodeAlloc>
2138 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_nodes(__node_ptr __n)
2142 __node_ptr __tmp = __n;
2143 __n = __n->_M_next();
2144 _M_deallocate_node(__tmp);
2148 template<
typename _NodeAlloc>
2150 _Hashtable_alloc<_NodeAlloc>::_M_allocate_buckets(std::size_t __bkt_count)
2153 __buckets_alloc_type __alloc(_M_node_allocator());
2155 auto __ptr = __buckets_alloc_traits::allocate(__alloc, __bkt_count);
2156 __buckets_ptr __p = std::__to_address(__ptr);
2157 __builtin_memset(__p, 0, __bkt_count *
sizeof(__node_base_ptr));
2161 template<
typename _NodeAlloc>
2163 _Hashtable_alloc<_NodeAlloc>::
2164 _M_deallocate_buckets(__buckets_ptr __bkts,
2165 std::size_t __bkt_count)
2167 typedef typename __buckets_alloc_traits::pointer _Ptr;
2169 __buckets_alloc_type __alloc(_M_node_allocator());
2170 __buckets_alloc_traits::deallocate(__alloc, __ptr, __bkt_count);
2176_GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
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 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.
Traits class for iterators.
Uniform interface to all pointer-like types.
Forward iterators support a superset of input iterator operations.
Uniform interface to C++98 and C++11 allocators.