31#ifndef _HASHTABLE_POLICY_H
32#define _HASHTABLE_POLICY_H 1
42namespace std _GLIBCXX_VISIBILITY(default)
44_GLIBCXX_BEGIN_NAMESPACE_VERSION
47 template<
typename _Key,
typename _Value,
typename _Alloc,
48 typename _ExtractKey,
typename _Equal,
49 typename _Hash,
typename _RangeHash,
typename _Unused,
50 typename _RehashPolicy,
typename _Traits>
60 template<
typename _Key,
typename _Value,
typename _ExtractKey,
61 typename _Equal,
typename _Hash,
typename _RangeHash,
62 typename _Unused,
typename _Traits>
63 struct _Hashtable_base;
67 template<
typename _Iterator>
69 __distance_fw(_Iterator __first, _Iterator __last,
71 {
return __first != __last ? 1 : 0; }
73 template<
typename _Iterator>
75 __distance_fw(_Iterator __first, _Iterator __last,
79 template<
typename _Iterator>
81 __distance_fw(_Iterator __first, _Iterator __last)
82 {
return __distance_fw(__first, __last,
87 template<
typename _Tp>
89 operator()(_Tp&& __x)
const noexcept
95 template<
typename _Pair>
98 template<
typename _Tp,
typename _Up>
99 struct __1st_type<
pair<_Tp, _Up>>
100 {
using type = _Tp; };
102 template<
typename _Tp,
typename _Up>
103 struct __1st_type<const
pair<_Tp, _Up>>
104 {
using type =
const _Tp; };
106 template<
typename _Pair>
107 struct __1st_type<_Pair&>
108 {
using type =
typename __1st_type<_Pair>::type&; };
110 template<
typename _Tp>
111 typename __1st_type<_Tp>::type&&
112 operator()(_Tp&& __x)
const noexcept
116 template<
typename _ExKey,
typename _Value>
117 struct _ConvertToValueType;
119 template<
typename _Value>
120 struct _ConvertToValueType<_Identity, _Value>
122 template<
typename _Kt>
124 operator()(_Kt&& __k)
const noexcept
128 template<
typename _Value>
129 struct _ConvertToValueType<_Select1st, _Value>
132 operator()(_Value&& __x)
const noexcept
135 constexpr const _Value&
136 operator()(
const _Value& __x)
const noexcept
139 template<
typename _Kt,
typename _Val>
144 template<
typename _Kt,
typename _Val>
150 template<
typename _ExKey>
154 struct _NodeBuilder<_Select1st>
156 template<
typename _Kt,
typename _Arg,
typename _NodeGenerator>
158 _S_build(_Kt&& __k, _Arg&& __arg,
const _NodeGenerator& __node_gen)
159 ->
typename _NodeGenerator::__node_ptr
167 struct _NodeBuilder<_Identity>
169 template<
typename _Kt,
typename _Arg,
typename _NodeGenerator>
171 _S_build(_Kt&& __k, _Arg&&,
const _NodeGenerator& __node_gen)
172 ->
typename _NodeGenerator::__node_ptr
176 template<
typename _HashtableAlloc,
typename _NodePtr>
179 _HashtableAlloc& _M_h;
185 _M_h._M_deallocate_node_ptr(_M_ptr);
189 template<
typename _NodeAlloc>
190 struct _Hashtable_alloc;
194 template<
typename _NodeAlloc>
195 struct _ReuseOrAllocNode
198 using __node_alloc_type = _NodeAlloc;
199 using __hashtable_alloc = _Hashtable_alloc<__node_alloc_type>;
200 using __node_alloc_traits =
201 typename __hashtable_alloc::__node_alloc_traits;
204 using __node_ptr =
typename __hashtable_alloc::__node_ptr;
206 _ReuseOrAllocNode(__node_ptr __nodes, __hashtable_alloc& __h)
207 : _M_nodes(__nodes), _M_h(__h) { }
208 _ReuseOrAllocNode(
const _ReuseOrAllocNode&) =
delete;
211 { _M_h._M_deallocate_nodes(_M_nodes); }
213 template<
typename... _Args>
215 operator()(_Args&&... __args)
const
220 __node_ptr __node = _M_nodes;
221 _M_nodes = _M_nodes->_M_next();
222 __node->_M_nxt =
nullptr;
223 auto& __a = _M_h._M_node_allocator();
224 __node_alloc_traits::destroy(__a, __node->_M_valptr());
225 _NodePtrGuard<__hashtable_alloc, __node_ptr> __guard { _M_h, __node };
226 __node_alloc_traits::construct(__a, __node->_M_valptr(),
228 __guard._M_ptr =
nullptr;
233 mutable __node_ptr _M_nodes;
234 __hashtable_alloc& _M_h;
239 template<
typename _NodeAlloc>
243 using __hashtable_alloc = _Hashtable_alloc<_NodeAlloc>;
246 using __node_ptr =
typename __hashtable_alloc::__node_ptr;
248 _AllocNode(__hashtable_alloc& __h)
251 template<
typename... _Args>
253 operator()(_Args&&... __args)
const
257 __hashtable_alloc& _M_h;
285 template<
bool _Cache_hash_code,
bool _Constant_iterators,
bool _Unique_keys>
286 struct _Hashtable_traits
288 using __hash_cached = __bool_constant<_Cache_hash_code>;
289 using __constant_iterators = __bool_constant<_Constant_iterators>;
290 using __unique_keys = __bool_constant<_Unique_keys>;
299 template<
typename _Hash>
300 struct _Hashtable_hash_traits
302 static constexpr std::size_t
303 __small_size_threshold() noexcept
315 struct _Hash_node_base
317 _Hash_node_base* _M_nxt;
319 _Hash_node_base() noexcept : _M_nxt() { }
321 _Hash_node_base(_Hash_node_base* __next) noexcept : _M_nxt(__next) { }
329 template<
typename _Value>
330 struct _Hash_node_value_base
332 typedef _Value value_type;
334 __gnu_cxx::__aligned_buffer<_Value> _M_storage;
336 [[__gnu__::__always_inline__]]
339 {
return _M_storage._M_ptr(); }
341 [[__gnu__::__always_inline__]]
343 _M_valptr() const noexcept
344 {
return _M_storage._M_ptr(); }
346 [[__gnu__::__always_inline__]]
349 {
return *_M_valptr(); }
351 [[__gnu__::__always_inline__]]
353 _M_v() const noexcept
354 {
return *_M_valptr(); }
360 template<
bool _Cache_hash_code>
361 struct _Hash_node_code_cache
368 struct _Hash_node_code_cache<true>
369 { std::size_t _M_hash_code; };
371 template<
typename _Value,
bool _Cache_hash_code>
372 struct _Hash_node_value
373 : _Hash_node_value_base<_Value>
374 , _Hash_node_code_cache<_Cache_hash_code>
380 template<
typename _Value,
bool _Cache_hash_code>
383 , _Hash_node_value<_Value, _Cache_hash_code>
386 _M_next() const noexcept
387 {
return static_cast<_Hash_node*
>(this->_M_nxt); }
391 template<
typename _Value,
bool _Cache_hash_code>
392 struct _Node_iterator_base
394 using __node_type = _Hash_node<_Value, _Cache_hash_code>;
398 _Node_iterator_base() : _M_cur(nullptr) { }
399 _Node_iterator_base(__node_type* __p) noexcept
404 { _M_cur = _M_cur->_M_next(); }
407 operator==(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
409 {
return __x._M_cur == __y._M_cur; }
411#if __cpp_impl_three_way_comparison < 201907L
413 operator!=(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
415 {
return __x._M_cur != __y._M_cur; }
420 template<
typename _Value,
bool __constant_iterators,
bool __cache>
421 struct _Node_iterator
422 :
public _Node_iterator_base<_Value, __cache>
425 using __base_type = _Node_iterator_base<_Value, __cache>;
426 using __node_type =
typename __base_type::__node_type;
429 using value_type = _Value;
430 using difference_type = std::ptrdiff_t;
433 using pointer = __conditional_t<__constant_iterators,
434 const value_type*, value_type*>;
436 using reference = __conditional_t<__constant_iterators,
437 const value_type&, value_type&>;
439 _Node_iterator() =
default;
442 _Node_iterator(__node_type* __p) noexcept
443 : __base_type(__p) { }
447 {
return this->_M_cur->_M_v(); }
450 operator->() const noexcept
451 {
return this->_M_cur->_M_valptr(); }
454 operator++() noexcept
461 operator++(
int)
noexcept
463 _Node_iterator __tmp(*
this);
470 template<
typename _Value,
bool __constant_iterators,
bool __cache>
471 struct _Node_const_iterator
472 :
public _Node_iterator_base<_Value, __cache>
475 using __base_type = _Node_iterator_base<_Value, __cache>;
476 using __node_type =
typename __base_type::__node_type;
479 typedef _Value value_type;
480 typedef std::ptrdiff_t difference_type;
483 typedef const value_type* pointer;
484 typedef const value_type& reference;
486 _Node_const_iterator() =
default;
489 _Node_const_iterator(__node_type* __p) noexcept
490 : __base_type(__p) { }
492 _Node_const_iterator(
const _Node_iterator<_Value, __constant_iterators,
493 __cache>& __x) noexcept
494 : __base_type(__x._M_cur) { }
498 {
return this->_M_cur->_M_v(); }
501 operator->() const noexcept
502 {
return this->_M_cur->_M_valptr(); }
504 _Node_const_iterator&
505 operator++() noexcept
512 operator++(
int)
noexcept
514 _Node_const_iterator __tmp(*
this);
525 struct _Mod_range_hashing
527 typedef std::size_t first_argument_type;
528 typedef std::size_t second_argument_type;
529 typedef std::size_t result_type;
532 operator()(first_argument_type __num,
533 second_argument_type __den)
const noexcept
534 {
return __num % __den; }
542 struct _Default_ranged_hash { };
546 struct _Prime_rehash_policy
548 using __has_load_factor = true_type;
550 _Prime_rehash_policy(
float __z = 1.0) noexcept
551 : _M_max_load_factor(__z), _M_next_resize(0) { }
554 max_load_factor() const noexcept
555 {
return _M_max_load_factor; }
559 _M_next_bkt(std::size_t __n)
const;
563 _M_bkt_for_elements(std::size_t __n)
const
564 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
571 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
572 std::size_t __n_ins)
const;
574 typedef std::size_t _State;
578 {
return _M_next_resize; }
582 { _M_next_resize = 0; }
585 _M_reset(_State __state)
586 { _M_next_resize = __state; }
588 static const std::size_t _S_growth_factor = 2;
590 float _M_max_load_factor;
591 mutable std::size_t _M_next_resize;
595 struct _Mask_range_hashing
597 typedef std::size_t first_argument_type;
598 typedef std::size_t second_argument_type;
599 typedef std::size_t result_type;
602 operator()(first_argument_type __num,
603 second_argument_type __den)
const noexcept
604 {
return __num & (__den - 1); }
609 __clp2(std::size_t __n)
noexcept
615 const unsigned __lz =
sizeof(size_t) >
sizeof(
long)
616 ? __builtin_clzll(__n - 1ull)
617 : __builtin_clzl(__n - 1ul);
619 return (
size_t(1) << (__int_traits<size_t>::__digits - __lz - 1)) << 1;
624 struct _Power2_rehash_policy
626 using __has_load_factor = true_type;
628 _Power2_rehash_policy(
float __z = 1.0) noexcept
629 : _M_max_load_factor(__z), _M_next_resize(0) { }
632 max_load_factor() const noexcept
633 {
return _M_max_load_factor; }
638 _M_next_bkt(std::size_t __n)
noexcept
647 const auto __max_bkt = size_t(1) << (__max_width * __CHAR_BIT__ - 1);
648 std::size_t __res = __clp2(__n);
658 if (__res == __max_bkt)
662 _M_next_resize = size_t(-1);
665 = __builtin_floor(__res * (
double)_M_max_load_factor);
672 _M_bkt_for_elements(std::size_t __n)
const noexcept
673 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
680 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
681 std::size_t __n_ins)
noexcept
683 if (__n_elt + __n_ins > _M_next_resize)
690 / (double)_M_max_load_factor;
691 if (__min_bkts >= __n_bkt)
694 __n_bkt * _S_growth_factor)) };
697 = __builtin_floor(__n_bkt * (
double)_M_max_load_factor);
704 typedef std::size_t _State;
707 _M_state() const noexcept
708 {
return _M_next_resize; }
712 { _M_next_resize = 0; }
715 _M_reset(_State __state)
noexcept
716 { _M_next_resize = __state; }
718 static const std::size_t _S_growth_factor = 2;
720 float _M_max_load_factor;
721 std::size_t _M_next_resize;
724 template<
typename _RehashPolicy>
725 struct _RehashStateGuard
727 _RehashPolicy* _M_guarded_obj;
728 typename _RehashPolicy::_State _M_prev_state;
730 _RehashStateGuard(_RehashPolicy& __policy)
732 , _M_prev_state(__policy._M_state())
734 _RehashStateGuard(
const _RehashStateGuard&) =
delete;
739 _M_guarded_obj->_M_reset(_M_prev_state);
761 template<
typename _Key,
typename _Value,
typename _Alloc,
762 typename _ExtractKey,
typename _Equal,
763 typename _Hash,
typename _RangeHash,
typename _Unused,
764 typename _RehashPolicy,
typename _Traits,
765 bool _Unique_keys = _Traits::__unique_keys::value>
766 struct _Map_base { };
769 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
770 typename _Hash,
typename _RangeHash,
typename _Unused,
771 typename _RehashPolicy,
typename _Traits>
772 struct _Map_base<_Key,
pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
773 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
775 using mapped_type = _Val;
779 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
780 typename _Hash,
typename _RangeHash,
typename _Unused,
781 typename _RehashPolicy,
typename _Traits>
782 struct _Map_base<_Key,
pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
783 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
786 using __hashtable_base = _Hashtable_base<_Key, pair<const _Key, _Val>,
787 _Select1st, _Equal, _Hash,
791 using __hashtable = _Hashtable<_Key, pair<const _Key, _Val>, _Alloc,
792 _Select1st, _Equal, _Hash, _RangeHash,
793 _Unused, _RehashPolicy, _Traits>;
795 using __hash_code =
typename __hashtable_base::__hash_code;
798 using key_type =
typename __hashtable_base::key_type;
799 using mapped_type = _Val;
802 operator[](
const key_type& __k);
805 operator[](key_type&& __k);
810 at(
const key_type& __k)
812 auto __ite =
static_cast<__hashtable*
>(
this)->find(__k);
814 __throw_out_of_range(__N(
"unordered_map::at"));
815 return __ite->second;
819 at(
const key_type& __k)
const
821 auto __ite =
static_cast<const __hashtable*
>(
this)->find(__k);
823 __throw_out_of_range(__N(
"unordered_map::at"));
824 return __ite->second;
828 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
829 typename _Hash,
typename _RangeHash,
typename _Unused,
830 typename _RehashPolicy,
typename _Traits>
832 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
833 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
834 operator[](
const key_type& __k)
837 __hashtable* __h =
static_cast<__hashtable*
>(
this);
838 __hash_code __code = __h->_M_hash_code(__k);
839 std::size_t __bkt = __h->_M_bucket_index(__code);
840 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
841 return __node->_M_v().second;
843 typename __hashtable::_Scoped_node __node {
850 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
851 __node._M_node =
nullptr;
852 return __pos->second;
855 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
856 typename _Hash,
typename _RangeHash,
typename _Unused,
857 typename _RehashPolicy,
typename _Traits>
859 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
860 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
861 operator[](key_type&& __k)
864 __hashtable* __h =
static_cast<__hashtable*
>(
this);
865 __hash_code __code = __h->_M_hash_code(__k);
866 std::size_t __bkt = __h->_M_bucket_index(__code);
867 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
868 return __node->_M_v().second;
870 typename __hashtable::_Scoped_node __node {
877 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
878 __node._M_node =
nullptr;
879 return __pos->second;
883 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
884 typename _Hash,
typename _RangeHash,
typename _Unused,
885 typename _RehashPolicy,
typename _Traits,
bool __uniq>
886 struct _Map_base<const _Key,
pair<const _Key, _Val>,
887 _Alloc, _Select1st, _Equal, _Hash,
888 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
889 : _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal, _Hash,
890 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
898 template<
typename _Key,
typename _Value,
typename _Alloc,
899 typename _ExtractKey,
typename _Equal,
900 typename _Hash,
typename _RangeHash,
typename _Unused,
901 typename _RehashPolicy,
typename _Traits>
905 using __hashtable_base = _Hashtable_base<_Key, _Value, _ExtractKey,
906 _Equal, _Hash, _RangeHash,
909 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
911 _Unused, _RehashPolicy, _Traits>;
913 using __hash_cached =
typename _Traits::__hash_cached;
914 using __constant_iterators =
typename _Traits::__constant_iterators;
916 using __hashtable_alloc = _Hashtable_alloc<
917 __alloc_rebind<_Alloc, _Hash_node<_Value,
918 __hash_cached::value>>>;
920 using value_type =
typename __hashtable_base::value_type;
921 using size_type =
typename __hashtable_base::size_type;
923 using __unique_keys =
typename _Traits::__unique_keys;
924 using __node_alloc_type =
typename __hashtable_alloc::__node_alloc_type;
925 using __node_gen_type = _AllocNode<__node_alloc_type>;
928 _M_conjure_hashtable()
929 {
return *(
static_cast<__hashtable*
>(
this)); }
931 template<
typename _InputIterator,
typename _NodeGetter>
933 _M_insert_range(_InputIterator __first, _InputIterator __last,
934 const _NodeGetter&, true_type __uks);
936 template<
typename _InputIterator,
typename _NodeGetter>
938 _M_insert_range(_InputIterator __first, _InputIterator __last,
939 const _NodeGetter&, false_type __uks);
942 using iterator = _Node_iterator<_Value, __constant_iterators::value,
943 __hash_cached::value>;
945 using const_iterator = _Node_const_iterator<_Value,
946 __constant_iterators::value,
947 __hash_cached::value>;
949 using __ireturn_type = __conditional_t<__unique_keys::value,
954 insert(
const value_type& __v)
956 __hashtable& __h = _M_conjure_hashtable();
957 __node_gen_type __node_gen(__h);
958 return __h._M_insert(__v, __node_gen, __unique_keys{});
962 insert(const_iterator __hint,
const value_type& __v)
964 __hashtable& __h = _M_conjure_hashtable();
965 __node_gen_type __node_gen(__h);
966 return __h._M_insert(__hint, __v, __node_gen, __unique_keys{});
969#ifdef __glibcxx_unordered_map_try_emplace
970 template<
typename _KType,
typename... _Args>
972 try_emplace(const_iterator, _KType&& __k, _Args&&... __args)
974 __hashtable& __h = _M_conjure_hashtable();
975 auto __code = __h._M_hash_code(__k);
976 std::size_t __bkt = __h._M_bucket_index(__code);
977 if (
auto __node = __h._M_find_node(__bkt, __k, __code))
978 return { iterator(__node),
false };
980 typename __hashtable::_Scoped_node __node {
987 = __h._M_insert_unique_node(__bkt, __code, __node._M_node);
988 __node._M_node =
nullptr;
989 return { __it,
true };
994 insert(initializer_list<value_type> __l)
995 { this->insert(__l.begin(), __l.end()); }
997 template<
typename _InputIterator>
999 insert(_InputIterator __first, _InputIterator __last)
1001 __hashtable& __h = _M_conjure_hashtable();
1002 __node_gen_type __node_gen(__h);
1003 return _M_insert_range(__first, __last, __node_gen, __unique_keys{});
1007 template<
typename _Key,
typename _Value,
typename _Alloc,
1008 typename _ExtractKey,
typename _Equal,
1009 typename _Hash,
typename _RangeHash,
typename _Unused,
1010 typename _RehashPolicy,
typename _Traits>
1011 template<
typename _InputIterator,
typename _NodeGetter>
1013 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1014 _Hash, _RangeHash, _Unused,
1015 _RehashPolicy, _Traits>::
1016 _M_insert_range(_InputIterator __first, _InputIterator __last,
1017 const _NodeGetter& __node_gen, true_type __uks)
1019 __hashtable& __h = _M_conjure_hashtable();
1020 for (; __first != __last; ++__first)
1021 __h._M_insert(*__first, __node_gen, __uks);
1024 template<
typename _Key,
typename _Value,
typename _Alloc,
1025 typename _ExtractKey,
typename _Equal,
1026 typename _Hash,
typename _RangeHash,
typename _Unused,
1027 typename _RehashPolicy,
typename _Traits>
1028 template<
typename _InputIterator,
typename _NodeGetter>
1030 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1031 _Hash, _RangeHash, _Unused,
1032 _RehashPolicy, _Traits>::
1033 _M_insert_range(_InputIterator __first, _InputIterator __last,
1034 const _NodeGetter& __node_gen, false_type __uks)
1036 using __rehash_guard_t =
typename __hashtable::__rehash_guard_t;
1039 size_type __n_elt = __detail::__distance_fw(__first, __last);
1043 __hashtable& __h = _M_conjure_hashtable();
1044 __rehash_guard_t __rehash_guard(__h._M_rehash_policy);
1045 __pair_type __do_rehash
1046 = __h._M_rehash_policy._M_need_rehash(__h._M_bucket_count,
1047 __h._M_element_count,
1050 if (__do_rehash.first)
1051 __h._M_rehash(__do_rehash.second, __uks);
1053 __rehash_guard._M_guarded_obj =
nullptr;
1054 for (; __first != __last; ++__first)
1055 __h._M_insert(*__first, __node_gen, __uks);
1064 template<
typename _Key,
typename _Value,
typename _Alloc,
1065 typename _ExtractKey,
typename _Equal,
1066 typename _Hash,
typename _RangeHash,
typename _Unused,
1067 typename _RehashPolicy,
typename _Traits,
1068 bool _Constant_iterators = _Traits::__constant_iterators::value>
1072 template<
typename _Key,
typename _Value,
typename _Alloc,
1073 typename _ExtractKey,
typename _Equal,
1074 typename _Hash,
typename _RangeHash,
typename _Unused,
1075 typename _RehashPolicy,
typename _Traits>
1076 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1077 _Hash, _RangeHash, _Unused,
1078 _RehashPolicy, _Traits, true>
1079 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1080 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1082 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1083 _Equal, _Hash, _RangeHash, _Unused,
1084 _RehashPolicy, _Traits>;
1086 using value_type =
typename __base_type::value_type;
1087 using iterator =
typename __base_type::iterator;
1088 using const_iterator =
typename __base_type::const_iterator;
1089 using __ireturn_type =
typename __base_type::__ireturn_type;
1091 using __unique_keys =
typename __base_type::__unique_keys;
1092 using __hashtable =
typename __base_type::__hashtable;
1093 using __node_gen_type =
typename __base_type::__node_gen_type;
1095 using __base_type::insert;
1098 insert(value_type&& __v)
1100 __hashtable& __h = this->_M_conjure_hashtable();
1101 __node_gen_type __node_gen(__h);
1102 return __h._M_insert(
std::move(__v), __node_gen, __unique_keys{});
1106 insert(const_iterator __hint, value_type&& __v)
1108 __hashtable& __h = this->_M_conjure_hashtable();
1109 __node_gen_type __node_gen(__h);
1110 return __h._M_insert(__hint,
std::move(__v), __node_gen,
1116 template<
typename _Key,
typename _Value,
typename _Alloc,
1117 typename _ExtractKey,
typename _Equal,
1118 typename _Hash,
typename _RangeHash,
typename _Unused,
1119 typename _RehashPolicy,
typename _Traits>
1120 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1121 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1122 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1123 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1125 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1126 _Equal, _Hash, _RangeHash, _Unused,
1127 _RehashPolicy, _Traits>;
1128 using value_type =
typename __base_type::value_type;
1129 using iterator =
typename __base_type::iterator;
1130 using const_iterator =
typename __base_type::const_iterator;
1132 using __unique_keys =
typename __base_type::__unique_keys;
1133 using __hashtable =
typename __base_type::__hashtable;
1134 using __ireturn_type =
typename __base_type::__ireturn_type;
1136 using __base_type::insert;
1138 template<
typename _Pair>
1141 template<
typename _Pair>
1144 template<
typename _Pair>
1145 using _IFconsp =
typename _IFcons<_Pair>::type;
1147 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1151 __hashtable& __h = this->_M_conjure_hashtable();
1155 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1157 insert(const_iterator __hint, _Pair&& __v)
1159 __hashtable& __h = this->_M_conjure_hashtable();
1160 return __h._M_emplace(__hint, __unique_keys{},
1165 template<
typename _Policy>
1166 using __has_load_factor =
typename _Policy::__has_load_factor;
1174 template<
typename _Key,
typename _Value,
typename _Alloc,
1175 typename _ExtractKey,
typename _Equal,
1176 typename _Hash,
typename _RangeHash,
typename _Unused,
1177 typename _RehashPolicy,
typename _Traits,
1179 __detected_or_t<false_type, __has_load_factor, _RehashPolicy>>
1180 struct _Rehash_base;
1183 template<
typename _Key,
typename _Value,
typename _Alloc,
1184 typename _ExtractKey,
typename _Equal,
1185 typename _Hash,
typename _RangeHash,
typename _Unused,
1186 typename _RehashPolicy,
typename _Traits>
1187 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1188 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1194 template<
typename _Key,
typename _Value,
typename _Alloc,
1195 typename _ExtractKey,
typename _Equal,
1196 typename _Hash,
typename _RangeHash,
typename _Unused,
1197 typename _RehashPolicy,
typename _Traits>
1198 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1199 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1203 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey,
1204 _Equal, _Hash, _RangeHash, _Unused,
1205 _RehashPolicy, _Traits>;
1209 max_load_factor() const noexcept
1211 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1212 return __this->__rehash_policy().max_load_factor();
1216 max_load_factor(
float __z)
1218 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1219 __this->__rehash_policy(_RehashPolicy(__z));
1223 reserve(std::size_t __n)
1225 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1226 __this->rehash(__this->__rehash_policy()._M_bkt_for_elements(__n));
1236 template<
int _Nm,
typename _Tp,
1237 bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
1238 struct _Hashtable_ebo_helper;
1241 template<
int _Nm,
typename _Tp>
1242 struct _Hashtable_ebo_helper<_Nm, _Tp, true>
1245 _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
1247 template<
typename _OtherTp>
1248 _Hashtable_ebo_helper(_OtherTp&& __tp)
1252 const _Tp& _M_cget()
const {
return static_cast<const _Tp&
>(*this); }
1253 _Tp& _M_get() {
return static_cast<_Tp&
>(*this); }
1257 template<
int _Nm,
typename _Tp>
1258 struct _Hashtable_ebo_helper<_Nm, _Tp, false>
1260 _Hashtable_ebo_helper() =
default;
1262 template<
typename _OtherTp>
1263 _Hashtable_ebo_helper(_OtherTp&& __tp)
1267 const _Tp& _M_cget()
const {
return _M_tp; }
1268 _Tp& _M_get() {
return _M_tp; }
1280 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1281 typename _Hash,
typename _RangeHash,
typename _Unused,
1282 bool __cache_hash_code>
1283 struct _Local_iterator_base;
1303 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1304 typename _Hash,
typename _RangeHash,
typename _Unused,
1305 bool __cache_hash_code>
1306 struct _Hash_code_base
1307 :
private _Hashtable_ebo_helper<1, _Hash>
1310 using __ebo_hash = _Hashtable_ebo_helper<1, _Hash>;
1313 friend struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1314 _Hash, _RangeHash, _Unused, false>;
1317 typedef _Hash hasher;
1320 hash_function()
const
1321 {
return _M_hash(); }
1324 typedef std::size_t __hash_code;
1328 _Hash_code_base() =
default;
1330 _Hash_code_base(
const _Hash& __hash) : __ebo_hash(__hash) { }
1333 _M_hash_code(
const _Key& __k)
const
1335 static_assert(__is_invocable<const _Hash&, const _Key&>{},
1336 "hash function must be invocable with an argument of key type");
1337 return _M_hash()(__k);
1340 template<
typename _Kt>
1342 _M_hash_code_tr(
const _Kt& __k)
const
1344 static_assert(__is_invocable<const _Hash&, const _Kt&>{},
1345 "hash function must be invocable with an argument of key type");
1346 return _M_hash()(__k);
1350 _M_hash_code(
const _Hash_node_value<_Value, false>& __n)
const
1351 {
return _M_hash_code(_ExtractKey{}(__n._M_v())); }
1354 _M_hash_code(
const _Hash_node_value<_Value, true>& __n)
const
1355 {
return __n._M_hash_code; }
1358 _M_bucket_index(__hash_code __c, std::size_t __bkt_count)
const
1359 {
return _RangeHash{}(__c, __bkt_count); }
1362 _M_bucket_index(
const _Hash_node_value<_Value, false>& __n,
1363 std::size_t __bkt_count)
const
1364 noexcept(
noexcept(declval<const _Hash&>()(declval<const _Key&>()))
1365 &&
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1368 return _RangeHash{}(_M_hash_code(_ExtractKey{}(__n._M_v())),
1373 _M_bucket_index(
const _Hash_node_value<_Value, true>& __n,
1374 std::size_t __bkt_count)
const
1375 noexcept(
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1377 {
return _RangeHash{}(__n._M_hash_code, __bkt_count); }
1380 _M_store_code(_Hash_node_code_cache<false>&, __hash_code)
const
1384 _M_copy_code(_Hash_node_code_cache<false>&,
1385 const _Hash_node_code_cache<false>&)
const
1389 _M_store_code(_Hash_node_code_cache<true>& __n, __hash_code __c)
const
1390 { __n._M_hash_code = __c; }
1393 _M_copy_code(_Hash_node_code_cache<true>& __to,
1394 const _Hash_node_code_cache<true>& __from)
const
1395 { __to._M_hash_code = __from._M_hash_code; }
1398 _M_swap(_Hash_code_base& __x)
1399 { std::swap(__ebo_hash::_M_get(), __x.__ebo_hash::_M_get()); }
1402 _M_hash()
const {
return __ebo_hash::_M_cget(); }
1406 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1407 typename _Hash,
typename _RangeHash,
typename _Unused>
1408 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1409 _Hash, _RangeHash, _Unused, true>
1410 :
public _Node_iterator_base<_Value, true>
1413 using __base_node_iter = _Node_iterator_base<_Value, true>;
1414 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1415 _Hash, _RangeHash, _Unused,
true>;
1417 _Local_iterator_base() =
default;
1418 _Local_iterator_base(
const __hash_code_base&,
1419 _Hash_node<_Value, true>* __p,
1420 std::size_t __bkt, std::size_t __bkt_count)
1421 : __base_node_iter(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1427 __base_node_iter::_M_incr();
1431 = _RangeHash{}(this->_M_cur->_M_hash_code, _M_bucket_count);
1432 if (__bkt != _M_bucket)
1433 this->_M_cur =
nullptr;
1437 std::size_t _M_bucket;
1438 std::size_t _M_bucket_count;
1442 _M_get_bucket()
const {
return _M_bucket; }
1449 template<typename _Tp, bool _IsEmpty = std::is_empty<_Tp>::value>
1450 struct _Hash_code_storage
1452 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
1455 _M_h() {
return _M_storage._M_ptr(); }
1458 _M_h()
const {
return _M_storage._M_ptr(); }
1462 template<
typename _Tp>
1463 struct _Hash_code_storage<_Tp, true>
1470 _M_h() {
return reinterpret_cast<_Tp*
>(
this); }
1473 _M_h()
const {
return reinterpret_cast<const _Tp*
>(
this); }
1476 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1477 typename _Hash,
typename _RangeHash,
typename _Unused>
1478 using __hash_code_for_local_iter
1479 = _Hash_code_storage<_Hash_code_base<_Key, _Value, _ExtractKey,
1480 _Hash, _RangeHash, _Unused,
false>>;
1483 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1484 typename _Hash,
typename _RangeHash,
typename _Unused>
1485 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1486 _Hash, _RangeHash, _Unused, false>
1487 : __hash_code_for_local_iter<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1489 , _Node_iterator_base<_Value, false>
1492 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1493 _Hash, _RangeHash, _Unused,
false>;
1494 using __node_iter_base = _Node_iterator_base<_Value, false>;
1496 _Local_iterator_base() : _M_bucket_count(-1) { }
1498 _Local_iterator_base(
const __hash_code_base& __base,
1499 _Hash_node<_Value, false>* __p,
1500 std::size_t __bkt, std::size_t __bkt_count)
1501 : __node_iter_base(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1502 { _M_init(__base); }
1504 ~_Local_iterator_base()
1506 if (_M_bucket_count !=
size_t(-1))
1510 _Local_iterator_base(
const _Local_iterator_base& __iter)
1511 : __node_iter_base(__iter._M_cur), _M_bucket(__iter._M_bucket)
1512 , _M_bucket_count(__iter._M_bucket_count)
1514 if (_M_bucket_count !=
size_t(-1))
1515 _M_init(*__iter._M_h());
1518 _Local_iterator_base&
1519 operator=(
const _Local_iterator_base& __iter)
1521 if (_M_bucket_count != -1)
1523 this->_M_cur = __iter._M_cur;
1524 _M_bucket = __iter._M_bucket;
1525 _M_bucket_count = __iter._M_bucket_count;
1526 if (_M_bucket_count != -1)
1527 _M_init(*__iter._M_h());
1534 __node_iter_base::_M_incr();
1537 std::size_t __bkt = this->_M_h()->_M_bucket_index(*this->_M_cur,
1539 if (__bkt != _M_bucket)
1540 this->_M_cur =
nullptr;
1544 std::size_t _M_bucket;
1545 std::size_t _M_bucket_count;
1548 _M_init(
const __hash_code_base& __base)
1549 { ::new(this->_M_h()) __hash_code_base(__base); }
1552 _M_destroy() { this->_M_h()->~__hash_code_base(); }
1556 _M_get_bucket()
const {
return _M_bucket; }
1560 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1561 typename _Hash,
typename _RangeHash,
typename _Unused,
1562 bool __constant_iterators,
bool __cache>
1563 struct _Local_iterator
1564 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1565 _Hash, _RangeHash, _Unused, __cache>
1568 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1569 _Hash, _RangeHash, _Unused, __cache>;
1570 using __hash_code_base =
typename __base_type::__hash_code_base;
1573 using value_type = _Value;
1574 using pointer = __conditional_t<__constant_iterators,
1575 const value_type*, value_type*>;
1576 using reference = __conditional_t<__constant_iterators,
1577 const value_type&, value_type&>;
1578 using difference_type = ptrdiff_t;
1579 using iterator_category = forward_iterator_tag;
1581 _Local_iterator() =
default;
1583 _Local_iterator(
const __hash_code_base& __base,
1584 _Hash_node<_Value, __cache>* __n,
1585 std::size_t __bkt, std::size_t __bkt_count)
1586 : __base_type(
__base, __n, __bkt, __bkt_count)
1591 {
return this->_M_cur->_M_v(); }
1595 {
return this->_M_cur->_M_valptr(); }
1607 _Local_iterator __tmp(*
this);
1614 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1615 typename _Hash,
typename _RangeHash,
typename _Unused,
1616 bool __constant_iterators,
bool __cache>
1617 struct _Local_const_iterator
1618 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1619 _Hash, _RangeHash, _Unused, __cache>
1622 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1623 _Hash, _RangeHash, _Unused, __cache>;
1624 using __hash_code_base =
typename __base_type::__hash_code_base;
1627 typedef _Value value_type;
1628 typedef const value_type* pointer;
1629 typedef const value_type& reference;
1630 typedef std::ptrdiff_t difference_type;
1633 _Local_const_iterator() =
default;
1635 _Local_const_iterator(
const __hash_code_base& __base,
1636 _Hash_node<_Value, __cache>* __n,
1637 std::size_t __bkt, std::size_t __bkt_count)
1638 : __base_type(
__base, __n, __bkt, __bkt_count)
1641 _Local_const_iterator(
const _Local_iterator<_Key, _Value, _ExtractKey,
1642 _Hash, _RangeHash, _Unused,
1643 __constant_iterators,
1650 {
return this->_M_cur->_M_v(); }
1654 {
return this->_M_cur->_M_valptr(); }
1656 _Local_const_iterator&
1663 _Local_const_iterator
1666 _Local_const_iterator __tmp(*
this);
1682 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1683 typename _Equal,
typename _Hash,
typename _RangeHash,
1684 typename _Unused,
typename _Traits>
1685 struct _Hashtable_base
1686 :
public _Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1687 _Unused, _Traits::__hash_cached::value>,
1688 private _Hashtable_ebo_helper<0, _Equal>
1691 typedef _Key key_type;
1692 typedef _Value value_type;
1693 typedef _Equal key_equal;
1694 typedef std::size_t size_type;
1695 typedef std::ptrdiff_t difference_type;
1697 using __traits_type = _Traits;
1698 using __hash_cached =
typename __traits_type::__hash_cached;
1700 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1701 _Hash, _RangeHash, _Unused,
1702 __hash_cached::value>;
1704 using __hash_code =
typename __hash_code_base::__hash_code;
1707 using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>;
1710 _S_equals(__hash_code,
const _Hash_node_code_cache<false>&)
1714 _S_node_equals(
const _Hash_node_code_cache<false>&,
1715 const _Hash_node_code_cache<false>&)
1719 _S_equals(__hash_code __c,
const _Hash_node_code_cache<true>& __n)
1720 {
return __c == __n._M_hash_code; }
1723 _S_node_equals(
const _Hash_node_code_cache<true>& __lhn,
1724 const _Hash_node_code_cache<true>& __rhn)
1725 {
return __lhn._M_hash_code == __rhn._M_hash_code; }
1728 _Hashtable_base() =
default;
1730 _Hashtable_base(
const _Hash& __hash,
const _Equal& __eq)
1731 : __hash_code_base(__hash), _EqualEBO(__eq)
1735 _M_key_equals(
const _Key& __k,
1736 const _Hash_node_value<_Value,
1737 __hash_cached::value>& __n)
const
1739 static_assert(__is_invocable<const _Equal&, const _Key&, const _Key&>{},
1740 "key equality predicate must be invocable with two arguments of "
1742 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1745 template<
typename _Kt>
1747 _M_key_equals_tr(
const _Kt& __k,
1748 const _Hash_node_value<_Value,
1749 __hash_cached::value>& __n)
const
1752 __is_invocable<const _Equal&, const _Kt&, const _Key&>{},
1753 "key equality predicate must be invocable with two arguments of "
1755 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1759 _M_equals(
const _Key& __k, __hash_code __c,
1760 const _Hash_node_value<_Value, __hash_cached::value>& __n)
const
1761 {
return _S_equals(__c, __n) && _M_key_equals(__k, __n); }
1763 template<
typename _Kt>
1765 _M_equals_tr(
const _Kt& __k, __hash_code __c,
1766 const _Hash_node_value<_Value,
1767 __hash_cached::value>& __n)
const
1768 {
return _S_equals(__c, __n) && _M_key_equals_tr(__k, __n); }
1772 const _Hash_node_value<_Value, __hash_cached::value>& __lhn,
1773 const _Hash_node_value<_Value, __hash_cached::value>& __rhn)
const
1775 return _S_node_equals(__lhn, __rhn)
1776 && _M_key_equals(_ExtractKey{}(__lhn._M_v()), __rhn);
1780 _M_swap(_Hashtable_base& __x)
1782 __hash_code_base::_M_swap(__x);
1783 std::swap(_EqualEBO::_M_get(), __x._EqualEBO::_M_get());
1787 _M_eq()
const {
return _EqualEBO::_M_cget(); }
1798 template<
typename _Key,
typename _Value,
typename _Alloc,
1799 typename _ExtractKey,
typename _Equal,
1800 typename _Hash,
typename _RangeHash,
typename _Unused,
1801 typename _RehashPolicy,
typename _Traits,
1802 bool _Unique_keys = _Traits::__unique_keys::value>
1806 template<
typename _Key,
typename _Value,
typename _Alloc,
1807 typename _ExtractKey,
typename _Equal,
1808 typename _Hash,
typename _RangeHash,
typename _Unused,
1809 typename _RehashPolicy,
typename _Traits>
1810 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1811 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
1813 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1814 _Hash, _RangeHash, _Unused,
1815 _RehashPolicy, _Traits>;
1818 _M_equal(
const __hashtable&)
const;
1821 template<
typename _Key,
typename _Value,
typename _Alloc,
1822 typename _ExtractKey,
typename _Equal,
1823 typename _Hash,
typename _RangeHash,
typename _Unused,
1824 typename _RehashPolicy,
typename _Traits>
1826 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1827 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
1828 _M_equal(
const __hashtable& __other)
const
1830 using __node_ptr =
typename __hashtable::__node_ptr;
1831 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1832 if (__this->size() != __other.size())
1835 for (
auto __x_n = __this->_M_begin(); __x_n; __x_n = __x_n->_M_next())
1837 std::size_t __ybkt = __other._M_bucket_index(*__x_n);
1838 auto __prev_n = __other._M_buckets[__ybkt];
1842 for (__node_ptr __n =
static_cast<__node_ptr
>(__prev_n->_M_nxt);;
1843 __n = __n->_M_next())
1845 if (__n->_M_v() == __x_n->_M_v())
1849 || __other._M_bucket_index(*__n->_M_next()) != __ybkt)
1858 template<
typename _Key,
typename _Value,
typename _Alloc,
1859 typename _ExtractKey,
typename _Equal,
1860 typename _Hash,
typename _RangeHash,
typename _Unused,
1861 typename _RehashPolicy,
typename _Traits>
1862 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1863 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1865 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1866 _Hash, _RangeHash, _Unused,
1867 _RehashPolicy, _Traits>;
1870 _M_equal(
const __hashtable&)
const;
1873 template<
typename _Key,
typename _Value,
typename _Alloc,
1874 typename _ExtractKey,
typename _Equal,
1875 typename _Hash,
typename _RangeHash,
typename _Unused,
1876 typename _RehashPolicy,
typename _Traits>
1878 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1879 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
false>::
1880 _M_equal(
const __hashtable& __other)
const
1882 using __node_ptr =
typename __hashtable::__node_ptr;
1883 using const_iterator =
typename __hashtable::const_iterator;
1884 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1885 if (__this->size() != __other.size())
1888 for (
auto __x_n = __this->_M_begin(); __x_n;)
1890 std::size_t __x_count = 1;
1891 auto __x_n_end = __x_n->_M_next();
1893 && __this->key_eq()(_ExtractKey{}(__x_n->_M_v()),
1894 _ExtractKey{}(__x_n_end->_M_v()));
1895 __x_n_end = __x_n_end->_M_next())
1898 std::size_t __ybkt = __other._M_bucket_index(*__x_n);
1899 auto __y_prev_n = __other._M_buckets[__ybkt];
1903 __node_ptr __y_n =
static_cast<__node_ptr
>(__y_prev_n->_M_nxt);
1906 if (__this->key_eq()(_ExtractKey{}(__y_n->_M_v()),
1907 _ExtractKey{}(__x_n->_M_v())))
1910 auto __y_ref_n = __y_n;
1911 for (__y_n = __y_n->_M_next(); __y_n; __y_n = __y_n->_M_next())
1912 if (!__other._M_node_equals(*__y_ref_n, *__y_n))
1915 if (!__y_n || __other._M_bucket_index(*__y_n) != __ybkt)
1919 auto __y_n_end = __y_n;
1920 for (; __y_n_end; __y_n_end = __y_n_end->_M_next())
1921 if (--__x_count == 0)
1927 const_iterator __itx(__x_n), __itx_end(__x_n_end);
1928 const_iterator __ity(__y_n);
1929 if (!std::is_permutation(__itx, __itx_end, __ity))
1941 template<
typename _NodeAlloc>
1942 struct _Hashtable_alloc :
private _Hashtable_ebo_helper<0, _NodeAlloc>
1945 using __ebo_node_alloc = _Hashtable_ebo_helper<0, _NodeAlloc>;
1948 struct __get_value_type;
1949 template<
typename _Val,
bool _Cache_hash_code>
1950 struct __get_value_type<_Hash_node<_Val, _Cache_hash_code>>
1951 {
using type = _Val; };
1954 using __node_type =
typename _NodeAlloc::value_type;
1955 using __node_alloc_type = _NodeAlloc;
1959 using __value_alloc_traits =
typename __node_alloc_traits::template
1960 rebind_traits<typename __get_value_type<__node_type>::type>;
1962 using __node_ptr = __node_type*;
1963 using __node_base = _Hash_node_base;
1964 using __node_base_ptr = __node_base*;
1965 using __buckets_alloc_type =
1966 __alloc_rebind<__node_alloc_type, __node_base_ptr>;
1968 using __buckets_ptr = __node_base_ptr*;
1970 _Hashtable_alloc() =
default;
1971 _Hashtable_alloc(
const _Hashtable_alloc&) =
default;
1972 _Hashtable_alloc(_Hashtable_alloc&&) =
default;
1974 template<
typename _Alloc>
1975 _Hashtable_alloc(_Alloc&& __a)
1976 : __ebo_node_alloc(
std::
forward<_Alloc>(__a))
1981 {
return __ebo_node_alloc::_M_get(); }
1983 const __node_alloc_type&
1984 _M_node_allocator()
const
1985 {
return __ebo_node_alloc::_M_cget(); }
1988 template<
typename... _Args>
1990 _M_allocate_node(_Args&&... __args);
1994 _M_deallocate_node(__node_ptr __n);
1998 _M_deallocate_node_ptr(__node_ptr __n);
2003 _M_deallocate_nodes(__node_ptr __n);
2006 _M_allocate_buckets(std::size_t __bkt_count);
2009 _M_deallocate_buckets(__buckets_ptr, std::size_t __bkt_count);
2014 template<
typename _NodeAlloc>
2015 template<
typename... _Args>
2017 _Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&&... __args)
2020 auto& __alloc = _M_node_allocator();
2021 auto __nptr = __node_alloc_traits::allocate(__alloc, 1);
2022 __node_ptr __n = std::__to_address(__nptr);
2025 ::new ((
void*)__n) __node_type;
2026 __node_alloc_traits::construct(__alloc, __n->_M_valptr(),
2032 __n->~__node_type();
2033 __node_alloc_traits::deallocate(__alloc, __nptr, 1);
2034 __throw_exception_again;
2038 template<
typename _NodeAlloc>
2040 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node(__node_ptr __n)
2042 __node_alloc_traits::destroy(_M_node_allocator(), __n->_M_valptr());
2043 _M_deallocate_node_ptr(__n);
2046 template<
typename _NodeAlloc>
2048 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node_ptr(__node_ptr __n)
2050 typedef typename __node_alloc_traits::pointer _Ptr;
2052 __n->~__node_type();
2053 __node_alloc_traits::deallocate(_M_node_allocator(), __ptr, 1);
2056 template<
typename _NodeAlloc>
2058 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_nodes(__node_ptr __n)
2062 __node_ptr __tmp = __n;
2063 __n = __n->_M_next();
2064 _M_deallocate_node(__tmp);
2068 template<
typename _NodeAlloc>
2070 _Hashtable_alloc<_NodeAlloc>::_M_allocate_buckets(std::size_t __bkt_count)
2073 __buckets_alloc_type __alloc(_M_node_allocator());
2075 auto __ptr = __buckets_alloc_traits::allocate(__alloc, __bkt_count);
2076 __buckets_ptr __p = std::__to_address(__ptr);
2077 __builtin_memset(__p, 0, __bkt_count *
sizeof(__node_base_ptr));
2081 template<
typename _NodeAlloc>
2083 _Hashtable_alloc<_NodeAlloc>::
2084 _M_deallocate_buckets(__buckets_ptr __bkts,
2085 std::size_t __bkt_count)
2087 typedef typename __buckets_alloc_traits::pointer _Ptr;
2089 __buckets_alloc_type __alloc(_M_node_allocator());
2090 __buckets_alloc_traits::deallocate(__alloc, __ptr, __bkt_count);
2096_GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
pair(_T1, _T2) -> pair< _T1, _T2 >
Two pairs of the same type are equal iff their members are equal.
constexpr tuple< _Elements &&... > forward_as_tuple(_Elements &&... __args) noexcept
Create a tuple of lvalue or rvalue references to the arguments.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr piecewise_construct_t piecewise_construct
Tag for piecewise construction of std::pair objects.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.
constexpr _Iterator __base(_Iterator __it)
Primary class template, tuple.
Define a member typedef type only if a boolean constant is true.
Uniform interface to all allocator types.
Traits class for iterators.
Uniform interface to all pointer-like types.
Struct holding two objects of arbitrary type.
Forward iterators support a superset of input iterator operations.
Uniform interface to C++98 and C++11 allocators.