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
90 {
return std::forward<_Tp>(__x); }
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
113 {
return std::forward<_Tp>(__x).first; }
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
125 {
return std::forward<_Kt>(__k); }
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_type*
161 return __node_gen(std::forward<_Kt>(__k),
162 std::forward<_Arg>(__arg).second);
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_type*
173 {
return __node_gen(std::forward<_Kt>(__k)); }
176 template<
typename _NodeAlloc>
177 struct _Hashtable_alloc;
181 template<
typename _NodeAlloc>
182 struct _ReuseOrAllocNode
185 using __node_alloc_type = _NodeAlloc;
186 using __hashtable_alloc = _Hashtable_alloc<__node_alloc_type>;
187 using __node_alloc_traits =
188 typename __hashtable_alloc::__node_alloc_traits;
191 using __node_type =
typename __hashtable_alloc::__node_type;
193 _ReuseOrAllocNode(__node_type* __nodes, __hashtable_alloc& __h)
194 : _M_nodes(__nodes), _M_h(__h) { }
195 _ReuseOrAllocNode(
const _ReuseOrAllocNode&) =
delete;
198 { _M_h._M_deallocate_nodes(_M_nodes); }
200 template<
typename... _Args>
202 operator()(_Args&&... __args)
const
206 __node_type* __node = _M_nodes;
207 _M_nodes = _M_nodes->_M_next();
208 __node->_M_nxt =
nullptr;
209 auto& __a = _M_h._M_node_allocator();
210 __node_alloc_traits::destroy(__a, __node->_M_valptr());
213 __node_alloc_traits::construct(__a, __node->_M_valptr(),
214 std::forward<_Args>(__args)...);
218 _M_h._M_deallocate_node_ptr(__node);
219 __throw_exception_again;
223 return _M_h._M_allocate_node(std::forward<_Args>(__args)...);
227 mutable __node_type* _M_nodes;
228 __hashtable_alloc& _M_h;
233 template<
typename _NodeAlloc>
237 using __hashtable_alloc = _Hashtable_alloc<_NodeAlloc>;
240 using __node_type =
typename __hashtable_alloc::__node_type;
242 _AllocNode(__hashtable_alloc& __h)
245 template<
typename... _Args>
247 operator()(_Args&&... __args)
const
248 {
return _M_h._M_allocate_node(std::forward<_Args>(__args)...); }
251 __hashtable_alloc& _M_h;
279 template<
bool _Cache_hash_code,
bool _Constant_iterators,
bool _Unique_keys>
280 struct _Hashtable_traits
282 using __hash_cached = __bool_constant<_Cache_hash_code>;
283 using __constant_iterators = __bool_constant<_Constant_iterators>;
284 using __unique_keys = __bool_constant<_Unique_keys>;
293 template<
typename _Hash>
294 struct _Hashtable_hash_traits
296 static constexpr std::size_t
297 __small_size_threshold() noexcept
309 struct _Hash_node_base
311 _Hash_node_base* _M_nxt;
313 _Hash_node_base() noexcept : _M_nxt() { }
315 _Hash_node_base(_Hash_node_base* __next) noexcept : _M_nxt(__next) { }
323 template<
typename _Value>
324 struct _Hash_node_value_base
326 typedef _Value value_type;
328 __gnu_cxx::__aligned_buffer<_Value> _M_storage;
330 [[__gnu__::__always_inline__]]
333 {
return _M_storage._M_ptr(); }
335 [[__gnu__::__always_inline__]]
337 _M_valptr() const noexcept
338 {
return _M_storage._M_ptr(); }
340 [[__gnu__::__always_inline__]]
343 {
return *_M_valptr(); }
345 [[__gnu__::__always_inline__]]
347 _M_v() const noexcept
348 {
return *_M_valptr(); }
354 template<
bool _Cache_hash_code>
355 struct _Hash_node_code_cache
362 struct _Hash_node_code_cache<true>
363 { std::size_t _M_hash_code; };
365 template<
typename _Value,
bool _Cache_hash_code>
366 struct _Hash_node_value
367 : _Hash_node_value_base<_Value>
368 , _Hash_node_code_cache<_Cache_hash_code>
374 template<
typename _Value,
bool _Cache_hash_code>
377 , _Hash_node_value<_Value, _Cache_hash_code>
380 _M_next() const noexcept
381 {
return static_cast<_Hash_node*
>(this->_M_nxt); }
385 template<
typename _Value,
bool _Cache_hash_code>
386 struct _Node_iterator_base
388 using __node_type = _Hash_node<_Value, _Cache_hash_code>;
392 _Node_iterator_base() : _M_cur(nullptr) { }
393 _Node_iterator_base(__node_type* __p) noexcept
398 { _M_cur = _M_cur->_M_next(); }
401 operator==(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
403 {
return __x._M_cur == __y._M_cur; }
405#if __cpp_impl_three_way_comparison < 201907L
407 operator!=(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
409 {
return __x._M_cur != __y._M_cur; }
414 template<
typename _Value,
bool __constant_iterators,
bool __cache>
415 struct _Node_iterator
416 :
public _Node_iterator_base<_Value, __cache>
419 using __base_type = _Node_iterator_base<_Value, __cache>;
420 using __node_type =
typename __base_type::__node_type;
423 using value_type = _Value;
424 using difference_type = std::ptrdiff_t;
427 using pointer = __conditional_t<__constant_iterators,
428 const value_type*, value_type*>;
430 using reference = __conditional_t<__constant_iterators,
431 const value_type&, value_type&>;
433 _Node_iterator() =
default;
436 _Node_iterator(__node_type* __p) noexcept
437 : __base_type(__p) { }
441 {
return this->_M_cur->_M_v(); }
444 operator->() const noexcept
445 {
return this->_M_cur->_M_valptr(); }
448 operator++() noexcept
455 operator++(
int)
noexcept
457 _Node_iterator __tmp(*
this);
464 template<
typename _Value,
bool __constant_iterators,
bool __cache>
465 struct _Node_const_iterator
466 :
public _Node_iterator_base<_Value, __cache>
469 using __base_type = _Node_iterator_base<_Value, __cache>;
470 using __node_type =
typename __base_type::__node_type;
473 typedef _Value value_type;
474 typedef std::ptrdiff_t difference_type;
477 typedef const value_type* pointer;
478 typedef const value_type& reference;
480 _Node_const_iterator() =
default;
483 _Node_const_iterator(__node_type* __p) noexcept
484 : __base_type(__p) { }
486 _Node_const_iterator(
const _Node_iterator<_Value, __constant_iterators,
487 __cache>& __x) noexcept
488 : __base_type(__x._M_cur) { }
492 {
return this->_M_cur->_M_v(); }
495 operator->() const noexcept
496 {
return this->_M_cur->_M_valptr(); }
498 _Node_const_iterator&
499 operator++() noexcept
506 operator++(
int)
noexcept
508 _Node_const_iterator __tmp(*
this);
519 struct _Mod_range_hashing
521 typedef std::size_t first_argument_type;
522 typedef std::size_t second_argument_type;
523 typedef std::size_t result_type;
526 operator()(first_argument_type __num,
527 second_argument_type __den)
const noexcept
528 {
return __num % __den; }
536 struct _Default_ranged_hash { };
540 struct _Prime_rehash_policy
544 _Prime_rehash_policy(
float __z = 1.0) noexcept
545 : _M_max_load_factor(__z), _M_next_resize(0) { }
548 max_load_factor() const noexcept
549 {
return _M_max_load_factor; }
553 _M_next_bkt(std::size_t __n)
const;
557 _M_bkt_for_elements(std::size_t __n)
const
558 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
565 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
566 std::size_t __n_ins)
const;
568 typedef std::size_t _State;
572 {
return _M_next_resize; }
576 { _M_next_resize = 0; }
579 _M_reset(_State __state)
580 { _M_next_resize = __state; }
582 static const std::size_t _S_growth_factor = 2;
584 float _M_max_load_factor;
585 mutable std::size_t _M_next_resize;
589 struct _Mask_range_hashing
591 typedef std::size_t first_argument_type;
592 typedef std::size_t second_argument_type;
593 typedef std::size_t result_type;
596 operator()(first_argument_type __num,
597 second_argument_type __den)
const noexcept
598 {
return __num & (__den - 1); }
603 __clp2(std::size_t __n)
noexcept
609 const unsigned __lz =
sizeof(size_t) >
sizeof(
long)
610 ? __builtin_clzll(__n - 1ull)
611 : __builtin_clzl(__n - 1ul);
613 return (
size_t(1) << (__int_traits<size_t>::__digits - __lz - 1)) << 1;
618 struct _Power2_rehash_policy
622 _Power2_rehash_policy(
float __z = 1.0) noexcept
623 : _M_max_load_factor(__z), _M_next_resize(0) { }
626 max_load_factor() const noexcept
627 {
return _M_max_load_factor; }
632 _M_next_bkt(std::size_t __n)
noexcept
640 const auto __max_width = std::min<size_t>(
sizeof(
size_t), 8);
641 const auto __max_bkt = size_t(1) << (__max_width * __CHAR_BIT__ - 1);
642 std::size_t __res = __clp2(__n);
652 if (__res == __max_bkt)
656 _M_next_resize = size_t(-1);
659 = __builtin_floor(__res * (
double)_M_max_load_factor);
666 _M_bkt_for_elements(std::size_t __n)
const noexcept
667 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
674 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
675 std::size_t __n_ins)
noexcept
677 if (__n_elt + __n_ins > _M_next_resize)
683 = std::max<std::size_t>(__n_elt + __n_ins, _M_next_resize ? 0 : 11)
684 / (double)_M_max_load_factor;
685 if (__min_bkts >= __n_bkt)
687 _M_next_bkt(std::max<std::size_t>(__builtin_floor(__min_bkts) + 1,
688 __n_bkt * _S_growth_factor)) };
691 = __builtin_floor(__n_bkt * (
double)_M_max_load_factor);
698 typedef std::size_t _State;
701 _M_state() const noexcept
702 {
return _M_next_resize; }
706 { _M_next_resize = 0; }
709 _M_reset(_State __state)
noexcept
710 { _M_next_resize = __state; }
712 static const std::size_t _S_growth_factor = 2;
714 float _M_max_load_factor;
715 std::size_t _M_next_resize;
736 template<
typename _Key,
typename _Value,
typename _Alloc,
737 typename _ExtractKey,
typename _Equal,
738 typename _Hash,
typename _RangeHash,
typename _Unused,
739 typename _RehashPolicy,
typename _Traits,
740 bool _Unique_keys = _Traits::__unique_keys::value>
741 struct _Map_base { };
744 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
745 typename _Hash,
typename _RangeHash,
typename _Unused,
746 typename _RehashPolicy,
typename _Traits>
747 struct _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
748 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
750 using mapped_type = _Val;
754 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
755 typename _Hash,
typename _RangeHash,
typename _Unused,
756 typename _RehashPolicy,
typename _Traits>
757 struct _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
758 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
761 using __hashtable_base = _Hashtable_base<_Key, pair<const _Key, _Val>,
762 _Select1st, _Equal, _Hash,
766 using __hashtable = _Hashtable<_Key, pair<const _Key, _Val>, _Alloc,
767 _Select1st, _Equal, _Hash, _RangeHash,
768 _Unused, _RehashPolicy, _Traits>;
770 using __hash_code =
typename __hashtable_base::__hash_code;
773 using key_type =
typename __hashtable_base::key_type;
774 using mapped_type = _Val;
777 operator[](
const key_type& __k);
780 operator[](key_type&& __k);
785 at(
const key_type& __k)
787 auto __ite =
static_cast<__hashtable*
>(
this)->find(__k);
789 __throw_out_of_range(__N(
"unordered_map::at"));
790 return __ite->second;
794 at(
const key_type& __k)
const
796 auto __ite =
static_cast<const __hashtable*
>(
this)->find(__k);
798 __throw_out_of_range(__N(
"unordered_map::at"));
799 return __ite->second;
803 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
804 typename _Hash,
typename _RangeHash,
typename _Unused,
805 typename _RehashPolicy,
typename _Traits>
807 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
808 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
809 operator[](
const key_type& __k)
812 __hashtable* __h =
static_cast<__hashtable*
>(
this);
813 __hash_code __code = __h->_M_hash_code(__k);
814 std::size_t __bkt = __h->_M_bucket_index(__code);
815 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
816 return __node->_M_v().second;
818 typename __hashtable::_Scoped_node __node {
825 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
826 __node._M_node =
nullptr;
827 return __pos->second;
830 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
831 typename _Hash,
typename _RangeHash,
typename _Unused,
832 typename _RehashPolicy,
typename _Traits>
834 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
835 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
836 operator[](key_type&& __k)
839 __hashtable* __h =
static_cast<__hashtable*
>(
this);
840 __hash_code __code = __h->_M_hash_code(__k);
841 std::size_t __bkt = __h->_M_bucket_index(__code);
842 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
843 return __node->_M_v().second;
845 typename __hashtable::_Scoped_node __node {
852 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
853 __node._M_node =
nullptr;
854 return __pos->second;
858 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
859 typename _Hash,
typename _RangeHash,
typename _Unused,
860 typename _RehashPolicy,
typename _Traits,
bool __uniq>
861 struct _Map_base<const _Key, pair<const _Key, _Val>,
862 _Alloc, _Select1st, _Equal, _Hash,
863 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
864 : _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal, _Hash,
865 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
873 template<
typename _Key,
typename _Value,
typename _Alloc,
874 typename _ExtractKey,
typename _Equal,
875 typename _Hash,
typename _RangeHash,
typename _Unused,
876 typename _RehashPolicy,
typename _Traits>
880 using __hashtable_base = _Hashtable_base<_Key, _Value, _ExtractKey,
881 _Equal, _Hash, _RangeHash,
884 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
886 _Unused, _RehashPolicy, _Traits>;
888 using __hash_cached =
typename _Traits::__hash_cached;
889 using __constant_iterators =
typename _Traits::__constant_iterators;
891 using __hashtable_alloc = _Hashtable_alloc<
892 __alloc_rebind<_Alloc, _Hash_node<_Value,
893 __hash_cached::value>>>;
895 using value_type =
typename __hashtable_base::value_type;
896 using size_type =
typename __hashtable_base::size_type;
898 using __unique_keys =
typename _Traits::__unique_keys;
899 using __node_alloc_type =
typename __hashtable_alloc::__node_alloc_type;
900 using __node_gen_type = _AllocNode<__node_alloc_type>;
903 _M_conjure_hashtable()
904 {
return *(
static_cast<__hashtable*
>(
this)); }
906 template<
typename _InputIterator,
typename _NodeGetter>
908 _M_insert_range(_InputIterator __first, _InputIterator __last,
909 const _NodeGetter&, true_type __uks);
911 template<
typename _InputIterator,
typename _NodeGetter>
913 _M_insert_range(_InputIterator __first, _InputIterator __last,
914 const _NodeGetter&, false_type __uks);
917 using iterator = _Node_iterator<_Value, __constant_iterators::value,
918 __hash_cached::value>;
920 using const_iterator = _Node_const_iterator<_Value,
921 __constant_iterators::value,
922 __hash_cached::value>;
924 using __ireturn_type = __conditional_t<__unique_keys::value,
929 insert(
const value_type& __v)
931 __hashtable& __h = _M_conjure_hashtable();
932 __node_gen_type __node_gen(__h);
933 return __h._M_insert(__v, __node_gen, __unique_keys{});
937 insert(const_iterator __hint,
const value_type& __v)
939 __hashtable& __h = _M_conjure_hashtable();
940 __node_gen_type __node_gen(__h);
941 return __h._M_insert(__hint, __v, __node_gen, __unique_keys{});
944 template<
typename _KType,
typename... _Args>
946 try_emplace(const_iterator, _KType&& __k, _Args&&... __args)
948 __hashtable& __h = _M_conjure_hashtable();
949 auto __code = __h._M_hash_code(__k);
950 std::size_t __bkt = __h._M_bucket_index(__code);
951 if (
auto __node = __h._M_find_node(__bkt, __k, __code))
952 return { iterator(__node),
false };
954 typename __hashtable::_Scoped_node __node {
961 = __h._M_insert_unique_node(__bkt, __code, __node._M_node);
962 __node._M_node =
nullptr;
963 return { __it,
true };
967 insert(initializer_list<value_type> __l)
968 { this->insert(__l.begin(), __l.end()); }
970 template<
typename _InputIterator>
972 insert(_InputIterator __first, _InputIterator __last)
974 __hashtable& __h = _M_conjure_hashtable();
975 __node_gen_type __node_gen(__h);
976 return _M_insert_range(__first, __last, __node_gen, __unique_keys{});
980 template<
typename _Key,
typename _Value,
typename _Alloc,
981 typename _ExtractKey,
typename _Equal,
982 typename _Hash,
typename _RangeHash,
typename _Unused,
983 typename _RehashPolicy,
typename _Traits>
984 template<
typename _InputIterator,
typename _NodeGetter>
986 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
987 _Hash, _RangeHash, _Unused,
988 _RehashPolicy, _Traits>::
989 _M_insert_range(_InputIterator __first, _InputIterator __last,
990 const _NodeGetter& __node_gen,
true_type __uks)
992 __hashtable& __h = _M_conjure_hashtable();
993 for (; __first != __last; ++__first)
994 __h._M_insert(*__first, __node_gen, __uks);
997 template<
typename _Key,
typename _Value,
typename _Alloc,
998 typename _ExtractKey,
typename _Equal,
999 typename _Hash,
typename _RangeHash,
typename _Unused,
1000 typename _RehashPolicy,
typename _Traits>
1001 template<
typename _InputIterator,
typename _NodeGetter>
1003 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1004 _Hash, _RangeHash, _Unused,
1005 _RehashPolicy, _Traits>::
1006 _M_insert_range(_InputIterator __first, _InputIterator __last,
1007 const _NodeGetter& __node_gen,
false_type __uks)
1009 using __rehash_type =
typename __hashtable::__rehash_type;
1010 using __rehash_state =
typename __hashtable::__rehash_state;
1013 size_type __n_elt = __detail::__distance_fw(__first, __last);
1017 __hashtable& __h = _M_conjure_hashtable();
1018 __rehash_type& __rehash = __h._M_rehash_policy;
1019 const __rehash_state& __saved_state = __rehash._M_state();
1020 pair_type __do_rehash = __rehash._M_need_rehash(__h._M_bucket_count,
1021 __h._M_element_count,
1024 if (__do_rehash.first)
1025 __h._M_rehash(__do_rehash.second, __saved_state);
1027 for (; __first != __last; ++__first)
1028 __h._M_insert(*__first, __node_gen, __uks);
1037 template<
typename _Key,
typename _Value,
typename _Alloc,
1038 typename _ExtractKey,
typename _Equal,
1039 typename _Hash,
typename _RangeHash,
typename _Unused,
1040 typename _RehashPolicy,
typename _Traits,
1041 bool _Constant_iterators = _Traits::__constant_iterators::value>
1045 template<
typename _Key,
typename _Value,
typename _Alloc,
1046 typename _ExtractKey,
typename _Equal,
1047 typename _Hash,
typename _RangeHash,
typename _Unused,
1048 typename _RehashPolicy,
typename _Traits>
1049 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1050 _Hash, _RangeHash, _Unused,
1051 _RehashPolicy, _Traits, true>
1052 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1053 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1055 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1056 _Equal, _Hash, _RangeHash, _Unused,
1057 _RehashPolicy, _Traits>;
1059 using value_type =
typename __base_type::value_type;
1060 using iterator =
typename __base_type::iterator;
1061 using const_iterator =
typename __base_type::const_iterator;
1062 using __ireturn_type =
typename __base_type::__ireturn_type;
1064 using __unique_keys =
typename __base_type::__unique_keys;
1065 using __hashtable =
typename __base_type::__hashtable;
1066 using __node_gen_type =
typename __base_type::__node_gen_type;
1068 using __base_type::insert;
1071 insert(value_type&& __v)
1073 __hashtable& __h = this->_M_conjure_hashtable();
1074 __node_gen_type __node_gen(__h);
1075 return __h._M_insert(
std::move(__v), __node_gen, __unique_keys{});
1079 insert(const_iterator __hint, value_type&& __v)
1081 __hashtable& __h = this->_M_conjure_hashtable();
1082 __node_gen_type __node_gen(__h);
1083 return __h._M_insert(__hint,
std::move(__v), __node_gen,
1089 template<
typename _Key,
typename _Value,
typename _Alloc,
1090 typename _ExtractKey,
typename _Equal,
1091 typename _Hash,
typename _RangeHash,
typename _Unused,
1092 typename _RehashPolicy,
typename _Traits>
1093 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1094 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1095 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1096 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1098 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1099 _Equal, _Hash, _RangeHash, _Unused,
1100 _RehashPolicy, _Traits>;
1101 using value_type =
typename __base_type::value_type;
1102 using iterator =
typename __base_type::iterator;
1103 using const_iterator =
typename __base_type::const_iterator;
1105 using __unique_keys =
typename __base_type::__unique_keys;
1106 using __hashtable =
typename __base_type::__hashtable;
1107 using __ireturn_type =
typename __base_type::__ireturn_type;
1109 using __base_type::insert;
1111 template<
typename _Pair>
1114 template<
typename _Pair>
1117 template<
typename _Pair>
1118 using _IFconsp =
typename _IFcons<_Pair>::type;
1120 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1124 __hashtable& __h = this->_M_conjure_hashtable();
1125 return __h._M_emplace(__unique_keys{}, std::forward<_Pair>(__v));
1128 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1130 insert(const_iterator __hint, _Pair&& __v)
1132 __hashtable& __h = this->_M_conjure_hashtable();
1133 return __h._M_emplace(__hint, __unique_keys{},
1134 std::forward<_Pair>(__v));
1138 template<
typename _Policy>
1139 using __has_load_factor =
typename _Policy::__has_load_factor;
1147 template<
typename _Key,
typename _Value,
typename _Alloc,
1148 typename _ExtractKey,
typename _Equal,
1149 typename _Hash,
typename _RangeHash,
typename _Unused,
1150 typename _RehashPolicy,
typename _Traits,
1152 __detected_or_t<false_type, __has_load_factor, _RehashPolicy>>
1153 struct _Rehash_base;
1156 template<
typename _Key,
typename _Value,
typename _Alloc,
1157 typename _ExtractKey,
typename _Equal,
1158 typename _Hash,
typename _RangeHash,
typename _Unused,
1159 typename _RehashPolicy,
typename _Traits>
1160 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1161 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1167 template<
typename _Key,
typename _Value,
typename _Alloc,
1168 typename _ExtractKey,
typename _Equal,
1169 typename _Hash,
typename _RangeHash,
typename _Unused,
1170 typename _RehashPolicy,
typename _Traits>
1171 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1172 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1176 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey,
1177 _Equal, _Hash, _RangeHash, _Unused,
1178 _RehashPolicy, _Traits>;
1182 max_load_factor() const noexcept
1184 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1185 return __this->__rehash_policy().max_load_factor();
1189 max_load_factor(
float __z)
1191 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1192 __this->__rehash_policy(_RehashPolicy(__z));
1196 reserve(std::size_t __n)
1198 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1199 __this->rehash(__this->__rehash_policy()._M_bkt_for_elements(__n));
1209 template<
int _Nm,
typename _Tp,
1210 bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
1211 struct _Hashtable_ebo_helper;
1214 template<
int _Nm,
typename _Tp>
1215 struct _Hashtable_ebo_helper<_Nm, _Tp, true>
1218 _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
1220 template<
typename _OtherTp>
1221 _Hashtable_ebo_helper(_OtherTp&& __tp)
1225 const _Tp& _M_cget()
const {
return static_cast<const _Tp&
>(*this); }
1226 _Tp& _M_get() {
return static_cast<_Tp&
>(*this); }
1230 template<
int _Nm,
typename _Tp>
1231 struct _Hashtable_ebo_helper<_Nm, _Tp, false>
1233 _Hashtable_ebo_helper() =
default;
1235 template<
typename _OtherTp>
1236 _Hashtable_ebo_helper(_OtherTp&& __tp)
1240 const _Tp& _M_cget()
const {
return _M_tp; }
1241 _Tp& _M_get() {
return _M_tp; }
1253 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1254 typename _Hash,
typename _RangeHash,
typename _Unused,
1255 bool __cache_hash_code>
1256 struct _Local_iterator_base;
1276 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1277 typename _Hash,
typename _RangeHash,
typename _Unused,
1278 bool __cache_hash_code>
1279 struct _Hash_code_base
1280 :
private _Hashtable_ebo_helper<1, _Hash>
1283 using __ebo_hash = _Hashtable_ebo_helper<1, _Hash>;
1286 friend struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1287 _Hash, _RangeHash, _Unused, false>;
1290 typedef _Hash hasher;
1293 hash_function()
const
1294 {
return _M_hash(); }
1297 typedef std::size_t __hash_code;
1301 _Hash_code_base() =
default;
1303 _Hash_code_base(
const _Hash& __hash) : __ebo_hash(__hash) { }
1306 _M_hash_code(
const _Key& __k)
const
1308 static_assert(__is_invocable<const _Hash&, const _Key&>{},
1309 "hash function must be invocable with an argument of key type");
1310 return _M_hash()(__k);
1313 template<
typename _Kt>
1315 _M_hash_code_tr(
const _Kt& __k)
const
1317 static_assert(__is_invocable<const _Hash&, const _Kt&>{},
1318 "hash function must be invocable with an argument of key type");
1319 return _M_hash()(__k);
1323 _M_hash_code(
const _Hash_node_value<_Value, false>& __n)
const
1324 {
return _M_hash_code(_ExtractKey{}(__n._M_v())); }
1327 _M_hash_code(
const _Hash_node_value<_Value, true>& __n)
const
1328 {
return __n._M_hash_code; }
1331 _M_bucket_index(__hash_code __c, std::size_t __bkt_count)
const
1332 {
return _RangeHash{}(__c, __bkt_count); }
1335 _M_bucket_index(
const _Hash_node_value<_Value, false>& __n,
1336 std::size_t __bkt_count)
const
1337 noexcept(
noexcept(declval<const _Hash&>()(declval<const _Key&>()))
1338 &&
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1341 return _RangeHash{}(_M_hash_code(_ExtractKey{}(__n._M_v())),
1346 _M_bucket_index(
const _Hash_node_value<_Value, true>& __n,
1347 std::size_t __bkt_count)
const
1348 noexcept(
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1350 {
return _RangeHash{}(__n._M_hash_code, __bkt_count); }
1353 _M_store_code(_Hash_node_code_cache<false>&, __hash_code)
const
1357 _M_copy_code(_Hash_node_code_cache<false>&,
1358 const _Hash_node_code_cache<false>&)
const
1362 _M_store_code(_Hash_node_code_cache<true>& __n, __hash_code __c)
const
1363 { __n._M_hash_code = __c; }
1366 _M_copy_code(_Hash_node_code_cache<true>& __to,
1367 const _Hash_node_code_cache<true>& __from)
const
1368 { __to._M_hash_code = __from._M_hash_code; }
1371 _M_swap(_Hash_code_base& __x)
1372 {
std::swap(__ebo_hash::_M_get(), __x.__ebo_hash::_M_get()); }
1375 _M_hash()
const {
return __ebo_hash::_M_cget(); }
1379 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1380 typename _Hash,
typename _RangeHash,
typename _Unused>
1381 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1382 _Hash, _RangeHash, _Unused, true>
1383 :
public _Node_iterator_base<_Value, true>
1386 using __base_node_iter = _Node_iterator_base<_Value, true>;
1387 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1388 _Hash, _RangeHash, _Unused,
true>;
1390 _Local_iterator_base() =
default;
1391 _Local_iterator_base(
const __hash_code_base&,
1392 _Hash_node<_Value, true>* __p,
1393 std::size_t __bkt, std::size_t __bkt_count)
1394 : __base_node_iter(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1400 __base_node_iter::_M_incr();
1404 = _RangeHash{}(this->_M_cur->_M_hash_code, _M_bucket_count);
1405 if (__bkt != _M_bucket)
1406 this->_M_cur =
nullptr;
1410 std::size_t _M_bucket;
1411 std::size_t _M_bucket_count;
1415 _M_get_bucket()
const {
return _M_bucket; }
1422 template<typename _Tp, bool _IsEmpty = std::is_empty<_Tp>::value>
1423 struct _Hash_code_storage
1425 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
1428 _M_h() {
return _M_storage._M_ptr(); }
1431 _M_h()
const {
return _M_storage._M_ptr(); }
1435 template<
typename _Tp>
1436 struct _Hash_code_storage<_Tp, true>
1443 _M_h() {
return reinterpret_cast<_Tp*
>(
this); }
1446 _M_h()
const {
return reinterpret_cast<const _Tp*
>(
this); }
1449 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1450 typename _Hash,
typename _RangeHash,
typename _Unused>
1451 using __hash_code_for_local_iter
1452 = _Hash_code_storage<_Hash_code_base<_Key, _Value, _ExtractKey,
1453 _Hash, _RangeHash, _Unused,
false>>;
1456 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1457 typename _Hash,
typename _RangeHash,
typename _Unused>
1458 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1459 _Hash, _RangeHash, _Unused, false>
1460 : __hash_code_for_local_iter<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1462 , _Node_iterator_base<_Value, false>
1465 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1466 _Hash, _RangeHash, _Unused,
false>;
1467 using __node_iter_base = _Node_iterator_base<_Value, false>;
1469 _Local_iterator_base() : _M_bucket_count(-1) { }
1471 _Local_iterator_base(
const __hash_code_base& __base,
1472 _Hash_node<_Value, false>* __p,
1473 std::size_t __bkt, std::size_t __bkt_count)
1474 : __node_iter_base(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1475 { _M_init(__base); }
1477 ~_Local_iterator_base()
1479 if (_M_bucket_count !=
size_t(-1))
1483 _Local_iterator_base(
const _Local_iterator_base& __iter)
1484 : __node_iter_base(__iter._M_cur), _M_bucket(__iter._M_bucket)
1485 , _M_bucket_count(__iter._M_bucket_count)
1487 if (_M_bucket_count !=
size_t(-1))
1488 _M_init(*__iter._M_h());
1491 _Local_iterator_base&
1492 operator=(
const _Local_iterator_base& __iter)
1494 if (_M_bucket_count != -1)
1496 this->_M_cur = __iter._M_cur;
1497 _M_bucket = __iter._M_bucket;
1498 _M_bucket_count = __iter._M_bucket_count;
1499 if (_M_bucket_count != -1)
1500 _M_init(*__iter._M_h());
1507 __node_iter_base::_M_incr();
1510 std::size_t __bkt = this->_M_h()->_M_bucket_index(*this->_M_cur,
1512 if (__bkt != _M_bucket)
1513 this->_M_cur =
nullptr;
1517 std::size_t _M_bucket;
1518 std::size_t _M_bucket_count;
1521 _M_init(
const __hash_code_base& __base)
1522 { ::new(this->_M_h()) __hash_code_base(__base); }
1525 _M_destroy() { this->_M_h()->~__hash_code_base(); }
1529 _M_get_bucket()
const {
return _M_bucket; }
1533 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1534 typename _Hash,
typename _RangeHash,
typename _Unused,
1535 bool __constant_iterators,
bool __cache>
1536 struct _Local_iterator
1537 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1538 _Hash, _RangeHash, _Unused, __cache>
1541 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1542 _Hash, _RangeHash, _Unused, __cache>;
1543 using __hash_code_base =
typename __base_type::__hash_code_base;
1546 using value_type = _Value;
1547 using pointer = __conditional_t<__constant_iterators,
1548 const value_type*, value_type*>;
1549 using reference = __conditional_t<__constant_iterators,
1550 const value_type&, value_type&>;
1551 using difference_type = ptrdiff_t;
1552 using iterator_category = forward_iterator_tag;
1554 _Local_iterator() =
default;
1556 _Local_iterator(
const __hash_code_base& __base,
1557 _Hash_node<_Value, __cache>* __n,
1558 std::size_t __bkt, std::size_t __bkt_count)
1559 : __base_type(
__base, __n, __bkt, __bkt_count)
1564 {
return this->_M_cur->_M_v(); }
1568 {
return this->_M_cur->_M_valptr(); }
1580 _Local_iterator __tmp(*
this);
1587 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1588 typename _Hash,
typename _RangeHash,
typename _Unused,
1589 bool __constant_iterators,
bool __cache>
1590 struct _Local_const_iterator
1591 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1592 _Hash, _RangeHash, _Unused, __cache>
1595 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1596 _Hash, _RangeHash, _Unused, __cache>;
1597 using __hash_code_base =
typename __base_type::__hash_code_base;
1600 typedef _Value value_type;
1601 typedef const value_type* pointer;
1602 typedef const value_type& reference;
1603 typedef std::ptrdiff_t difference_type;
1606 _Local_const_iterator() =
default;
1608 _Local_const_iterator(
const __hash_code_base& __base,
1609 _Hash_node<_Value, __cache>* __n,
1610 std::size_t __bkt, std::size_t __bkt_count)
1611 : __base_type(
__base, __n, __bkt, __bkt_count)
1614 _Local_const_iterator(
const _Local_iterator<_Key, _Value, _ExtractKey,
1615 _Hash, _RangeHash, _Unused,
1616 __constant_iterators,
1623 {
return this->_M_cur->_M_v(); }
1627 {
return this->_M_cur->_M_valptr(); }
1629 _Local_const_iterator&
1636 _Local_const_iterator
1639 _Local_const_iterator __tmp(*
this);
1655 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1656 typename _Equal,
typename _Hash,
typename _RangeHash,
1657 typename _Unused,
typename _Traits>
1658 struct _Hashtable_base
1659 :
public _Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1660 _Unused, _Traits::__hash_cached::value>,
1661 private _Hashtable_ebo_helper<0, _Equal>
1664 typedef _Key key_type;
1665 typedef _Value value_type;
1666 typedef _Equal key_equal;
1667 typedef std::size_t size_type;
1668 typedef std::ptrdiff_t difference_type;
1670 using __traits_type = _Traits;
1671 using __hash_cached =
typename __traits_type::__hash_cached;
1673 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1674 _Hash, _RangeHash, _Unused,
1675 __hash_cached::value>;
1677 using __hash_code =
typename __hash_code_base::__hash_code;
1680 using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>;
1683 _S_equals(__hash_code,
const _Hash_node_code_cache<false>&)
1687 _S_node_equals(
const _Hash_node_code_cache<false>&,
1688 const _Hash_node_code_cache<false>&)
1692 _S_equals(__hash_code __c,
const _Hash_node_code_cache<true>& __n)
1693 {
return __c == __n._M_hash_code; }
1696 _S_node_equals(
const _Hash_node_code_cache<true>& __lhn,
1697 const _Hash_node_code_cache<true>& __rhn)
1698 {
return __lhn._M_hash_code == __rhn._M_hash_code; }
1701 _Hashtable_base() =
default;
1703 _Hashtable_base(
const _Hash& __hash,
const _Equal& __eq)
1704 : __hash_code_base(__hash), _EqualEBO(__eq)
1708 _M_key_equals(
const _Key& __k,
1709 const _Hash_node_value<_Value,
1710 __hash_cached::value>& __n)
const
1712 static_assert(__is_invocable<const _Equal&, const _Key&, const _Key&>{},
1713 "key equality predicate must be invocable with two arguments of "
1715 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1718 template<
typename _Kt>
1720 _M_key_equals_tr(
const _Kt& __k,
1721 const _Hash_node_value<_Value,
1722 __hash_cached::value>& __n)
const
1725 __is_invocable<const _Equal&, const _Kt&, const _Key&>{},
1726 "key equality predicate must be invocable with two arguments of "
1728 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1732 _M_equals(
const _Key& __k, __hash_code __c,
1733 const _Hash_node_value<_Value, __hash_cached::value>& __n)
const
1734 {
return _S_equals(__c, __n) && _M_key_equals(__k, __n); }
1736 template<
typename _Kt>
1738 _M_equals_tr(
const _Kt& __k, __hash_code __c,
1739 const _Hash_node_value<_Value,
1740 __hash_cached::value>& __n)
const
1741 {
return _S_equals(__c, __n) && _M_key_equals_tr(__k, __n); }
1745 const _Hash_node_value<_Value, __hash_cached::value>& __lhn,
1746 const _Hash_node_value<_Value, __hash_cached::value>& __rhn)
const
1748 return _S_node_equals(__lhn, __rhn)
1749 && _M_key_equals(_ExtractKey{}(__lhn._M_v()), __rhn);
1753 _M_swap(_Hashtable_base& __x)
1755 __hash_code_base::_M_swap(__x);
1756 std::swap(_EqualEBO::_M_get(), __x._EqualEBO::_M_get());
1760 _M_eq()
const {
return _EqualEBO::_M_cget(); }
1771 template<
typename _Key,
typename _Value,
typename _Alloc,
1772 typename _ExtractKey,
typename _Equal,
1773 typename _Hash,
typename _RangeHash,
typename _Unused,
1774 typename _RehashPolicy,
typename _Traits,
1775 bool _Unique_keys = _Traits::__unique_keys::value>
1779 template<
typename _Key,
typename _Value,
typename _Alloc,
1780 typename _ExtractKey,
typename _Equal,
1781 typename _Hash,
typename _RangeHash,
typename _Unused,
1782 typename _RehashPolicy,
typename _Traits>
1783 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1784 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
1786 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1787 _Hash, _RangeHash, _Unused,
1788 _RehashPolicy, _Traits>;
1791 _M_equal(
const __hashtable&)
const;
1794 template<
typename _Key,
typename _Value,
typename _Alloc,
1795 typename _ExtractKey,
typename _Equal,
1796 typename _Hash,
typename _RangeHash,
typename _Unused,
1797 typename _RehashPolicy,
typename _Traits>
1799 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1800 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
1801 _M_equal(
const __hashtable& __other)
const
1803 using __node_type =
typename __hashtable::__node_type;
1804 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1805 if (__this->size() != __other.size())
1808 for (
auto __itx = __this->begin(); __itx != __this->end(); ++__itx)
1810 std::size_t __ybkt = __other._M_bucket_index(*__itx._M_cur);
1811 auto __prev_n = __other._M_buckets[__ybkt];
1815 for (__node_type* __n =
static_cast<__node_type*
>(__prev_n->_M_nxt);;
1816 __n = __n->_M_next())
1818 if (__n->_M_v() == *__itx)
1822 || __other._M_bucket_index(*__n->_M_next()) != __ybkt)
1831 template<
typename _Key,
typename _Value,
typename _Alloc,
1832 typename _ExtractKey,
typename _Equal,
1833 typename _Hash,
typename _RangeHash,
typename _Unused,
1834 typename _RehashPolicy,
typename _Traits>
1835 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1836 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1838 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1839 _Hash, _RangeHash, _Unused,
1840 _RehashPolicy, _Traits>;
1843 _M_equal(
const __hashtable&)
const;
1846 template<
typename _Key,
typename _Value,
typename _Alloc,
1847 typename _ExtractKey,
typename _Equal,
1848 typename _Hash,
typename _RangeHash,
typename _Unused,
1849 typename _RehashPolicy,
typename _Traits>
1851 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1852 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
false>::
1853 _M_equal(
const __hashtable& __other)
const
1855 using __node_type =
typename __hashtable::__node_type;
1856 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1857 if (__this->size() != __other.size())
1860 for (
auto __itx = __this->begin(); __itx != __this->end();)
1862 std::size_t __x_count = 1;
1863 auto __itx_end = __itx;
1864 for (++__itx_end; __itx_end != __this->end()
1865 && __this->key_eq()(_ExtractKey{}(*__itx),
1866 _ExtractKey{}(*__itx_end));
1870 std::size_t __ybkt = __other._M_bucket_index(*__itx._M_cur);
1871 auto __y_prev_n = __other._M_buckets[__ybkt];
1875 __node_type* __y_n =
static_cast<__node_type*
>(__y_prev_n->_M_nxt);
1878 if (__this->key_eq()(_ExtractKey{}(__y_n->_M_v()),
1879 _ExtractKey{}(*__itx)))
1882 auto __y_ref_n = __y_n;
1883 for (__y_n = __y_n->_M_next(); __y_n; __y_n = __y_n->_M_next())
1884 if (!__other._M_node_equals(*__y_ref_n, *__y_n))
1887 if (!__y_n || __other._M_bucket_index(*__y_n) != __ybkt)
1891 typename __hashtable::const_iterator __ity(__y_n);
1892 for (
auto __ity_end = __ity; __ity_end != __other.end(); ++__ity_end)
1893 if (--__x_count == 0)
1899 if (!std::is_permutation(__itx, __itx_end, __ity))
1911 template<
typename _NodeAlloc>
1912 struct _Hashtable_alloc :
private _Hashtable_ebo_helper<0, _NodeAlloc>
1915 using __ebo_node_alloc = _Hashtable_ebo_helper<0, _NodeAlloc>;
1918 struct __get_value_type;
1919 template<
typename _Val,
bool _Cache_hash_code>
1920 struct __get_value_type<_Hash_node<_Val, _Cache_hash_code>>
1921 {
using type = _Val; };
1924 using __node_type =
typename _NodeAlloc::value_type;
1925 using __node_alloc_type = _NodeAlloc;
1929 using __value_alloc_traits =
typename __node_alloc_traits::template
1930 rebind_traits<typename __get_value_type<__node_type>::type>;
1932 using __node_ptr = __node_type*;
1933 using __node_base = _Hash_node_base;
1934 using __node_base_ptr = __node_base*;
1935 using __buckets_alloc_type =
1936 __alloc_rebind<__node_alloc_type, __node_base_ptr>;
1938 using __buckets_ptr = __node_base_ptr*;
1940 _Hashtable_alloc() =
default;
1941 _Hashtable_alloc(
const _Hashtable_alloc&) =
default;
1942 _Hashtable_alloc(_Hashtable_alloc&&) =
default;
1944 template<
typename _Alloc>
1945 _Hashtable_alloc(_Alloc&& __a)
1946 : __ebo_node_alloc(
std::
forward<_Alloc>(__a))
1951 {
return __ebo_node_alloc::_M_get(); }
1953 const __node_alloc_type&
1954 _M_node_allocator()
const
1955 {
return __ebo_node_alloc::_M_cget(); }
1958 template<
typename... _Args>
1960 _M_allocate_node(_Args&&... __args);
1964 _M_deallocate_node(__node_ptr __n);
1968 _M_deallocate_node_ptr(__node_ptr __n);
1973 _M_deallocate_nodes(__node_ptr __n);
1976 _M_allocate_buckets(std::size_t __bkt_count);
1979 _M_deallocate_buckets(__buckets_ptr, std::size_t __bkt_count);
1984 template<
typename _NodeAlloc>
1985 template<
typename... _Args>
1987 _Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&&... __args)
1990 auto __nptr = __node_alloc_traits::allocate(_M_node_allocator(), 1);
1991 __node_ptr __n = std::__to_address(__nptr);
1994 ::new ((
void*)__n) __node_type;
1995 __node_alloc_traits::construct(_M_node_allocator(),
1997 std::forward<_Args>(__args)...);
2002 __node_alloc_traits::deallocate(_M_node_allocator(), __nptr, 1);
2003 __throw_exception_again;
2007 template<
typename _NodeAlloc>
2009 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node(__node_ptr __n)
2011 __node_alloc_traits::destroy(_M_node_allocator(), __n->_M_valptr());
2012 _M_deallocate_node_ptr(__n);
2015 template<
typename _NodeAlloc>
2017 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node_ptr(__node_ptr __n)
2019 typedef typename __node_alloc_traits::pointer _Ptr;
2021 __n->~__node_type();
2022 __node_alloc_traits::deallocate(_M_node_allocator(), __ptr, 1);
2025 template<
typename _NodeAlloc>
2027 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_nodes(__node_ptr __n)
2031 __node_ptr __tmp = __n;
2032 __n = __n->_M_next();
2033 _M_deallocate_node(__tmp);
2037 template<
typename _NodeAlloc>
2039 _Hashtable_alloc<_NodeAlloc>::_M_allocate_buckets(std::size_t __bkt_count)
2042 __buckets_alloc_type __alloc(_M_node_allocator());
2044 auto __ptr = __buckets_alloc_traits::allocate(__alloc, __bkt_count);
2045 __buckets_ptr __p = std::__to_address(__ptr);
2046 __builtin_memset(__p, 0, __bkt_count *
sizeof(__node_base_ptr));
2050 template<
typename _NodeAlloc>
2052 _Hashtable_alloc<_NodeAlloc>::
2053 _M_deallocate_buckets(__buckets_ptr __bkts,
2054 std::size_t __bkt_count)
2056 typedef typename __buckets_alloc_traits::pointer _Ptr;
2058 __buckets_alloc_type __alloc(_M_node_allocator());
2059 __buckets_alloc_traits::deallocate(__alloc, __ptr, __bkt_count);
2065_GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr 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.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
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.
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.