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());
63 template <
typename _Key,
typename _Hash>
65 noexcept(declval<const _Hash&>()(declval<const _Key&>()))>
75 struct _Hash_node_base
77 _Hash_node_base* _M_nxt;
81 _Hash_node_base(_Hash_node_base* __next)
85 template<
typename _Value,
bool __cache_hash_code>
88 template<
typename _Value>
89 struct _Hash_node<_Value, true> : _Hash_node_base
92 std::size_t _M_hash_code;
94 template<
typename... _Args>
95 _Hash_node(_Args&&... __args)
96 : _M_v(std::
forward<_Args>(__args)...), _M_hash_code() { }
98 _Hash_node* _M_next()
const
99 {
return static_cast<_Hash_node*
>(_M_nxt); }
102 template<
typename _Value>
103 struct _Hash_node<_Value, false> : _Hash_node_base
107 template<
typename... _Args>
108 _Hash_node(_Args&&... __args)
109 : _M_v(std::
forward<_Args>(__args)...) { }
111 _Hash_node* _M_next()
const
112 {
return static_cast<_Hash_node*
>(_M_nxt); }
116 template<
typename _Value,
bool __cache>
117 struct _Node_iterator_base
119 _Node_iterator_base(_Hash_node<_Value, __cache>* __p)
124 { _M_cur = _M_cur->_M_next(); }
126 _Hash_node<_Value, __cache>* _M_cur;
129 template<
typename _Value,
bool __cache>
131 operator==(
const _Node_iterator_base<_Value, __cache>& __x,
132 const _Node_iterator_base<_Value, __cache>& __y)
133 {
return __x._M_cur == __y._M_cur; }
135 template<
typename _Value,
bool __cache>
137 operator!=(
const _Node_iterator_base<_Value, __cache>& __x,
138 const _Node_iterator_base<_Value, __cache>& __y)
139 {
return __x._M_cur != __y._M_cur; }
141 template<
typename _Value,
bool __constant_iterators,
bool __cache>
142 struct _Node_iterator
143 :
public _Node_iterator_base<_Value, __cache>
145 typedef _Value value_type;
147 const _Value*, _Value*>::type
150 const _Value&, _Value&>::type
152 typedef std::ptrdiff_t difference_type;
156 : _Node_iterator_base<_Value, __cache>(0) { }
159 _Node_iterator(_Hash_node<_Value, __cache>* __p)
160 : _Node_iterator_base<_Value, __cache>(__p) { }
164 {
return this->_M_cur->_M_v; }
180 _Node_iterator __tmp(*
this);
186 template<
typename _Value,
bool __constant_iterators,
bool __cache>
187 struct _Node_const_iterator
188 :
public _Node_iterator_base<_Value, __cache>
190 typedef _Value value_type;
191 typedef const _Value* pointer;
192 typedef const _Value& reference;
193 typedef std::ptrdiff_t difference_type;
196 _Node_const_iterator()
197 : _Node_iterator_base<_Value, __cache>(0) { }
200 _Node_const_iterator(_Hash_node<_Value, __cache>* __p)
201 : _Node_iterator_base<_Value, __cache>(__p) { }
203 _Node_const_iterator(
const _Node_iterator<_Value, __constant_iterators,
205 : _Node_iterator_base<_Value, __cache>(__x._M_cur) { }
209 {
return this->_M_cur->_M_v; }
215 _Node_const_iterator&
225 _Node_const_iterator __tmp(*
this);
236 struct _Mod_range_hashing
238 typedef std::size_t first_argument_type;
239 typedef std::size_t second_argument_type;
240 typedef std::size_t result_type;
243 operator()(first_argument_type __num, second_argument_type __den)
const
244 {
return __num % __den; }
252 struct _Default_ranged_hash { };
256 struct _Prime_rehash_policy
258 _Prime_rehash_policy(
float __z = 1.0)
259 : _M_max_load_factor(__z), _M_prev_resize(0), _M_next_resize(0) { }
262 max_load_factor() const noexcept
263 {
return _M_max_load_factor; }
267 _M_next_bkt(std::size_t __n)
const;
271 _M_bkt_for_elements(std::size_t __n)
const;
278 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
279 std::size_t __n_ins)
const;
288 _M_reset(
const _State& __state)
290 _M_prev_resize = __state.first;
291 _M_next_resize = __state.second;
294 enum { _S_n_primes =
sizeof(
unsigned long) != 8 ? 256 : 256 + 48 };
296 static const std::size_t _S_growth_factor = 2;
298 float _M_max_load_factor;
299 mutable std::size_t _M_prev_resize;
300 mutable std::size_t _M_next_resize;
303 extern const unsigned long __prime_list[];
310 _Prime_rehash_policy::
311 _M_next_bkt(std::size_t __n)
const
315 static const unsigned char __fast_bkt[12]
316 = { 2, 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11 };
318 const std::size_t __grown_n = __n * _S_growth_factor;
323 = __builtin_ceil(__fast_bkt[__grown_n]
324 * (
long double)_M_max_load_factor);
325 return __fast_bkt[__grown_n];
328 const unsigned long* __next_bkt
331 const unsigned long* __prev_bkt
335 = __builtin_floor(*(__prev_bkt - 1) * (
long double)_M_max_load_factor);
337 = __builtin_ceil(*__next_bkt * (
long double)_M_max_load_factor);
344 _Prime_rehash_policy::
345 _M_bkt_for_elements(std::size_t __n)
const
346 {
return _M_next_bkt(__builtin_ceil(__n / (
long double)_M_max_load_factor)); }
358 _Prime_rehash_policy::
359 _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
360 std::size_t __n_ins)
const
362 if (__n_elt + __n_ins >= _M_next_resize)
364 long double __min_bkts = (__n_elt + __n_ins)
365 / (
long double)_M_max_load_factor;
366 if (__min_bkts >= __n_bkt)
368 _M_next_bkt(__builtin_floor(__min_bkts) + 1));
372 = __builtin_floor(__n_bkt * (
long double)_M_max_load_factor);
376 else if (__n_elt + __n_ins < _M_prev_resize)
378 long double __min_bkts = (__n_elt + __n_ins)
379 / (
long double)_M_max_load_factor;
381 _M_next_bkt(__builtin_floor(__min_bkts) + 1));
401 template<
typename _Key,
typename _Value,
typename _Ex,
bool __unique,
403 struct _Map_base { };
405 template<
typename _Key,
typename _Pair,
typename _Hashtable>
406 struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, false, _Hashtable>
408 typedef typename _Pair::second_type mapped_type;
411 template<
typename _Key,
typename _Pair,
typename _Hashtable>
412 struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>
414 typedef typename _Pair::second_type mapped_type;
428 at(
const _Key& __k)
const;
431 template<
typename _Key,
typename _Pair,
typename _Hashtable>
432 typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
433 true, _Hashtable>::mapped_type&
434 _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
true, _Hashtable>::
435 operator[](
const _Key& __k)
437 _Hashtable* __h =
static_cast<_Hashtable*
>(
this);
438 typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k);
439 std::size_t __n = __h->_M_bucket_index(__k, __code);
441 typename _Hashtable::_Node* __p = __h->_M_find_node(__n, __k, __code);
444 __n, __code)->second;
445 return (__p->_M_v).second;
448 template<
typename _Key,
typename _Pair,
typename _Hashtable>
449 typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
450 true, _Hashtable>::mapped_type&
451 _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
true, _Hashtable>::
452 operator[](_Key&& __k)
454 _Hashtable* __h =
static_cast<_Hashtable*
>(
this);
455 typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k);
456 std::size_t __n = __h->_M_bucket_index(__k, __code);
458 typename _Hashtable::_Node* __p = __h->_M_find_node(__n, __k, __code);
462 __n, __code)->second;
463 return (__p->_M_v).second;
466 template<
typename _Key,
typename _Pair,
typename _Hashtable>
467 typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
468 true, _Hashtable>::mapped_type&
469 _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
true, _Hashtable>::
472 _Hashtable* __h =
static_cast<_Hashtable*
>(
this);
473 typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k);
474 std::size_t __n = __h->_M_bucket_index(__k, __code);
476 typename _Hashtable::_Node* __p = __h->_M_find_node(__n, __k, __code);
478 __throw_out_of_range(__N(
"_Map_base::at"));
479 return (__p->_M_v).second;
482 template<
typename _Key,
typename _Pair,
typename _Hashtable>
483 const typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
484 true, _Hashtable>::mapped_type&
485 _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
true, _Hashtable>::
486 at(
const _Key& __k)
const
488 const _Hashtable* __h =
static_cast<const _Hashtable*
>(
this);
489 typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k);
490 std::size_t __n = __h->_M_bucket_index(__k, __code);
492 typename _Hashtable::_Node* __p = __h->_M_find_node(__n, __k, __code);
494 __throw_out_of_range(__N(
"_Map_base::at"));
495 return (__p->_M_v).second;
500 template<
typename _RehashPolicy,
typename _Hashtable>
501 struct _Rehash_base { };
503 template<
typename _Hashtable>
504 struct _Rehash_base<_Prime_rehash_policy, _Hashtable>
507 max_load_factor() const noexcept
509 const _Hashtable* __this =
static_cast<const _Hashtable*
>(
this);
510 return __this->__rehash_policy().max_load_factor();
514 max_load_factor(
float __z)
516 _Hashtable* __this =
static_cast<_Hashtable*
>(
this);
517 __this->__rehash_policy(_Prime_rehash_policy(__z));
521 reserve(std::size_t __n)
523 _Hashtable* __this =
static_cast<_Hashtable*
>(
this);
524 __this->rehash(__builtin_ceil(__n / max_load_factor()));
530 template<
int _Nm,
typename _Tp,
531 bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
532 struct _Hashtable_ebo_helper;
535 template<
int _Nm,
typename _Tp>
536 struct _Hashtable_ebo_helper<_Nm, _Tp, true>
540 _Hashtable_ebo_helper() =
default;
541 _Hashtable_ebo_helper(
const _Tp& __tp) : _Tp(__tp)
545 _S_cget(
const _Hashtable_ebo_helper& __eboh)
546 {
return static_cast<const _Tp&
>(__eboh); }
549 _S_get(_Hashtable_ebo_helper& __eboh)
550 {
return static_cast<_Tp&
>(__eboh); }
554 template<
int _Nm,
typename _Tp>
555 struct _Hashtable_ebo_helper<_Nm, _Tp, false>
557 _Hashtable_ebo_helper() =
default;
558 _Hashtable_ebo_helper(
const _Tp& __tp) : _M_tp(__tp)
562 _S_cget(
const _Hashtable_ebo_helper& __eboh)
563 {
return __eboh._M_tp; }
566 _S_get(_Hashtable_ebo_helper& __eboh)
567 {
return __eboh._M_tp; }
590 template<
typename _Key,
typename _Value,
typename _ExtractKey,
591 typename _H1,
typename _H2,
typename _Hash,
592 bool __cache_hash_code>
593 struct _Hash_code_base;
597 template<
typename _Key,
typename _Value,
typename _ExtractKey,
598 typename _H1,
typename _H2,
typename _Hash>
599 struct _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash, false>
601 :
public _Hashtable_ebo_helper<0, _ExtractKey>,
602 public _Hashtable_ebo_helper<1, _Hash>
605 typedef _Hashtable_ebo_helper<0, _ExtractKey> _EboExtractKey;
606 typedef _Hashtable_ebo_helper<1, _Hash> _EboHash;
610 _Hash_code_base() =
default;
611 _Hash_code_base(
const _ExtractKey& __ex,
612 const _H1&,
const _H2&,
const _Hash& __h)
613 : _EboExtractKey(__ex), _EboHash(__h) { }
615 typedef void* _Hash_code_type;
618 _M_hash_code(
const _Key& __key)
const
622 _M_bucket_index(
const _Key& __k, _Hash_code_type,
623 std::size_t __n)
const
624 {
return _M_ranged_hash()(__k, __n); }
627 _M_bucket_index(
const _Hash_node<_Value, false>* __p,
628 std::size_t __n)
const
629 {
return _M_ranged_hash()(_M_extract()(__p->_M_v), __n); }
632 _M_store_code(_Hash_node<_Value, false>*, _Hash_code_type)
const
636 _M_copy_code(_Hash_node<_Value, false>*,
637 const _Hash_node<_Value, false>*)
const
641 _M_swap(_Hash_code_base& __x)
643 std::swap(_M_extract(), __x._M_extract());
644 std::swap(_M_ranged_hash(), __x._M_ranged_hash());
649 _M_extract()
const {
return _EboExtractKey::_S_cget(*
this); }
651 _M_extract() {
return _EboExtractKey::_S_get(*
this); }
653 _M_ranged_hash()
const {
return _EboHash::_S_cget(*
this); }
655 _M_ranged_hash() {
return _EboHash::_S_get(*
this); }
664 template<
typename _Key,
typename _Value,
typename _ExtractKey,
665 typename _H1,
typename _H2,
typename _Hash>
666 struct _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash, true>;
671 template<
typename _Key,
typename _Value,
typename _ExtractKey,
672 typename _H1,
typename _H2>
673 struct _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2,
674 _Default_ranged_hash, false>
676 :
public _Hashtable_ebo_helper<0, _ExtractKey>,
677 public _Hashtable_ebo_helper<1, _H1>,
678 public _Hashtable_ebo_helper<2, _H2>
681 typedef _Hashtable_ebo_helper<0, _ExtractKey> _EboExtractKey;
682 typedef _Hashtable_ebo_helper<1, _H1> _EboH1;
683 typedef _Hashtable_ebo_helper<2, _H2> _EboH2;
689 hash_function()
const
694 _Hash_code_base() =
default;
695 _Hash_code_base(
const _ExtractKey& __ex,
696 const _H1& __h1,
const _H2& __h2,
697 const _Default_ranged_hash&)
698 : _EboExtractKey(__ex), _EboH1(__h1), _EboH2(__h2) { }
700 typedef std::size_t _Hash_code_type;
703 _M_hash_code(
const _Key& __k)
const
704 {
return _M_h1()(__k); }
707 _M_bucket_index(
const _Key&, _Hash_code_type __c,
708 std::size_t __n)
const
709 {
return _M_h2()(__c, __n); }
712 _M_bucket_index(
const _Hash_node<_Value, false>* __p,
713 std::size_t __n)
const
714 {
return _M_h2()(_M_h1()(_M_extract()(__p->_M_v)), __n); }
717 _M_store_code(_Hash_node<_Value, false>*, _Hash_code_type)
const
721 _M_copy_code(_Hash_node<_Value, false>*,
722 const _Hash_node<_Value, false>*)
const
726 _M_swap(_Hash_code_base& __x)
728 std::swap(_M_extract(), __x._M_extract());
729 std::swap(_M_h1(), __x._M_h1());
730 std::swap(_M_h2(), __x._M_h2());
735 _M_extract()
const {
return _EboExtractKey::_S_cget(*
this); }
737 _M_extract() {
return _EboExtractKey::_S_get(*
this); }
739 _M_h1()
const {
return _EboH1::_S_cget(*
this); }
741 _M_h1() {
return _EboH1::_S_get(*
this); }
743 _M_h2()
const {
return _EboH2::_S_cget(*
this); }
745 _M_h2() {
return _EboH2::_S_get(*
this); }
751 template<
typename _Key,
typename _Value,
typename _ExtractKey,
752 typename _H1,
typename _H2>
753 struct _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2,
754 _Default_ranged_hash, true>
756 :
public _Hashtable_ebo_helper<0, _ExtractKey>,
757 public _Hashtable_ebo_helper<1, _H1>,
758 public _Hashtable_ebo_helper<2, _H2>
761 typedef _Hashtable_ebo_helper<0, _ExtractKey> _EboExtractKey;
762 typedef _Hashtable_ebo_helper<1, _H1> _EboH1;
763 typedef _Hashtable_ebo_helper<2, _H2> _EboH2;
769 hash_function()
const
773 _Hash_code_base(
const _ExtractKey& __ex,
774 const _H1& __h1,
const _H2& __h2,
775 const _Default_ranged_hash&)
776 : _EboExtractKey(__ex), _EboH1(__h1), _EboH2(__h2) { }
778 typedef std::size_t _Hash_code_type;
781 _M_hash_code(
const _Key& __k)
const
782 {
return _M_h1()(__k); }
785 _M_bucket_index(
const _Key&, _Hash_code_type __c,
786 std::size_t __n)
const
787 {
return _M_h2()(__c, __n); }
790 _M_bucket_index(
const _Hash_node<_Value, true>* __p,
791 std::size_t __n)
const
792 {
return _M_h2()(__p->_M_hash_code, __n); }
795 _M_store_code(_Hash_node<_Value, true>* __n, _Hash_code_type __c)
const
796 { __n->_M_hash_code = __c; }
799 _M_copy_code(_Hash_node<_Value, true>* __to,
800 const _Hash_node<_Value, true>* __from)
const
801 { __to->_M_hash_code = __from->_M_hash_code; }
804 _M_swap(_Hash_code_base& __x)
806 std::swap(_M_extract(), __x._M_extract());
807 std::swap(_M_h1(), __x._M_h1());
808 std::swap(_M_h2(), __x._M_h2());
813 _M_extract()
const {
return _EboExtractKey::_S_cget(*
this); }
815 _M_extract() {
return _EboExtractKey::_S_get(*
this); }
817 _M_h1()
const {
return _EboH1::_S_cget(*
this); }
819 _M_h1() {
return _EboH1::_S_get(*
this); }
821 _M_h2()
const {
return _EboH2::_S_cget(*
this); }
823 _M_h2() {
return _EboH2::_S_get(*
this); }
826 template <
typename _Key,
typename _Value,
typename _ExtractKey,
827 typename _Equal,
typename _HashCodeType,
828 bool __cache_hash_code>
829 struct _Equal_helper;
831 template<
typename _Key,
typename _Value,
typename _ExtractKey,
832 typename _Equal,
typename _HashCodeType>
833 struct _Equal_helper<_Key, _Value, _ExtractKey, _Equal, _HashCodeType, true>
836 _S_equals(
const _Equal& __eq,
const _ExtractKey& __extract,
837 const _Key& __k, _HashCodeType __c,
838 _Hash_node<_Value, true>* __n)
839 {
return __c == __n->_M_hash_code
840 && __eq(__k, __extract(__n->_M_v)); }
843 template<
typename _Key,
typename _Value,
typename _ExtractKey,
844 typename _Equal,
typename _HashCodeType>
845 struct _Equal_helper<_Key, _Value, _ExtractKey, _Equal, _HashCodeType, false>
848 _S_equals(
const _Equal& __eq,
const _ExtractKey& __extract,
849 const _Key& __k, _HashCodeType,
850 _Hash_node<_Value, false>* __n)
851 {
return __eq(__k, __extract(__n->_M_v)); }
856 template<
typename _Key,
typename _Value,
857 typename _ExtractKey,
typename _Equal,
858 typename _H1,
typename _H2,
typename _Hash,
859 bool __cache_hash_code>
860 struct _Hashtable_base
862 :
public _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash,
864 public _Hashtable_ebo_helper<0, _Equal>
867 typedef _Hashtable_ebo_helper<0, _Equal> _EboEqual;
870 typedef _Hash_code_base<_Key, _Value, _ExtractKey,
871 _H1, _H2, _Hash, __cache_hash_code> _HCBase;
872 typedef typename _HCBase::_Hash_code_type _Hash_code_type;
874 _Hashtable_base(
const _ExtractKey& __ex,
875 const _H1& __h1,
const _H2& __h2,
876 const _Hash& __hash,
const _Equal& __eq)
877 : _HCBase(__ex, __h1, __h2, __hash), _EboEqual(__eq) { }
880 _M_equals(
const _Key& __k, _Hash_code_type __c,
881 _Hash_node<_Value, __cache_hash_code>* __n)
const
883 typedef _Equal_helper<_Key, _Value, _ExtractKey,
884 _Equal, _Hash_code_type,
885 __cache_hash_code> _EqualHelper;
886 return _EqualHelper::_S_equals(_M_eq(), this->_M_extract(),
891 _M_swap(_Hashtable_base& __x)
893 _HCBase::_M_swap(__x);
894 std::swap(_M_eq(), __x._M_eq());
899 _M_eq()
const {
return _EboEqual::_S_cget(*
this); }
901 _M_eq() {
return _EboEqual::_S_get(*
this); }
906 template<
typename _Key,
typename _Value,
typename _ExtractKey,
907 typename _H1,
typename _H2,
typename _Hash,
908 bool __cache_hash_code>
909 struct _Local_iterator_base;
911 template<
typename _Key,
typename _Value,
typename _ExtractKey,
912 typename _H1,
typename _H2,
typename _Hash>
913 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
914 _H1, _H2, _Hash, true>
918 _Local_iterator_base() =
default;
919 _Local_iterator_base(_Hash_node<_Value, true>* __p,
920 std::size_t __bkt, std::size_t __bkt_count)
921 : _M_cur(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count) { }
926 _M_cur = _M_cur->_M_next();
929 std::size_t __bkt = _M_h2()(_M_cur->_M_hash_code, _M_bucket_count);
930 if (__bkt != _M_bucket)
935 const _H2& _M_h2()
const
938 _Hash_node<_Value, true>* _M_cur;
939 std::size_t _M_bucket;
940 std::size_t _M_bucket_count;
943 template<
typename _Key,
typename _Value,
typename _ExtractKey,
944 typename _H1,
typename _H2,
typename _Hash>
945 struct _Local_iterator_base<_Key, _Value, _ExtractKey,
946 _H1, _H2, _Hash, false>
948 :
public _Hash_code_base<_Key, _Value, _ExtractKey,
949 _H1, _H2, _Hash, false>
951 _Local_iterator_base() =
default;
952 _Local_iterator_base(_Hash_node<_Value, false>* __p,
953 std::size_t __bkt, std::size_t __bkt_count)
954 : _M_cur(__p), _M_bucket(__bkt), _M_bucket_count(__bkt_count) { }
959 _M_cur = _M_cur->_M_next();
962 std::size_t __bkt = this->_M_bucket_index(_M_cur, _M_bucket_count);
963 if (__bkt != _M_bucket)
968 _Hash_node<_Value, false>* _M_cur;
969 std::size_t _M_bucket;
970 std::size_t _M_bucket_count;
973 template<
typename _Key,
typename _Value,
typename _ExtractKey,
974 typename _H1,
typename _H2,
typename _Hash,
bool __cache>
976 operator==(
const _Local_iterator_base<_Key, _Value, _ExtractKey,
977 _H1, _H2, _Hash, __cache>& __x,
978 const _Local_iterator_base<_Key, _Value, _ExtractKey,
979 _H1, _H2, _Hash, __cache>& __y)
980 {
return __x._M_cur == __y._M_cur; }
982 template<
typename _Key,
typename _Value,
typename _ExtractKey,
983 typename _H1,
typename _H2,
typename _Hash,
bool __cache>
985 operator!=(
const _Local_iterator_base<_Key, _Value, _ExtractKey,
986 _H1, _H2, _Hash, __cache>& __x,
987 const _Local_iterator_base<_Key, _Value, _ExtractKey,
988 _H1, _H2, _Hash, __cache>& __y)
989 {
return __x._M_cur != __y._M_cur; }
991 template<
typename _Key,
typename _Value,
typename _ExtractKey,
992 typename _H1,
typename _H2,
typename _Hash,
993 bool __constant_iterators,
bool __cache>
994 struct _Local_iterator
995 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
996 _H1, _H2, _Hash, __cache>
998 typedef _Value value_type;
1000 const _Value*, _Value*>::type
1003 const _Value&, _Value&>::type
1005 typedef std::ptrdiff_t difference_type;
1008 _Local_iterator() =
default;
1011 _Local_iterator(_Hash_node<_Value, __cache>* __p,
1012 std::size_t __bkt, std::size_t __bkt_count)
1013 : _Local_iterator_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash,
1014 __cache>(__p, __bkt, __bkt_count)
1019 {
return this->_M_cur->_M_v; }
1035 _Local_iterator __tmp(*
this);
1041 template<
typename _Key,
typename _Value,
typename _ExtractKey,
1042 typename _H1,
typename _H2,
typename _Hash,
1043 bool __constant_iterators,
bool __cache>
1044 struct _Local_const_iterator
1045 :
public _Local_iterator_base<_Key, _Value, _ExtractKey,
1046 _H1, _H2, _Hash, __cache>
1048 typedef _Value value_type;
1049 typedef const _Value* pointer;
1050 typedef const _Value& reference;
1051 typedef std::ptrdiff_t difference_type;
1054 _Local_const_iterator() =
default;
1057 _Local_const_iterator(_Hash_node<_Value, __cache>* __p,
1058 std::size_t __bkt, std::size_t __bkt_count)
1059 : _Local_iterator_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash,
1060 __cache>(__p, __bkt, __bkt_count)
1063 _Local_const_iterator(
const _Local_iterator<_Key, _Value, _ExtractKey,
1065 __constant_iterators,
1067 : _Local_iterator_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash,
1068 __cache>(__x._M_cur, __x._M_bucket,
1069 __x._M_bucket_count)
1074 {
return this->_M_cur->_M_v; }
1080 _Local_const_iterator&
1087 _Local_const_iterator
1090 _Local_const_iterator __tmp(*
this);
1101 template<
typename _ExtractKey,
bool __unique_keys,
1102 typename _Hashtable>
1103 struct _Equality_base;
1105 template<
typename _ExtractKey,
typename _Hashtable>
1106 struct _Equality_base<_ExtractKey, true, _Hashtable>
1108 bool _M_equal(
const _Hashtable&)
const;
1111 template<
typename _ExtractKey,
typename _Hashtable>
1113 _Equality_base<_ExtractKey, true, _Hashtable>::
1114 _M_equal(
const _Hashtable& __other)
const
1116 const _Hashtable* __this =
static_cast<const _Hashtable*
>(
this);
1118 if (__this->size() != __other.size())
1121 for (
auto __itx = __this->begin(); __itx != __this->end(); ++__itx)
1123 const auto __ity = __other.find(_ExtractKey()(*__itx));
1124 if (__ity == __other.end() || !bool(*__ity == *__itx))
1130 template<
typename _ExtractKey,
typename _Hashtable>
1131 struct _Equality_base<_ExtractKey, false, _Hashtable>
1133 bool _M_equal(
const _Hashtable&)
const;
1136 template<
typename _Uiterator>
1138 _S_is_permutation(_Uiterator, _Uiterator, _Uiterator);
1142 template<
typename _ExtractKey,
typename _Hashtable>
1143 template<
typename _Uiterator>
1145 _Equality_base<_ExtractKey, false, _Hashtable>::
1146 _S_is_permutation(_Uiterator __first1, _Uiterator __last1,
1147 _Uiterator __first2)
1149 for (; __first1 != __last1; ++__first1, ++__first2)
1150 if (!(*__first1 == *__first2))
1153 if (__first1 == __last1)
1156 _Uiterator __last2 = __first2;
1159 for (_Uiterator __it1 = __first1; __it1 != __last1; ++__it1)
1161 _Uiterator __tmp = __first1;
1162 while (__tmp != __it1 && !
bool(*__tmp == *__it1))
1169 std::ptrdiff_t __n2 = 0;
1170 for (__tmp = __first2; __tmp != __last2; ++__tmp)
1171 if (*__tmp == *__it1)
1177 std::ptrdiff_t __n1 = 0;
1178 for (__tmp = __it1; __tmp != __last1; ++__tmp)
1179 if (*__tmp == *__it1)
1188 template<
typename _ExtractKey,
typename _Hashtable>
1190 _Equality_base<_ExtractKey, false, _Hashtable>::
1191 _M_equal(
const _Hashtable& __other)
const
1193 const _Hashtable* __this =
static_cast<const _Hashtable*
>(
this);
1195 if (__this->size() != __other.size())
1198 for (
auto __itx = __this->begin(); __itx != __this->end();)
1200 const auto __xrange = __this->equal_range(_ExtractKey()(*__itx));
1201 const auto __yrange = __other.equal_range(_ExtractKey()(*__itx));
1207 if (!_S_is_permutation(__xrange.first,
1212 __itx = __xrange.second;
1217 _GLIBCXX_END_NAMESPACE_VERSION
1221 #endif // _HASHTABLE_POLICY_H
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
reference operator[](size_t __position)
Array-indexing support.
Define a member typedef type to one of two argument types.
Struct holding two objects of arbitrary type.
Forward iterators support a superset of input iterator operations.
void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
_Tp * __addressof(_Tp &__r) _GLIBCXX_NOEXCEPT
Same as C++11 std::addressof.
_ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__val)
Finds the first position in which val could be inserted without changing the ordering.
complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.