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_ptr
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_ptr
173 {
return __node_gen(std::forward<_Kt>(__k)); }
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
218 return _M_h._M_allocate_node(std::forward<_Args>(__args)...);
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(),
227 std::forward<_Args>(__args)...);
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
254 {
return _M_h._M_allocate_node(std::forward<_Args>(__args)...); }
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
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
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
646 const auto __max_width = std::min<size_t>(
sizeof(
size_t), 8);
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)
689 = std::max<std::size_t>(__n_elt + __n_ins, _M_next_resize ? 0 : 11)
690 / (double)_M_max_load_factor;
691 if (__min_bkts >= __n_bkt)
693 _M_next_bkt(std::max<std::size_t>(__builtin_floor(__min_bkts) + 1,
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 template<
typename _KType,
typename... _Args>
971 try_emplace(const_iterator, _KType&& __k, _Args&&... __args)
973 __hashtable& __h = _M_conjure_hashtable();
974 auto __code = __h._M_hash_code(__k);
975 std::size_t __bkt = __h._M_bucket_index(__code);
976 if (
auto __node = __h._M_find_node(__bkt, __k, __code))
977 return { iterator(__node),
false };
979 typename __hashtable::_Scoped_node __node {
986 = __h._M_insert_unique_node(__bkt, __code, __node._M_node);
987 __node._M_node =
nullptr;
988 return { __it,
true };
992 insert(initializer_list<value_type> __l)
993 { this->insert(__l.begin(), __l.end()); }
995 template<
typename _InputIterator>
997 insert(_InputIterator __first, _InputIterator __last)
999 __hashtable& __h = _M_conjure_hashtable();
1000 __node_gen_type __node_gen(__h);
1001 return _M_insert_range(__first, __last, __node_gen, __unique_keys{});
1005 template<
typename _Key,
typename _Value,
typename _Alloc,
1006 typename _ExtractKey,
typename _Equal,
1007 typename _Hash,
typename _RangeHash,
typename _Unused,
1008 typename _RehashPolicy,
typename _Traits>
1009 template<
typename _InputIterator,
typename _NodeGetter>
1011 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1012 _Hash, _RangeHash, _Unused,
1013 _RehashPolicy, _Traits>::
1014 _M_insert_range(_InputIterator __first, _InputIterator __last,
1015 const _NodeGetter& __node_gen,
true_type __uks)
1017 __hashtable& __h = _M_conjure_hashtable();
1018 for (; __first != __last; ++__first)
1019 __h._M_insert(*__first, __node_gen, __uks);
1022 template<
typename _Key,
typename _Value,
typename _Alloc,
1023 typename _ExtractKey,
typename _Equal,
1024 typename _Hash,
typename _RangeHash,
typename _Unused,
1025 typename _RehashPolicy,
typename _Traits>
1026 template<
typename _InputIterator,
typename _NodeGetter>
1028 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1029 _Hash, _RangeHash, _Unused,
1030 _RehashPolicy, _Traits>::
1031 _M_insert_range(_InputIterator __first, _InputIterator __last,
1032 const _NodeGetter& __node_gen,
false_type __uks)
1034 using __rehash_guard_t =
typename __hashtable::__rehash_guard_t;
1037 size_type __n_elt = __detail::__distance_fw(__first, __last);
1041 __hashtable& __h = _M_conjure_hashtable();
1042 __rehash_guard_t __rehash_guard(__h._M_rehash_policy);
1043 __pair_type __do_rehash
1044 = __h._M_rehash_policy._M_need_rehash(__h._M_bucket_count,
1045 __h._M_element_count,
1048 if (__do_rehash.first)
1049 __h._M_rehash(__do_rehash.second, __uks);
1051 __rehash_guard._M_guarded_obj =
nullptr;
1052 for (; __first != __last; ++__first)
1053 __h._M_insert(*__first, __node_gen, __uks);
1062 template<
typename _Key,
typename _Value,
typename _Alloc,
1063 typename _ExtractKey,
typename _Equal,
1064 typename _Hash,
typename _RangeHash,
typename _Unused,
1065 typename _RehashPolicy,
typename _Traits,
1066 bool _Constant_iterators = _Traits::__constant_iterators::value>
1070 template<
typename _Key,
typename _Value,
typename _Alloc,
1071 typename _ExtractKey,
typename _Equal,
1072 typename _Hash,
typename _RangeHash,
typename _Unused,
1073 typename _RehashPolicy,
typename _Traits>
1074 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1075 _Hash, _RangeHash, _Unused,
1076 _RehashPolicy, _Traits, true>
1077 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1078 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1080 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1081 _Equal, _Hash, _RangeHash, _Unused,
1082 _RehashPolicy, _Traits>;
1084 using value_type =
typename __base_type::value_type;
1085 using iterator =
typename __base_type::iterator;
1086 using const_iterator =
typename __base_type::const_iterator;
1087 using __ireturn_type =
typename __base_type::__ireturn_type;
1089 using __unique_keys =
typename __base_type::__unique_keys;
1090 using __hashtable =
typename __base_type::__hashtable;
1091 using __node_gen_type =
typename __base_type::__node_gen_type;
1093 using __base_type::insert;
1096 insert(value_type&& __v)
1098 __hashtable& __h = this->_M_conjure_hashtable();
1099 __node_gen_type __node_gen(__h);
1100 return __h._M_insert(
std::move(__v), __node_gen, __unique_keys{});
1104 insert(const_iterator __hint, value_type&& __v)
1106 __hashtable& __h = this->_M_conjure_hashtable();
1107 __node_gen_type __node_gen(__h);
1108 return __h._M_insert(__hint,
std::move(__v), __node_gen,
1114 template<
typename _Key,
typename _Value,
typename _Alloc,
1115 typename _ExtractKey,
typename _Equal,
1116 typename _Hash,
typename _RangeHash,
typename _Unused,
1117 typename _RehashPolicy,
typename _Traits>
1118 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1119 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1120 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1121 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1123 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1124 _Equal, _Hash, _RangeHash, _Unused,
1125 _RehashPolicy, _Traits>;
1126 using value_type =
typename __base_type::value_type;
1127 using iterator =
typename __base_type::iterator;
1128 using const_iterator =
typename __base_type::const_iterator;
1130 using __unique_keys =
typename __base_type::__unique_keys;
1131 using __hashtable =
typename __base_type::__hashtable;
1132 using __ireturn_type =
typename __base_type::__ireturn_type;
1134 using __base_type::insert;
1136 template<
typename _Pair>
1139 template<
typename _Pair>
1142 template<
typename _Pair>
1143 using _IFconsp =
typename _IFcons<_Pair>::type;
1145 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1149 __hashtable& __h = this->_M_conjure_hashtable();
1150 return __h._M_emplace(__unique_keys{}, std::forward<_Pair>(__v));
1153 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1155 insert(const_iterator __hint, _Pair&& __v)
1157 __hashtable& __h = this->_M_conjure_hashtable();
1158 return __h._M_emplace(__hint, __unique_keys{},
1159 std::forward<_Pair>(__v));
1163 template<
typename _Policy>
1164 using __has_load_factor =
typename _Policy::__has_load_factor;
1172 template<
typename _Key,
typename _Value,
typename _Alloc,
1173 typename _ExtractKey,
typename _Equal,
1174 typename _Hash,
typename _RangeHash,
typename _Unused,
1175 typename _RehashPolicy,
typename _Traits,
1177 __detected_or_t<false_type, __has_load_factor, _RehashPolicy>>
1178 struct _Rehash_base;
1181 template<
typename _Key,
typename _Value,
typename _Alloc,
1182 typename _ExtractKey,
typename _Equal,
1183 typename _Hash,
typename _RangeHash,
typename _Unused,
1184 typename _RehashPolicy,
typename _Traits>
1185 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1186 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1192 template<
typename _Key,
typename _Value,
typename _Alloc,
1193 typename _ExtractKey,
typename _Equal,
1194 typename _Hash,
typename _RangeHash,
typename _Unused,
1195 typename _RehashPolicy,
typename _Traits>
1196 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1197 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1201 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey,
1202 _Equal, _Hash, _RangeHash, _Unused,
1203 _RehashPolicy, _Traits>;
1207 max_load_factor() const noexcept
1209 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1210 return __this->__rehash_policy().max_load_factor();
1214 max_load_factor(
float __z)
1216 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1217 __this->__rehash_policy(_RehashPolicy(__z));
1221 reserve(std::size_t __n)
1223 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1224 __this->rehash(__this->__rehash_policy()._M_bkt_for_elements(__n));
1234 template<
int _Nm,
typename _Tp,
1235 bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
1236 struct _Hashtable_ebo_helper;
1239 template<
int _Nm,
typename _Tp>
1240 struct _Hashtable_ebo_helper<_Nm, _Tp, true>
1243 _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
1245 template<
typename _OtherTp>
1246 _Hashtable_ebo_helper(_OtherTp&& __tp)
1250 const _Tp& _M_cget()
const {
return static_cast<const _Tp&
>(*this); }
1251 _Tp& _M_get() {
return static_cast<_Tp&
>(*this); }
1255 template<
int _Nm,
typename _Tp>
1256 struct _Hashtable_ebo_helper<_Nm, _Tp, false>
1258 _Hashtable_ebo_helper() =
default;
1260 template<
typename _OtherTp>
1261 _Hashtable_ebo_helper(_OtherTp&& __tp)
1265 const _Tp& _M_cget()
const {
return _M_tp; }
1266 _Tp& _M_get() {
return _M_tp; }
1278 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1279 typename _Hash,
typename _RangeHash,
typename _Unused,
1280 bool __cache_hash_code>
1281 struct _Local_iterator_base;
1301 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1302 typename _Hash,
typename _RangeHash,
typename _Unused,
1303 bool __cache_hash_code>
1304 struct _Hash_code_base
1305 :
private _Hashtable_ebo_helper<1, _Hash>
1308 using __ebo_hash = _Hashtable_ebo_helper<1, _Hash>;
1311 friend struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1312 _Hash, _RangeHash, _Unused, false>;
1315 typedef _Hash hasher;
1318 hash_function()
const
1319 {
return _M_hash(); }
1322 typedef std::size_t __hash_code;
1326 _Hash_code_base() =
default;
1328 _Hash_code_base(
const _Hash& __hash) : __ebo_hash(__hash) { }
1331 _M_hash_code(
const _Key& __k)
const
1333 static_assert(__is_invocable<const _Hash&, const _Key&>{},
1334 "hash function must be invocable with an argument of key type");
1335 return _M_hash()(__k);
1338 template<
typename _Kt>
1340 _M_hash_code_tr(
const _Kt& __k)
const
1342 static_assert(__is_invocable<const _Hash&, const _Kt&>{},
1343 "hash function must be invocable with an argument of key type");
1344 return _M_hash()(__k);
1348 _M_hash_code(
const _Hash_node_value<_Value, false>& __n)
const
1349 {
return _M_hash_code(_ExtractKey{}(__n._M_v())); }
1352 _M_hash_code(
const _Hash_node_value<_Value, true>& __n)
const
1353 {
return __n._M_hash_code; }
1356 _M_bucket_index(__hash_code __c, std::size_t __bkt_count)
const
1357 {
return _RangeHash{}(__c, __bkt_count); }
1360 _M_bucket_index(
const _Hash_node_value<_Value, false>& __n,
1361 std::size_t __bkt_count)
const
1362 noexcept(
noexcept(declval<const _Hash&>()(declval<const _Key&>()))
1363 &&
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1366 return _RangeHash{}(_M_hash_code(_ExtractKey{}(__n._M_v())),
1371 _M_bucket_index(
const _Hash_node_value<_Value, true>& __n,
1372 std::size_t __bkt_count)
const
1373 noexcept(
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1375 {
return _RangeHash{}(__n._M_hash_code, __bkt_count); }
1378 _M_store_code(_Hash_node_code_cache<false>&, __hash_code)
const
1382 _M_copy_code(_Hash_node_code_cache<false>&,
1383 const _Hash_node_code_cache<false>&)
const
1387 _M_store_code(_Hash_node_code_cache<true>& __n, __hash_code __c)
const
1388 { __n._M_hash_code = __c; }
1391 _M_copy_code(_Hash_node_code_cache<true>& __to,
1392 const _Hash_node_code_cache<true>& __from)
const
1393 { __to._M_hash_code = __from._M_hash_code; }
1396 _M_swap(_Hash_code_base& __x)
1397 { std::swap(__ebo_hash::_M_get(), __x.__ebo_hash::_M_get()); }
1400 _M_hash()
const {
return __ebo_hash::_M_cget(); }
1404 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1405 typename _Hash,
typename _RangeHash,
typename _Unused>
1406 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1407 _Hash, _RangeHash, _Unused, true>
1408 :
public _Node_iterator_base<_Value, true>
1411 using __base_node_iter = _Node_iterator_base<_Value, true>;
1412 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1413 _Hash, _RangeHash, _Unused,
true>;
1415 _Local_iterator_base() =
default;
1416 _Local_iterator_base(
const __hash_code_base&,
1417 _Hash_node<_Value, true>* __p,
1418 std::size_t __bkt, std::size_t __bkt_count)
1419 : __base_node_iter(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1425 __base_node_iter::_M_incr();
1429 = _RangeHash{}(this->_M_cur->_M_hash_code, _M_bucket_count);
1430 if (__bkt != _M_bucket)
1431 this->_M_cur =
nullptr;
1435 std::size_t _M_bucket;
1436 std::size_t _M_bucket_count;
1440 _M_get_bucket()
const {
return _M_bucket; }
1447 template<typename _Tp, bool _IsEmpty = std::is_empty<_Tp>::value>
1448 struct _Hash_code_storage
1450 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
1453 _M_h() {
return _M_storage._M_ptr(); }
1456 _M_h()
const {
return _M_storage._M_ptr(); }
1460 template<
typename _Tp>
1461 struct _Hash_code_storage<_Tp, true>
1468 _M_h() {
return reinterpret_cast<_Tp*
>(
this); }
1471 _M_h()
const {
return reinterpret_cast<const _Tp*
>(
this); }
1474 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1475 typename _Hash,
typename _RangeHash,
typename _Unused>
1476 using __hash_code_for_local_iter
1477 = _Hash_code_storage<_Hash_code_base<_Key, _Value, _ExtractKey,
1478 _Hash, _RangeHash, _Unused,
false>>;
1481 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1482 typename _Hash,
typename _RangeHash,
typename _Unused>
1483 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1484 _Hash, _RangeHash, _Unused, false>
1485 : __hash_code_for_local_iter<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1487 , _Node_iterator_base<_Value, false>
1490 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1491 _Hash, _RangeHash, _Unused,
false>;
1492 using __node_iter_base = _Node_iterator_base<_Value, false>;
1494 _Local_iterator_base() : _M_bucket_count(-1) { }
1496 _Local_iterator_base(
const __hash_code_base& __base,
1497 _Hash_node<_Value, false>* __p,
1498 std::size_t __bkt, std::size_t __bkt_count)
1499 : __node_iter_base(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1500 { _M_init(__base); }
1502 ~_Local_iterator_base()
1504 if (_M_bucket_count !=
size_t(-1))
1508 _Local_iterator_base(
const _Local_iterator_base& __iter)
1509 : __node_iter_base(__iter._M_cur), _M_bucket(__iter._M_bucket)
1510 , _M_bucket_count(__iter._M_bucket_count)
1512 if (_M_bucket_count !=
size_t(-1))
1513 _M_init(*__iter._M_h());
1516 _Local_iterator_base&
1517 operator=(
const _Local_iterator_base& __iter)
1519 if (_M_bucket_count != -1)
1521 this->_M_cur = __iter._M_cur;
1522 _M_bucket = __iter._M_bucket;
1523 _M_bucket_count = __iter._M_bucket_count;
1524 if (_M_bucket_count != -1)
1525 _M_init(*__iter._M_h());
1532 __node_iter_base::_M_incr();
1535 std::size_t __bkt = this->_M_h()->_M_bucket_index(*this->_M_cur,
1537 if (__bkt != _M_bucket)
1538 this->_M_cur =
nullptr;
1542 std::size_t _M_bucket;
1543 std::size_t _M_bucket_count;
1546 _M_init(
const __hash_code_base& __base)
1547 { ::new(this->_M_h()) __hash_code_base(__base); }
1550 _M_destroy() { this->_M_h()->~__hash_code_base(); }
1554 _M_get_bucket()
const {
return _M_bucket; }
1558 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1559 typename _Hash,
typename _RangeHash,
typename _Unused,
1560 bool __constant_iterators,
bool __cache>
1561 struct _Local_iterator
1562 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1563 _Hash, _RangeHash, _Unused, __cache>
1566 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1567 _Hash, _RangeHash, _Unused, __cache>;
1568 using __hash_code_base =
typename __base_type::__hash_code_base;
1571 using value_type = _Value;
1572 using pointer = __conditional_t<__constant_iterators,
1573 const value_type*, value_type*>;
1574 using reference = __conditional_t<__constant_iterators,
1575 const value_type&, value_type&>;
1576 using difference_type = ptrdiff_t;
1577 using iterator_category = forward_iterator_tag;
1579 _Local_iterator() =
default;
1581 _Local_iterator(
const __hash_code_base& __base,
1582 _Hash_node<_Value, __cache>* __n,
1583 std::size_t __bkt, std::size_t __bkt_count)
1584 : __base_type(
__base, __n, __bkt, __bkt_count)
1589 {
return this->_M_cur->_M_v(); }
1593 {
return this->_M_cur->_M_valptr(); }
1605 _Local_iterator __tmp(*
this);
1612 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1613 typename _Hash,
typename _RangeHash,
typename _Unused,
1614 bool __constant_iterators,
bool __cache>
1615 struct _Local_const_iterator
1616 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1617 _Hash, _RangeHash, _Unused, __cache>
1620 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1621 _Hash, _RangeHash, _Unused, __cache>;
1622 using __hash_code_base =
typename __base_type::__hash_code_base;
1625 typedef _Value value_type;
1626 typedef const value_type* pointer;
1627 typedef const value_type& reference;
1628 typedef std::ptrdiff_t difference_type;
1631 _Local_const_iterator() =
default;
1633 _Local_const_iterator(
const __hash_code_base& __base,
1634 _Hash_node<_Value, __cache>* __n,
1635 std::size_t __bkt, std::size_t __bkt_count)
1636 : __base_type(
__base, __n, __bkt, __bkt_count)
1639 _Local_const_iterator(
const _Local_iterator<_Key, _Value, _ExtractKey,
1640 _Hash, _RangeHash, _Unused,
1641 __constant_iterators,
1648 {
return this->_M_cur->_M_v(); }
1652 {
return this->_M_cur->_M_valptr(); }
1654 _Local_const_iterator&
1661 _Local_const_iterator
1664 _Local_const_iterator __tmp(*
this);
1680 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1681 typename _Equal,
typename _Hash,
typename _RangeHash,
1682 typename _Unused,
typename _Traits>
1683 struct _Hashtable_base
1684 :
public _Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1685 _Unused, _Traits::__hash_cached::value>,
1686 private _Hashtable_ebo_helper<0, _Equal>
1689 typedef _Key key_type;
1690 typedef _Value value_type;
1691 typedef _Equal key_equal;
1692 typedef std::size_t size_type;
1693 typedef std::ptrdiff_t difference_type;
1695 using __traits_type = _Traits;
1696 using __hash_cached =
typename __traits_type::__hash_cached;
1698 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1699 _Hash, _RangeHash, _Unused,
1700 __hash_cached::value>;
1702 using __hash_code =
typename __hash_code_base::__hash_code;
1705 using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>;
1708 _S_equals(__hash_code,
const _Hash_node_code_cache<false>&)
1712 _S_node_equals(
const _Hash_node_code_cache<false>&,
1713 const _Hash_node_code_cache<false>&)
1717 _S_equals(__hash_code __c,
const _Hash_node_code_cache<true>& __n)
1718 {
return __c == __n._M_hash_code; }
1721 _S_node_equals(
const _Hash_node_code_cache<true>& __lhn,
1722 const _Hash_node_code_cache<true>& __rhn)
1723 {
return __lhn._M_hash_code == __rhn._M_hash_code; }
1726 _Hashtable_base() =
default;
1728 _Hashtable_base(
const _Hash& __hash,
const _Equal& __eq)
1729 : __hash_code_base(__hash), _EqualEBO(__eq)
1733 _M_key_equals(
const _Key& __k,
1734 const _Hash_node_value<_Value,
1735 __hash_cached::value>& __n)
const
1737 static_assert(__is_invocable<const _Equal&, const _Key&, const _Key&>{},
1738 "key equality predicate must be invocable with two arguments of "
1740 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1743 template<
typename _Kt>
1745 _M_key_equals_tr(
const _Kt& __k,
1746 const _Hash_node_value<_Value,
1747 __hash_cached::value>& __n)
const
1750 __is_invocable<const _Equal&, const _Kt&, const _Key&>{},
1751 "key equality predicate must be invocable with two arguments of "
1753 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1757 _M_equals(
const _Key& __k, __hash_code __c,
1758 const _Hash_node_value<_Value, __hash_cached::value>& __n)
const
1759 {
return _S_equals(__c, __n) && _M_key_equals(__k, __n); }
1761 template<
typename _Kt>
1763 _M_equals_tr(
const _Kt& __k, __hash_code __c,
1764 const _Hash_node_value<_Value,
1765 __hash_cached::value>& __n)
const
1766 {
return _S_equals(__c, __n) && _M_key_equals_tr(__k, __n); }
1770 const _Hash_node_value<_Value, __hash_cached::value>& __lhn,
1771 const _Hash_node_value<_Value, __hash_cached::value>& __rhn)
const
1773 return _S_node_equals(__lhn, __rhn)
1774 && _M_key_equals(_ExtractKey{}(__lhn._M_v()), __rhn);
1778 _M_swap(_Hashtable_base& __x)
1780 __hash_code_base::_M_swap(__x);
1781 std::swap(_EqualEBO::_M_get(), __x._EqualEBO::_M_get());
1785 _M_eq()
const {
return _EqualEBO::_M_cget(); }
1796 template<
typename _Key,
typename _Value,
typename _Alloc,
1797 typename _ExtractKey,
typename _Equal,
1798 typename _Hash,
typename _RangeHash,
typename _Unused,
1799 typename _RehashPolicy,
typename _Traits,
1800 bool _Unique_keys = _Traits::__unique_keys::value>
1804 template<
typename _Key,
typename _Value,
typename _Alloc,
1805 typename _ExtractKey,
typename _Equal,
1806 typename _Hash,
typename _RangeHash,
typename _Unused,
1807 typename _RehashPolicy,
typename _Traits>
1808 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1809 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
1811 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1812 _Hash, _RangeHash, _Unused,
1813 _RehashPolicy, _Traits>;
1816 _M_equal(
const __hashtable&)
const;
1819 template<
typename _Key,
typename _Value,
typename _Alloc,
1820 typename _ExtractKey,
typename _Equal,
1821 typename _Hash,
typename _RangeHash,
typename _Unused,
1822 typename _RehashPolicy,
typename _Traits>
1824 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1825 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
1826 _M_equal(
const __hashtable& __other)
const
1828 using __node_ptr =
typename __hashtable::__node_ptr;
1829 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1830 if (__this->size() != __other.size())
1833 for (
auto __x_n = __this->_M_begin(); __x_n; __x_n = __x_n->_M_next())
1835 std::size_t __ybkt = __other._M_bucket_index(*__x_n);
1836 auto __prev_n = __other._M_buckets[__ybkt];
1840 for (__node_ptr __n =
static_cast<__node_ptr
>(__prev_n->_M_nxt);;
1841 __n = __n->_M_next())
1843 if (__n->_M_v() == __x_n->_M_v())
1847 || __other._M_bucket_index(*__n->_M_next()) != __ybkt)
1856 template<
typename _Key,
typename _Value,
typename _Alloc,
1857 typename _ExtractKey,
typename _Equal,
1858 typename _Hash,
typename _RangeHash,
typename _Unused,
1859 typename _RehashPolicy,
typename _Traits>
1860 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1861 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1863 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1864 _Hash, _RangeHash, _Unused,
1865 _RehashPolicy, _Traits>;
1868 _M_equal(
const __hashtable&)
const;
1871 template<
typename _Key,
typename _Value,
typename _Alloc,
1872 typename _ExtractKey,
typename _Equal,
1873 typename _Hash,
typename _RangeHash,
typename _Unused,
1874 typename _RehashPolicy,
typename _Traits>
1876 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1877 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
false>::
1878 _M_equal(
const __hashtable& __other)
const
1880 using __node_ptr =
typename __hashtable::__node_ptr;
1881 using const_iterator =
typename __hashtable::const_iterator;
1882 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1883 if (__this->size() != __other.size())
1886 for (
auto __x_n = __this->_M_begin(); __x_n;)
1888 std::size_t __x_count = 1;
1889 auto __x_n_end = __x_n->_M_next();
1891 && __this->key_eq()(_ExtractKey{}(__x_n->_M_v()),
1892 _ExtractKey{}(__x_n_end->_M_v()));
1893 __x_n_end = __x_n_end->_M_next())
1896 std::size_t __ybkt = __other._M_bucket_index(*__x_n);
1897 auto __y_prev_n = __other._M_buckets[__ybkt];
1901 __node_ptr __y_n =
static_cast<__node_ptr
>(__y_prev_n->_M_nxt);
1904 if (__this->key_eq()(_ExtractKey{}(__y_n->_M_v()),
1905 _ExtractKey{}(__x_n->_M_v())))
1908 auto __y_ref_n = __y_n;
1909 for (__y_n = __y_n->_M_next(); __y_n; __y_n = __y_n->_M_next())
1910 if (!__other._M_node_equals(*__y_ref_n, *__y_n))
1913 if (!__y_n || __other._M_bucket_index(*__y_n) != __ybkt)
1917 auto __y_n_end = __y_n;
1918 for (; __y_n_end; __y_n_end = __y_n_end->_M_next())
1919 if (--__x_count == 0)
1925 const_iterator __itx(__x_n), __itx_end(__x_n_end);
1926 const_iterator __ity(__y_n);
1927 if (!std::is_permutation(__itx, __itx_end, __ity))
1939 template<
typename _NodeAlloc>
1940 struct _Hashtable_alloc :
private _Hashtable_ebo_helper<0, _NodeAlloc>
1943 using __ebo_node_alloc = _Hashtable_ebo_helper<0, _NodeAlloc>;
1946 struct __get_value_type;
1947 template<
typename _Val,
bool _Cache_hash_code>
1948 struct __get_value_type<_Hash_node<_Val, _Cache_hash_code>>
1949 {
using type = _Val; };
1952 using __node_type =
typename _NodeAlloc::value_type;
1953 using __node_alloc_type = _NodeAlloc;
1957 using __value_alloc_traits =
typename __node_alloc_traits::template
1958 rebind_traits<typename __get_value_type<__node_type>::type>;
1960 using __node_ptr = __node_type*;
1961 using __node_base = _Hash_node_base;
1962 using __node_base_ptr = __node_base*;
1963 using __buckets_alloc_type =
1964 __alloc_rebind<__node_alloc_type, __node_base_ptr>;
1966 using __buckets_ptr = __node_base_ptr*;
1968 _Hashtable_alloc() =
default;
1969 _Hashtable_alloc(
const _Hashtable_alloc&) =
default;
1970 _Hashtable_alloc(_Hashtable_alloc&&) =
default;
1972 template<
typename _Alloc>
1973 _Hashtable_alloc(_Alloc&& __a)
1974 : __ebo_node_alloc(
std::
forward<_Alloc>(__a))
1979 {
return __ebo_node_alloc::_M_get(); }
1981 const __node_alloc_type&
1982 _M_node_allocator()
const
1983 {
return __ebo_node_alloc::_M_cget(); }
1986 template<
typename... _Args>
1988 _M_allocate_node(_Args&&... __args);
1992 _M_deallocate_node(__node_ptr __n);
1996 _M_deallocate_node_ptr(__node_ptr __n);
2001 _M_deallocate_nodes(__node_ptr __n);
2004 _M_allocate_buckets(std::size_t __bkt_count);
2007 _M_deallocate_buckets(__buckets_ptr, std::size_t __bkt_count);
2012 template<
typename _NodeAlloc>
2013 template<
typename... _Args>
2015 _Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&&... __args)
2018 auto& __alloc = _M_node_allocator();
2019 auto __nptr = __node_alloc_traits::allocate(__alloc, 1);
2020 __node_ptr __n = std::__to_address(__nptr);
2023 ::new ((
void*)__n) __node_type;
2024 __node_alloc_traits::construct(__alloc, __n->_M_valptr(),
2025 std::forward<_Args>(__args)...);
2030 __n->~__node_type();
2031 __node_alloc_traits::deallocate(__alloc, __nptr, 1);
2032 __throw_exception_again;
2036 template<
typename _NodeAlloc>
2038 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node(__node_ptr __n)
2040 __node_alloc_traits::destroy(_M_node_allocator(), __n->_M_valptr());
2041 _M_deallocate_node_ptr(__n);
2044 template<
typename _NodeAlloc>
2046 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node_ptr(__node_ptr __n)
2048 typedef typename __node_alloc_traits::pointer _Ptr;
2050 __n->~__node_type();
2051 __node_alloc_traits::deallocate(_M_node_allocator(), __ptr, 1);
2054 template<
typename _NodeAlloc>
2056 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_nodes(__node_ptr __n)
2060 __node_ptr __tmp = __n;
2061 __n = __n->_M_next();
2062 _M_deallocate_node(__tmp);
2066 template<
typename _NodeAlloc>
2068 _Hashtable_alloc<_NodeAlloc>::_M_allocate_buckets(std::size_t __bkt_count)
2071 __buckets_alloc_type __alloc(_M_node_allocator());
2073 auto __ptr = __buckets_alloc_traits::allocate(__alloc, __bkt_count);
2074 __buckets_ptr __p = std::__to_address(__ptr);
2075 __builtin_memset(__p, 0, __bkt_count *
sizeof(__node_base_ptr));
2079 template<
typename _NodeAlloc>
2081 _Hashtable_alloc<_NodeAlloc>::
2082 _M_deallocate_buckets(__buckets_ptr __bkts,
2083 std::size_t __bkt_count)
2085 typedef typename __buckets_alloc_traits::pointer _Ptr;
2087 __buckets_alloc_type __alloc(_M_node_allocator());
2088 __buckets_alloc_traits::deallocate(__alloc, __ptr, __bkt_count);
2094_GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
constexpr tuple< _Elements &&... > forward_as_tuple(_Elements &&... __args) noexcept
Create a tuple of lvalue or rvalue references to the arguments.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr piecewise_construct_t piecewise_construct
Tag for piecewise construction of std::pair objects.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.
constexpr _Iterator __base(_Iterator __it)
Primary class template, tuple.
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.