31 #ifndef _HASHTABLE_POLICY_H
32 #define _HASHTABLE_POLICY_H 1
34 namespace std _GLIBCXX_VISIBILITY(default)
38 _GLIBCXX_BEGIN_NAMESPACE_VERSION
42 template<
class _Iterator>
43 inline typename std::iterator_traits<_Iterator>::difference_type
44 __distance_fw(_Iterator __first, _Iterator __last,
48 template<
class _Iterator>
49 inline typename std::iterator_traits<_Iterator>::difference_type
50 __distance_fw(_Iterator __first, _Iterator __last,
54 template<
class _Iterator>
55 inline typename std::iterator_traits<_Iterator>::difference_type
56 __distance_fw(_Iterator __first, _Iterator __last)
58 typedef typename std::iterator_traits<_Iterator>::iterator_category _Tag;
59 return __distance_fw(__first, __last, _Tag());
64 template <
typename _Key,
typename _Hash>
66 noexcept(declval<const _Hash&>()(declval<const _Key&>()))>
76 struct _Hash_node_base
78 _Hash_node_base* _M_nxt;
82 _Hash_node_base(_Hash_node_base* __next)
86 template<
typename _Value,
bool __cache_hash_code>
89 template<
typename _Value>
90 struct _Hash_node<_Value, true> : _Hash_node_base
93 std::size_t _M_hash_code;
95 template<
typename... _Args>
96 _Hash_node(_Args&&... __args)
97 : _M_v(std::
forward<_Args>(__args)...), _M_hash_code() { }
99 _Hash_node* _M_next()
const
100 {
return static_cast<_Hash_node*
>(_M_nxt); }
103 template<
typename _Value>
104 struct _Hash_node<_Value, false> : _Hash_node_base
108 template<
typename... _Args>
109 _Hash_node(_Args&&... __args)
110 : _M_v(std::
forward<_Args>(__args)...) { }
112 _Hash_node* _M_next()
const
113 {
return static_cast<_Hash_node*
>(_M_nxt); }
117 template<
typename _Value,
bool __cache>
118 struct _Node_iterator_base
120 _Node_iterator_base(_Hash_node<_Value, __cache>* __p)
125 { _M_cur = _M_cur->_M_next(); }
127 _Hash_node<_Value, __cache>* _M_cur;
130 template<
typename _Value,
bool __cache>
132 operator==(
const _Node_iterator_base<_Value, __cache>& __x,
133 const _Node_iterator_base<_Value, __cache>& __y)
134 {
return __x._M_cur == __y._M_cur; }
136 template<
typename _Value,
bool __cache>
138 operator!=(
const _Node_iterator_base<_Value, __cache>& __x,
139 const _Node_iterator_base<_Value, __cache>& __y)
140 {
return __x._M_cur != __y._M_cur; }
142 template<
typename _Value,
bool __constant_iterators,
bool __cache>
143 struct _Node_iterator
144 :
public _Node_iterator_base<_Value, __cache>
146 typedef _Value value_type;
148 const _Value*, _Value*>::type
151 const _Value&, _Value&>::type
153 typedef std::ptrdiff_t difference_type;
157 : _Node_iterator_base<_Value, __cache>(0) { }
160 _Node_iterator(_Hash_node<_Value, __cache>* __p)
161 : _Node_iterator_base<_Value, __cache>(__p) { }
165 {
return this->_M_cur->_M_v; }
181 _Node_iterator __tmp(*
this);
187 template<
typename _Value,
bool __constant_iterators,
bool __cache>
188 struct _Node_const_iterator
189 :
public _Node_iterator_base<_Value, __cache>
191 typedef _Value value_type;
192 typedef const _Value* pointer;
193 typedef const _Value& reference;
194 typedef std::ptrdiff_t difference_type;
197 _Node_const_iterator()
198 : _Node_iterator_base<_Value, __cache>(0) { }
201 _Node_const_iterator(_Hash_node<_Value, __cache>* __p)
202 : _Node_iterator_base<_Value, __cache>(__p) { }
204 _Node_const_iterator(
const _Node_iterator<_Value, __constant_iterators,
206 : _Node_iterator_base<_Value, __cache>(__x._M_cur) { }
210 {
return this->_M_cur->_M_v; }
216 _Node_const_iterator&
226 _Node_const_iterator __tmp(*
this);
237 struct _Mod_range_hashing
239 typedef std::size_t first_argument_type;
240 typedef std::size_t second_argument_type;
241 typedef std::size_t result_type;
244 operator()(first_argument_type __num, second_argument_type __den)
const
245 {
return __num % __den; }
253 struct _Default_ranged_hash { };
257 struct _Prime_rehash_policy
259 _Prime_rehash_policy(
float __z = 1.0)
260 : _M_max_load_factor(__z), _M_prev_resize(0), _M_next_resize(0) { }
263 max_load_factor() const noexcept
264 {
return _M_max_load_factor; }
268 _M_next_bkt(std::size_t __n)
const;
272 _M_bkt_for_elements(std::size_t __n)
const;
279 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
280 std::size_t __n_ins)
const;
289 _M_reset(
const _State& __state)
291 _M_prev_resize = __state.first;
292 _M_next_resize = __state.second;
295 enum { _S_n_primes =
sizeof(
unsigned long) != 8 ? 256 : 256 + 48 };
297 static const std::size_t _S_growth_factor = 2;
299 float _M_max_load_factor;
300 mutable std::size_t _M_prev_resize;
301 mutable std::size_t _M_next_resize;
304 extern const unsigned long __prime_list[];
311 _Prime_rehash_policy::
312 _M_next_bkt(std::size_t __n)
const
316 static const unsigned char __fast_bkt[12]
317 = { 2, 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11 };
319 const std::size_t __grown_n = __n * _S_growth_factor;
324 = __builtin_ceil(__fast_bkt[__grown_n]
325 * (
long double)_M_max_load_factor);
326 return __fast_bkt[__grown_n];
329 const unsigned long* __next_bkt
332 const unsigned long* __prev_bkt
336 = __builtin_floor(*(__prev_bkt - 1) * (
long double)_M_max_load_factor);
338 = __builtin_ceil(*__next_bkt * (
long double)_M_max_load_factor);
345 _Prime_rehash_policy::
346 _M_bkt_for_elements(std::size_t __n)
const
347 {
return _M_next_bkt(__builtin_ceil(__n / (
long double)_M_max_load_factor)); }
359 _Prime_rehash_policy::
360 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
361 std::size_t __n_ins)
const
363 if (__n_elt + __n_ins >= _M_next_resize)
365 long double __min_bkts = (__n_elt + __n_ins)
366 / (
long double)_M_max_load_factor;
367 if (__min_bkts >= __n_bkt)
369 _M_next_bkt(__builtin_floor(__min_bkts) + 1));
373 = __builtin_floor(__n_bkt * (
long double)_M_max_load_factor);
377 else if (__n_elt + __n_ins < _M_prev_resize)
379 long double __min_bkts = (__n_elt + __n_ins)
380 / (
long double)_M_max_load_factor;
382 _M_next_bkt(__builtin_floor(__min_bkts) + 1));
402 template<
typename _Key,
typename _Value,
typename _Ex,
bool __unique,
404 struct _Map_base { };
406 template<
typename _Key,
typename _Pair,
typename _Hashtable>
407 struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, false, _Hashtable>
409 typedef typename _Pair::second_type mapped_type;
412 template<
typename _Key,
typename _Pair,
typename _Hashtable>
413 struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>
415 typedef typename _Pair::second_type mapped_type;
429 at(
const _Key& __k)
const;
432 template<
typename _Key,
typename _Pair,
typename _Hashtable>
433 typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
434 true, _Hashtable>::mapped_type&
435 _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
true, _Hashtable>::
436 operator[](
const _Key& __k)
438 _Hashtable* __h =
static_cast<_Hashtable*
>(
this);
439 typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k);
440 std::size_t __n = __h->_M_bucket_index(__k, __code);
442 typename _Hashtable::_Node* __p = __h->_M_find_node(__n, __k, __code);
445 __n, __code)->second;
446 return (__p->_M_v).second;
449 template<
typename _Key,
typename _Pair,
typename _Hashtable>
450 typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
451 true, _Hashtable>::mapped_type&
452 _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
true, _Hashtable>::
453 operator[](_Key&& __k)
455 _Hashtable* __h =
static_cast<_Hashtable*
>(
this);
456 typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k);
457 std::size_t __n = __h->_M_bucket_index(__k, __code);
459 typename _Hashtable::_Node* __p = __h->_M_find_node(__n, __k, __code);
463 __n, __code)->second;
464 return (__p->_M_v).second;
467 template<
typename _Key,
typename _Pair,
typename _Hashtable>
468 typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
469 true, _Hashtable>::mapped_type&
470 _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
true, _Hashtable>::
473 _Hashtable* __h =
static_cast<_Hashtable*
>(
this);
474 typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k);
475 std::size_t __n = __h->_M_bucket_index(__k, __code);
477 typename _Hashtable::_Node* __p = __h->_M_find_node(__n, __k, __code);
479 __throw_out_of_range(__N(
"_Map_base::at"));
480 return (__p->_M_v).second;
483 template<
typename _Key,
typename _Pair,
typename _Hashtable>
484 const typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
485 true, _Hashtable>::mapped_type&
486 _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
true, _Hashtable>::
487 at(
const _Key& __k)
const
489 const _Hashtable* __h =
static_cast<const _Hashtable*
>(
this);
490 typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k);
491 std::size_t __n = __h->_M_bucket_index(__k, __code);
493 typename _Hashtable::_Node* __p = __h->_M_find_node(__n, __k, __code);
495 __throw_out_of_range(__N(
"_Map_base::at"));
496 return (__p->_M_v).second;
501 template<
typename _RehashPolicy,
typename _Hashtable>
502 struct _Rehash_base { };
504 template<
typename _Hashtable>
505 struct _Rehash_base<_Prime_rehash_policy, _Hashtable>
508 max_load_factor() const noexcept
510 const _Hashtable* __this =
static_cast<const _Hashtable*
>(
this);
511 return __this->__rehash_policy().max_load_factor();
515 max_load_factor(
float __z)
517 _Hashtable* __this =
static_cast<_Hashtable*
>(
this);
518 __this->__rehash_policy(_Prime_rehash_policy(__z));
522 reserve(std::size_t __n)
524 _Hashtable* __this =
static_cast<_Hashtable*
>(
this);
525 __this->rehash(__builtin_ceil(__n / max_load_factor()));
531 template<
int _Nm,
typename _Tp,
532 bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
533 struct _Hashtable_ebo_helper;
536 template<
int _Nm,
typename _Tp>
537 struct _Hashtable_ebo_helper<_Nm, _Tp, true>
541 _Hashtable_ebo_helper() =
default;
542 _Hashtable_ebo_helper(
const _Tp& __tp) : _Tp(__tp)
546 _S_cget(
const _Hashtable_ebo_helper& __eboh)
547 {
return static_cast<const _Tp&
>(__eboh); }
550 _S_get(_Hashtable_ebo_helper& __eboh)
551 {
return static_cast<_Tp&
>(__eboh); }
555 template<
int _Nm,
typename _Tp>
556 struct _Hashtable_ebo_helper<_Nm, _Tp, false>
558 _Hashtable_ebo_helper() =
default;
559 _Hashtable_ebo_helper(
const _Tp& __tp) : _M_tp(__tp)
563 _S_cget(
const _Hashtable_ebo_helper& __eboh)
564 {
return __eboh._M_tp; }
567 _S_get(_Hashtable_ebo_helper& __eboh)
568 {
return __eboh._M_tp; }
591 template<
typename _Key,
typename _Value,
typename _ExtractKey,
592 typename _H1,
typename _H2,
typename _Hash,
593 bool __cache_hash_code>
594 struct _Hash_code_base;
598 template<
typename _Key,
typename _Value,
typename _ExtractKey,
599 typename _H1,
typename _H2,
typename _Hash>
600 struct _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash, false>
602 :
public _Hashtable_ebo_helper<0, _ExtractKey>,
603 public _Hashtable_ebo_helper<1, _Hash>
606 typedef _Hashtable_ebo_helper<0, _ExtractKey> _EboExtractKey;
607 typedef _Hashtable_ebo_helper<1, _Hash> _EboHash;
611 _Hash_code_base() =
default;
612 _Hash_code_base(
const _ExtractKey& __ex,
613 const _H1&,
const _H2&,
const _Hash& __h)
614 : _EboExtractKey(__ex), _EboHash(__h) { }
616 typedef void* _Hash_code_type;
619 _M_hash_code(
const _Key& __key)
const
623 _M_bucket_index(
const _Key& __k, _Hash_code_type,
624 std::size_t __n)
const
625 {
return _M_ranged_hash()(__k, __n); }
628 _M_bucket_index(
const _Hash_node<_Value, false>* __p,
629 std::size_t __n)
const
630 {
return _M_ranged_hash()(_M_extract()(__p->_M_v), __n); }
633 _M_store_code(_Hash_node<_Value, false>*, _Hash_code_type)
const
637 _M_copy_code(_Hash_node<_Value, false>*,
638 const _Hash_node<_Value, false>*)
const
642 _M_swap(_Hash_code_base& __x)
644 std::swap(_M_extract(), __x._M_extract());
645 std::swap(_M_ranged_hash(), __x._M_ranged_hash());
650 _M_extract()
const {
return _EboExtractKey::_S_cget(*
this); }
652 _M_extract() {
return _EboExtractKey::_S_get(*
this); }
654 _M_ranged_hash()
const {
return _EboHash::_S_cget(*
this); }
656 _M_ranged_hash() {
return _EboHash::_S_get(*
this); }
665 template<
typename _Key,
typename _Value,
typename _ExtractKey,
666 typename _H1,
typename _H2,
typename _Hash>
667 struct _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash, true>;
672 template<
typename _Key,
typename _Value,
typename _ExtractKey,
673 typename _H1,
typename _H2>
674 struct _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2,
675 _Default_ranged_hash, false>
677 :
public _Hashtable_ebo_helper<0, _ExtractKey>,
678 public _Hashtable_ebo_helper<1, _H1>,
679 public _Hashtable_ebo_helper<2, _H2>
682 typedef _Hashtable_ebo_helper<0, _ExtractKey> _EboExtractKey;
683 typedef _Hashtable_ebo_helper<1, _H1> _EboH1;
684 typedef _Hashtable_ebo_helper<2, _H2> _EboH2;
690 hash_function()
const
695 _Hash_code_base() =
default;
696 _Hash_code_base(
const _ExtractKey& __ex,
697 const _H1& __h1,
const _H2& __h2,
698 const _Default_ranged_hash&)
699 : _EboExtractKey(__ex), _EboH1(__h1), _EboH2(__h2) { }
701 typedef std::size_t _Hash_code_type;
704 _M_hash_code(
const _Key& __k)
const
705 {
return _M_h1()(__k); }
708 _M_bucket_index(
const _Key&, _Hash_code_type __c,
709 std::size_t __n)
const
710 {
return _M_h2()(__c, __n); }
713 _M_bucket_index(
const _Hash_node<_Value, false>* __p,
714 std::size_t __n)
const
715 {
return _M_h2()(_M_h1()(_M_extract()(__p->_M_v)), __n); }
718 _M_store_code(_Hash_node<_Value, false>*, _Hash_code_type)
const
722 _M_copy_code(_Hash_node<_Value, false>*,
723 const _Hash_node<_Value, false>*)
const
727 _M_swap(_Hash_code_base& __x)
729 std::swap(_M_extract(), __x._M_extract());
730 std::swap(_M_h1(), __x._M_h1());
731 std::swap(_M_h2(), __x._M_h2());
736 _M_extract()
const {
return _EboExtractKey::_S_cget(*
this); }
738 _M_extract() {
return _EboExtractKey::_S_get(*
this); }
740 _M_h1()
const {
return _EboH1::_S_cget(*
this); }
742 _M_h1() {
return _EboH1::_S_get(*
this); }
744 _M_h2()
const {
return _EboH2::_S_cget(*
this); }
746 _M_h2() {
return _EboH2::_S_get(*
this); }
752 template<
typename _Key,
typename _Value,
typename _ExtractKey,
753 typename _H1,
typename _H2>
754 struct _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2,
755 _Default_ranged_hash, true>
757 :
public _Hashtable_ebo_helper<0, _ExtractKey>,
758 public _Hashtable_ebo_helper<1, _H1>,
759 public _Hashtable_ebo_helper<2, _H2>
762 typedef _Hashtable_ebo_helper<0, _ExtractKey> _EboExtractKey;
763 typedef _Hashtable_ebo_helper<1, _H1> _EboH1;
764 typedef _Hashtable_ebo_helper<2, _H2> _EboH2;
770 hash_function()
const
774 _Hash_code_base(
const _ExtractKey& __ex,
775 const _H1& __h1,
const _H2& __h2,
776 const _Default_ranged_hash&)
777 : _EboExtractKey(__ex), _EboH1(__h1), _EboH2(__h2) { }
779 typedef std::size_t _Hash_code_type;
782 _M_hash_code(
const _Key& __k)
const
783 {
return _M_h1()(__k); }
786 _M_bucket_index(
const _Key&, _Hash_code_type __c,
787 std::size_t __n)
const
788 {
return _M_h2()(__c, __n); }
791 _M_bucket_index(
const _Hash_node<_Value, true>* __p,
792 std::size_t __n)
const
793 {
return _M_h2()(__p->_M_hash_code, __n); }
796 _M_store_code(_Hash_node<_Value, true>* __n, _Hash_code_type __c)
const
797 { __n->_M_hash_code = __c; }
800 _M_copy_code(_Hash_node<_Value, true>* __to,
801 const _Hash_node<_Value, true>* __from)
const
802 { __to->_M_hash_code = __from->_M_hash_code; }
805 _M_swap(_Hash_code_base& __x)
807 std::swap(_M_extract(), __x._M_extract());
808 std::swap(_M_h1(), __x._M_h1());
809 std::swap(_M_h2(), __x._M_h2());
814 _M_extract()
const {
return _EboExtractKey::_S_cget(*
this); }
816 _M_extract() {
return _EboExtractKey::_S_get(*
this); }
818 _M_h1()
const {
return _EboH1::_S_cget(*
this); }
820 _M_h1() {
return _EboH1::_S_get(*
this); }
822 _M_h2()
const {
return _EboH2::_S_cget(*
this); }
824 _M_h2() {
return _EboH2::_S_get(*
this); }
827 template <
typename _Key,
typename _Value,
typename _ExtractKey,
828 typename _Equal,
typename _HashCodeType,
829 bool __cache_hash_code>
830 struct _Equal_helper;
832 template<
typename _Key,
typename _Value,
typename _ExtractKey,
833 typename _Equal,
typename _HashCodeType>
834 struct _Equal_helper<_Key, _Value, _ExtractKey, _Equal, _HashCodeType, true>
837 _S_equals(
const _Equal& __eq,
const _ExtractKey& __extract,
838 const _Key& __k, _HashCodeType __c,
839 _Hash_node<_Value, true>* __n)
840 {
return __c == __n->_M_hash_code
841 && __eq(__k, __extract(__n->_M_v)); }
844 template<
typename _Key,
typename _Value,
typename _ExtractKey,
845 typename _Equal,
typename _HashCodeType>
846 struct _Equal_helper<_Key, _Value, _ExtractKey, _Equal, _HashCodeType, false>
849 _S_equals(
const _Equal& __eq,
const _ExtractKey& __extract,
850 const _Key& __k, _HashCodeType,
851 _Hash_node<_Value, false>* __n)
852 {
return __eq(__k, __extract(__n->_M_v)); }
857 template<
typename _Key,
typename _Value,
858 typename _ExtractKey,
typename _Equal,
859 typename _H1,
typename _H2,
typename _Hash,
860 bool __cache_hash_code>
861 struct _Hashtable_base
863 :
public _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash,
865 public _Hashtable_ebo_helper<0, _Equal>
868 typedef _Hashtable_ebo_helper<0, _Equal> _EboEqual;
871 typedef _Hash_code_base<_Key, _Value, _ExtractKey,
872 _H1, _H2, _Hash, __cache_hash_code> _HCBase;
873 typedef typename _HCBase::_Hash_code_type _Hash_code_type;
875 _Hashtable_base(
const _ExtractKey& __ex,
876 const _H1& __h1,
const _H2& __h2,
877 const _Hash& __hash,
const _Equal& __eq)
878 : _HCBase(__ex, __h1, __h2, __hash), _EboEqual(__eq) { }
881 _M_equals(
const _Key& __k, _Hash_code_type __c,
882 _Hash_node<_Value, __cache_hash_code>* __n)
const
884 typedef _Equal_helper<_Key, _Value, _ExtractKey,
885 _Equal, _Hash_code_type,
886 __cache_hash_code> _EqualHelper;
887 return _EqualHelper::_S_equals(_M_eq(), this->_M_extract(),
892 _M_swap(_Hashtable_base& __x)
894 _HCBase::_M_swap(__x);
895 std::swap(_M_eq(), __x._M_eq());
900 _M_eq()
const {
return _EboEqual::_S_cget(*
this); }
902 _M_eq() {
return _EboEqual::_S_get(*
this); }
907 template<
typename _Key,
typename _Value,
typename _ExtractKey,
908 typename _H1,
typename _H2,
typename _Hash,
909 bool __cache_hash_code>
910 struct _Local_iterator_base;
912 template<
typename _Key,
typename _Value,
typename _ExtractKey,
913 typename _H1,
typename _H2,
typename _Hash>
914 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
915 _H1, _H2, _Hash, true>
919 _Local_iterator_base() =
default;
920 _Local_iterator_base(_Hash_node<_Value, true>* __p,
921 std::size_t __bkt, std::size_t __bkt_count)
922 : _M_cur(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count) { }
927 _M_cur = _M_cur->_M_next();
930 std::size_t __bkt = _M_h2()(_M_cur->_M_hash_code, _M_bucket_count);
931 if (__bkt != _M_bucket)
936 const _H2& _M_h2()
const
939 _Hash_node<_Value, true>* _M_cur;
940 std::size_t _M_bucket;
941 std::size_t _M_bucket_count;
944 template<
typename _Key,
typename _Value,
typename _ExtractKey,
945 typename _H1,
typename _H2,
typename _Hash>
946 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
947 _H1, _H2, _Hash, false>
949 :
public _Hash_code_base<_Key, _Value, _ExtractKey,
950 _H1, _H2, _Hash, false>
952 _Local_iterator_base() =
default;
953 _Local_iterator_base(_Hash_node<_Value, false>* __p,
954 std::size_t __bkt, std::size_t __bkt_count)
955 : _M_cur(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count) { }
960 _M_cur = _M_cur->_M_next();
963 std::size_t __bkt = this->_M_bucket_index(_M_cur, _M_bucket_count);
964 if (__bkt != _M_bucket)
969 _Hash_node<_Value, false>* _M_cur;
970 std::size_t _M_bucket;
971 std::size_t _M_bucket_count;
974 template<
typename _Key,
typename _Value,
typename _ExtractKey,
975 typename _H1,
typename _H2,
typename _Hash,
bool __cache>
977 operator==(
const _Local_iterator_base<_Key, _Value, _ExtractKey,
978 _H1, _H2, _Hash, __cache>& __x,
979 const _Local_iterator_base<_Key, _Value, _ExtractKey,
980 _H1, _H2, _Hash, __cache>& __y)
981 {
return __x._M_cur == __y._M_cur; }
983 template<
typename _Key,
typename _Value,
typename _ExtractKey,
984 typename _H1,
typename _H2,
typename _Hash,
bool __cache>
986 operator!=(
const _Local_iterator_base<_Key, _Value, _ExtractKey,
987 _H1, _H2, _Hash, __cache>& __x,
988 const _Local_iterator_base<_Key, _Value, _ExtractKey,
989 _H1, _H2, _Hash, __cache>& __y)
990 {
return __x._M_cur != __y._M_cur; }
992 template<
typename _Key,
typename _Value,
typename _ExtractKey,
993 typename _H1,
typename _H2,
typename _Hash,
994 bool __constant_iterators,
bool __cache>
995 struct _Local_iterator
996 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
997 _H1, _H2, _Hash, __cache>
999 typedef _Value value_type;
1001 const _Value*, _Value*>::type
1004 const _Value&, _Value&>::type
1006 typedef std::ptrdiff_t difference_type;
1009 _Local_iterator() =
default;
1012 _Local_iterator(_Hash_node<_Value, __cache>* __p,
1013 std::size_t __bkt, std::size_t __bkt_count)
1014 : _Local_iterator_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash,
1015 __cache>(__p, __bkt, __bkt_count)
1020 {
return this->_M_cur->_M_v; }
1036 _Local_iterator __tmp(*
this);
1042 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1043 typename _H1,
typename _H2,
typename _Hash,
1044 bool __constant_iterators,
bool __cache>
1045 struct _Local_const_iterator
1046 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1047 _H1, _H2, _Hash, __cache>
1049 typedef _Value value_type;
1050 typedef const _Value* pointer;
1051 typedef const _Value& reference;
1052 typedef std::ptrdiff_t difference_type;
1055 _Local_const_iterator() =
default;
1058 _Local_const_iterator(_Hash_node<_Value, __cache>* __p,
1059 std::size_t __bkt, std::size_t __bkt_count)
1060 : _Local_iterator_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash,
1061 __cache>(__p, __bkt, __bkt_count)
1064 _Local_const_iterator(
const _Local_iterator<_Key, _Value, _ExtractKey,
1066 __constant_iterators,
1068 : _Local_iterator_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash,
1069 __cache>(__x._M_cur, __x._M_bucket,
1070 __x._M_bucket_count)
1075 {
return this->_M_cur->_M_v; }
1081 _Local_const_iterator&
1088 _Local_const_iterator
1091 _Local_const_iterator __tmp(*
this);
1102 template<
typename _ExtractKey,
bool __unique_keys,
1103 typename _Hashtable>
1104 struct _Equality_base;
1106 template<
typename _ExtractKey,
typename _Hashtable>
1107 struct _Equality_base<_ExtractKey, true, _Hashtable>
1109 bool _M_equal(
const _Hashtable&)
const;
1112 template<
typename _ExtractKey,
typename _Hashtable>
1114 _Equality_base<_ExtractKey, true, _Hashtable>::
1115 _M_equal(
const _Hashtable& __other)
const
1117 const _Hashtable* __this =
static_cast<const _Hashtable*
>(
this);
1119 if (__this->size() != __other.size())
1122 for (
auto __itx = __this->begin(); __itx != __this->end(); ++__itx)
1124 const auto __ity = __other.find(_ExtractKey()(*__itx));
1125 if (__ity == __other.end() || !bool(*__ity == *__itx))
1131 template<
typename _ExtractKey,
typename _Hashtable>
1132 struct _Equality_base<_ExtractKey, false, _Hashtable>
1134 bool _M_equal(
const _Hashtable&)
const;
1137 template<
typename _Uiterator>
1139 _S_is_permutation(_Uiterator, _Uiterator, _Uiterator);
1143 template<
typename _ExtractKey,
typename _Hashtable>
1144 template<
typename _Uiterator>
1146 _Equality_base<_ExtractKey, false, _Hashtable>::
1147 _S_is_permutation(_Uiterator __first1, _Uiterator __last1,
1148 _Uiterator __first2)
1150 for (; __first1 != __last1; ++__first1, ++__first2)
1151 if (!(*__first1 == *__first2))
1154 if (__first1 == __last1)
1157 _Uiterator __last2 = __first2;
1160 for (_Uiterator __it1 = __first1; __it1 != __last1; ++__it1)
1162 _Uiterator __tmp = __first1;
1163 while (__tmp != __it1 && !
bool(*__tmp == *__it1))
1170 std::ptrdiff_t __n2 = 0;
1171 for (__tmp = __first2; __tmp != __last2; ++__tmp)
1172 if (*__tmp == *__it1)
1178 std::ptrdiff_t __n1 = 0;
1179 for (__tmp = __it1; __tmp != __last1; ++__tmp)
1180 if (*__tmp == *__it1)
1189 template<
typename _ExtractKey,
typename _Hashtable>
1191 _Equality_base<_ExtractKey, false, _Hashtable>::
1192 _M_equal(
const _Hashtable& __other)
const
1194 const _Hashtable* __this =
static_cast<const _Hashtable*
>(
this);
1196 if (__this->size() != __other.size())
1199 for (
auto __itx = __this->begin(); __itx != __this->end();)
1201 const auto __xrange = __this->equal_range(_ExtractKey()(*__itx));
1202 const auto __yrange = __other.equal_range(_ExtractKey()(*__itx));
1208 if (!_S_is_permutation(__xrange.first,
1213 __itx = __xrange.second;
1218 _GLIBCXX_END_NAMESPACE_VERSION
1222 #endif // _HASHTABLE_POLICY_H