31#ifndef _HASHTABLE_POLICY_H
32#define _HASHTABLE_POLICY_H 1
40namespace std _GLIBCXX_VISIBILITY(default)
42_GLIBCXX_BEGIN_NAMESPACE_VERSION
45 template<
typename _Key,
typename _Value,
typename _Alloc,
46 typename _ExtractKey,
typename _Equal,
47 typename _Hash,
typename _RangeHash,
typename _Unused,
48 typename _RehashPolicy,
typename _Traits>
58 template<
typename _Key,
typename _Value,
typename _ExtractKey,
59 typename _Equal,
typename _Hash,
typename _RangeHash,
60 typename _Unused,
typename _Traits>
61 struct _Hashtable_base;
65 template<
typename _Iterator>
67 __distance_fw(_Iterator __first, _Iterator __last,
69 {
return __first != __last ? 1 : 0; }
71 template<
typename _Iterator>
73 __distance_fw(_Iterator __first, _Iterator __last,
77 template<
typename _Iterator>
79 __distance_fw(_Iterator __first, _Iterator __last)
80 {
return __distance_fw(__first, __last,
85 template<
typename _Tp>
87 operator()(_Tp&& __x)
const noexcept
93 template<
typename _Pair>
96 template<
typename _Tp,
typename _Up>
97 struct __1st_type<pair<_Tp, _Up>>
98 {
using type = _Tp; };
100 template<
typename _Tp,
typename _Up>
101 struct __1st_type<const pair<_Tp, _Up>>
102 {
using type =
const _Tp; };
104 template<
typename _Pair>
105 struct __1st_type<_Pair&>
106 {
using type =
typename __1st_type<_Pair>::type&; };
108 template<
typename _Tp>
109 typename __1st_type<_Tp>::type&&
110 operator()(_Tp&& __x)
const noexcept
114 template<
typename _ExKey>
118 struct _NodeBuilder<_Select1st>
120 template<
typename _Kt,
typename _Arg,
typename _NodeGenerator>
122 _S_build(_Kt&& __k, _Arg&& __arg,
const _NodeGenerator& __node_gen)
123 ->
typename _NodeGenerator::__node_type*
131 struct _NodeBuilder<_Identity>
133 template<
typename _Kt,
typename _Arg,
typename _NodeGenerator>
135 _S_build(_Kt&& __k, _Arg&&,
const _NodeGenerator& __node_gen)
136 ->
typename _NodeGenerator::__node_type*
140 template<
typename _NodeAlloc>
141 struct _Hashtable_alloc;
145 template<
typename _NodeAlloc>
146 struct _ReuseOrAllocNode
149 using __node_alloc_type = _NodeAlloc;
150 using __hashtable_alloc = _Hashtable_alloc<__node_alloc_type>;
151 using __node_alloc_traits =
152 typename __hashtable_alloc::__node_alloc_traits;
155 using __node_type =
typename __hashtable_alloc::__node_type;
157 _ReuseOrAllocNode(__node_type* __nodes, __hashtable_alloc& __h)
158 : _M_nodes(__nodes), _M_h(__h) { }
159 _ReuseOrAllocNode(
const _ReuseOrAllocNode&) =
delete;
162 { _M_h._M_deallocate_nodes(_M_nodes); }
164 template<
typename... _Args>
166 operator()(_Args&&... __args)
const
170 __node_type* __node = _M_nodes;
171 _M_nodes = _M_nodes->_M_next();
172 __node->_M_nxt =
nullptr;
173 auto& __a = _M_h._M_node_allocator();
174 __node_alloc_traits::destroy(__a, __node->_M_valptr());
177 __node_alloc_traits::construct(__a, __node->_M_valptr(),
182 _M_h._M_deallocate_node_ptr(__node);
183 __throw_exception_again;
191 mutable __node_type* _M_nodes;
192 __hashtable_alloc& _M_h;
197 template<
typename _NodeAlloc>
201 using __hashtable_alloc = _Hashtable_alloc<_NodeAlloc>;
204 using __node_type =
typename __hashtable_alloc::__node_type;
206 _AllocNode(__hashtable_alloc& __h)
209 template<
typename... _Args>
211 operator()(_Args&&... __args)
const
215 __hashtable_alloc& _M_h;
243 template<
bool _Cache_hash_code,
bool _Constant_iterators,
bool _Unique_keys>
244 struct _Hashtable_traits
246 using __hash_cached = __bool_constant<_Cache_hash_code>;
247 using __constant_iterators = __bool_constant<_Constant_iterators>;
248 using __unique_keys = __bool_constant<_Unique_keys>;
257 template<
typename _Hash>
258 struct _Hashtable_hash_traits
260 static constexpr std::size_t
261 __small_size_threshold() noexcept
262 {
return std::__is_fast_hash<_Hash>::value ? 0 : 20; }
273 struct _Hash_node_base
275 _Hash_node_base* _M_nxt;
277 _Hash_node_base() noexcept : _M_nxt() { }
279 _Hash_node_base(_Hash_node_base* __next) noexcept : _M_nxt(__next) { }
287 template<
typename _Value>
288 struct _Hash_node_value_base
290 typedef _Value value_type;
292 __gnu_cxx::__aligned_buffer<_Value> _M_storage;
294 [[__gnu__::__always_inline__]]
297 {
return _M_storage._M_ptr(); }
299 [[__gnu__::__always_inline__]]
301 _M_valptr() const noexcept
302 {
return _M_storage._M_ptr(); }
304 [[__gnu__::__always_inline__]]
307 {
return *_M_valptr(); }
309 [[__gnu__::__always_inline__]]
311 _M_v() const noexcept
312 {
return *_M_valptr(); }
318 template<
bool _Cache_hash_code>
319 struct _Hash_node_code_cache
326 struct _Hash_node_code_cache<true>
327 { std::size_t _M_hash_code; };
329 template<
typename _Value,
bool _Cache_hash_code>
330 struct _Hash_node_value
331 : _Hash_node_value_base<_Value>
332 , _Hash_node_code_cache<_Cache_hash_code>
338 template<
typename _Value,
bool _Cache_hash_code>
341 , _Hash_node_value<_Value, _Cache_hash_code>
344 _M_next() const noexcept
345 {
return static_cast<_Hash_node*
>(this->_M_nxt); }
349 template<
typename _Value,
bool _Cache_hash_code>
350 struct _Node_iterator_base
352 using __node_type = _Hash_node<_Value, _Cache_hash_code>;
356 _Node_iterator_base() : _M_cur(nullptr) { }
357 _Node_iterator_base(__node_type* __p) noexcept
362 { _M_cur = _M_cur->_M_next(); }
365 operator==(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
367 {
return __x._M_cur == __y._M_cur; }
369#if __cpp_impl_three_way_comparison < 201907L
371 operator!=(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
373 {
return __x._M_cur != __y._M_cur; }
378 template<
typename _Value,
bool __constant_iterators,
bool __cache>
379 struct _Node_iterator
380 :
public _Node_iterator_base<_Value, __cache>
383 using __base_type = _Node_iterator_base<_Value, __cache>;
384 using __node_type =
typename __base_type::__node_type;
387 using value_type = _Value;
388 using difference_type = std::ptrdiff_t;
391 using pointer = __conditional_t<__constant_iterators,
392 const value_type*, value_type*>;
394 using reference = __conditional_t<__constant_iterators,
395 const value_type&, value_type&>;
397 _Node_iterator() =
default;
400 _Node_iterator(__node_type* __p) noexcept
401 : __base_type(__p) { }
405 {
return this->_M_cur->_M_v(); }
408 operator->() const noexcept
409 {
return this->_M_cur->_M_valptr(); }
412 operator++() noexcept
419 operator++(
int)
noexcept
421 _Node_iterator __tmp(*
this);
428 template<
typename _Value,
bool __constant_iterators,
bool __cache>
429 struct _Node_const_iterator
430 :
public _Node_iterator_base<_Value, __cache>
433 using __base_type = _Node_iterator_base<_Value, __cache>;
434 using __node_type =
typename __base_type::__node_type;
437 typedef _Value value_type;
438 typedef std::ptrdiff_t difference_type;
441 typedef const value_type* pointer;
442 typedef const value_type& reference;
444 _Node_const_iterator() =
default;
447 _Node_const_iterator(__node_type* __p) noexcept
448 : __base_type(__p) { }
450 _Node_const_iterator(
const _Node_iterator<_Value, __constant_iterators,
451 __cache>& __x) noexcept
452 : __base_type(__x._M_cur) { }
456 {
return this->_M_cur->_M_v(); }
459 operator->() const noexcept
460 {
return this->_M_cur->_M_valptr(); }
462 _Node_const_iterator&
463 operator++() noexcept
470 operator++(
int)
noexcept
472 _Node_const_iterator __tmp(*
this);
483 struct _Mod_range_hashing
485 typedef std::size_t first_argument_type;
486 typedef std::size_t second_argument_type;
487 typedef std::size_t result_type;
490 operator()(first_argument_type __num,
491 second_argument_type __den)
const noexcept
492 {
return __num % __den; }
500 struct _Default_ranged_hash { };
504 struct _Prime_rehash_policy
508 _Prime_rehash_policy(
float __z = 1.0) noexcept
509 : _M_max_load_factor(__z), _M_next_resize(0) { }
512 max_load_factor() const noexcept
513 {
return _M_max_load_factor; }
517 _M_next_bkt(std::size_t __n)
const;
521 _M_bkt_for_elements(std::size_t __n)
const
522 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
529 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
530 std::size_t __n_ins)
const;
532 typedef std::size_t _State;
536 {
return _M_next_resize; }
540 { _M_next_resize = 0; }
543 _M_reset(_State __state)
544 { _M_next_resize = __state; }
546 static const std::size_t _S_growth_factor = 2;
548 float _M_max_load_factor;
549 mutable std::size_t _M_next_resize;
553 struct _Mask_range_hashing
555 typedef std::size_t first_argument_type;
556 typedef std::size_t second_argument_type;
557 typedef std::size_t result_type;
560 operator()(first_argument_type __num,
561 second_argument_type __den)
const noexcept
562 {
return __num & (__den - 1); }
567 __clp2(std::size_t __n)
noexcept
573 const unsigned __lz =
sizeof(size_t) >
sizeof(
long)
574 ? __builtin_clzll(__n - 1ull)
575 : __builtin_clzl(__n - 1ul);
577 return (
size_t(1) << (__int_traits<size_t>::__digits - __lz - 1)) << 1;
582 struct _Power2_rehash_policy
586 _Power2_rehash_policy(
float __z = 1.0) noexcept
587 : _M_max_load_factor(__z), _M_next_resize(0) { }
590 max_load_factor() const noexcept
591 {
return _M_max_load_factor; }
596 _M_next_bkt(std::size_t __n)
noexcept
605 const auto __max_bkt = size_t(1) << (__max_width * __CHAR_BIT__ - 1);
606 std::size_t __res = __clp2(__n);
616 if (__res == __max_bkt)
620 _M_next_resize = size_t(-1);
623 = __builtin_floor(__res * (
double)_M_max_load_factor);
630 _M_bkt_for_elements(std::size_t __n)
const noexcept
631 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
638 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
639 std::size_t __n_ins)
noexcept
641 if (__n_elt + __n_ins > _M_next_resize)
648 / (double)_M_max_load_factor;
649 if (__min_bkts >= __n_bkt)
652 __n_bkt * _S_growth_factor)) };
655 = __builtin_floor(__n_bkt * (
double)_M_max_load_factor);
662 typedef std::size_t _State;
665 _M_state() const noexcept
666 {
return _M_next_resize; }
670 { _M_next_resize = 0; }
673 _M_reset(_State __state)
noexcept
674 { _M_next_resize = __state; }
676 static const std::size_t _S_growth_factor = 2;
678 float _M_max_load_factor;
679 std::size_t _M_next_resize;
700 template<
typename _Key,
typename _Value,
typename _Alloc,
701 typename _ExtractKey,
typename _Equal,
702 typename _Hash,
typename _RangeHash,
typename _Unused,
703 typename _RehashPolicy,
typename _Traits,
704 bool _Unique_keys = _Traits::__unique_keys::value>
705 struct _Map_base { };
708 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
709 typename _Hash,
typename _RangeHash,
typename _Unused,
710 typename _RehashPolicy,
typename _Traits>
711 struct _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
712 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
714 using mapped_type = _Val;
718 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
719 typename _Hash,
typename _RangeHash,
typename _Unused,
720 typename _RehashPolicy,
typename _Traits>
721 struct _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
722 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
725 using __hashtable_base = _Hashtable_base<_Key, pair<const _Key, _Val>,
726 _Select1st, _Equal, _Hash,
730 using __hashtable = _Hashtable<_Key, pair<const _Key, _Val>, _Alloc,
731 _Select1st, _Equal, _Hash, _RangeHash,
732 _Unused, _RehashPolicy, _Traits>;
734 using __hash_code =
typename __hashtable_base::__hash_code;
737 using key_type =
typename __hashtable_base::key_type;
738 using mapped_type = _Val;
741 operator[](
const key_type& __k);
744 operator[](key_type&& __k);
749 at(
const key_type& __k)
751 auto __ite =
static_cast<__hashtable*
>(
this)->find(__k);
753 __throw_out_of_range(__N(
"unordered_map::at"));
754 return __ite->second;
758 at(
const key_type& __k)
const
760 auto __ite =
static_cast<const __hashtable*
>(
this)->find(__k);
762 __throw_out_of_range(__N(
"unordered_map::at"));
763 return __ite->second;
767 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
768 typename _Hash,
typename _RangeHash,
typename _Unused,
769 typename _RehashPolicy,
typename _Traits>
771 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
772 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
773 operator[](
const key_type& __k)
776 __hashtable* __h =
static_cast<__hashtable*
>(
this);
777 __hash_code __code = __h->_M_hash_code(__k);
778 std::size_t __bkt = __h->_M_bucket_index(__code);
779 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
780 return __node->_M_v().second;
782 typename __hashtable::_Scoped_node __node {
789 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
790 __node._M_node =
nullptr;
791 return __pos->second;
794 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
795 typename _Hash,
typename _RangeHash,
typename _Unused,
796 typename _RehashPolicy,
typename _Traits>
798 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
799 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
800 operator[](key_type&& __k)
803 __hashtable* __h =
static_cast<__hashtable*
>(
this);
804 __hash_code __code = __h->_M_hash_code(__k);
805 std::size_t __bkt = __h->_M_bucket_index(__code);
806 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
807 return __node->_M_v().second;
809 typename __hashtable::_Scoped_node __node {
816 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
817 __node._M_node =
nullptr;
818 return __pos->second;
822 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
823 typename _Hash,
typename _RangeHash,
typename _Unused,
824 typename _RehashPolicy,
typename _Traits,
bool __uniq>
825 struct _Map_base<const _Key, pair<const _Key, _Val>,
826 _Alloc, _Select1st, _Equal, _Hash,
827 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
828 : _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal, _Hash,
829 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
837 template<
typename _Key,
typename _Value,
typename _Alloc,
838 typename _ExtractKey,
typename _Equal,
839 typename _Hash,
typename _RangeHash,
typename _Unused,
840 typename _RehashPolicy,
typename _Traits>
844 using __hashtable_base = _Hashtable_base<_Key, _Value, _ExtractKey,
845 _Equal, _Hash, _RangeHash,
848 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
850 _Unused, _RehashPolicy, _Traits>;
852 using __hash_cached =
typename _Traits::__hash_cached;
853 using __constant_iterators =
typename _Traits::__constant_iterators;
855 using __hashtable_alloc = _Hashtable_alloc<
856 __alloc_rebind<_Alloc, _Hash_node<_Value,
857 __hash_cached::value>>>;
859 using value_type =
typename __hashtable_base::value_type;
860 using size_type =
typename __hashtable_base::size_type;
862 using __unique_keys =
typename _Traits::__unique_keys;
863 using __node_alloc_type =
typename __hashtable_alloc::__node_alloc_type;
864 using __node_gen_type = _AllocNode<__node_alloc_type>;
867 _M_conjure_hashtable()
868 {
return *(
static_cast<__hashtable*
>(
this)); }
870 template<
typename _InputIterator,
typename _NodeGetter>
872 _M_insert_range(_InputIterator __first, _InputIterator __last,
873 const _NodeGetter&, true_type __uks);
875 template<
typename _InputIterator,
typename _NodeGetter>
877 _M_insert_range(_InputIterator __first, _InputIterator __last,
878 const _NodeGetter&, false_type __uks);
881 using iterator = _Node_iterator<_Value, __constant_iterators::value,
882 __hash_cached::value>;
884 using const_iterator = _Node_const_iterator<_Value,
885 __constant_iterators::value,
886 __hash_cached::value>;
888 using __ireturn_type = __conditional_t<__unique_keys::value,
893 insert(
const value_type& __v)
895 __hashtable& __h = _M_conjure_hashtable();
896 __node_gen_type __node_gen(__h);
897 return __h._M_insert(__v, __node_gen, __unique_keys{});
901 insert(const_iterator __hint,
const value_type& __v)
903 __hashtable& __h = _M_conjure_hashtable();
904 __node_gen_type __node_gen(__h);
905 return __h._M_insert(__hint, __v, __node_gen, __unique_keys{});
908 template<
typename _KType,
typename... _Args>
910 try_emplace(const_iterator, _KType&& __k, _Args&&... __args)
912 __hashtable& __h = _M_conjure_hashtable();
913 auto __code = __h._M_hash_code(__k);
914 std::size_t __bkt = __h._M_bucket_index(__code);
915 if (
auto __node = __h._M_find_node(__bkt, __k, __code))
916 return { iterator(__node),
false };
918 typename __hashtable::_Scoped_node __node {
925 = __h._M_insert_unique_node(__bkt, __code, __node._M_node);
926 __node._M_node =
nullptr;
927 return { __it,
true };
931 insert(initializer_list<value_type> __l)
932 { this->insert(__l.begin(), __l.end()); }
934 template<
typename _InputIterator>
936 insert(_InputIterator __first, _InputIterator __last)
938 __hashtable& __h = _M_conjure_hashtable();
939 __node_gen_type __node_gen(__h);
940 return _M_insert_range(__first, __last, __node_gen, __unique_keys{});
944 template<
typename _Key,
typename _Value,
typename _Alloc,
945 typename _ExtractKey,
typename _Equal,
946 typename _Hash,
typename _RangeHash,
typename _Unused,
947 typename _RehashPolicy,
typename _Traits>
948 template<
typename _InputIterator,
typename _NodeGetter>
950 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
951 _Hash, _RangeHash, _Unused,
952 _RehashPolicy, _Traits>::
953 _M_insert_range(_InputIterator __first, _InputIterator __last,
954 const _NodeGetter& __node_gen,
true_type __uks)
956 __hashtable& __h = _M_conjure_hashtable();
957 for (; __first != __last; ++__first)
958 __h._M_insert(*__first, __node_gen, __uks);
961 template<
typename _Key,
typename _Value,
typename _Alloc,
962 typename _ExtractKey,
typename _Equal,
963 typename _Hash,
typename _RangeHash,
typename _Unused,
964 typename _RehashPolicy,
typename _Traits>
965 template<
typename _InputIterator,
typename _NodeGetter>
967 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
968 _Hash, _RangeHash, _Unused,
969 _RehashPolicy, _Traits>::
970 _M_insert_range(_InputIterator __first, _InputIterator __last,
971 const _NodeGetter& __node_gen,
false_type __uks)
973 using __rehash_type =
typename __hashtable::__rehash_type;
974 using __rehash_state =
typename __hashtable::__rehash_state;
977 size_type __n_elt = __detail::__distance_fw(__first, __last);
981 __hashtable& __h = _M_conjure_hashtable();
982 __rehash_type& __rehash = __h._M_rehash_policy;
983 const __rehash_state& __saved_state = __rehash._M_state();
984 pair_type __do_rehash = __rehash._M_need_rehash(__h._M_bucket_count,
985 __h._M_element_count,
988 if (__do_rehash.first)
989 __h._M_rehash(__do_rehash.second, __saved_state);
991 for (; __first != __last; ++__first)
992 __h._M_insert(*__first, __node_gen, __uks);
1001 template<
typename _Key,
typename _Value,
typename _Alloc,
1002 typename _ExtractKey,
typename _Equal,
1003 typename _Hash,
typename _RangeHash,
typename _Unused,
1004 typename _RehashPolicy,
typename _Traits,
1005 bool _Constant_iterators = _Traits::__constant_iterators::value>
1009 template<
typename _Key,
typename _Value,
typename _Alloc,
1010 typename _ExtractKey,
typename _Equal,
1011 typename _Hash,
typename _RangeHash,
typename _Unused,
1012 typename _RehashPolicy,
typename _Traits>
1013 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1014 _Hash, _RangeHash, _Unused,
1015 _RehashPolicy, _Traits, true>
1016 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1017 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1019 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1020 _Equal, _Hash, _RangeHash, _Unused,
1021 _RehashPolicy, _Traits>;
1023 using value_type =
typename __base_type::value_type;
1024 using iterator =
typename __base_type::iterator;
1025 using const_iterator =
typename __base_type::const_iterator;
1026 using __ireturn_type =
typename __base_type::__ireturn_type;
1028 using __unique_keys =
typename __base_type::__unique_keys;
1029 using __hashtable =
typename __base_type::__hashtable;
1030 using __node_gen_type =
typename __base_type::__node_gen_type;
1032 using __base_type::insert;
1035 insert(value_type&& __v)
1037 __hashtable& __h = this->_M_conjure_hashtable();
1038 __node_gen_type __node_gen(__h);
1039 return __h._M_insert(
std::move(__v), __node_gen, __unique_keys{});
1043 insert(const_iterator __hint, value_type&& __v)
1045 __hashtable& __h = this->_M_conjure_hashtable();
1046 __node_gen_type __node_gen(__h);
1047 return __h._M_insert(__hint,
std::move(__v), __node_gen,
1053 template<
typename _Key,
typename _Value,
typename _Alloc,
1054 typename _ExtractKey,
typename _Equal,
1055 typename _Hash,
typename _RangeHash,
typename _Unused,
1056 typename _RehashPolicy,
typename _Traits>
1057 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1058 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1059 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1060 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1062 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1063 _Equal, _Hash, _RangeHash, _Unused,
1064 _RehashPolicy, _Traits>;
1065 using value_type =
typename __base_type::value_type;
1066 using iterator =
typename __base_type::iterator;
1067 using const_iterator =
typename __base_type::const_iterator;
1069 using __unique_keys =
typename __base_type::__unique_keys;
1070 using __hashtable =
typename __base_type::__hashtable;
1071 using __ireturn_type =
typename __base_type::__ireturn_type;
1073 using __base_type::insert;
1075 template<
typename _Pair>
1078 template<
typename _Pair>
1081 template<
typename _Pair>
1082 using _IFconsp =
typename _IFcons<_Pair>::type;
1084 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1088 __hashtable& __h = this->_M_conjure_hashtable();
1092 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1094 insert(const_iterator __hint, _Pair&& __v)
1096 __hashtable& __h = this->_M_conjure_hashtable();
1097 return __h._M_emplace(__hint, __unique_keys{},
1102 template<
typename _Policy>
1103 using __has_load_factor =
typename _Policy::__has_load_factor;
1111 template<
typename _Key,
typename _Value,
typename _Alloc,
1112 typename _ExtractKey,
typename _Equal,
1113 typename _Hash,
typename _RangeHash,
typename _Unused,
1114 typename _RehashPolicy,
typename _Traits,
1116 __detected_or_t<false_type, __has_load_factor, _RehashPolicy>>
1117 struct _Rehash_base;
1120 template<
typename _Key,
typename _Value,
typename _Alloc,
1121 typename _ExtractKey,
typename _Equal,
1122 typename _Hash,
typename _RangeHash,
typename _Unused,
1123 typename _RehashPolicy,
typename _Traits>
1124 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1125 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1131 template<
typename _Key,
typename _Value,
typename _Alloc,
1132 typename _ExtractKey,
typename _Equal,
1133 typename _Hash,
typename _RangeHash,
typename _Unused,
1134 typename _RehashPolicy,
typename _Traits>
1135 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1136 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1140 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey,
1141 _Equal, _Hash, _RangeHash, _Unused,
1142 _RehashPolicy, _Traits>;
1146 max_load_factor() const noexcept
1148 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1149 return __this->__rehash_policy().max_load_factor();
1153 max_load_factor(
float __z)
1155 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1156 __this->__rehash_policy(_RehashPolicy(__z));
1160 reserve(std::size_t __n)
1162 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1163 __this->rehash(__this->__rehash_policy()._M_bkt_for_elements(__n));
1173 template<
int _Nm,
typename _Tp,
1174 bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
1175 struct _Hashtable_ebo_helper;
1178 template<
int _Nm,
typename _Tp>
1179 struct _Hashtable_ebo_helper<_Nm, _Tp, true>
1182 _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
1184 template<
typename _OtherTp>
1185 _Hashtable_ebo_helper(_OtherTp&& __tp)
1189 const _Tp& _M_cget()
const {
return static_cast<const _Tp&
>(*this); }
1190 _Tp& _M_get() {
return static_cast<_Tp&
>(*this); }
1194 template<
int _Nm,
typename _Tp>
1195 struct _Hashtable_ebo_helper<_Nm, _Tp, false>
1197 _Hashtable_ebo_helper() =
default;
1199 template<
typename _OtherTp>
1200 _Hashtable_ebo_helper(_OtherTp&& __tp)
1204 const _Tp& _M_cget()
const {
return _M_tp; }
1205 _Tp& _M_get() {
return _M_tp; }
1217 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1218 typename _Hash,
typename _RangeHash,
typename _Unused,
1219 bool __cache_hash_code>
1220 struct _Local_iterator_base;
1240 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1241 typename _Hash,
typename _RangeHash,
typename _Unused,
1242 bool __cache_hash_code>
1243 struct _Hash_code_base
1244 :
private _Hashtable_ebo_helper<1, _Hash>
1247 using __ebo_hash = _Hashtable_ebo_helper<1, _Hash>;
1250 friend struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1251 _Hash, _RangeHash, _Unused, false>;
1254 typedef _Hash hasher;
1257 hash_function()
const
1258 {
return _M_hash(); }
1261 typedef std::size_t __hash_code;
1265 _Hash_code_base() =
default;
1267 _Hash_code_base(
const _Hash& __hash) : __ebo_hash(__hash) { }
1270 _M_hash_code(
const _Key& __k)
const
1272 static_assert(__is_invocable<const _Hash&, const _Key&>{},
1273 "hash function must be invocable with an argument of key type");
1274 return _M_hash()(__k);
1277 template<
typename _Kt>
1279 _M_hash_code_tr(
const _Kt& __k)
const
1281 static_assert(__is_invocable<const _Hash&, const _Kt&>{},
1282 "hash function must be invocable with an argument of key type");
1283 return _M_hash()(__k);
1287 _M_hash_code(
const _Hash_node_value<_Value, false>& __n)
const
1288 {
return _M_hash_code(_ExtractKey{}(__n._M_v())); }
1291 _M_hash_code(
const _Hash_node_value<_Value, true>& __n)
const
1292 {
return __n._M_hash_code; }
1295 _M_bucket_index(__hash_code __c, std::size_t __bkt_count)
const
1296 {
return _RangeHash{}(__c, __bkt_count); }
1299 _M_bucket_index(
const _Hash_node_value<_Value, false>& __n,
1300 std::size_t __bkt_count)
const
1301 noexcept(
noexcept(declval<const _Hash&>()(declval<const _Key&>()))
1302 &&
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1305 return _RangeHash{}(_M_hash_code(_ExtractKey{}(__n._M_v())),
1310 _M_bucket_index(
const _Hash_node_value<_Value, true>& __n,
1311 std::size_t __bkt_count)
const
1312 noexcept(
noexcept(declval<const _RangeHash&>()((__hash_code)0,
1314 {
return _RangeHash{}(__n._M_hash_code, __bkt_count); }
1317 _M_store_code(_Hash_node_code_cache<false>&, __hash_code)
const
1321 _M_copy_code(_Hash_node_code_cache<false>&,
1322 const _Hash_node_code_cache<false>&)
const
1326 _M_store_code(_Hash_node_code_cache<true>& __n, __hash_code __c)
const
1327 { __n._M_hash_code = __c; }
1330 _M_copy_code(_Hash_node_code_cache<true>& __to,
1331 const _Hash_node_code_cache<true>& __from)
const
1332 { __to._M_hash_code = __from._M_hash_code; }
1335 _M_swap(_Hash_code_base& __x)
1336 {
std::swap(__ebo_hash::_M_get(), __x.__ebo_hash::_M_get()); }
1339 _M_hash()
const {
return __ebo_hash::_M_cget(); }
1343 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1344 typename _Hash,
typename _RangeHash,
typename _Unused>
1345 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1346 _Hash, _RangeHash, _Unused, true>
1347 :
public _Node_iterator_base<_Value, true>
1350 using __base_node_iter = _Node_iterator_base<_Value, true>;
1351 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1352 _Hash, _RangeHash, _Unused,
true>;
1354 _Local_iterator_base() =
default;
1355 _Local_iterator_base(
const __hash_code_base&,
1356 _Hash_node<_Value, true>* __p,
1357 std::size_t __bkt, std::size_t __bkt_count)
1358 : __base_node_iter(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1364 __base_node_iter::_M_incr();
1368 = _RangeHash{}(this->_M_cur->_M_hash_code, _M_bucket_count);
1369 if (__bkt != _M_bucket)
1370 this->_M_cur =
nullptr;
1374 std::size_t _M_bucket;
1375 std::size_t _M_bucket_count;
1379 _M_get_bucket()
const {
return _M_bucket; }
1386 template<typename _Tp, bool _IsEmpty = std::is_empty<_Tp>::value>
1387 struct _Hash_code_storage
1389 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
1392 _M_h() {
return _M_storage._M_ptr(); }
1395 _M_h()
const {
return _M_storage._M_ptr(); }
1399 template<
typename _Tp>
1400 struct _Hash_code_storage<_Tp, true>
1407 _M_h() {
return reinterpret_cast<_Tp*
>(
this); }
1410 _M_h()
const {
return reinterpret_cast<const _Tp*
>(
this); }
1413 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1414 typename _Hash,
typename _RangeHash,
typename _Unused>
1415 using __hash_code_for_local_iter
1416 = _Hash_code_storage<_Hash_code_base<_Key, _Value, _ExtractKey,
1417 _Hash, _RangeHash, _Unused,
false>>;
1420 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1421 typename _Hash,
typename _RangeHash,
typename _Unused>
1422 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1423 _Hash, _RangeHash, _Unused, false>
1424 : __hash_code_for_local_iter<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1426 , _Node_iterator_base<_Value, false>
1429 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1430 _Hash, _RangeHash, _Unused,
false>;
1431 using __node_iter_base = _Node_iterator_base<_Value, false>;
1433 _Local_iterator_base() : _M_bucket_count(-1) { }
1435 _Local_iterator_base(
const __hash_code_base& __base,
1436 _Hash_node<_Value, false>* __p,
1437 std::size_t __bkt, std::size_t __bkt_count)
1438 : __node_iter_base(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1439 { _M_init(__base); }
1441 ~_Local_iterator_base()
1443 if (_M_bucket_count !=
size_t(-1))
1447 _Local_iterator_base(
const _Local_iterator_base& __iter)
1448 : __node_iter_base(__iter._M_cur), _M_bucket(__iter._M_bucket)
1449 , _M_bucket_count(__iter._M_bucket_count)
1451 if (_M_bucket_count !=
size_t(-1))
1452 _M_init(*__iter._M_h());
1455 _Local_iterator_base&
1456 operator=(
const _Local_iterator_base& __iter)
1458 if (_M_bucket_count != -1)
1460 this->_M_cur = __iter._M_cur;
1461 _M_bucket = __iter._M_bucket;
1462 _M_bucket_count = __iter._M_bucket_count;
1463 if (_M_bucket_count != -1)
1464 _M_init(*__iter._M_h());
1471 __node_iter_base::_M_incr();
1474 std::size_t __bkt = this->_M_h()->_M_bucket_index(*this->_M_cur,
1476 if (__bkt != _M_bucket)
1477 this->_M_cur =
nullptr;
1481 std::size_t _M_bucket;
1482 std::size_t _M_bucket_count;
1485 _M_init(
const __hash_code_base& __base)
1486 { ::new(this->_M_h()) __hash_code_base(__base); }
1489 _M_destroy() { this->_M_h()->~__hash_code_base(); }
1493 _M_get_bucket()
const {
return _M_bucket; }
1497 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1498 typename _Hash,
typename _RangeHash,
typename _Unused,
1499 bool __constant_iterators,
bool __cache>
1500 struct _Local_iterator
1501 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1502 _Hash, _RangeHash, _Unused, __cache>
1505 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1506 _Hash, _RangeHash, _Unused, __cache>;
1507 using __hash_code_base =
typename __base_type::__hash_code_base;
1510 using value_type = _Value;
1511 using pointer = __conditional_t<__constant_iterators,
1512 const value_type*, value_type*>;
1513 using reference = __conditional_t<__constant_iterators,
1514 const value_type&, value_type&>;
1515 using difference_type = ptrdiff_t;
1516 using iterator_category = forward_iterator_tag;
1518 _Local_iterator() =
default;
1520 _Local_iterator(
const __hash_code_base& __base,
1521 _Hash_node<_Value, __cache>* __n,
1522 std::size_t __bkt, std::size_t __bkt_count)
1523 : __base_type(
__base, __n, __bkt, __bkt_count)
1528 {
return this->_M_cur->_M_v(); }
1532 {
return this->_M_cur->_M_valptr(); }
1544 _Local_iterator __tmp(*
this);
1551 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1552 typename _Hash,
typename _RangeHash,
typename _Unused,
1553 bool __constant_iterators,
bool __cache>
1554 struct _Local_const_iterator
1555 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1556 _Hash, _RangeHash, _Unused, __cache>
1559 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1560 _Hash, _RangeHash, _Unused, __cache>;
1561 using __hash_code_base =
typename __base_type::__hash_code_base;
1564 typedef _Value value_type;
1565 typedef const value_type* pointer;
1566 typedef const value_type& reference;
1567 typedef std::ptrdiff_t difference_type;
1570 _Local_const_iterator() =
default;
1572 _Local_const_iterator(
const __hash_code_base& __base,
1573 _Hash_node<_Value, __cache>* __n,
1574 std::size_t __bkt, std::size_t __bkt_count)
1575 : __base_type(
__base, __n, __bkt, __bkt_count)
1578 _Local_const_iterator(
const _Local_iterator<_Key, _Value, _ExtractKey,
1579 _Hash, _RangeHash, _Unused,
1580 __constant_iterators,
1587 {
return this->_M_cur->_M_v(); }
1591 {
return this->_M_cur->_M_valptr(); }
1593 _Local_const_iterator&
1600 _Local_const_iterator
1603 _Local_const_iterator __tmp(*
this);
1619 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1620 typename _Equal,
typename _Hash,
typename _RangeHash,
1621 typename _Unused,
typename _Traits>
1622 struct _Hashtable_base
1623 :
public _Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1624 _Unused, _Traits::__hash_cached::value>,
1625 private _Hashtable_ebo_helper<0, _Equal>
1628 typedef _Key key_type;
1629 typedef _Value value_type;
1630 typedef _Equal key_equal;
1631 typedef std::size_t size_type;
1632 typedef std::ptrdiff_t difference_type;
1634 using __traits_type = _Traits;
1635 using __hash_cached =
typename __traits_type::__hash_cached;
1637 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1638 _Hash, _RangeHash, _Unused,
1639 __hash_cached::value>;
1641 using __hash_code =
typename __hash_code_base::__hash_code;
1644 using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>;
1647 _S_equals(__hash_code,
const _Hash_node_code_cache<false>&)
1651 _S_node_equals(
const _Hash_node_code_cache<false>&,
1652 const _Hash_node_code_cache<false>&)
1656 _S_equals(__hash_code __c,
const _Hash_node_code_cache<true>& __n)
1657 {
return __c == __n._M_hash_code; }
1660 _S_node_equals(
const _Hash_node_code_cache<true>& __lhn,
1661 const _Hash_node_code_cache<true>& __rhn)
1662 {
return __lhn._M_hash_code == __rhn._M_hash_code; }
1665 _Hashtable_base() =
default;
1667 _Hashtable_base(
const _Hash& __hash,
const _Equal& __eq)
1668 : __hash_code_base(__hash), _EqualEBO(__eq)
1672 _M_key_equals(
const _Key& __k,
1673 const _Hash_node_value<_Value,
1674 __hash_cached::value>& __n)
const
1676 static_assert(__is_invocable<const _Equal&, const _Key&, const _Key&>{},
1677 "key equality predicate must be invocable with two arguments of "
1679 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1682 template<
typename _Kt>
1684 _M_key_equals_tr(
const _Kt& __k,
1685 const _Hash_node_value<_Value,
1686 __hash_cached::value>& __n)
const
1689 __is_invocable<const _Equal&, const _Kt&, const _Key&>{},
1690 "key equality predicate must be invocable with two arguments of "
1692 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1696 _M_equals(
const _Key& __k, __hash_code __c,
1697 const _Hash_node_value<_Value, __hash_cached::value>& __n)
const
1698 {
return _S_equals(__c, __n) && _M_key_equals(__k, __n); }
1700 template<
typename _Kt>
1702 _M_equals_tr(
const _Kt& __k, __hash_code __c,
1703 const _Hash_node_value<_Value,
1704 __hash_cached::value>& __n)
const
1705 {
return _S_equals(__c, __n) && _M_key_equals_tr(__k, __n); }
1709 const _Hash_node_value<_Value, __hash_cached::value>& __lhn,
1710 const _Hash_node_value<_Value, __hash_cached::value>& __rhn)
const
1712 return _S_node_equals(__lhn, __rhn)
1713 && _M_key_equals(_ExtractKey{}(__lhn._M_v()), __rhn);
1717 _M_swap(_Hashtable_base& __x)
1719 __hash_code_base::_M_swap(__x);
1720 std::swap(_EqualEBO::_M_get(), __x._EqualEBO::_M_get());
1724 _M_eq()
const {
return _EqualEBO::_M_cget(); }
1735 template<
typename _Key,
typename _Value,
typename _Alloc,
1736 typename _ExtractKey,
typename _Equal,
1737 typename _Hash,
typename _RangeHash,
typename _Unused,
1738 typename _RehashPolicy,
typename _Traits,
1739 bool _Unique_keys = _Traits::__unique_keys::value>
1743 template<
typename _Key,
typename _Value,
typename _Alloc,
1744 typename _ExtractKey,
typename _Equal,
1745 typename _Hash,
typename _RangeHash,
typename _Unused,
1746 typename _RehashPolicy,
typename _Traits>
1747 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1748 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
1750 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1751 _Hash, _RangeHash, _Unused,
1752 _RehashPolicy, _Traits>;
1755 _M_equal(
const __hashtable&)
const;
1758 template<
typename _Key,
typename _Value,
typename _Alloc,
1759 typename _ExtractKey,
typename _Equal,
1760 typename _Hash,
typename _RangeHash,
typename _Unused,
1761 typename _RehashPolicy,
typename _Traits>
1763 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1764 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
1765 _M_equal(
const __hashtable& __other)
const
1767 using __node_type =
typename __hashtable::__node_type;
1768 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1769 if (__this->size() != __other.size())
1772 for (
auto __itx = __this->begin(); __itx != __this->end(); ++__itx)
1774 std::size_t __ybkt = __other._M_bucket_index(*__itx._M_cur);
1775 auto __prev_n = __other._M_buckets[__ybkt];
1779 for (__node_type* __n =
static_cast<__node_type*
>(__prev_n->_M_nxt);;
1780 __n = __n->_M_next())
1782 if (__n->_M_v() == *__itx)
1786 || __other._M_bucket_index(*__n->_M_next()) != __ybkt)
1795 template<
typename _Key,
typename _Value,
typename _Alloc,
1796 typename _ExtractKey,
typename _Equal,
1797 typename _Hash,
typename _RangeHash,
typename _Unused,
1798 typename _RehashPolicy,
typename _Traits>
1799 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1800 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1802 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1803 _Hash, _RangeHash, _Unused,
1804 _RehashPolicy, _Traits>;
1807 _M_equal(
const __hashtable&)
const;
1810 template<
typename _Key,
typename _Value,
typename _Alloc,
1811 typename _ExtractKey,
typename _Equal,
1812 typename _Hash,
typename _RangeHash,
typename _Unused,
1813 typename _RehashPolicy,
typename _Traits>
1815 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1816 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
false>::
1817 _M_equal(
const __hashtable& __other)
const
1819 using __node_type =
typename __hashtable::__node_type;
1820 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1821 if (__this->size() != __other.size())
1824 for (
auto __itx = __this->begin(); __itx != __this->end();)
1826 std::size_t __x_count = 1;
1827 auto __itx_end = __itx;
1828 for (++__itx_end; __itx_end != __this->end()
1829 && __this->key_eq()(_ExtractKey{}(*__itx),
1830 _ExtractKey{}(*__itx_end));
1834 std::size_t __ybkt = __other._M_bucket_index(*__itx._M_cur);
1835 auto __y_prev_n = __other._M_buckets[__ybkt];
1839 __node_type* __y_n =
static_cast<__node_type*
>(__y_prev_n->_M_nxt);
1842 if (__this->key_eq()(_ExtractKey{}(__y_n->_M_v()),
1843 _ExtractKey{}(*__itx)))
1846 auto __y_ref_n = __y_n;
1847 for (__y_n = __y_n->_M_next(); __y_n; __y_n = __y_n->_M_next())
1848 if (!__other._M_node_equals(*__y_ref_n, *__y_n))
1851 if (!__y_n || __other._M_bucket_index(*__y_n) != __ybkt)
1855 typename __hashtable::const_iterator __ity(__y_n);
1856 for (
auto __ity_end = __ity; __ity_end != __other.end(); ++__ity_end)
1857 if (--__x_count == 0)
1863 if (!std::is_permutation(__itx, __itx_end, __ity))
1875 template<
typename _NodeAlloc>
1876 struct _Hashtable_alloc :
private _Hashtable_ebo_helper<0, _NodeAlloc>
1879 using __ebo_node_alloc = _Hashtable_ebo_helper<0, _NodeAlloc>;
1882 struct __get_value_type;
1883 template<
typename _Val,
bool _Cache_hash_code>
1884 struct __get_value_type<_Hash_node<_Val, _Cache_hash_code>>
1885 {
using type = _Val; };
1888 using __node_type =
typename _NodeAlloc::value_type;
1889 using __node_alloc_type = _NodeAlloc;
1893 using __value_alloc_traits =
typename __node_alloc_traits::template
1894 rebind_traits<typename __get_value_type<__node_type>::type>;
1896 using __node_ptr = __node_type*;
1897 using __node_base = _Hash_node_base;
1898 using __node_base_ptr = __node_base*;
1899 using __buckets_alloc_type =
1900 __alloc_rebind<__node_alloc_type, __node_base_ptr>;
1902 using __buckets_ptr = __node_base_ptr*;
1904 _Hashtable_alloc() =
default;
1905 _Hashtable_alloc(
const _Hashtable_alloc&) =
default;
1906 _Hashtable_alloc(_Hashtable_alloc&&) =
default;
1908 template<
typename _Alloc>
1909 _Hashtable_alloc(_Alloc&& __a)
1910 : __ebo_node_alloc(
std::
forward<_Alloc>(__a))
1915 {
return __ebo_node_alloc::_M_get(); }
1917 const __node_alloc_type&
1918 _M_node_allocator()
const
1919 {
return __ebo_node_alloc::_M_cget(); }
1922 template<
typename... _Args>
1924 _M_allocate_node(_Args&&... __args);
1928 _M_deallocate_node(__node_ptr __n);
1932 _M_deallocate_node_ptr(__node_ptr __n);
1937 _M_deallocate_nodes(__node_ptr __n);
1940 _M_allocate_buckets(std::size_t __bkt_count);
1943 _M_deallocate_buckets(__buckets_ptr, std::size_t __bkt_count);
1948 template<
typename _NodeAlloc>
1949 template<
typename... _Args>
1951 _Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&&... __args)
1954 auto __nptr = __node_alloc_traits::allocate(_M_node_allocator(), 1);
1955 __node_ptr __n = std::__to_address(__nptr);
1958 ::new ((
void*)__n) __node_type;
1959 __node_alloc_traits::construct(_M_node_allocator(),
1966 __node_alloc_traits::deallocate(_M_node_allocator(), __nptr, 1);
1967 __throw_exception_again;
1971 template<
typename _NodeAlloc>
1973 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node(__node_ptr __n)
1975 __node_alloc_traits::destroy(_M_node_allocator(), __n->_M_valptr());
1976 _M_deallocate_node_ptr(__n);
1979 template<
typename _NodeAlloc>
1981 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node_ptr(__node_ptr __n)
1983 typedef typename __node_alloc_traits::pointer _Ptr;
1985 __n->~__node_type();
1986 __node_alloc_traits::deallocate(_M_node_allocator(), __ptr, 1);
1989 template<
typename _NodeAlloc>
1991 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_nodes(__node_ptr __n)
1995 __node_ptr __tmp = __n;
1996 __n = __n->_M_next();
1997 _M_deallocate_node(__tmp);
2001 template<
typename _NodeAlloc>
2003 _Hashtable_alloc<_NodeAlloc>::_M_allocate_buckets(std::size_t __bkt_count)
2006 __buckets_alloc_type __alloc(_M_node_allocator());
2008 auto __ptr = __buckets_alloc_traits::allocate(__alloc, __bkt_count);
2009 __buckets_ptr __p = std::__to_address(__ptr);
2010 __builtin_memset(__p, 0, __bkt_count *
sizeof(__node_base_ptr));
2014 template<
typename _NodeAlloc>
2016 _Hashtable_alloc<_NodeAlloc>::
2017 _M_deallocate_buckets(__buckets_ptr __bkts,
2018 std::size_t __bkt_count)
2020 typedef typename __buckets_alloc_traits::pointer _Ptr;
2022 __buckets_alloc_type __alloc(_M_node_allocator());
2023 __buckets_alloc_traits::deallocate(__alloc, __ptr, __bkt_count);
2029_GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr tuple< _Elements &&... > forward_as_tuple(_Elements &&... __args) noexcept
Create a tuple of lvalue or rvalue references to the arguments.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr piecewise_construct_t piecewise_construct
Tag for piecewise construction of std::pair objects.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.
constexpr _Iterator __base(_Iterator __it)
Primary class template, tuple.
Traits class for iterators.
Uniform interface to all pointer-like types.
Forward iterators support a superset of input iterator operations.
Uniform interface to C++98 and C++11 allocators.