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;
332 {
return _M_storage._M_ptr(); }
335 _M_valptr() const noexcept
336 {
return _M_storage._M_ptr(); }
340 {
return *_M_valptr(); }
343 _M_v() const noexcept
344 {
return *_M_valptr(); }
350 template<
bool _Cache_hash_code>
351 struct _Hash_node_code_cache
358 struct _Hash_node_code_cache<true>
359 { std::size_t _M_hash_code; };
361 template<
typename _Value,
bool _Cache_hash_code>
362 struct _Hash_node_value
363 : _Hash_node_value_base<_Value>
364 , _Hash_node_code_cache<_Cache_hash_code>
370 template<
typename _Value,
bool _Cache_hash_code>
373 , _Hash_node_value<_Value, _Cache_hash_code>
376 _M_next() const noexcept
377 {
return static_cast<_Hash_node*
>(this->_M_nxt); }
381 template<
typename _Value,
bool _Cache_hash_code>
382 struct _Node_iterator_base
384 using __node_type = _Hash_node<_Value, _Cache_hash_code>;
388 _Node_iterator_base() : _M_cur(nullptr) { }
389 _Node_iterator_base(__node_type* __p) noexcept
394 { _M_cur = _M_cur->_M_next(); }
397 operator==(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
399 {
return __x._M_cur == __y._M_cur; }
401#if __cpp_impl_three_way_comparison < 201907L
403 operator!=(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
405 {
return __x._M_cur != __y._M_cur; }
410 template<
typename _Value,
bool __constant_iterators,
bool __cache>
411 struct _Node_iterator
412 :
public _Node_iterator_base<_Value, __cache>
415 using __base_type = _Node_iterator_base<_Value, __cache>;
416 using __node_type =
typename __base_type::__node_type;
419 using value_type = _Value;
420 using difference_type = std::ptrdiff_t;
423 using pointer = __conditional_t<__constant_iterators,
424 const value_type*, value_type*>;
426 using reference = __conditional_t<__constant_iterators,
427 const value_type&, value_type&>;
429 _Node_iterator() =
default;
432 _Node_iterator(__node_type* __p) noexcept
433 : __base_type(__p) { }
437 {
return this->_M_cur->_M_v(); }
440 operator->() const noexcept
441 {
return this->_M_cur->_M_valptr(); }
444 operator++() noexcept
451 operator++(
int)
noexcept
453 _Node_iterator __tmp(*
this);
460 template<
typename _Value,
bool __constant_iterators,
bool __cache>
461 struct _Node_const_iterator
462 :
public _Node_iterator_base<_Value, __cache>
465 using __base_type = _Node_iterator_base<_Value, __cache>;
466 using __node_type =
typename __base_type::__node_type;
469 typedef _Value value_type;
470 typedef std::ptrdiff_t difference_type;
473 typedef const value_type* pointer;
474 typedef const value_type& reference;
476 _Node_const_iterator() =
default;
479 _Node_const_iterator(__node_type* __p) noexcept
480 : __base_type(__p) { }
482 _Node_const_iterator(
const _Node_iterator<_Value, __constant_iterators,
483 __cache>& __x) noexcept
484 : __base_type(__x._M_cur) { }
488 {
return this->_M_cur->_M_v(); }
491 operator->() const noexcept
492 {
return this->_M_cur->_M_valptr(); }
494 _Node_const_iterator&
495 operator++() noexcept
502 operator++(
int)
noexcept
504 _Node_const_iterator __tmp(*
this);
515 struct _Mod_range_hashing
517 typedef std::size_t first_argument_type;
518 typedef std::size_t second_argument_type;
519 typedef std::size_t result_type;
522 operator()(first_argument_type __num,
523 second_argument_type __den)
const noexcept
524 {
return __num % __den; }
532 struct _Default_ranged_hash { };
536 struct _Prime_rehash_policy
540 _Prime_rehash_policy(
float __z = 1.0) noexcept
541 : _M_max_load_factor(__z), _M_next_resize(0) { }
544 max_load_factor() const noexcept
545 {
return _M_max_load_factor; }
549 _M_next_bkt(std::size_t __n)
const;
553 _M_bkt_for_elements(std::size_t __n)
const
554 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
561 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
562 std::size_t __n_ins)
const;
564 typedef std::size_t _State;
568 {
return _M_next_resize; }
572 { _M_next_resize = 0; }
575 _M_reset(_State __state)
576 { _M_next_resize = __state; }
578 static const std::size_t _S_growth_factor = 2;
580 float _M_max_load_factor;
581 mutable std::size_t _M_next_resize;
585 struct _Mask_range_hashing
587 typedef std::size_t first_argument_type;
588 typedef std::size_t second_argument_type;
589 typedef std::size_t result_type;
592 operator()(first_argument_type __num,
593 second_argument_type __den)
const noexcept
594 {
return __num & (__den - 1); }
599 __clp2(std::size_t __n)
noexcept
605 const unsigned __lz =
sizeof(size_t) >
sizeof(
long)
606 ? __builtin_clzll(__n - 1ull)
607 : __builtin_clzl(__n - 1ul);
609 return (
size_t(1) << (__int_traits<size_t>::__digits - __lz - 1)) << 1;
614 struct _Power2_rehash_policy
618 _Power2_rehash_policy(
float __z = 1.0) noexcept
619 : _M_max_load_factor(__z), _M_next_resize(0) { }
622 max_load_factor() const noexcept
623 {
return _M_max_load_factor; }
628 _M_next_bkt(std::size_t __n)
noexcept
636 const auto __max_width = std::min<size_t>(
sizeof(
size_t), 8);
637 const auto __max_bkt = size_t(1) << (__max_width * __CHAR_BIT__ - 1);
638 std::size_t __res = __clp2(__n);
648 if (__res == __max_bkt)
652 _M_next_resize = size_t(-1);
655 = __builtin_floor(__res * (
double)_M_max_load_factor);
662 _M_bkt_for_elements(std::size_t __n)
const noexcept
663 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
670 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
671 std::size_t __n_ins)
noexcept
673 if (__n_elt + __n_ins > _M_next_resize)
679 = std::max<std::size_t>(__n_elt + __n_ins, _M_next_resize ? 0 : 11)
680 / (double)_M_max_load_factor;
681 if (__min_bkts >= __n_bkt)
683 _M_next_bkt(std::max<std::size_t>(__builtin_floor(__min_bkts) + 1,
684 __n_bkt * _S_growth_factor)) };
687 = __builtin_floor(__n_bkt * (
double)_M_max_load_factor);
694 typedef std::size_t _State;
697 _M_state() const noexcept
698 {
return _M_next_resize; }
702 { _M_next_resize = 0; }
705 _M_reset(_State __state)
noexcept
706 { _M_next_resize = __state; }
708 static const std::size_t _S_growth_factor = 2;
710 float _M_max_load_factor;
711 std::size_t _M_next_resize;
732 template<
typename _Key,
typename _Value,
typename _Alloc,
733 typename _ExtractKey,
typename _Equal,
734 typename _Hash,
typename _RangeHash,
typename _Unused,
735 typename _RehashPolicy,
typename _Traits,
736 bool _Unique_keys = _Traits::__unique_keys::value>
737 struct _Map_base { };
740 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
741 typename _Hash,
typename _RangeHash,
typename _Unused,
742 typename _RehashPolicy,
typename _Traits>
743 struct _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
744 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
746 using mapped_type = _Val;
750 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
751 typename _Hash,
typename _RangeHash,
typename _Unused,
752 typename _RehashPolicy,
typename _Traits>
753 struct _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
754 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
757 using __hashtable_base = _Hashtable_base<_Key, pair<const _Key, _Val>,
758 _Select1st, _Equal, _Hash,
762 using __hashtable = _Hashtable<_Key, pair<const _Key, _Val>, _Alloc,
763 _Select1st, _Equal, _Hash, _RangeHash,
764 _Unused, _RehashPolicy, _Traits>;
766 using __hash_code =
typename __hashtable_base::__hash_code;
769 using key_type =
typename __hashtable_base::key_type;
770 using mapped_type = _Val;
773 operator[](
const key_type& __k);
776 operator[](key_type&& __k);
781 at(
const key_type& __k)
783 auto __ite =
static_cast<__hashtable*
>(
this)->find(__k);
785 __throw_out_of_range(__N(
"unordered_map::at"));
786 return __ite->second;
790 at(
const key_type& __k)
const
792 auto __ite =
static_cast<const __hashtable*
>(
this)->find(__k);
794 __throw_out_of_range(__N(
"unordered_map::at"));
795 return __ite->second;
799 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
800 typename _Hash,
typename _RangeHash,
typename _Unused,
801 typename _RehashPolicy,
typename _Traits>
803 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
804 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
805 operator[](
const key_type& __k)
808 __hashtable* __h =
static_cast<__hashtable*
>(
this);
809 __hash_code __code = __h->_M_hash_code(__k);
810 std::size_t __bkt = __h->_M_bucket_index(__code);
811 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
812 return __node->_M_v().second;
814 typename __hashtable::_Scoped_node __node {
821 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
822 __node._M_node =
nullptr;
823 return __pos->second;
826 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
827 typename _Hash,
typename _RangeHash,
typename _Unused,
828 typename _RehashPolicy,
typename _Traits>
830 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
831 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
832 operator[](key_type&& __k)
835 __hashtable* __h =
static_cast<__hashtable*
>(
this);
836 __hash_code __code = __h->_M_hash_code(__k);
837 std::size_t __bkt = __h->_M_bucket_index(__code);
838 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
839 return __node->_M_v().second;
841 typename __hashtable::_Scoped_node __node {
848 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
849 __node._M_node =
nullptr;
850 return __pos->second;
854 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
855 typename _Hash,
typename _RangeHash,
typename _Unused,
856 typename _RehashPolicy,
typename _Traits,
bool __uniq>
857 struct _Map_base<const _Key, pair<const _Key, _Val>,
858 _Alloc, _Select1st, _Equal, _Hash,
859 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
860 : _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal, _Hash,
861 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
869 template<
typename _Key,
typename _Value,
typename _Alloc,
870 typename _ExtractKey,
typename _Equal,
871 typename _Hash,
typename _RangeHash,
typename _Unused,
872 typename _RehashPolicy,
typename _Traits>
876 using __hashtable_base = _Hashtable_base<_Key, _Value, _ExtractKey,
877 _Equal, _Hash, _RangeHash,
880 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
882 _Unused, _RehashPolicy, _Traits>;
884 using __hash_cached =
typename _Traits::__hash_cached;
885 using __constant_iterators =
typename _Traits::__constant_iterators;
887 using __hashtable_alloc = _Hashtable_alloc<
888 __alloc_rebind<_Alloc, _Hash_node<_Value,
889 __hash_cached::value>>>;
891 using value_type =
typename __hashtable_base::value_type;
892 using size_type =
typename __hashtable_base::size_type;
894 using __unique_keys =
typename _Traits::__unique_keys;
895 using __node_alloc_type =
typename __hashtable_alloc::__node_alloc_type;
896 using __node_gen_type = _AllocNode<__node_alloc_type>;
899 _M_conjure_hashtable()
900 {
return *(
static_cast<__hashtable*
>(
this)); }
902 template<
typename _InputIterator,
typename _NodeGetter>
904 _M_insert_range(_InputIterator __first, _InputIterator __last,
905 const _NodeGetter&, true_type __uks);
907 template<
typename _InputIterator,
typename _NodeGetter>
909 _M_insert_range(_InputIterator __first, _InputIterator __last,
910 const _NodeGetter&, false_type __uks);
913 using iterator = _Node_iterator<_Value, __constant_iterators::value,
914 __hash_cached::value>;
916 using const_iterator = _Node_const_iterator<_Value,
917 __constant_iterators::value,
918 __hash_cached::value>;
920 using __ireturn_type = __conditional_t<__unique_keys::value,
925 insert(
const value_type& __v)
927 __hashtable& __h = _M_conjure_hashtable();
928 __node_gen_type __node_gen(__h);
929 return __h._M_insert(__v, __node_gen, __unique_keys{});
933 insert(const_iterator __hint,
const value_type& __v)
935 __hashtable& __h = _M_conjure_hashtable();
936 __node_gen_type __node_gen(__h);
937 return __h._M_insert(__hint, __v, __node_gen, __unique_keys{});
940 template<
typename _KType,
typename... _Args>
942 try_emplace(const_iterator, _KType&& __k, _Args&&... __args)
944 __hashtable& __h = _M_conjure_hashtable();
945 auto __code = __h._M_hash_code(__k);
946 std::size_t __bkt = __h._M_bucket_index(__code);
947 if (
auto __node = __h._M_find_node(__bkt, __k, __code))
948 return { iterator(__node),
false };
950 typename __hashtable::_Scoped_node __node {
957 = __h._M_insert_unique_node(__bkt, __code, __node._M_node);
958 __node._M_node =
nullptr;
959 return { __it,
true };
963 insert(initializer_list<value_type> __l)
964 { this->insert(__l.begin(), __l.end()); }
966 template<
typename _InputIterator>
968 insert(_InputIterator __first, _InputIterator __last)
970 __hashtable& __h = _M_conjure_hashtable();
971 __node_gen_type __node_gen(__h);
972 return _M_insert_range(__first, __last, __node_gen, __unique_keys{});
976 template<
typename _Key,
typename _Value,
typename _Alloc,
977 typename _ExtractKey,
typename _Equal,
978 typename _Hash,
typename _RangeHash,
typename _Unused,
979 typename _RehashPolicy,
typename _Traits>
980 template<
typename _InputIterator,
typename _NodeGetter>
982 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
983 _Hash, _RangeHash, _Unused,
984 _RehashPolicy, _Traits>::
985 _M_insert_range(_InputIterator __first, _InputIterator __last,
986 const _NodeGetter& __node_gen,
true_type __uks)
988 __hashtable& __h = _M_conjure_hashtable();
989 for (; __first != __last; ++__first)
990 __h._M_insert(*__first, __node_gen, __uks);
993 template<
typename _Key,
typename _Value,
typename _Alloc,
994 typename _ExtractKey,
typename _Equal,
995 typename _Hash,
typename _RangeHash,
typename _Unused,
996 typename _RehashPolicy,
typename _Traits>
997 template<
typename _InputIterator,
typename _NodeGetter>
999 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1000 _Hash, _RangeHash, _Unused,
1001 _RehashPolicy, _Traits>::
1002 _M_insert_range(_InputIterator __first, _InputIterator __last,
1003 const _NodeGetter& __node_gen,
false_type __uks)
1005 using __rehash_type =
typename __hashtable::__rehash_type;
1006 using __rehash_state =
typename __hashtable::__rehash_state;
1009 size_type __n_elt = __detail::__distance_fw(__first, __last);
1013 __hashtable& __h = _M_conjure_hashtable();
1014 __rehash_type& __rehash = __h._M_rehash_policy;
1015 const __rehash_state& __saved_state = __rehash._M_state();
1016 pair_type __do_rehash = __rehash._M_need_rehash(__h._M_bucket_count,
1017 __h._M_element_count,
1020 if (__do_rehash.first)
1021 __h._M_rehash(__do_rehash.second, __saved_state);
1023 for (; __first != __last; ++__first)
1024 __h._M_insert(*__first, __node_gen, __uks);
1033 template<
typename _Key,
typename _Value,
typename _Alloc,
1034 typename _ExtractKey,
typename _Equal,
1035 typename _Hash,
typename _RangeHash,
typename _Unused,
1036 typename _RehashPolicy,
typename _Traits,
1037 bool _Constant_iterators = _Traits::__constant_iterators::value>
1041 template<
typename _Key,
typename _Value,
typename _Alloc,
1042 typename _ExtractKey,
typename _Equal,
1043 typename _Hash,
typename _RangeHash,
typename _Unused,
1044 typename _RehashPolicy,
typename _Traits>
1045 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1046 _Hash, _RangeHash, _Unused,
1047 _RehashPolicy, _Traits, true>
1048 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1049 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1051 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1052 _Equal, _Hash, _RangeHash, _Unused,
1053 _RehashPolicy, _Traits>;
1055 using value_type =
typename __base_type::value_type;
1056 using iterator =
typename __base_type::iterator;
1057 using const_iterator =
typename __base_type::const_iterator;
1058 using __ireturn_type =
typename __base_type::__ireturn_type;
1060 using __unique_keys =
typename __base_type::__unique_keys;
1061 using __hashtable =
typename __base_type::__hashtable;
1062 using __node_gen_type =
typename __base_type::__node_gen_type;
1064 using __base_type::insert;
1067 insert(value_type&& __v)
1069 __hashtable& __h = this->_M_conjure_hashtable();
1070 __node_gen_type __node_gen(__h);
1071 return __h._M_insert(
std::move(__v), __node_gen, __unique_keys{});
1075 insert(const_iterator __hint, value_type&& __v)
1077 __hashtable& __h = this->_M_conjure_hashtable();
1078 __node_gen_type __node_gen(__h);
1079 return __h._M_insert(__hint,
std::move(__v), __node_gen,
1085 template<
typename _Key,
typename _Value,
typename _Alloc,
1086 typename _ExtractKey,
typename _Equal,
1087 typename _Hash,
typename _RangeHash,
typename _Unused,
1088 typename _RehashPolicy,
typename _Traits>
1089 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1090 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1091 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1092 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1094 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1095 _Equal, _Hash, _RangeHash, _Unused,
1096 _RehashPolicy, _Traits>;
1097 using value_type =
typename __base_type::value_type;
1098 using iterator =
typename __base_type::iterator;
1099 using const_iterator =
typename __base_type::const_iterator;
1101 using __unique_keys =
typename __base_type::__unique_keys;
1102 using __hashtable =
typename __base_type::__hashtable;
1103 using __ireturn_type =
typename __base_type::__ireturn_type;
1105 using __base_type::insert;
1107 template<
typename _Pair>
1110 template<
typename _Pair>
1113 template<
typename _Pair>
1114 using _IFconsp =
typename _IFcons<_Pair>::type;
1116 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1120 __hashtable& __h = this->_M_conjure_hashtable();
1121 return __h._M_emplace(__unique_keys{}, std::forward<_Pair>(__v));
1124 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1126 insert(const_iterator __hint, _Pair&& __v)
1128 __hashtable& __h = this->_M_conjure_hashtable();
1129 return __h._M_emplace(__hint, __unique_keys{},
1130 std::forward<_Pair>(__v));
1134 template<
typename _Policy>
1135 using __has_load_factor =
typename _Policy::__has_load_factor;
1143 template<
typename _Key,
typename _Value,
typename _Alloc,
1144 typename _ExtractKey,
typename _Equal,
1145 typename _Hash,
typename _RangeHash,
typename _Unused,
1146 typename _RehashPolicy,
typename _Traits,
1148 __detected_or_t<false_type, __has_load_factor, _RehashPolicy>>
1149 struct _Rehash_base;
1152 template<
typename _Key,
typename _Value,
typename _Alloc,
1153 typename _ExtractKey,
typename _Equal,
1154 typename _Hash,
typename _RangeHash,
typename _Unused,
1155 typename _RehashPolicy,
typename _Traits>
1156 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1157 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1163 template<
typename _Key,
typename _Value,
typename _Alloc,
1164 typename _ExtractKey,
typename _Equal,
1165 typename _Hash,
typename _RangeHash,
typename _Unused,
1166 typename _RehashPolicy,
typename _Traits>
1167 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1168 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1172 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey,
1173 _Equal, _Hash, _RangeHash, _Unused,
1174 _RehashPolicy, _Traits>;
1178 max_load_factor() const noexcept
1180 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1181 return __this->__rehash_policy().max_load_factor();
1185 max_load_factor(
float __z)
1187 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1188 __this->__rehash_policy(_RehashPolicy(__z));
1192 reserve(std::size_t __n)
1194 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1195 __this->rehash(__this->__rehash_policy()._M_bkt_for_elements(__n));
1205 template<
int _Nm,
typename _Tp,
1206 bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
1207 struct _Hashtable_ebo_helper;
1210 template<
int _Nm,
typename _Tp>
1211 struct _Hashtable_ebo_helper<_Nm, _Tp, true>
1214 _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
1216 template<
typename _OtherTp>
1217 _Hashtable_ebo_helper(_OtherTp&& __tp)
1221 const _Tp& _M_cget()
const {
return static_cast<const _Tp&
>(*this); }
1222 _Tp& _M_get() {
return static_cast<_Tp&
>(*this); }
1226 template<
int _Nm,
typename _Tp>
1227 struct _Hashtable_ebo_helper<_Nm, _Tp, false>
1229 _Hashtable_ebo_helper() =
default;
1231 template<
typename _OtherTp>
1232 _Hashtable_ebo_helper(_OtherTp&& __tp)
1236 const _Tp& _M_cget()
const {
return _M_tp; }
1237 _Tp& _M_get() {
return _M_tp; }
1249 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1250 typename _Hash,
typename _RangeHash,
typename _Unused,
1251 bool __cache_hash_code>
1252 struct _Local_iterator_base;
1272 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1273 typename _Hash,
typename _RangeHash,
typename _Unused,
1274 bool __cache_hash_code>
1275 struct _Hash_code_base
1276 :
private _Hashtable_ebo_helper<1, _Hash>
1279 using __ebo_hash = _Hashtable_ebo_helper<1, _Hash>;
1282 friend struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1283 _Hash, _RangeHash, _Unused, false>;
1286 typedef _Hash hasher;
1289 hash_function()
const
1290 {
return _M_hash(); }
1293 typedef std::size_t __hash_code;
1297 _Hash_code_base() =
default;
1299 _Hash_code_base(
const _Hash& __hash) : __ebo_hash(__hash) { }
1302 _M_hash_code(
const _Key& __k)
const
1304 static_assert(__is_invocable<const _Hash&, const _Key&>{},
1305 "hash function must be invocable with an argument of key type");
1306 return _M_hash()(__k);
1309 template<
typename _Kt>
1311 _M_hash_code_tr(
const _Kt& __k)
const
1313 static_assert(__is_invocable<const _Hash&, const _Kt&>{},
1314 "hash function must be invocable with an argument of key type");
1315 return _M_hash()(__k);
1319 _M_hash_code(
const _Hash&,
1320 const _Hash_node_value<_Value, true>& __n)
const
1321 {
return __n._M_hash_code; }
1325 template<
typename _H2>
1327 _M_hash_code(
const _H2&,
1328 const _Hash_node_value<_Value, __cache_hash_code>& __n)
const
1329 {
return _M_hash_code(_ExtractKey{}(__n._M_v())); }
1332 _M_hash_code(
const _Hash_node_value<_Value, false>& __n)
const
1333 {
return _M_hash_code(_ExtractKey{}(__n._M_v())); }
1336 _M_hash_code(
const _Hash_node_value<_Value, true>& __n)
const
1337 {
return __n._M_hash_code; }
1340 _M_bucket_index(__hash_code __c, std::size_t __bkt_count)
const
1341 {
return _RangeHash{}(__c, __bkt_count); }
1344 _M_bucket_index(
const _Hash_node_value<_Value, false>& __n,
1345 std::size_t __bkt_count)
const
1346 noexcept(
noexcept(declval<const _Hash&>()(declval<const _Key&>()))
1347 &&
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1350 return _RangeHash{}(_M_hash_code(_ExtractKey{}(__n._M_v())),
1355 _M_bucket_index(
const _Hash_node_value<_Value, true>& __n,
1356 std::size_t __bkt_count)
const
1357 noexcept(
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1359 {
return _RangeHash{}(__n._M_hash_code, __bkt_count); }
1362 _M_store_code(_Hash_node_code_cache<false>&, __hash_code)
const
1366 _M_copy_code(_Hash_node_code_cache<false>&,
1367 const _Hash_node_code_cache<false>&)
const
1371 _M_store_code(_Hash_node_code_cache<true>& __n, __hash_code __c)
const
1372 { __n._M_hash_code = __c; }
1375 _M_copy_code(_Hash_node_code_cache<true>& __to,
1376 const _Hash_node_code_cache<true>& __from)
const
1377 { __to._M_hash_code = __from._M_hash_code; }
1380 _M_swap(_Hash_code_base& __x)
1381 {
std::swap(__ebo_hash::_M_get(), __x.__ebo_hash::_M_get()); }
1384 _M_hash()
const {
return __ebo_hash::_M_cget(); }
1388 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1389 typename _Hash,
typename _RangeHash,
typename _Unused>
1390 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1391 _Hash, _RangeHash, _Unused, true>
1392 :
public _Node_iterator_base<_Value, true>
1395 using __base_node_iter = _Node_iterator_base<_Value, true>;
1396 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1397 _Hash, _RangeHash, _Unused,
true>;
1399 _Local_iterator_base() =
default;
1400 _Local_iterator_base(
const __hash_code_base&,
1401 _Hash_node<_Value, true>* __p,
1402 std::size_t __bkt, std::size_t __bkt_count)
1403 : __base_node_iter(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1409 __base_node_iter::_M_incr();
1413 = _RangeHash{}(this->_M_cur->_M_hash_code, _M_bucket_count);
1414 if (__bkt != _M_bucket)
1415 this->_M_cur =
nullptr;
1419 std::size_t _M_bucket;
1420 std::size_t _M_bucket_count;
1424 _M_get_bucket()
const {
return _M_bucket; }
1431 template<typename _Tp, bool _IsEmpty = std::is_empty<_Tp>::value>
1432 struct _Hash_code_storage
1434 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
1437 _M_h() {
return _M_storage._M_ptr(); }
1440 _M_h()
const {
return _M_storage._M_ptr(); }
1444 template<
typename _Tp>
1445 struct _Hash_code_storage<_Tp, true>
1452 _M_h() {
return reinterpret_cast<_Tp*
>(
this); }
1455 _M_h()
const {
return reinterpret_cast<const _Tp*
>(
this); }
1458 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1459 typename _Hash,
typename _RangeHash,
typename _Unused>
1460 using __hash_code_for_local_iter
1461 = _Hash_code_storage<_Hash_code_base<_Key, _Value, _ExtractKey,
1462 _Hash, _RangeHash, _Unused,
false>>;
1465 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1466 typename _Hash,
typename _RangeHash,
typename _Unused>
1467 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1468 _Hash, _RangeHash, _Unused, false>
1469 : __hash_code_for_local_iter<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1471 , _Node_iterator_base<_Value, false>
1474 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1475 _Hash, _RangeHash, _Unused,
false>;
1476 using __node_iter_base = _Node_iterator_base<_Value, false>;
1478 _Local_iterator_base() : _M_bucket_count(-1) { }
1480 _Local_iterator_base(
const __hash_code_base& __base,
1481 _Hash_node<_Value, false>* __p,
1482 std::size_t __bkt, std::size_t __bkt_count)
1483 : __node_iter_base(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1484 { _M_init(__base); }
1486 ~_Local_iterator_base()
1488 if (_M_bucket_count !=
size_t(-1))
1492 _Local_iterator_base(
const _Local_iterator_base& __iter)
1493 : __node_iter_base(__iter._M_cur), _M_bucket(__iter._M_bucket)
1494 , _M_bucket_count(__iter._M_bucket_count)
1496 if (_M_bucket_count !=
size_t(-1))
1497 _M_init(*__iter._M_h());
1500 _Local_iterator_base&
1501 operator=(
const _Local_iterator_base& __iter)
1503 if (_M_bucket_count != -1)
1505 this->_M_cur = __iter._M_cur;
1506 _M_bucket = __iter._M_bucket;
1507 _M_bucket_count = __iter._M_bucket_count;
1508 if (_M_bucket_count != -1)
1509 _M_init(*__iter._M_h());
1516 __node_iter_base::_M_incr();
1519 std::size_t __bkt = this->_M_h()->_M_bucket_index(*this->_M_cur,
1521 if (__bkt != _M_bucket)
1522 this->_M_cur =
nullptr;
1526 std::size_t _M_bucket;
1527 std::size_t _M_bucket_count;
1530 _M_init(
const __hash_code_base& __base)
1531 { ::new(this->_M_h()) __hash_code_base(__base); }
1534 _M_destroy() { this->_M_h()->~__hash_code_base(); }
1538 _M_get_bucket()
const {
return _M_bucket; }
1542 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1543 typename _Hash,
typename _RangeHash,
typename _Unused,
1544 bool __constant_iterators,
bool __cache>
1545 struct _Local_iterator
1546 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1547 _Hash, _RangeHash, _Unused, __cache>
1550 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1551 _Hash, _RangeHash, _Unused, __cache>;
1552 using __hash_code_base =
typename __base_type::__hash_code_base;
1555 using value_type = _Value;
1556 using pointer = __conditional_t<__constant_iterators,
1557 const value_type*, value_type*>;
1558 using reference = __conditional_t<__constant_iterators,
1559 const value_type&, value_type&>;
1560 using difference_type = ptrdiff_t;
1561 using iterator_category = forward_iterator_tag;
1563 _Local_iterator() =
default;
1565 _Local_iterator(
const __hash_code_base& __base,
1566 _Hash_node<_Value, __cache>* __n,
1567 std::size_t __bkt, std::size_t __bkt_count)
1568 : __base_type(
__base, __n, __bkt, __bkt_count)
1573 {
return this->_M_cur->_M_v(); }
1577 {
return this->_M_cur->_M_valptr(); }
1589 _Local_iterator __tmp(*
this);
1596 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1597 typename _Hash,
typename _RangeHash,
typename _Unused,
1598 bool __constant_iterators,
bool __cache>
1599 struct _Local_const_iterator
1600 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1601 _Hash, _RangeHash, _Unused, __cache>
1604 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1605 _Hash, _RangeHash, _Unused, __cache>;
1606 using __hash_code_base =
typename __base_type::__hash_code_base;
1609 typedef _Value value_type;
1610 typedef const value_type* pointer;
1611 typedef const value_type& reference;
1612 typedef std::ptrdiff_t difference_type;
1615 _Local_const_iterator() =
default;
1617 _Local_const_iterator(
const __hash_code_base& __base,
1618 _Hash_node<_Value, __cache>* __n,
1619 std::size_t __bkt, std::size_t __bkt_count)
1620 : __base_type(
__base, __n, __bkt, __bkt_count)
1623 _Local_const_iterator(
const _Local_iterator<_Key, _Value, _ExtractKey,
1624 _Hash, _RangeHash, _Unused,
1625 __constant_iterators,
1632 {
return this->_M_cur->_M_v(); }
1636 {
return this->_M_cur->_M_valptr(); }
1638 _Local_const_iterator&
1645 _Local_const_iterator
1648 _Local_const_iterator __tmp(*
this);
1664 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1665 typename _Equal,
typename _Hash,
typename _RangeHash,
1666 typename _Unused,
typename _Traits>
1667 struct _Hashtable_base
1668 :
public _Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1669 _Unused, _Traits::__hash_cached::value>,
1670 private _Hashtable_ebo_helper<0, _Equal>
1673 typedef _Key key_type;
1674 typedef _Value value_type;
1675 typedef _Equal key_equal;
1676 typedef std::size_t size_type;
1677 typedef std::ptrdiff_t difference_type;
1679 using __traits_type = _Traits;
1680 using __hash_cached =
typename __traits_type::__hash_cached;
1682 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1683 _Hash, _RangeHash, _Unused,
1684 __hash_cached::value>;
1686 using __hash_code =
typename __hash_code_base::__hash_code;
1689 using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>;
1692 _S_equals(__hash_code,
const _Hash_node_code_cache<false>&)
1696 _S_node_equals(
const _Hash_node_code_cache<false>&,
1697 const _Hash_node_code_cache<false>&)
1701 _S_equals(__hash_code __c,
const _Hash_node_code_cache<true>& __n)
1702 {
return __c == __n._M_hash_code; }
1705 _S_node_equals(
const _Hash_node_code_cache<true>& __lhn,
1706 const _Hash_node_code_cache<true>& __rhn)
1707 {
return __lhn._M_hash_code == __rhn._M_hash_code; }
1710 _Hashtable_base() =
default;
1712 _Hashtable_base(
const _Hash& __hash,
const _Equal& __eq)
1713 : __hash_code_base(__hash), _EqualEBO(__eq)
1717 _M_key_equals(
const _Key& __k,
1718 const _Hash_node_value<_Value,
1719 __hash_cached::value>& __n)
const
1721 static_assert(__is_invocable<const _Equal&, const _Key&, const _Key&>{},
1722 "key equality predicate must be invocable with two arguments of "
1724 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1727 template<
typename _Kt>
1729 _M_key_equals_tr(
const _Kt& __k,
1730 const _Hash_node_value<_Value,
1731 __hash_cached::value>& __n)
const
1734 __is_invocable<const _Equal&, const _Kt&, const _Key&>{},
1735 "key equality predicate must be invocable with two arguments of "
1737 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1741 _M_equals(
const _Key& __k, __hash_code __c,
1742 const _Hash_node_value<_Value, __hash_cached::value>& __n)
const
1743 {
return _S_equals(__c, __n) && _M_key_equals(__k, __n); }
1745 template<
typename _Kt>
1747 _M_equals_tr(
const _Kt& __k, __hash_code __c,
1748 const _Hash_node_value<_Value,
1749 __hash_cached::value>& __n)
const
1750 {
return _S_equals(__c, __n) && _M_key_equals_tr(__k, __n); }
1754 const _Hash_node_value<_Value, __hash_cached::value>& __lhn,
1755 const _Hash_node_value<_Value, __hash_cached::value>& __rhn)
const
1757 return _S_node_equals(__lhn, __rhn)
1758 && _M_key_equals(_ExtractKey{}(__lhn._M_v()), __rhn);
1762 _M_swap(_Hashtable_base& __x)
1764 __hash_code_base::_M_swap(__x);
1765 std::swap(_EqualEBO::_M_get(), __x._EqualEBO::_M_get());
1769 _M_eq()
const {
return _EqualEBO::_M_cget(); }
1780 template<
typename _Key,
typename _Value,
typename _Alloc,
1781 typename _ExtractKey,
typename _Equal,
1782 typename _Hash,
typename _RangeHash,
typename _Unused,
1783 typename _RehashPolicy,
typename _Traits,
1784 bool _Unique_keys = _Traits::__unique_keys::value>
1788 template<
typename _Key,
typename _Value,
typename _Alloc,
1789 typename _ExtractKey,
typename _Equal,
1790 typename _Hash,
typename _RangeHash,
typename _Unused,
1791 typename _RehashPolicy,
typename _Traits>
1792 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1793 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
1795 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1796 _Hash, _RangeHash, _Unused,
1797 _RehashPolicy, _Traits>;
1800 _M_equal(
const __hashtable&)
const;
1803 template<
typename _Key,
typename _Value,
typename _Alloc,
1804 typename _ExtractKey,
typename _Equal,
1805 typename _Hash,
typename _RangeHash,
typename _Unused,
1806 typename _RehashPolicy,
typename _Traits>
1808 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1809 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
1810 _M_equal(
const __hashtable& __other)
const
1812 using __node_type =
typename __hashtable::__node_type;
1813 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1814 if (__this->size() != __other.size())
1817 for (
auto __itx = __this->begin(); __itx != __this->end(); ++__itx)
1819 std::size_t __ybkt = __other._M_bucket_index(*__itx._M_cur);
1820 auto __prev_n = __other._M_buckets[__ybkt];
1824 for (__node_type* __n =
static_cast<__node_type*
>(__prev_n->_M_nxt);;
1825 __n = __n->_M_next())
1827 if (__n->_M_v() == *__itx)
1831 || __other._M_bucket_index(*__n->_M_next()) != __ybkt)
1840 template<
typename _Key,
typename _Value,
typename _Alloc,
1841 typename _ExtractKey,
typename _Equal,
1842 typename _Hash,
typename _RangeHash,
typename _Unused,
1843 typename _RehashPolicy,
typename _Traits>
1844 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1845 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1847 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1848 _Hash, _RangeHash, _Unused,
1849 _RehashPolicy, _Traits>;
1852 _M_equal(
const __hashtable&)
const;
1855 template<
typename _Key,
typename _Value,
typename _Alloc,
1856 typename _ExtractKey,
typename _Equal,
1857 typename _Hash,
typename _RangeHash,
typename _Unused,
1858 typename _RehashPolicy,
typename _Traits>
1860 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1861 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
false>::
1862 _M_equal(
const __hashtable& __other)
const
1864 using __node_type =
typename __hashtable::__node_type;
1865 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1866 if (__this->size() != __other.size())
1869 for (
auto __itx = __this->begin(); __itx != __this->end();)
1871 std::size_t __x_count = 1;
1872 auto __itx_end = __itx;
1873 for (++__itx_end; __itx_end != __this->end()
1874 && __this->key_eq()(_ExtractKey{}(*__itx),
1875 _ExtractKey{}(*__itx_end));
1879 std::size_t __ybkt = __other._M_bucket_index(*__itx._M_cur);
1880 auto __y_prev_n = __other._M_buckets[__ybkt];
1884 __node_type* __y_n =
static_cast<__node_type*
>(__y_prev_n->_M_nxt);
1887 if (__this->key_eq()(_ExtractKey{}(__y_n->_M_v()),
1888 _ExtractKey{}(*__itx)))
1891 auto __y_ref_n = __y_n;
1892 for (__y_n = __y_n->_M_next(); __y_n; __y_n = __y_n->_M_next())
1893 if (!__other._M_node_equals(*__y_ref_n, *__y_n))
1896 if (!__y_n || __other._M_bucket_index(*__y_n) != __ybkt)
1900 typename __hashtable::const_iterator __ity(__y_n);
1901 for (
auto __ity_end = __ity; __ity_end != __other.end(); ++__ity_end)
1902 if (--__x_count == 0)
1908 if (!std::is_permutation(__itx, __itx_end, __ity))
1920 template<
typename _NodeAlloc>
1921 struct _Hashtable_alloc :
private _Hashtable_ebo_helper<0, _NodeAlloc>
1924 using __ebo_node_alloc = _Hashtable_ebo_helper<0, _NodeAlloc>;
1927 struct __get_value_type;
1928 template<
typename _Val,
bool _Cache_hash_code>
1929 struct __get_value_type<_Hash_node<_Val, _Cache_hash_code>>
1930 {
using type = _Val; };
1933 using __node_type =
typename _NodeAlloc::value_type;
1934 using __node_alloc_type = _NodeAlloc;
1938 using __value_alloc_traits =
typename __node_alloc_traits::template
1939 rebind_traits<typename __get_value_type<__node_type>::type>;
1941 using __node_ptr = __node_type*;
1942 using __node_base = _Hash_node_base;
1943 using __node_base_ptr = __node_base*;
1944 using __buckets_alloc_type =
1945 __alloc_rebind<__node_alloc_type, __node_base_ptr>;
1947 using __buckets_ptr = __node_base_ptr*;
1949 _Hashtable_alloc() =
default;
1950 _Hashtable_alloc(
const _Hashtable_alloc&) =
default;
1951 _Hashtable_alloc(_Hashtable_alloc&&) =
default;
1953 template<
typename _Alloc>
1954 _Hashtable_alloc(_Alloc&& __a)
1955 : __ebo_node_alloc(
std::
forward<_Alloc>(__a))
1960 {
return __ebo_node_alloc::_M_get(); }
1962 const __node_alloc_type&
1963 _M_node_allocator()
const
1964 {
return __ebo_node_alloc::_M_cget(); }
1967 template<
typename... _Args>
1969 _M_allocate_node(_Args&&... __args);
1973 _M_deallocate_node(__node_ptr __n);
1977 _M_deallocate_node_ptr(__node_ptr __n);
1982 _M_deallocate_nodes(__node_ptr __n);
1985 _M_allocate_buckets(std::size_t __bkt_count);
1988 _M_deallocate_buckets(__buckets_ptr, std::size_t __bkt_count);
1993 template<
typename _NodeAlloc>
1994 template<
typename... _Args>
1996 _Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&&... __args)
1999 auto __nptr = __node_alloc_traits::allocate(_M_node_allocator(), 1);
2000 __node_ptr __n = std::__to_address(__nptr);
2003 ::new ((
void*)__n) __node_type;
2004 __node_alloc_traits::construct(_M_node_allocator(),
2006 std::forward<_Args>(__args)...);
2011 __node_alloc_traits::deallocate(_M_node_allocator(), __nptr, 1);
2012 __throw_exception_again;
2016 template<
typename _NodeAlloc>
2018 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node(__node_ptr __n)
2020 __node_alloc_traits::destroy(_M_node_allocator(), __n->_M_valptr());
2021 _M_deallocate_node_ptr(__n);
2024 template<
typename _NodeAlloc>
2026 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node_ptr(__node_ptr __n)
2028 typedef typename __node_alloc_traits::pointer _Ptr;
2030 __n->~__node_type();
2031 __node_alloc_traits::deallocate(_M_node_allocator(), __ptr, 1);
2034 template<
typename _NodeAlloc>
2036 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_nodes(__node_ptr __n)
2040 __node_ptr __tmp = __n;
2041 __n = __n->_M_next();
2042 _M_deallocate_node(__tmp);
2046 template<
typename _NodeAlloc>
2048 _Hashtable_alloc<_NodeAlloc>::_M_allocate_buckets(std::size_t __bkt_count)
2051 __buckets_alloc_type __alloc(_M_node_allocator());
2053 auto __ptr = __buckets_alloc_traits::allocate(__alloc, __bkt_count);
2054 __buckets_ptr __p = std::__to_address(__ptr);
2055 __builtin_memset(__p, 0, __bkt_count *
sizeof(__node_base_ptr));
2059 template<
typename _NodeAlloc>
2061 _Hashtable_alloc<_NodeAlloc>::
2062 _M_deallocate_buckets(__buckets_ptr __bkts,
2063 std::size_t __bkt_count)
2065 typedef typename __buckets_alloc_traits::pointer _Ptr;
2067 __buckets_alloc_type __alloc(_M_node_allocator());
2068 __buckets_alloc_traits::deallocate(__alloc, __ptr, __bkt_count);
2074_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.