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,
911 template<
typename _InputIterator,
typename _NodeGetter>
913 _M_insert_range(_InputIterator __first, _InputIterator __last,
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#if __cplusplus >= 201703L && _GLIBCXX_HOSTED
945 template<
typename _KType,
typename... _Args>
947 try_emplace(const_iterator, _KType&& __k, _Args&&... __args)
949 __hashtable& __h = _M_conjure_hashtable();
950 auto __code = __h._M_hash_code(__k);
951 std::size_t __bkt = __h._M_bucket_index(__code);
952 if (
auto __node = __h._M_find_node(__bkt, __k, __code))
953 return { iterator(__node),
false };
955 typename __hashtable::_Scoped_node __node {
962 = __h._M_insert_unique_node(__bkt, __code, __node._M_node);
963 __node._M_node =
nullptr;
964 return { __it,
true };
969 insert(initializer_list<value_type> __l)
970 { this->insert(__l.begin(), __l.end()); }
972 template<
typename _InputIterator>
974 insert(_InputIterator __first, _InputIterator __last)
976 __hashtable& __h = _M_conjure_hashtable();
977 __node_gen_type __node_gen(__h);
978 return _M_insert_range(__first, __last, __node_gen, __unique_keys{});
982 template<
typename _Key,
typename _Value,
typename _Alloc,
983 typename _ExtractKey,
typename _Equal,
984 typename _Hash,
typename _RangeHash,
typename _Unused,
985 typename _RehashPolicy,
typename _Traits>
986 template<
typename _InputIterator,
typename _NodeGetter>
988 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
989 _Hash, _RangeHash, _Unused,
990 _RehashPolicy, _Traits>::
991 _M_insert_range(_InputIterator __first, _InputIterator __last,
992 const _NodeGetter& __node_gen,
true_type __uks)
994 __hashtable& __h = _M_conjure_hashtable();
995 for (; __first != __last; ++__first)
996 __h._M_insert(*__first, __node_gen, __uks);
999 template<
typename _Key,
typename _Value,
typename _Alloc,
1000 typename _ExtractKey,
typename _Equal,
1001 typename _Hash,
typename _RangeHash,
typename _Unused,
1002 typename _RehashPolicy,
typename _Traits>
1003 template<
typename _InputIterator,
typename _NodeGetter>
1005 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1006 _Hash, _RangeHash, _Unused,
1007 _RehashPolicy, _Traits>::
1008 _M_insert_range(_InputIterator __first, _InputIterator __last,
1009 const _NodeGetter& __node_gen,
false_type __uks)
1011 using __rehash_type =
typename __hashtable::__rehash_type;
1012 using __rehash_state =
typename __hashtable::__rehash_state;
1015 size_type __n_elt = __detail::__distance_fw(__first, __last);
1019 __hashtable& __h = _M_conjure_hashtable();
1020 __rehash_type& __rehash = __h._M_rehash_policy;
1021 const __rehash_state& __saved_state = __rehash._M_state();
1022 pair_type __do_rehash = __rehash._M_need_rehash(__h._M_bucket_count,
1023 __h._M_element_count,
1026 if (__do_rehash.first)
1027 __h._M_rehash(__do_rehash.second, __saved_state);
1029 for (; __first != __last; ++__first)
1030 __h._M_insert(*__first, __node_gen, __uks);
1039 template<
typename _Key,
typename _Value,
typename _Alloc,
1040 typename _ExtractKey,
typename _Equal,
1041 typename _Hash,
typename _RangeHash,
typename _Unused,
1042 typename _RehashPolicy,
typename _Traits,
1043 bool _Constant_iterators = _Traits::__constant_iterators::value>
1047 template<
typename _Key,
typename _Value,
typename _Alloc,
1048 typename _ExtractKey,
typename _Equal,
1049 typename _Hash,
typename _RangeHash,
typename _Unused,
1050 typename _RehashPolicy,
typename _Traits>
1051 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1052 _Hash, _RangeHash, _Unused,
1053 _RehashPolicy, _Traits, true>
1054 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1055 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1057 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1058 _Equal, _Hash, _RangeHash, _Unused,
1059 _RehashPolicy, _Traits>;
1061 using value_type =
typename __base_type::value_type;
1062 using iterator =
typename __base_type::iterator;
1063 using const_iterator =
typename __base_type::const_iterator;
1064 using __ireturn_type =
typename __base_type::__ireturn_type;
1066 using __unique_keys =
typename __base_type::__unique_keys;
1067 using __hashtable =
typename __base_type::__hashtable;
1068 using __node_gen_type =
typename __base_type::__node_gen_type;
1070 using __base_type::insert;
1073 insert(value_type&& __v)
1075 __hashtable& __h = this->_M_conjure_hashtable();
1076 __node_gen_type __node_gen(__h);
1077 return __h._M_insert(
std::move(__v), __node_gen, __unique_keys{});
1081 insert(const_iterator __hint, value_type&& __v)
1083 __hashtable& __h = this->_M_conjure_hashtable();
1084 __node_gen_type __node_gen(__h);
1085 return __h._M_insert(__hint,
std::move(__v), __node_gen,
1091 template<
typename _Key,
typename _Value,
typename _Alloc,
1092 typename _ExtractKey,
typename _Equal,
1093 typename _Hash,
typename _RangeHash,
typename _Unused,
1094 typename _RehashPolicy,
typename _Traits>
1095 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1096 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1097 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1098 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1100 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1101 _Equal, _Hash, _RangeHash, _Unused,
1102 _RehashPolicy, _Traits>;
1103 using value_type =
typename __base_type::value_type;
1104 using iterator =
typename __base_type::iterator;
1105 using const_iterator =
typename __base_type::const_iterator;
1107 using __unique_keys =
typename __base_type::__unique_keys;
1108 using __hashtable =
typename __base_type::__hashtable;
1109 using __ireturn_type =
typename __base_type::__ireturn_type;
1111 using __base_type::insert;
1113 template<
typename _Pair>
1116 template<
typename _Pair>
1119 template<
typename _Pair>
1120 using _IFconsp =
typename _IFcons<_Pair>::type;
1122 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1126 __hashtable& __h = this->_M_conjure_hashtable();
1127 return __h._M_emplace(__unique_keys{}, std::forward<_Pair>(__v));
1130 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1132 insert(const_iterator __hint, _Pair&& __v)
1134 __hashtable& __h = this->_M_conjure_hashtable();
1135 return __h._M_emplace(__hint, __unique_keys{},
1136 std::forward<_Pair>(__v));
1140 template<
typename _Policy>
1141 using __has_load_factor =
typename _Policy::__has_load_factor;
1149 template<
typename _Key,
typename _Value,
typename _Alloc,
1150 typename _ExtractKey,
typename _Equal,
1151 typename _Hash,
typename _RangeHash,
typename _Unused,
1152 typename _RehashPolicy,
typename _Traits,
1154 __detected_or_t<false_type, __has_load_factor, _RehashPolicy>>
1155 struct _Rehash_base;
1158 template<
typename _Key,
typename _Value,
typename _Alloc,
1159 typename _ExtractKey,
typename _Equal,
1160 typename _Hash,
typename _RangeHash,
typename _Unused,
1161 typename _RehashPolicy,
typename _Traits>
1162 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1163 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1169 template<
typename _Key,
typename _Value,
typename _Alloc,
1170 typename _ExtractKey,
typename _Equal,
1171 typename _Hash,
typename _RangeHash,
typename _Unused,
1172 typename _RehashPolicy,
typename _Traits>
1173 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1174 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1178 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey,
1179 _Equal, _Hash, _RangeHash, _Unused,
1180 _RehashPolicy, _Traits>;
1184 max_load_factor() const noexcept
1186 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1187 return __this->__rehash_policy().max_load_factor();
1191 max_load_factor(
float __z)
1193 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1194 __this->__rehash_policy(_RehashPolicy(__z));
1198 reserve(std::size_t __n)
1200 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1201 __this->rehash(__this->__rehash_policy()._M_bkt_for_elements(__n));
1211 template<
int _Nm,
typename _Tp,
1212 bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
1213 struct _Hashtable_ebo_helper;
1216 template<
int _Nm,
typename _Tp>
1217 struct _Hashtable_ebo_helper<_Nm, _Tp, true>
1220 _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
1222 template<
typename _OtherTp>
1223 _Hashtable_ebo_helper(_OtherTp&& __tp)
1227 const _Tp& _M_cget()
const {
return static_cast<const _Tp&
>(*this); }
1228 _Tp& _M_get() {
return static_cast<_Tp&
>(*this); }
1232 template<
int _Nm,
typename _Tp>
1233 struct _Hashtable_ebo_helper<_Nm, _Tp, false>
1235 _Hashtable_ebo_helper() =
default;
1237 template<
typename _OtherTp>
1238 _Hashtable_ebo_helper(_OtherTp&& __tp)
1242 const _Tp& _M_cget()
const {
return _M_tp; }
1243 _Tp& _M_get() {
return _M_tp; }
1255 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1256 typename _Hash,
typename _RangeHash,
typename _Unused,
1257 bool __cache_hash_code>
1258 struct _Local_iterator_base;
1278 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1279 typename _Hash,
typename _RangeHash,
typename _Unused,
1280 bool __cache_hash_code>
1281 struct _Hash_code_base
1282 :
private _Hashtable_ebo_helper<1, _Hash>
1285 using __ebo_hash = _Hashtable_ebo_helper<1, _Hash>;
1288 friend struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1289 _Hash, _RangeHash, _Unused, false>;
1292 typedef _Hash hasher;
1295 hash_function()
const
1296 {
return _M_hash(); }
1299 typedef std::size_t __hash_code;
1303 _Hash_code_base() =
default;
1305 _Hash_code_base(
const _Hash& __hash) : __ebo_hash(__hash) { }
1308 _M_hash_code(
const _Key& __k)
const
1310 static_assert(__is_invocable<const _Hash&, const _Key&>{},
1311 "hash function must be invocable with an argument of key type");
1312 return _M_hash()(__k);
1315 template<
typename _Kt>
1317 _M_hash_code_tr(
const _Kt& __k)
const
1319 static_assert(__is_invocable<const _Hash&, const _Kt&>{},
1320 "hash function must be invocable with an argument of key type");
1321 return _M_hash()(__k);
1325 _M_hash_code(
const _Hash_node_value<_Value, false>& __n)
const
1326 {
return _M_hash_code(_ExtractKey{}(__n._M_v())); }
1329 _M_hash_code(
const _Hash_node_value<_Value, true>& __n)
const
1330 {
return __n._M_hash_code; }
1333 _M_bucket_index(__hash_code __c, std::size_t __bkt_count)
const
1334 {
return _RangeHash{}(__c, __bkt_count); }
1337 _M_bucket_index(
const _Hash_node_value<_Value, false>& __n,
1338 std::size_t __bkt_count)
const
1339 noexcept(
noexcept(declval<const _Hash&>()(declval<const _Key&>()))
1340 &&
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1343 return _RangeHash{}(_M_hash_code(_ExtractKey{}(__n._M_v())),
1348 _M_bucket_index(
const _Hash_node_value<_Value, true>& __n,
1349 std::size_t __bkt_count)
const
1350 noexcept(
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1352 {
return _RangeHash{}(__n._M_hash_code, __bkt_count); }
1355 _M_store_code(_Hash_node_code_cache<false>&, __hash_code)
const
1359 _M_copy_code(_Hash_node_code_cache<false>&,
1360 const _Hash_node_code_cache<false>&)
const
1364 _M_store_code(_Hash_node_code_cache<true>& __n, __hash_code __c)
const
1365 { __n._M_hash_code = __c; }
1368 _M_copy_code(_Hash_node_code_cache<true>& __to,
1369 const _Hash_node_code_cache<true>& __from)
const
1370 { __to._M_hash_code = __from._M_hash_code; }
1373 _M_swap(_Hash_code_base& __x)
1374 {
std::swap(__ebo_hash::_M_get(), __x.__ebo_hash::_M_get()); }
1377 _M_hash()
const {
return __ebo_hash::_M_cget(); }
1381 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1382 typename _Hash,
typename _RangeHash,
typename _Unused>
1383 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1384 _Hash, _RangeHash, _Unused, true>
1385 :
public _Node_iterator_base<_Value, true>
1388 using __base_node_iter = _Node_iterator_base<_Value, true>;
1389 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1390 _Hash, _RangeHash, _Unused,
true>;
1392 _Local_iterator_base() =
default;
1393 _Local_iterator_base(
const __hash_code_base&,
1394 _Hash_node<_Value, true>* __p,
1395 std::size_t __bkt, std::size_t __bkt_count)
1396 : __base_node_iter(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1402 __base_node_iter::_M_incr();
1406 = _RangeHash{}(this->_M_cur->_M_hash_code, _M_bucket_count);
1407 if (__bkt != _M_bucket)
1408 this->_M_cur =
nullptr;
1412 std::size_t _M_bucket;
1413 std::size_t _M_bucket_count;
1417 _M_get_bucket()
const {
return _M_bucket; }
1424 template<typename _Tp, bool _IsEmpty = std::is_empty<_Tp>::value>
1425 struct _Hash_code_storage
1427 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
1430 _M_h() {
return _M_storage._M_ptr(); }
1433 _M_h()
const {
return _M_storage._M_ptr(); }
1437 template<
typename _Tp>
1438 struct _Hash_code_storage<_Tp, true>
1445 _M_h() {
return reinterpret_cast<_Tp*
>(
this); }
1448 _M_h()
const {
return reinterpret_cast<const _Tp*
>(
this); }
1451 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1452 typename _Hash,
typename _RangeHash,
typename _Unused>
1453 using __hash_code_for_local_iter
1454 = _Hash_code_storage<_Hash_code_base<_Key, _Value, _ExtractKey,
1455 _Hash, _RangeHash, _Unused,
false>>;
1458 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1459 typename _Hash,
typename _RangeHash,
typename _Unused>
1460 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1461 _Hash, _RangeHash, _Unused, false>
1462 : __hash_code_for_local_iter<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1464 , _Node_iterator_base<_Value, false>
1467 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1468 _Hash, _RangeHash, _Unused,
false>;
1469 using __node_iter_base = _Node_iterator_base<_Value, false>;
1471 _Local_iterator_base() : _M_bucket_count(-1) { }
1473 _Local_iterator_base(
const __hash_code_base&
__base,
1474 _Hash_node<_Value, false>* __p,
1475 std::size_t __bkt, std::size_t __bkt_count)
1476 : __node_iter_base(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1479 ~_Local_iterator_base()
1481 if (_M_bucket_count !=
size_t(-1))
1485 _Local_iterator_base(
const _Local_iterator_base& __iter)
1486 : __node_iter_base(__iter._M_cur), _M_bucket(__iter._M_bucket)
1487 , _M_bucket_count(__iter._M_bucket_count)
1489 if (_M_bucket_count !=
size_t(-1))
1490 _M_init(*__iter._M_h());
1493 _Local_iterator_base&
1494 operator=(
const _Local_iterator_base& __iter)
1496 if (_M_bucket_count != -1)
1498 this->_M_cur = __iter._M_cur;
1499 _M_bucket = __iter._M_bucket;
1500 _M_bucket_count = __iter._M_bucket_count;
1501 if (_M_bucket_count != -1)
1502 _M_init(*__iter._M_h());
1509 __node_iter_base::_M_incr();
1512 std::size_t __bkt = this->_M_h()->_M_bucket_index(*this->_M_cur,
1514 if (__bkt != _M_bucket)
1515 this->_M_cur =
nullptr;
1519 std::size_t _M_bucket;
1520 std::size_t _M_bucket_count;
1523 _M_init(
const __hash_code_base&
__base)
1524 { ::new(this->_M_h()) __hash_code_base(
__base); }
1527 _M_destroy() { this->_M_h()->~__hash_code_base(); }
1531 _M_get_bucket()
const {
return _M_bucket; }
1535 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1536 typename _Hash,
typename _RangeHash,
typename _Unused,
1537 bool __constant_iterators,
bool __cache>
1538 struct _Local_iterator
1539 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1540 _Hash, _RangeHash, _Unused, __cache>
1543 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1544 _Hash, _RangeHash, _Unused, __cache>;
1545 using __hash_code_base =
typename __base_type::__hash_code_base;
1548 using value_type = _Value;
1549 using pointer = __conditional_t<__constant_iterators,
1550 const value_type*, value_type*>;
1551 using reference = __conditional_t<__constant_iterators,
1552 const value_type&, value_type&>;
1553 using difference_type = ptrdiff_t;
1554 using iterator_category = forward_iterator_tag;
1556 _Local_iterator() =
default;
1558 _Local_iterator(
const __hash_code_base&
__base,
1559 _Hash_node<_Value, __cache>* __n,
1560 std::size_t __bkt, std::size_t __bkt_count)
1561 : __base_type(
__base, __n, __bkt, __bkt_count)
1566 {
return this->_M_cur->_M_v(); }
1570 {
return this->_M_cur->_M_valptr(); }
1582 _Local_iterator __tmp(*
this);
1589 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1590 typename _Hash,
typename _RangeHash,
typename _Unused,
1591 bool __constant_iterators,
bool __cache>
1592 struct _Local_const_iterator
1593 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1594 _Hash, _RangeHash, _Unused, __cache>
1597 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1598 _Hash, _RangeHash, _Unused, __cache>;
1599 using __hash_code_base =
typename __base_type::__hash_code_base;
1602 typedef _Value value_type;
1603 typedef const value_type* pointer;
1604 typedef const value_type& reference;
1605 typedef std::ptrdiff_t difference_type;
1608 _Local_const_iterator() =
default;
1610 _Local_const_iterator(
const __hash_code_base&
__base,
1611 _Hash_node<_Value, __cache>* __n,
1612 std::size_t __bkt, std::size_t __bkt_count)
1613 : __base_type(
__base, __n, __bkt, __bkt_count)
1616 _Local_const_iterator(
const _Local_iterator<_Key, _Value, _ExtractKey,
1617 _Hash, _RangeHash, _Unused,
1618 __constant_iterators,
1625 {
return this->_M_cur->_M_v(); }
1629 {
return this->_M_cur->_M_valptr(); }
1631 _Local_const_iterator&
1638 _Local_const_iterator
1641 _Local_const_iterator __tmp(*
this);
1657 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1658 typename _Equal,
typename _Hash,
typename _RangeHash,
1659 typename _Unused,
typename _Traits>
1660 struct _Hashtable_base
1661 :
public _Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1662 _Unused, _Traits::__hash_cached::value>,
1663 private _Hashtable_ebo_helper<0, _Equal>
1666 typedef _Key key_type;
1667 typedef _Value value_type;
1668 typedef _Equal key_equal;
1669 typedef std::size_t size_type;
1670 typedef std::ptrdiff_t difference_type;
1672 using __traits_type = _Traits;
1673 using __hash_cached =
typename __traits_type::__hash_cached;
1675 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1676 _Hash, _RangeHash, _Unused,
1677 __hash_cached::value>;
1679 using __hash_code =
typename __hash_code_base::__hash_code;
1682 using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>;
1685 _S_equals(__hash_code,
const _Hash_node_code_cache<false>&)
1689 _S_node_equals(
const _Hash_node_code_cache<false>&,
1690 const _Hash_node_code_cache<false>&)
1694 _S_equals(__hash_code __c,
const _Hash_node_code_cache<true>& __n)
1695 {
return __c == __n._M_hash_code; }
1698 _S_node_equals(
const _Hash_node_code_cache<true>& __lhn,
1699 const _Hash_node_code_cache<true>& __rhn)
1700 {
return __lhn._M_hash_code == __rhn._M_hash_code; }
1703 _Hashtable_base() =
default;
1705 _Hashtable_base(
const _Hash& __hash,
const _Equal& __eq)
1706 : __hash_code_base(__hash), _EqualEBO(__eq)
1710 _M_key_equals(
const _Key& __k,
1711 const _Hash_node_value<_Value,
1712 __hash_cached::value>& __n)
const
1714 static_assert(__is_invocable<const _Equal&, const _Key&, const _Key&>{},
1715 "key equality predicate must be invocable with two arguments of "
1717 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1720 template<
typename _Kt>
1722 _M_key_equals_tr(
const _Kt& __k,
1723 const _Hash_node_value<_Value,
1724 __hash_cached::value>& __n)
const
1727 __is_invocable<const _Equal&, const _Kt&, const _Key&>{},
1728 "key equality predicate must be invocable with two arguments of "
1730 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1734 _M_equals(
const _Key& __k, __hash_code __c,
1735 const _Hash_node_value<_Value, __hash_cached::value>& __n)
const
1736 {
return _S_equals(__c, __n) && _M_key_equals(__k, __n); }
1738 template<
typename _Kt>
1740 _M_equals_tr(
const _Kt& __k, __hash_code __c,
1741 const _Hash_node_value<_Value,
1742 __hash_cached::value>& __n)
const
1743 {
return _S_equals(__c, __n) && _M_key_equals_tr(__k, __n); }
1747 const _Hash_node_value<_Value, __hash_cached::value>& __lhn,
1748 const _Hash_node_value<_Value, __hash_cached::value>& __rhn)
const
1750 return _S_node_equals(__lhn, __rhn)
1751 && _M_key_equals(_ExtractKey{}(__lhn._M_v()), __rhn);
1755 _M_swap(_Hashtable_base& __x)
1757 __hash_code_base::_M_swap(__x);
1758 std::swap(_EqualEBO::_M_get(), __x._EqualEBO::_M_get());
1762 _M_eq()
const {
return _EqualEBO::_M_cget(); }
1773 template<
typename _Key,
typename _Value,
typename _Alloc,
1774 typename _ExtractKey,
typename _Equal,
1775 typename _Hash,
typename _RangeHash,
typename _Unused,
1776 typename _RehashPolicy,
typename _Traits,
1777 bool _Unique_keys = _Traits::__unique_keys::value>
1781 template<
typename _Key,
typename _Value,
typename _Alloc,
1782 typename _ExtractKey,
typename _Equal,
1783 typename _Hash,
typename _RangeHash,
typename _Unused,
1784 typename _RehashPolicy,
typename _Traits>
1785 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1786 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
1788 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1789 _Hash, _RangeHash, _Unused,
1790 _RehashPolicy, _Traits>;
1793 _M_equal(
const __hashtable&)
const;
1796 template<
typename _Key,
typename _Value,
typename _Alloc,
1797 typename _ExtractKey,
typename _Equal,
1798 typename _Hash,
typename _RangeHash,
typename _Unused,
1799 typename _RehashPolicy,
typename _Traits>
1801 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1802 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
1803 _M_equal(
const __hashtable& __other)
const
1805 using __node_type =
typename __hashtable::__node_type;
1806 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1807 if (__this->size() != __other.size())
1810 for (
auto __itx = __this->begin(); __itx != __this->end(); ++__itx)
1812 std::size_t __ybkt = __other._M_bucket_index(*__itx._M_cur);
1813 auto __prev_n = __other._M_buckets[__ybkt];
1817 for (__node_type* __n =
static_cast<__node_type*
>(__prev_n->_M_nxt);;
1818 __n = __n->_M_next())
1820 if (__n->_M_v() == *__itx)
1824 || __other._M_bucket_index(*__n->_M_next()) != __ybkt)
1833 template<
typename _Key,
typename _Value,
typename _Alloc,
1834 typename _ExtractKey,
typename _Equal,
1835 typename _Hash,
typename _RangeHash,
typename _Unused,
1836 typename _RehashPolicy,
typename _Traits>
1837 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1838 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1840 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1841 _Hash, _RangeHash, _Unused,
1842 _RehashPolicy, _Traits>;
1845 _M_equal(
const __hashtable&)
const;
1848 template<
typename _Key,
typename _Value,
typename _Alloc,
1849 typename _ExtractKey,
typename _Equal,
1850 typename _Hash,
typename _RangeHash,
typename _Unused,
1851 typename _RehashPolicy,
typename _Traits>
1853 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1854 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
false>::
1855 _M_equal(
const __hashtable& __other)
const
1857 using __node_type =
typename __hashtable::__node_type;
1858 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1859 if (__this->size() != __other.size())
1862 for (
auto __itx = __this->begin(); __itx != __this->end();)
1864 std::size_t __x_count = 1;
1865 auto __itx_end = __itx;
1866 for (++__itx_end; __itx_end != __this->end()
1867 && __this->key_eq()(_ExtractKey{}(*__itx),
1868 _ExtractKey{}(*__itx_end));
1872 std::size_t __ybkt = __other._M_bucket_index(*__itx._M_cur);
1873 auto __y_prev_n = __other._M_buckets[__ybkt];
1877 __node_type* __y_n =
static_cast<__node_type*
>(__y_prev_n->_M_nxt);
1880 if (__this->key_eq()(_ExtractKey{}(__y_n->_M_v()),
1881 _ExtractKey{}(*__itx)))
1884 auto __y_ref_n = __y_n;
1885 for (__y_n = __y_n->_M_next(); __y_n; __y_n = __y_n->_M_next())
1886 if (!__other._M_node_equals(*__y_ref_n, *__y_n))
1889 if (!__y_n || __other._M_bucket_index(*__y_n) != __ybkt)
1893 typename __hashtable::const_iterator __ity(__y_n);
1894 for (
auto __ity_end = __ity; __ity_end != __other.end(); ++__ity_end)
1895 if (--__x_count == 0)
1901 if (!std::is_permutation(__itx, __itx_end, __ity))
1913 template<
typename _NodeAlloc>
1914 struct _Hashtable_alloc :
private _Hashtable_ebo_helper<0, _NodeAlloc>
1917 using __ebo_node_alloc = _Hashtable_ebo_helper<0, _NodeAlloc>;
1920 struct __get_value_type;
1921 template<
typename _Val,
bool _Cache_hash_code>
1922 struct __get_value_type<_Hash_node<_Val, _Cache_hash_code>>
1923 {
using type = _Val; };
1926 using __node_type =
typename _NodeAlloc::value_type;
1927 using __node_alloc_type = _NodeAlloc;
1931 using __value_alloc_traits =
typename __node_alloc_traits::template
1932 rebind_traits<typename __get_value_type<__node_type>::type>;
1934 using __node_ptr = __node_type*;
1935 using __node_base = _Hash_node_base;
1936 using __node_base_ptr = __node_base*;
1937 using __buckets_alloc_type =
1938 __alloc_rebind<__node_alloc_type, __node_base_ptr>;
1940 using __buckets_ptr = __node_base_ptr*;
1942 _Hashtable_alloc() =
default;
1943 _Hashtable_alloc(
const _Hashtable_alloc&) =
default;
1944 _Hashtable_alloc(_Hashtable_alloc&&) =
default;
1946 template<
typename _Alloc>
1947 _Hashtable_alloc(_Alloc&& __a)
1948 : __ebo_node_alloc(
std::
forward<_Alloc>(__a))
1953 {
return __ebo_node_alloc::_M_get(); }
1955 const __node_alloc_type&
1956 _M_node_allocator()
const
1957 {
return __ebo_node_alloc::_M_cget(); }
1960 template<
typename... _Args>
1962 _M_allocate_node(_Args&&... __args);
1966 _M_deallocate_node(__node_ptr __n);
1970 _M_deallocate_node_ptr(__node_ptr __n);
1975 _M_deallocate_nodes(__node_ptr __n);
1978 _M_allocate_buckets(std::size_t __bkt_count);
1981 _M_deallocate_buckets(__buckets_ptr, std::size_t __bkt_count);
1986 template<
typename _NodeAlloc>
1987 template<
typename... _Args>
1989 _Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&&... __args)
1992 auto __nptr = __node_alloc_traits::allocate(_M_node_allocator(), 1);
1993 __node_ptr __n = std::__to_address(__nptr);
1996 ::new ((
void*)__n) __node_type;
1997 __node_alloc_traits::construct(_M_node_allocator(),
1999 std::forward<_Args>(__args)...);
2004 __node_alloc_traits::deallocate(_M_node_allocator(), __nptr, 1);
2005 __throw_exception_again;
2009 template<
typename _NodeAlloc>
2011 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node(__node_ptr __n)
2013 __node_alloc_traits::destroy(_M_node_allocator(), __n->_M_valptr());
2014 _M_deallocate_node_ptr(__n);
2017 template<
typename _NodeAlloc>
2019 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node_ptr(__node_ptr __n)
2021 typedef typename __node_alloc_traits::pointer _Ptr;
2023 __n->~__node_type();
2024 __node_alloc_traits::deallocate(_M_node_allocator(), __ptr, 1);
2027 template<
typename _NodeAlloc>
2029 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_nodes(__node_ptr __n)
2033 __node_ptr __tmp = __n;
2034 __n = __n->_M_next();
2035 _M_deallocate_node(__tmp);
2039 template<
typename _NodeAlloc>
2041 _Hashtable_alloc<_NodeAlloc>::_M_allocate_buckets(std::size_t __bkt_count)
2044 __buckets_alloc_type __alloc(_M_node_allocator());
2046 auto __ptr = __buckets_alloc_traits::allocate(__alloc, __bkt_count);
2047 __buckets_ptr __p = std::__to_address(__ptr);
2048 __builtin_memset(__p, 0, __bkt_count *
sizeof(__node_base_ptr));
2052 template<
typename _NodeAlloc>
2054 _Hashtable_alloc<_NodeAlloc>::
2055 _M_deallocate_buckets(__buckets_ptr __bkts,
2056 std::size_t __bkt_count)
2058 typedef typename __buckets_alloc_traits::pointer _Ptr;
2060 __buckets_alloc_type __alloc(_M_node_allocator());
2061 __buckets_alloc_traits::deallocate(__alloc, __ptr, __bkt_count);
2067_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.