31 #ifndef _HASHTABLE_POLICY_H 32 #define _HASHTABLE_POLICY_H 1 38 namespace std _GLIBCXX_VISIBILITY(default)
40 _GLIBCXX_BEGIN_NAMESPACE_VERSION
43 template<
typename _Key,
typename _Value,
typename _Alloc,
44 typename _ExtractKey,
typename _Equal,
45 typename _Hash,
typename _RangeHash,
typename _Unused,
46 typename _RehashPolicy,
typename _Traits>
56 template<
typename _Key,
typename _Value,
typename _ExtractKey,
57 typename _Equal,
typename _Hash,
typename _RangeHash,
58 typename _Unused,
typename _Traits>
59 struct _Hashtable_base;
63 template<
typename _Iterator>
65 __distance_fw(_Iterator __first, _Iterator __last,
67 {
return __first != __last ? 1 : 0; }
69 template<
typename _Iterator>
71 __distance_fw(_Iterator __first, _Iterator __last,
75 template<
typename _Iterator>
77 __distance_fw(_Iterator __first, _Iterator __last)
78 {
return __distance_fw(__first, __last,
83 template<
typename _Tp>
85 operator()(_Tp&& __x)
const noexcept
86 {
return std::forward<_Tp>(__x); }
91 template<
typename _Pair>
94 template<
typename _Tp,
typename _Up>
95 struct __1st_type<pair<_Tp, _Up>>
96 {
using type = _Tp; };
98 template<
typename _Tp,
typename _Up>
99 struct __1st_type<const pair<_Tp, _Up>>
100 {
using type =
const _Tp; };
102 template<
typename _Pair>
103 struct __1st_type<_Pair&>
104 {
using type =
typename __1st_type<_Pair>::type&; };
106 template<
typename _Tp>
107 typename __1st_type<_Tp>::type&&
108 operator()(_Tp&& __x)
const noexcept
109 {
return std::forward<_Tp>(__x).first; }
112 template<
typename _ExKey>
116 struct _NodeBuilder<_Select1st>
118 template<
typename _Kt,
typename _Arg,
typename _NodeGenerator>
120 _S_build(_Kt&& __k, _Arg&& __arg,
const _NodeGenerator& __node_gen)
121 ->
typename _NodeGenerator::__node_type*
123 return __node_gen(std::forward<_Kt>(__k),
124 std::forward<_Arg>(__arg).second);
129 struct _NodeBuilder<_Identity>
131 template<
typename _Kt,
typename _Arg,
typename _NodeGenerator>
133 _S_build(_Kt&& __k, _Arg&&,
const _NodeGenerator& __node_gen)
134 ->
typename _NodeGenerator::__node_type*
135 {
return __node_gen(std::forward<_Kt>(__k)); }
138 template<
typename _NodeAlloc>
139 struct _Hashtable_alloc;
143 template<
typename _NodeAlloc>
144 struct _ReuseOrAllocNode
147 using __node_alloc_type = _NodeAlloc;
148 using __hashtable_alloc = _Hashtable_alloc<__node_alloc_type>;
149 using __node_alloc_traits =
150 typename __hashtable_alloc::__node_alloc_traits;
153 using __node_type =
typename __hashtable_alloc::__node_type;
155 _ReuseOrAllocNode(__node_type* __nodes, __hashtable_alloc& __h)
156 : _M_nodes(__nodes), _M_h(__h) { }
157 _ReuseOrAllocNode(
const _ReuseOrAllocNode&) =
delete;
160 { _M_h._M_deallocate_nodes(_M_nodes); }
162 template<
typename... _Args>
164 operator()(_Args&&... __args)
const 168 __node_type* __node = _M_nodes;
169 _M_nodes = _M_nodes->_M_next();
170 __node->_M_nxt =
nullptr;
171 auto& __a = _M_h._M_node_allocator();
172 __node_alloc_traits::destroy(__a, __node->_M_valptr());
175 __node_alloc_traits::construct(__a, __node->_M_valptr(),
176 std::forward<_Args>(__args)...);
180 _M_h._M_deallocate_node_ptr(__node);
181 __throw_exception_again;
185 return _M_h._M_allocate_node(std::forward<_Args>(__args)...);
189 mutable __node_type* _M_nodes;
190 __hashtable_alloc& _M_h;
195 template<
typename _NodeAlloc>
199 using __hashtable_alloc = _Hashtable_alloc<_NodeAlloc>;
202 using __node_type =
typename __hashtable_alloc::__node_type;
204 _AllocNode(__hashtable_alloc& __h)
207 template<
typename... _Args>
209 operator()(_Args&&... __args)
const 210 {
return _M_h._M_allocate_node(std::forward<_Args>(__args)...); }
213 __hashtable_alloc& _M_h;
241 template<
bool _Cache_hash_code,
bool _Constant_iterators,
bool _Unique_keys>
242 struct _Hashtable_traits
244 using __hash_cached = __bool_constant<_Cache_hash_code>;
245 using __constant_iterators = __bool_constant<_Constant_iterators>;
246 using __unique_keys = __bool_constant<_Unique_keys>;
255 template<
typename _Hash>
256 struct _Hashtable_hash_traits
258 static constexpr std::size_t
259 __small_size_threshold() noexcept
260 {
return std::__is_fast_hash<_Hash>::value ? 0 : 20; }
271 struct _Hash_node_base
273 _Hash_node_base* _M_nxt;
275 _Hash_node_base() noexcept : _M_nxt() { }
277 _Hash_node_base(_Hash_node_base* __next) noexcept : _M_nxt(__next) { }
285 template<
typename _Value>
286 struct _Hash_node_value_base
288 typedef _Value value_type;
290 __gnu_cxx::__aligned_buffer<_Value> _M_storage;
294 {
return _M_storage._M_ptr(); }
297 _M_valptr() const noexcept
298 {
return _M_storage._M_ptr(); }
302 {
return *_M_valptr(); }
305 _M_v() const noexcept
306 {
return *_M_valptr(); }
312 template<
bool _Cache_hash_code>
313 struct _Hash_node_code_cache
320 struct _Hash_node_code_cache<true>
321 { std::size_t _M_hash_code; };
323 template<
typename _Value,
bool _Cache_hash_code>
324 struct _Hash_node_value
325 : _Hash_node_value_base<_Value>
326 , _Hash_node_code_cache<_Cache_hash_code>
332 template<
typename _Value,
bool _Cache_hash_code>
335 , _Hash_node_value<_Value, _Cache_hash_code>
338 _M_next() const noexcept
339 {
return static_cast<_Hash_node*
>(this->_M_nxt); }
343 template<
typename _Value,
bool _Cache_hash_code>
344 struct _Node_iterator_base
346 using __node_type = _Hash_node<_Value, _Cache_hash_code>;
350 _Node_iterator_base() : _M_cur(nullptr) { }
351 _Node_iterator_base(__node_type* __p) noexcept
356 { _M_cur = _M_cur->_M_next(); }
359 operator==(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
361 {
return __x._M_cur == __y._M_cur; }
363 #if __cpp_impl_three_way_comparison < 201907L 365 operator!=(
const _Node_iterator_base& __x,
const _Node_iterator_base& __y)
367 {
return __x._M_cur != __y._M_cur; }
372 template<
typename _Value,
bool __constant_iterators,
bool __cache>
373 struct _Node_iterator
374 :
public _Node_iterator_base<_Value, __cache>
377 using __base_type = _Node_iterator_base<_Value, __cache>;
378 using __node_type =
typename __base_type::__node_type;
381 using value_type = _Value;
382 using difference_type = std::ptrdiff_t;
385 using pointer = __conditional_t<__constant_iterators,
386 const value_type*, value_type*>;
388 using reference = __conditional_t<__constant_iterators,
389 const value_type&, value_type&>;
391 _Node_iterator() =
default;
394 _Node_iterator(__node_type* __p) noexcept
395 : __base_type(__p) { }
399 {
return this->_M_cur->_M_v(); }
402 operator->() const noexcept
403 {
return this->_M_cur->_M_valptr(); }
406 operator++() noexcept
413 operator++(
int) noexcept
415 _Node_iterator __tmp(*
this);
422 template<
typename _Value,
bool __constant_iterators,
bool __cache>
423 struct _Node_const_iterator
424 :
public _Node_iterator_base<_Value, __cache>
427 using __base_type = _Node_iterator_base<_Value, __cache>;
428 using __node_type =
typename __base_type::__node_type;
431 typedef _Value value_type;
432 typedef std::ptrdiff_t difference_type;
435 typedef const value_type* pointer;
436 typedef const value_type& reference;
438 _Node_const_iterator() =
default;
441 _Node_const_iterator(__node_type* __p) noexcept
442 : __base_type(__p) { }
444 _Node_const_iterator(
const _Node_iterator<_Value, __constant_iterators,
445 __cache>& __x) noexcept
446 : __base_type(__x._M_cur) { }
450 {
return this->_M_cur->_M_v(); }
453 operator->() const noexcept
454 {
return this->_M_cur->_M_valptr(); }
456 _Node_const_iterator&
457 operator++() noexcept
464 operator++(
int) noexcept
466 _Node_const_iterator __tmp(*
this);
477 struct _Mod_range_hashing
479 typedef std::size_t first_argument_type;
480 typedef std::size_t second_argument_type;
481 typedef std::size_t result_type;
484 operator()(first_argument_type __num,
485 second_argument_type __den)
const noexcept
486 {
return __num % __den; }
494 struct _Default_ranged_hash { };
498 struct _Prime_rehash_policy
502 _Prime_rehash_policy(
float __z = 1.0) noexcept
503 : _M_max_load_factor(__z), _M_next_resize(0) { }
506 max_load_factor() const noexcept
507 {
return _M_max_load_factor; }
511 _M_next_bkt(std::size_t __n)
const;
515 _M_bkt_for_elements(std::size_t __n)
const 516 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
523 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
524 std::size_t __n_ins)
const;
526 typedef std::size_t _State;
530 {
return _M_next_resize; }
534 { _M_next_resize = 0; }
537 _M_reset(_State __state)
538 { _M_next_resize = __state; }
540 static const std::size_t _S_growth_factor = 2;
542 float _M_max_load_factor;
543 mutable std::size_t _M_next_resize;
547 struct _Mask_range_hashing
549 typedef std::size_t first_argument_type;
550 typedef std::size_t second_argument_type;
551 typedef std::size_t result_type;
554 operator()(first_argument_type __num,
555 second_argument_type __den)
const noexcept
556 {
return __num & (__den - 1); }
561 __clp2(std::size_t __n) noexcept
567 const unsigned __lz =
sizeof(size_t) >
sizeof(
long)
568 ? __builtin_clzll(__n - 1ull)
569 : __builtin_clzl(__n - 1ul);
571 return (
size_t(1) << (__int_traits<size_t>::__digits - __lz - 1)) << 1;
576 struct _Power2_rehash_policy
580 _Power2_rehash_policy(
float __z = 1.0) noexcept
581 : _M_max_load_factor(__z), _M_next_resize(0) { }
584 max_load_factor() const noexcept
585 {
return _M_max_load_factor; }
590 _M_next_bkt(std::size_t __n) noexcept
598 const auto __max_width = std::min<size_t>(
sizeof(size_t), 8);
599 const auto __max_bkt = size_t(1) << (__max_width * __CHAR_BIT__ - 1);
600 std::size_t __res = __clp2(__n);
610 if (__res == __max_bkt)
614 _M_next_resize = size_t(-1);
617 = __builtin_floor(__res * (
double)_M_max_load_factor);
624 _M_bkt_for_elements(std::size_t __n)
const noexcept
625 {
return __builtin_ceil(__n / (
double)_M_max_load_factor); }
632 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
633 std::size_t __n_ins) noexcept
635 if (__n_elt + __n_ins > _M_next_resize)
641 = std::max<std::size_t>(__n_elt + __n_ins, _M_next_resize ? 0 : 11)
642 / (
double)_M_max_load_factor;
643 if (__min_bkts >= __n_bkt)
645 _M_next_bkt(std::max<std::size_t>(__builtin_floor(__min_bkts) + 1,
646 __n_bkt * _S_growth_factor)) };
649 = __builtin_floor(__n_bkt * (
double)_M_max_load_factor);
656 typedef std::size_t _State;
659 _M_state() const noexcept
660 {
return _M_next_resize; }
664 { _M_next_resize = 0; }
667 _M_reset(_State __state) noexcept
668 { _M_next_resize = __state; }
670 static const std::size_t _S_growth_factor = 2;
672 float _M_max_load_factor;
673 std::size_t _M_next_resize;
694 template<
typename _Key,
typename _Value,
typename _Alloc,
695 typename _ExtractKey,
typename _Equal,
696 typename _Hash,
typename _RangeHash,
typename _Unused,
697 typename _RehashPolicy,
typename _Traits,
698 bool _Unique_keys = _Traits::__unique_keys::value>
699 struct _Map_base { };
702 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
703 typename _Hash,
typename _RangeHash,
typename _Unused,
704 typename _RehashPolicy,
typename _Traits>
705 struct _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
706 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
708 using mapped_type = _Val;
712 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
713 typename _Hash,
typename _RangeHash,
typename _Unused,
714 typename _RehashPolicy,
typename _Traits>
715 struct _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
716 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
719 using __hashtable_base = _Hashtable_base<_Key, pair<const _Key, _Val>,
720 _Select1st, _Equal, _Hash,
724 using __hashtable = _Hashtable<_Key, pair<const _Key, _Val>, _Alloc,
725 _Select1st, _Equal, _Hash, _RangeHash,
726 _Unused, _RehashPolicy, _Traits>;
728 using __hash_code =
typename __hashtable_base::__hash_code;
731 using key_type =
typename __hashtable_base::key_type;
732 using mapped_type = _Val;
735 operator[](
const key_type& __k);
738 operator[](key_type&& __k);
743 at(
const key_type& __k)
745 auto __ite =
static_cast<__hashtable*
>(
this)->find(__k);
747 __throw_out_of_range(__N(
"unordered_map::at"));
748 return __ite->second;
752 at(
const key_type& __k)
const 754 auto __ite =
static_cast<const __hashtable*
>(
this)->find(__k);
756 __throw_out_of_range(__N(
"unordered_map::at"));
757 return __ite->second;
761 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
762 typename _Hash,
typename _RangeHash,
typename _Unused,
763 typename _RehashPolicy,
typename _Traits>
765 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
766 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
767 operator[](
const key_type& __k)
770 __hashtable* __h =
static_cast<__hashtable*
>(
this);
771 __hash_code __code = __h->_M_hash_code(__k);
772 std::size_t __bkt = __h->_M_bucket_index(__code);
773 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
774 return __node->_M_v().second;
776 typename __hashtable::_Scoped_node __node {
783 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
784 __node._M_node =
nullptr;
785 return __pos->second;
788 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
789 typename _Hash,
typename _RangeHash,
typename _Unused,
790 typename _RehashPolicy,
typename _Traits>
792 _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal,
793 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
794 operator[](key_type&& __k)
797 __hashtable* __h =
static_cast<__hashtable*
>(
this);
798 __hash_code __code = __h->_M_hash_code(__k);
799 std::size_t __bkt = __h->_M_bucket_index(__code);
800 if (
auto __node = __h->_M_find_node(__bkt, __k, __code))
801 return __node->_M_v().second;
803 typename __hashtable::_Scoped_node __node {
810 = __h->_M_insert_unique_node(__bkt, __code, __node._M_node);
811 __node._M_node =
nullptr;
812 return __pos->second;
816 template<
typename _Key,
typename _Val,
typename _Alloc,
typename _Equal,
817 typename _Hash,
typename _RangeHash,
typename _Unused,
818 typename _RehashPolicy,
typename _Traits,
bool __uniq>
819 struct _Map_base<const _Key, pair<const _Key, _Val>,
820 _Alloc, _Select1st, _Equal, _Hash,
821 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
822 : _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal, _Hash,
823 _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
831 template<
typename _Key,
typename _Value,
typename _Alloc,
832 typename _ExtractKey,
typename _Equal,
833 typename _Hash,
typename _RangeHash,
typename _Unused,
834 typename _RehashPolicy,
typename _Traits>
838 using __hashtable_base = _Hashtable_base<_Key, _Value, _ExtractKey,
839 _Equal, _Hash, _RangeHash,
842 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
844 _Unused, _RehashPolicy, _Traits>;
846 using __hash_cached =
typename _Traits::__hash_cached;
847 using __constant_iterators =
typename _Traits::__constant_iterators;
849 using __hashtable_alloc = _Hashtable_alloc<
850 __alloc_rebind<_Alloc, _Hash_node<_Value,
851 __hash_cached::value>>>;
853 using value_type =
typename __hashtable_base::value_type;
854 using size_type =
typename __hashtable_base::size_type;
856 using __unique_keys =
typename _Traits::__unique_keys;
857 using __node_alloc_type =
typename __hashtable_alloc::__node_alloc_type;
858 using __node_gen_type = _AllocNode<__node_alloc_type>;
861 _M_conjure_hashtable()
862 {
return *(
static_cast<__hashtable*
>(
this)); }
864 template<
typename _InputIterator,
typename _NodeGetter>
866 _M_insert_range(_InputIterator __first, _InputIterator __last,
869 template<
typename _InputIterator,
typename _NodeGetter>
871 _M_insert_range(_InputIterator __first, _InputIterator __last,
875 using iterator = _Node_iterator<_Value, __constant_iterators::value,
876 __hash_cached::value>;
878 using const_iterator = _Node_const_iterator<_Value,
879 __constant_iterators::value,
880 __hash_cached::value>;
882 using __ireturn_type = __conditional_t<__unique_keys::value,
887 insert(
const value_type& __v)
889 __hashtable& __h = _M_conjure_hashtable();
890 __node_gen_type __node_gen(__h);
891 return __h._M_insert(__v, __node_gen, __unique_keys{});
895 insert(const_iterator __hint,
const value_type& __v)
897 __hashtable& __h = _M_conjure_hashtable();
898 __node_gen_type __node_gen(__h);
899 return __h._M_insert(__hint, __v, __node_gen, __unique_keys{});
902 template<
typename _KType,
typename... _Args>
904 try_emplace(const_iterator, _KType&& __k, _Args&&... __args)
906 __hashtable& __h = _M_conjure_hashtable();
907 auto __code = __h._M_hash_code(__k);
908 std::size_t __bkt = __h._M_bucket_index(__code);
909 if (
auto __node = __h._M_find_node(__bkt, __k, __code))
910 return { iterator(__node),
false };
912 typename __hashtable::_Scoped_node __node {
919 = __h._M_insert_unique_node(__bkt, __code, __node._M_node);
920 __node._M_node =
nullptr;
921 return { __it,
true };
925 insert(initializer_list<value_type> __l)
926 { this->insert(__l.begin(), __l.end()); }
928 template<
typename _InputIterator>
930 insert(_InputIterator __first, _InputIterator __last)
932 __hashtable& __h = _M_conjure_hashtable();
933 __node_gen_type __node_gen(__h);
934 return _M_insert_range(__first, __last, __node_gen, __unique_keys{});
938 template<
typename _Key,
typename _Value,
typename _Alloc,
939 typename _ExtractKey,
typename _Equal,
940 typename _Hash,
typename _RangeHash,
typename _Unused,
941 typename _RehashPolicy,
typename _Traits>
942 template<
typename _InputIterator,
typename _NodeGetter>
944 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
945 _Hash, _RangeHash, _Unused,
946 _RehashPolicy, _Traits>::
947 _M_insert_range(_InputIterator __first, _InputIterator __last,
948 const _NodeGetter& __node_gen,
true_type __uks)
950 __hashtable& __h = _M_conjure_hashtable();
951 for (; __first != __last; ++__first)
952 __h._M_insert(*__first, __node_gen, __uks);
955 template<
typename _Key,
typename _Value,
typename _Alloc,
956 typename _ExtractKey,
typename _Equal,
957 typename _Hash,
typename _RangeHash,
typename _Unused,
958 typename _RehashPolicy,
typename _Traits>
959 template<
typename _InputIterator,
typename _NodeGetter>
961 _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
962 _Hash, _RangeHash, _Unused,
963 _RehashPolicy, _Traits>::
964 _M_insert_range(_InputIterator __first, _InputIterator __last,
965 const _NodeGetter& __node_gen,
false_type __uks)
967 using __rehash_type =
typename __hashtable::__rehash_type;
968 using __rehash_state =
typename __hashtable::__rehash_state;
971 size_type __n_elt = __detail::__distance_fw(__first, __last);
975 __hashtable& __h = _M_conjure_hashtable();
976 __rehash_type& __rehash = __h._M_rehash_policy;
977 const __rehash_state& __saved_state = __rehash._M_state();
978 pair_type __do_rehash = __rehash._M_need_rehash(__h._M_bucket_count,
979 __h._M_element_count,
982 if (__do_rehash.first)
983 __h._M_rehash(__do_rehash.second, __saved_state);
985 for (; __first != __last; ++__first)
986 __h._M_insert(*__first, __node_gen, __uks);
995 template<
typename _Key,
typename _Value,
typename _Alloc,
996 typename _ExtractKey,
typename _Equal,
997 typename _Hash,
typename _RangeHash,
typename _Unused,
998 typename _RehashPolicy,
typename _Traits,
999 bool _Constant_iterators = _Traits::__constant_iterators::value>
1003 template<
typename _Key,
typename _Value,
typename _Alloc,
1004 typename _ExtractKey,
typename _Equal,
1005 typename _Hash,
typename _RangeHash,
typename _Unused,
1006 typename _RehashPolicy,
typename _Traits>
1007 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1008 _Hash, _RangeHash, _Unused,
1009 _RehashPolicy, _Traits, true>
1010 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1011 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1013 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1014 _Equal, _Hash, _RangeHash, _Unused,
1015 _RehashPolicy, _Traits>;
1017 using value_type =
typename __base_type::value_type;
1018 using iterator =
typename __base_type::iterator;
1019 using const_iterator =
typename __base_type::const_iterator;
1020 using __ireturn_type =
typename __base_type::__ireturn_type;
1022 using __unique_keys =
typename __base_type::__unique_keys;
1023 using __hashtable =
typename __base_type::__hashtable;
1024 using __node_gen_type =
typename __base_type::__node_gen_type;
1026 using __base_type::insert;
1029 insert(value_type&& __v)
1031 __hashtable& __h = this->_M_conjure_hashtable();
1032 __node_gen_type __node_gen(__h);
1033 return __h._M_insert(
std::move(__v), __node_gen, __unique_keys{});
1037 insert(const_iterator __hint, value_type&& __v)
1039 __hashtable& __h = this->_M_conjure_hashtable();
1040 __node_gen_type __node_gen(__h);
1041 return __h._M_insert(__hint,
std::move(__v), __node_gen,
1047 template<
typename _Key,
typename _Value,
typename _Alloc,
1048 typename _ExtractKey,
typename _Equal,
1049 typename _Hash,
typename _RangeHash,
typename _Unused,
1050 typename _RehashPolicy,
typename _Traits>
1051 struct _Insert<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1052 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1053 :
public _Insert_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1054 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>
1056 using __base_type = _Insert_base<_Key, _Value, _Alloc, _ExtractKey,
1057 _Equal, _Hash, _RangeHash, _Unused,
1058 _RehashPolicy, _Traits>;
1059 using value_type =
typename __base_type::value_type;
1060 using iterator =
typename __base_type::iterator;
1061 using const_iterator =
typename __base_type::const_iterator;
1063 using __unique_keys =
typename __base_type::__unique_keys;
1064 using __hashtable =
typename __base_type::__hashtable;
1065 using __ireturn_type =
typename __base_type::__ireturn_type;
1067 using __base_type::insert;
1069 template<
typename _Pair>
1072 template<
typename _Pair>
1075 template<
typename _Pair>
1076 using _IFconsp =
typename _IFcons<_Pair>::type;
1078 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1082 __hashtable& __h = this->_M_conjure_hashtable();
1083 return __h._M_emplace(__unique_keys{}, std::forward<_Pair>(__v));
1086 template<
typename _Pair,
typename = _IFconsp<_Pair>>
1088 insert(const_iterator __hint, _Pair&& __v)
1090 __hashtable& __h = this->_M_conjure_hashtable();
1091 return __h._M_emplace(__hint, __unique_keys{},
1092 std::forward<_Pair>(__v));
1096 template<
typename _Policy>
1097 using __has_load_factor =
typename _Policy::__has_load_factor;
1105 template<
typename _Key,
typename _Value,
typename _Alloc,
1106 typename _ExtractKey,
typename _Equal,
1107 typename _Hash,
typename _RangeHash,
typename _Unused,
1108 typename _RehashPolicy,
typename _Traits,
1110 __detected_or_t<false_type, __has_load_factor, _RehashPolicy>>
1111 struct _Rehash_base;
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 _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1119 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1125 template<
typename _Key,
typename _Value,
typename _Alloc,
1126 typename _ExtractKey,
typename _Equal,
1127 typename _Hash,
typename _RangeHash,
typename _Unused,
1128 typename _RehashPolicy,
typename _Traits>
1129 struct _Rehash_base<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1130 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
1134 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey,
1135 _Equal, _Hash, _RangeHash, _Unused,
1136 _RehashPolicy, _Traits>;
1140 max_load_factor() const noexcept
1142 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1143 return __this->__rehash_policy().max_load_factor();
1147 max_load_factor(
float __z)
1149 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1150 __this->__rehash_policy(_RehashPolicy(__z));
1154 reserve(std::size_t __n)
1156 __hashtable* __this =
static_cast<__hashtable*
>(
this);
1157 __this->rehash(__this->__rehash_policy()._M_bkt_for_elements(__n));
1167 template<
int _Nm,
typename _Tp,
1168 bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
1169 struct _Hashtable_ebo_helper;
1172 template<
int _Nm,
typename _Tp>
1173 struct _Hashtable_ebo_helper<_Nm, _Tp, true>
1176 _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
1178 template<
typename _OtherTp>
1179 _Hashtable_ebo_helper(_OtherTp&& __tp)
1183 const _Tp& _M_cget()
const {
return static_cast<const _Tp&
>(*this); }
1184 _Tp& _M_get() {
return static_cast<_Tp&
>(*this); }
1188 template<
int _Nm,
typename _Tp>
1189 struct _Hashtable_ebo_helper<_Nm, _Tp, false>
1191 _Hashtable_ebo_helper() =
default;
1193 template<
typename _OtherTp>
1194 _Hashtable_ebo_helper(_OtherTp&& __tp)
1198 const _Tp& _M_cget()
const {
return _M_tp; }
1199 _Tp& _M_get() {
return _M_tp; }
1211 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1212 typename _Hash,
typename _RangeHash,
typename _Unused,
1213 bool __cache_hash_code>
1214 struct _Local_iterator_base;
1234 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1235 typename _Hash,
typename _RangeHash,
typename _Unused,
1236 bool __cache_hash_code>
1237 struct _Hash_code_base
1238 :
private _Hashtable_ebo_helper<1, _Hash>
1241 using __ebo_hash = _Hashtable_ebo_helper<1, _Hash>;
1244 friend struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1245 _Hash, _RangeHash, _Unused, false>;
1248 typedef _Hash hasher;
1251 hash_function()
const 1252 {
return _M_hash(); }
1255 typedef std::size_t __hash_code;
1259 _Hash_code_base() =
default;
1261 _Hash_code_base(
const _Hash& __hash) : __ebo_hash(__hash) { }
1264 _M_hash_code(
const _Key& __k)
const 1266 static_assert(__is_invocable<const _Hash&, const _Key&>{},
1267 "hash function must be invocable with an argument of key type");
1268 return _M_hash()(__k);
1271 template<
typename _Kt>
1273 _M_hash_code_tr(
const _Kt& __k)
const 1275 static_assert(__is_invocable<const _Hash&, const _Kt&>{},
1276 "hash function must be invocable with an argument of key type");
1277 return _M_hash()(__k);
1281 _M_hash_code(
const _Hash&,
1282 const _Hash_node_value<_Value, true>& __n)
const 1283 {
return __n._M_hash_code; }
1287 template<
typename _H2>
1289 _M_hash_code(
const _H2&,
1290 const _Hash_node_value<_Value, __cache_hash_code>& __n)
const 1291 {
return _M_hash_code(_ExtractKey{}(__n._M_v())); }
1294 _M_hash_code(
const _Hash_node_value<_Value, false>& __n)
const 1295 {
return _M_hash_code(_ExtractKey{}(__n._M_v())); }
1298 _M_hash_code(
const _Hash_node_value<_Value, true>& __n)
const 1299 {
return __n._M_hash_code; }
1302 _M_bucket_index(__hash_code __c, std::size_t __bkt_count)
const 1303 {
return _RangeHash{}(__c, __bkt_count); }
1306 _M_bucket_index(
const _Hash_node_value<_Value, false>& __n,
1307 std::size_t __bkt_count)
const 1308 noexcept( noexcept(declval<const _Hash&>()(declval<const _Key&>()))
1309 && noexcept(declval<const _RangeHash&>()((__hash_code)0,
1312 return _RangeHash{}(_M_hash_code(_ExtractKey{}(__n._M_v())),
1317 _M_bucket_index(
const _Hash_node_value<_Value, true>& __n,
1318 std::size_t __bkt_count)
const 1319 noexcept( noexcept(declval<const _RangeHash&>()((__hash_code)0,
1321 {
return _RangeHash{}(__n._M_hash_code, __bkt_count); }
1324 _M_store_code(_Hash_node_code_cache<false>&, __hash_code)
const 1328 _M_copy_code(_Hash_node_code_cache<false>&,
1329 const _Hash_node_code_cache<false>&)
const 1333 _M_store_code(_Hash_node_code_cache<true>& __n, __hash_code __c)
const 1334 { __n._M_hash_code = __c; }
1337 _M_copy_code(_Hash_node_code_cache<true>& __to,
1338 const _Hash_node_code_cache<true>& __from)
const 1339 { __to._M_hash_code = __from._M_hash_code; }
1342 _M_swap(_Hash_code_base& __x)
1343 { std::swap(__ebo_hash::_M_get(), __x.__ebo_hash::_M_get()); }
1346 _M_hash()
const {
return __ebo_hash::_M_cget(); }
1350 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1351 typename _Hash,
typename _RangeHash,
typename _Unused>
1352 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1353 _Hash, _RangeHash, _Unused, true>
1354 :
public _Node_iterator_base<_Value, true>
1357 using __base_node_iter = _Node_iterator_base<_Value, true>;
1358 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1359 _Hash, _RangeHash, _Unused,
true>;
1361 _Local_iterator_base() =
default;
1362 _Local_iterator_base(
const __hash_code_base&,
1363 _Hash_node<_Value, true>* __p,
1364 std::size_t __bkt, std::size_t __bkt_count)
1365 : __base_node_iter(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1371 __base_node_iter::_M_incr();
1375 = _RangeHash{}(this->_M_cur->_M_hash_code, _M_bucket_count);
1376 if (__bkt != _M_bucket)
1377 this->_M_cur =
nullptr;
1381 std::size_t _M_bucket;
1382 std::size_t _M_bucket_count;
1386 _M_get_bucket()
const {
return _M_bucket; }
1393 template<typename _Tp, bool _IsEmpty = std::is_empty<_Tp>::value>
1394 struct _Hash_code_storage
1396 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
1399 _M_h() {
return _M_storage._M_ptr(); }
1402 _M_h()
const {
return _M_storage._M_ptr(); }
1406 template<
typename _Tp>
1407 struct _Hash_code_storage<_Tp, true>
1414 _M_h() {
return reinterpret_cast<_Tp*
>(
this); }
1417 _M_h()
const {
return reinterpret_cast<const _Tp*
>(
this); }
1420 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1421 typename _Hash,
typename _RangeHash,
typename _Unused>
1422 using __hash_code_for_local_iter
1423 = _Hash_code_storage<_Hash_code_base<_Key, _Value, _ExtractKey,
1424 _Hash, _RangeHash, _Unused,
false>>;
1427 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1428 typename _Hash,
typename _RangeHash,
typename _Unused>
1429 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
1430 _Hash, _RangeHash, _Unused, false>
1431 : __hash_code_for_local_iter<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1433 , _Node_iterator_base<_Value, false>
1436 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1437 _Hash, _RangeHash, _Unused,
false>;
1438 using __node_iter_base = _Node_iterator_base<_Value, false>;
1440 _Local_iterator_base() : _M_bucket_count(-1) { }
1442 _Local_iterator_base(
const __hash_code_base&
__base,
1443 _Hash_node<_Value, false>* __p,
1444 std::size_t __bkt, std::size_t __bkt_count)
1445 : __node_iter_base(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count)
1448 ~_Local_iterator_base()
1450 if (_M_bucket_count !=
size_t(-1))
1454 _Local_iterator_base(
const _Local_iterator_base& __iter)
1455 : __node_iter_base(__iter._M_cur), _M_bucket(__iter._M_bucket)
1456 , _M_bucket_count(__iter._M_bucket_count)
1458 if (_M_bucket_count !=
size_t(-1))
1459 _M_init(*__iter._M_h());
1462 _Local_iterator_base&
1463 operator=(
const _Local_iterator_base& __iter)
1465 if (_M_bucket_count != -1)
1467 this->_M_cur = __iter._M_cur;
1468 _M_bucket = __iter._M_bucket;
1469 _M_bucket_count = __iter._M_bucket_count;
1470 if (_M_bucket_count != -1)
1471 _M_init(*__iter._M_h());
1478 __node_iter_base::_M_incr();
1481 std::size_t __bkt = this->_M_h()->_M_bucket_index(*this->_M_cur,
1483 if (__bkt != _M_bucket)
1484 this->_M_cur =
nullptr;
1488 std::size_t _M_bucket;
1489 std::size_t _M_bucket_count;
1492 _M_init(
const __hash_code_base&
__base)
1493 { ::new(this->_M_h()) __hash_code_base(
__base); }
1496 _M_destroy() { this->_M_h()->~__hash_code_base(); }
1500 _M_get_bucket()
const {
return _M_bucket; }
1504 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1505 typename _Hash,
typename _RangeHash,
typename _Unused,
1506 bool __constant_iterators,
bool __cache>
1507 struct _Local_iterator
1508 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1509 _Hash, _RangeHash, _Unused, __cache>
1512 using __base_type = _Local_iterator_base<_Key, _Value, _ExtractKey,
1513 _Hash, _RangeHash, _Unused, __cache>;
1514 using __hash_code_base =
typename __base_type::__hash_code_base;
1517 using value_type = _Value;
1518 using pointer = __conditional_t<__constant_iterators,
1519 const value_type*, value_type*>;
1520 using reference = __conditional_t<__constant_iterators,
1521 const value_type&, value_type&>;
1522 using difference_type = ptrdiff_t;
1523 using iterator_category = forward_iterator_tag;
1525 _Local_iterator() =
default;
1527 _Local_iterator(
const __hash_code_base&
__base,
1528 _Hash_node<_Value, __cache>* __n,
1529 std::size_t __bkt, std::size_t __bkt_count)
1530 : __base_type(
__base, __n, __bkt, __bkt_count)
1535 {
return this->_M_cur->_M_v(); }
1539 {
return this->_M_cur->_M_valptr(); }
1551 _Local_iterator __tmp(*
this);
1558 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1559 typename _Hash,
typename _RangeHash,
typename _Unused,
1560 bool __constant_iterators,
bool __cache>
1561 struct _Local_const_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 typedef _Value value_type;
1572 typedef const value_type* pointer;
1573 typedef const value_type& reference;
1574 typedef std::ptrdiff_t difference_type;
1577 _Local_const_iterator() =
default;
1579 _Local_const_iterator(
const __hash_code_base&
__base,
1580 _Hash_node<_Value, __cache>* __n,
1581 std::size_t __bkt, std::size_t __bkt_count)
1582 : __base_type(
__base, __n, __bkt, __bkt_count)
1585 _Local_const_iterator(
const _Local_iterator<_Key, _Value, _ExtractKey,
1586 _Hash, _RangeHash, _Unused,
1587 __constant_iterators,
1594 {
return this->_M_cur->_M_v(); }
1598 {
return this->_M_cur->_M_valptr(); }
1600 _Local_const_iterator&
1607 _Local_const_iterator
1610 _Local_const_iterator __tmp(*
this);
1626 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1627 typename _Equal,
typename _Hash,
typename _RangeHash,
1628 typename _Unused,
typename _Traits>
1629 struct _Hashtable_base
1630 :
public _Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash,
1631 _Unused, _Traits::__hash_cached::value>,
1632 private _Hashtable_ebo_helper<0, _Equal>
1635 typedef _Key key_type;
1636 typedef _Value value_type;
1637 typedef _Equal key_equal;
1638 typedef std::size_t size_type;
1639 typedef std::ptrdiff_t difference_type;
1641 using __traits_type = _Traits;
1642 using __hash_cached =
typename __traits_type::__hash_cached;
1644 using __hash_code_base = _Hash_code_base<_Key, _Value, _ExtractKey,
1645 _Hash, _RangeHash, _Unused,
1646 __hash_cached::value>;
1648 using __hash_code =
typename __hash_code_base::__hash_code;
1651 using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>;
1654 _S_equals(__hash_code,
const _Hash_node_code_cache<false>&)
1658 _S_node_equals(
const _Hash_node_code_cache<false>&,
1659 const _Hash_node_code_cache<false>&)
1663 _S_equals(__hash_code __c,
const _Hash_node_code_cache<true>& __n)
1664 {
return __c == __n._M_hash_code; }
1667 _S_node_equals(
const _Hash_node_code_cache<true>& __lhn,
1668 const _Hash_node_code_cache<true>& __rhn)
1669 {
return __lhn._M_hash_code == __rhn._M_hash_code; }
1672 _Hashtable_base() =
default;
1674 _Hashtable_base(
const _Hash& __hash,
const _Equal& __eq)
1675 : __hash_code_base(__hash), _EqualEBO(__eq)
1679 _M_key_equals(
const _Key& __k,
1680 const _Hash_node_value<_Value,
1681 __hash_cached::value>& __n)
const 1683 static_assert(__is_invocable<const _Equal&, const _Key&, const _Key&>{},
1684 "key equality predicate must be invocable with two arguments of " 1686 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1689 template<
typename _Kt>
1691 _M_key_equals_tr(
const _Kt& __k,
1692 const _Hash_node_value<_Value,
1693 __hash_cached::value>& __n)
const 1696 __is_invocable<const _Equal&, const _Kt&, const _Key&>{},
1697 "key equality predicate must be invocable with two arguments of " 1699 return _M_eq()(__k, _ExtractKey{}(__n._M_v()));
1703 _M_equals(
const _Key& __k, __hash_code __c,
1704 const _Hash_node_value<_Value, __hash_cached::value>& __n)
const 1705 {
return _S_equals(__c, __n) && _M_key_equals(__k, __n); }
1707 template<
typename _Kt>
1709 _M_equals_tr(
const _Kt& __k, __hash_code __c,
1710 const _Hash_node_value<_Value,
1711 __hash_cached::value>& __n)
const 1712 {
return _S_equals(__c, __n) && _M_key_equals_tr(__k, __n); }
1716 const _Hash_node_value<_Value, __hash_cached::value>& __lhn,
1717 const _Hash_node_value<_Value, __hash_cached::value>& __rhn)
const 1719 return _S_node_equals(__lhn, __rhn)
1720 && _M_key_equals(_ExtractKey{}(__lhn._M_v()), __rhn);
1724 _M_swap(_Hashtable_base& __x)
1726 __hash_code_base::_M_swap(__x);
1727 std::swap(_EqualEBO::_M_get(), __x._EqualEBO::_M_get());
1731 _M_eq()
const {
return _EqualEBO::_M_cget(); }
1742 template<
typename _Key,
typename _Value,
typename _Alloc,
1743 typename _ExtractKey,
typename _Equal,
1744 typename _Hash,
typename _RangeHash,
typename _Unused,
1745 typename _RehashPolicy,
typename _Traits,
1746 bool _Unique_keys = _Traits::__unique_keys::value>
1750 template<
typename _Key,
typename _Value,
typename _Alloc,
1751 typename _ExtractKey,
typename _Equal,
1752 typename _Hash,
typename _RangeHash,
typename _Unused,
1753 typename _RehashPolicy,
typename _Traits>
1754 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1755 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>
1757 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1758 _Hash, _RangeHash, _Unused,
1759 _RehashPolicy, _Traits>;
1762 _M_equal(
const __hashtable&)
const;
1765 template<
typename _Key,
typename _Value,
typename _Alloc,
1766 typename _ExtractKey,
typename _Equal,
1767 typename _Hash,
typename _RangeHash,
typename _Unused,
1768 typename _RehashPolicy,
typename _Traits>
1770 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1771 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
true>::
1772 _M_equal(
const __hashtable& __other)
const 1774 using __node_type =
typename __hashtable::__node_type;
1775 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1776 if (__this->size() != __other.size())
1779 for (
auto __itx = __this->begin(); __itx != __this->end(); ++__itx)
1781 std::size_t __ybkt = __other._M_bucket_index(*__itx._M_cur);
1782 auto __prev_n = __other._M_buckets[__ybkt];
1786 for (__node_type* __n = static_cast<__node_type*>(__prev_n->_M_nxt);;
1787 __n = __n->_M_next())
1789 if (__n->_M_v() == *__itx)
1793 || __other._M_bucket_index(*__n->_M_next()) != __ybkt)
1802 template<
typename _Key,
typename _Value,
typename _Alloc,
1803 typename _ExtractKey,
typename _Equal,
1804 typename _Hash,
typename _RangeHash,
typename _Unused,
1805 typename _RehashPolicy,
typename _Traits>
1806 struct _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1807 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, false>
1809 using __hashtable = _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1810 _Hash, _RangeHash, _Unused,
1811 _RehashPolicy, _Traits>;
1814 _M_equal(
const __hashtable&)
const;
1817 template<
typename _Key,
typename _Value,
typename _Alloc,
1818 typename _ExtractKey,
typename _Equal,
1819 typename _Hash,
typename _RangeHash,
typename _Unused,
1820 typename _RehashPolicy,
typename _Traits>
1822 _Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal,
1823 _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits,
false>::
1824 _M_equal(
const __hashtable& __other)
const 1826 using __node_type =
typename __hashtable::__node_type;
1827 const __hashtable* __this =
static_cast<const __hashtable*
>(
this);
1828 if (__this->size() != __other.size())
1831 for (
auto __itx = __this->begin(); __itx != __this->end();)
1833 std::size_t __x_count = 1;
1834 auto __itx_end = __itx;
1835 for (++__itx_end; __itx_end != __this->end()
1836 && __this->key_eq()(_ExtractKey{}(*__itx),
1837 _ExtractKey{}(*__itx_end));
1841 std::size_t __ybkt = __other._M_bucket_index(*__itx._M_cur);
1842 auto __y_prev_n = __other._M_buckets[__ybkt];
1846 __node_type* __y_n =
static_cast<__node_type*
>(__y_prev_n->_M_nxt);
1849 if (__this->key_eq()(_ExtractKey{}(__y_n->_M_v()),
1850 _ExtractKey{}(*__itx)))
1853 auto __y_ref_n = __y_n;
1854 for (__y_n = __y_n->_M_next(); __y_n; __y_n = __y_n->_M_next())
1855 if (!__other._M_node_equals(*__y_ref_n, *__y_n))
1858 if (!__y_n || __other._M_bucket_index(*__y_n) != __ybkt)
1862 typename __hashtable::const_iterator __ity(__y_n);
1863 for (
auto __ity_end = __ity; __ity_end != __other.end(); ++__ity_end)
1864 if (--__x_count == 0)
1870 if (!std::is_permutation(__itx, __itx_end, __ity))
1882 template<
typename _NodeAlloc>
1883 struct _Hashtable_alloc :
private _Hashtable_ebo_helper<0, _NodeAlloc>
1886 using __ebo_node_alloc = _Hashtable_ebo_helper<0, _NodeAlloc>;
1889 struct __get_value_type;
1890 template<
typename _Val,
bool _Cache_hash_code>
1891 struct __get_value_type<_Hash_node<_Val, _Cache_hash_code>>
1892 {
using type = _Val; };
1895 using __node_type =
typename _NodeAlloc::value_type;
1896 using __node_alloc_type = _NodeAlloc;
1900 using __value_alloc_traits =
typename __node_alloc_traits::template
1901 rebind_traits<typename __get_value_type<__node_type>::type>;
1903 using __node_ptr = __node_type*;
1904 using __node_base = _Hash_node_base;
1905 using __node_base_ptr = __node_base*;
1906 using __buckets_alloc_type =
1907 __alloc_rebind<__node_alloc_type, __node_base_ptr>;
1909 using __buckets_ptr = __node_base_ptr*;
1911 _Hashtable_alloc() =
default;
1912 _Hashtable_alloc(
const _Hashtable_alloc&) =
default;
1913 _Hashtable_alloc(_Hashtable_alloc&&) =
default;
1915 template<
typename _Alloc>
1916 _Hashtable_alloc(_Alloc&& __a)
1917 : __ebo_node_alloc(
std::
forward<_Alloc>(__a))
1922 {
return __ebo_node_alloc::_M_get(); }
1924 const __node_alloc_type&
1925 _M_node_allocator()
const 1926 {
return __ebo_node_alloc::_M_cget(); }
1929 template<
typename... _Args>
1931 _M_allocate_node(_Args&&... __args);
1935 _M_deallocate_node(__node_ptr __n);
1939 _M_deallocate_node_ptr(__node_ptr __n);
1944 _M_deallocate_nodes(__node_ptr __n);
1947 _M_allocate_buckets(std::size_t __bkt_count);
1950 _M_deallocate_buckets(__buckets_ptr, std::size_t __bkt_count);
1955 template<
typename _NodeAlloc>
1956 template<
typename... _Args>
1958 _Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&&... __args)
1961 auto __nptr = __node_alloc_traits::allocate(_M_node_allocator(), 1);
1962 __node_ptr __n = std::__to_address(__nptr);
1965 ::new ((
void*)__n) __node_type;
1966 __node_alloc_traits::construct(_M_node_allocator(),
1968 std::forward<_Args>(__args)...);
1973 __node_alloc_traits::deallocate(_M_node_allocator(), __nptr, 1);
1974 __throw_exception_again;
1978 template<
typename _NodeAlloc>
1980 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node(__node_ptr __n)
1982 __node_alloc_traits::destroy(_M_node_allocator(), __n->_M_valptr());
1983 _M_deallocate_node_ptr(__n);
1986 template<
typename _NodeAlloc>
1988 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_node_ptr(__node_ptr __n)
1990 typedef typename __node_alloc_traits::pointer _Ptr;
1992 __n->~__node_type();
1993 __node_alloc_traits::deallocate(_M_node_allocator(), __ptr, 1);
1996 template<
typename _NodeAlloc>
1998 _Hashtable_alloc<_NodeAlloc>::_M_deallocate_nodes(__node_ptr __n)
2002 __node_ptr __tmp = __n;
2003 __n = __n->_M_next();
2004 _M_deallocate_node(__tmp);
2008 template<
typename _NodeAlloc>
2010 _Hashtable_alloc<_NodeAlloc>::_M_allocate_buckets(std::size_t __bkt_count)
2013 __buckets_alloc_type __alloc(_M_node_allocator());
2015 auto __ptr = __buckets_alloc_traits::allocate(__alloc, __bkt_count);
2016 __buckets_ptr __p = std::__to_address(__ptr);
2017 __builtin_memset(__p, 0, __bkt_count *
sizeof(__node_base_ptr));
2021 template<
typename _NodeAlloc>
2023 _Hashtable_alloc<_NodeAlloc>::
2024 _M_deallocate_buckets(__buckets_ptr __bkts,
2025 std::size_t __bkt_count)
2027 typedef typename __buckets_alloc_traits::pointer _Ptr;
2029 __buckets_alloc_type __alloc(_M_node_allocator());
2030 __buckets_alloc_traits::deallocate(__alloc, __ptr, __bkt_count);
2036 _GLIBCXX_END_NAMESPACE_VERSION
2039 #endif // _HASHTABLE_POLICY_H
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr piecewise_construct_t piecewise_construct
Tag for piecewise construction of std::pair objects.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Iterator __base(_Iterator __it)
Define a member typedef type only if a boolean constant is true.
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
Uniform interface to all pointer-like types.
constexpr tuple< _Elements &&... > forward_as_tuple(_Elements &&... __args) noexcept
std::forward_as_tuple
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.
Uniform interface to all allocator types.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
Primary class template, tuple.
Struct holding two objects of arbitrary type.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
Forward iterators support a superset of input iterator operations.
Traits class for iterators.
Uniform interface to C++98 and C++11 allocators.