37 _GLIBCXX_BEGIN_NAMESPACE_VERSION
41 template<
class _Iterator>
42 inline typename std::iterator_traits<_Iterator>::difference_type
43 __distance_fw(_Iterator __first, _Iterator __last,
44 std::input_iterator_tag)
47 template<
class _Iterator>
48 inline typename std::iterator_traits<_Iterator>::difference_type
49 __distance_fw(_Iterator __first, _Iterator __last,
50 std::forward_iterator_tag)
51 {
return std::distance(__first, __last); }
53 template<
class _Iterator>
54 inline typename std::iterator_traits<_Iterator>::difference_type
55 __distance_fw(_Iterator __first, _Iterator __last)
57 typedef typename std::iterator_traits<_Iterator>::iterator_category _Tag;
58 return __distance_fw(__first, __last, _Tag());
68 template<
typename _Value,
bool __cache_hash_code>
71 template<
typename _Value>
72 struct _Hash_node<_Value,
true>
79 template<
typename _Value>
80 struct _Hash_node<_Value,
false>
88 template<
typename _Value,
bool __cache>
89 struct _Node_iterator_base
91 _Node_iterator_base(_Hash_node<_Value, __cache>* __p)
96 { _M_cur = _M_cur->_M_next; }
98 _Hash_node<_Value, __cache>* _M_cur;
101 template<
typename _Value,
bool __cache>
103 operator==(
const _Node_iterator_base<_Value, __cache>& __x,
104 const _Node_iterator_base<_Value, __cache>& __y)
105 {
return __x._M_cur == __y._M_cur; }
107 template<
typename _Value,
bool __cache>
109 operator!=(
const _Node_iterator_base<_Value, __cache>& __x,
110 const _Node_iterator_base<_Value, __cache>& __y)
111 {
return __x._M_cur != __y._M_cur; }
113 template<
typename _Value,
bool __constant_iterators,
bool __cache>
114 struct _Node_iterator
115 :
public _Node_iterator_base<_Value, __cache>
117 typedef _Value value_type;
119 __gnu_cxx::__conditional_type<__constant_iterators,
120 const _Value*, _Value*>::__type
123 __gnu_cxx::__conditional_type<__constant_iterators,
124 const _Value&, _Value&>::__type
127 typedef std::forward_iterator_tag iterator_category;
130 : _Node_iterator_base<_Value, __cache>(0) { }
133 _Node_iterator(_Hash_node<_Value, __cache>* __p)
134 : _Node_iterator_base<_Value, __cache>(__p) { }
138 {
return this->_M_cur->_M_v; }
142 {
return std::__addressof(this->_M_cur->_M_v); }
154 _Node_iterator __tmp(*
this);
160 template<
typename _Value,
bool __constant_iterators,
bool __cache>
161 struct _Node_const_iterator
162 :
public _Node_iterator_base<_Value, __cache>
164 typedef _Value value_type;
165 typedef const _Value* pointer;
166 typedef const _Value& reference;
168 typedef std::forward_iterator_tag iterator_category;
170 _Node_const_iterator()
171 : _Node_iterator_base<_Value, __cache>(0) { }
174 _Node_const_iterator(_Hash_node<_Value, __cache>* __p)
175 : _Node_iterator_base<_Value, __cache>(__p) { }
177 _Node_const_iterator(
const _Node_iterator<_Value, __constant_iterators,
179 : _Node_iterator_base<_Value, __cache>(__x._M_cur) { }
183 {
return this->_M_cur->_M_v; }
187 {
return std::__addressof(this->_M_cur->_M_v); }
189 _Node_const_iterator&
199 _Node_const_iterator __tmp(*
this);
205 template<
typename _Value,
bool __cache>
206 struct _Hashtable_iterator_base
208 _Hashtable_iterator_base(_Hash_node<_Value, __cache>* __node,
209 _Hash_node<_Value, __cache>** __bucket)
210 : _M_cur_node(__node), _M_cur_bucket(__bucket) { }
215 _M_cur_node = _M_cur_node->_M_next;
223 _Hash_node<_Value, __cache>* _M_cur_node;
224 _Hash_node<_Value, __cache>** _M_cur_bucket;
229 template<
typename _Value,
bool __cache>
231 _Hashtable_iterator_base<_Value, __cache>::
237 while (!*_M_cur_bucket)
239 _M_cur_node = *_M_cur_bucket;
242 template<
typename _Value,
bool __cache>
244 operator==(
const _Hashtable_iterator_base<_Value, __cache>& __x,
245 const _Hashtable_iterator_base<_Value, __cache>& __y)
246 {
return __x._M_cur_node == __y._M_cur_node; }
248 template<
typename _Value,
bool __cache>
250 operator!=(
const _Hashtable_iterator_base<_Value, __cache>& __x,
251 const _Hashtable_iterator_base<_Value, __cache>& __y)
252 {
return __x._M_cur_node != __y._M_cur_node; }
254 template<
typename _Value,
bool __constant_iterators,
bool __cache>
255 struct _Hashtable_iterator
256 :
public _Hashtable_iterator_base<_Value, __cache>
258 typedef _Value value_type;
260 __gnu_cxx::__conditional_type<__constant_iterators,
261 const _Value*, _Value*>::__type
264 __gnu_cxx::__conditional_type<__constant_iterators,
265 const _Value&, _Value&>::__type
268 typedef std::forward_iterator_tag iterator_category;
270 _Hashtable_iterator()
271 : _Hashtable_iterator_base<_Value, __cache>(0, 0) { }
273 _Hashtable_iterator(_Hash_node<_Value, __cache>* __p,
274 _Hash_node<_Value, __cache>** __b)
275 : _Hashtable_iterator_base<_Value, __cache>(__p, __b) { }
278 _Hashtable_iterator(_Hash_node<_Value, __cache>** __b)
279 : _Hashtable_iterator_base<_Value, __cache>(*__b, __b) { }
283 {
return this->_M_cur_node->_M_v; }
287 {
return std::__addressof(this->_M_cur_node->_M_v); }
299 _Hashtable_iterator __tmp(*
this);
305 template<
typename _Value,
bool __constant_iterators,
bool __cache>
306 struct _Hashtable_const_iterator
307 :
public _Hashtable_iterator_base<_Value, __cache>
309 typedef _Value value_type;
310 typedef const _Value* pointer;
311 typedef const _Value& reference;
313 typedef std::forward_iterator_tag iterator_category;
315 _Hashtable_const_iterator()
316 : _Hashtable_iterator_base<_Value, __cache>(0, 0) { }
318 _Hashtable_const_iterator(_Hash_node<_Value, __cache>* __p,
319 _Hash_node<_Value, __cache>** __b)
320 : _Hashtable_iterator_base<_Value, __cache>(__p, __b) { }
323 _Hashtable_const_iterator(_Hash_node<_Value, __cache>** __b)
324 : _Hashtable_iterator_base<_Value, __cache>(*__b, __b) { }
326 _Hashtable_const_iterator(
const _Hashtable_iterator<_Value,
327 __constant_iterators, __cache>& __x)
328 : _Hashtable_iterator_base<_Value, __cache>(__x._M_cur_node,
329 __x._M_cur_bucket) { }
333 {
return this->_M_cur_node->_M_v; }
337 {
return std::__addressof(this->_M_cur_node->_M_v); }
339 _Hashtable_const_iterator&
346 _Hashtable_const_iterator
349 _Hashtable_const_iterator __tmp(*
this);
361 struct _Mod_range_hashing
368 operator()(first_argument_type __num, second_argument_type __den)
const
369 {
return __num % __den; }
377 struct _Default_ranged_hash { };
381 struct _Prime_rehash_policy
383 _Prime_rehash_policy(
float __z = 1.0)
384 : _M_max_load_factor(__z), _M_growth_factor(2.f), _M_next_resize(0) { }
387 max_load_factor()
const
388 {
return _M_max_load_factor; }
402 std::pair<bool, std::size_t>
406 enum { _S_n_primes =
sizeof(
unsigned long) != 8 ? 256 : 256 + 48 };
408 float _M_max_load_factor;
409 float _M_growth_factor;
413 extern const unsigned long __prime_list[];
420 _Prime_rehash_policy::
423 const unsigned long* __p = std::lower_bound(__prime_list, __prime_list
426 static_cast<std::size_t>(__builtin_ceil(*__p * _M_max_load_factor));
433 _Prime_rehash_policy::
436 const float __min_bkts = __n / _M_max_load_factor;
437 const unsigned long* __p = std::lower_bound(__prime_list, __prime_list
438 + _S_n_primes, __min_bkts);
440 static_cast<std::size_t>(__builtin_ceil(*__p * _M_max_load_factor));
453 inline std::pair<bool, std::size_t>
454 _Prime_rehash_policy::
458 if (__n_elt + __n_ins > _M_next_resize)
460 float __min_bkts = ((float(__n_ins) + float(__n_elt))
461 / _M_max_load_factor);
462 if (__min_bkts > __n_bkt)
464 __min_bkts =
std::max(__min_bkts, _M_growth_factor * __n_bkt);
465 const unsigned long* __p =
466 std::lower_bound(__prime_list, __prime_list + _S_n_primes,
469 (__builtin_ceil(*__p * _M_max_load_factor));
470 return std::make_pair(
true, *__p);
475 (__builtin_ceil(__n_bkt * _M_max_load_factor));
476 return std::make_pair(
false, 0);
480 return std::make_pair(
false, 0);
497 template<
typename _Key,
typename _Value,
typename _Ex,
bool __unique,
499 struct _Map_base { };
501 template<
typename _Key,
typename _Pair,
typename _Hashtable>
502 struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
false, _Hashtable>
504 typedef typename _Pair::second_type mapped_type;
507 template<
typename _Key,
typename _Pair,
typename _Hashtable>
508 struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
true, _Hashtable>
510 typedef typename _Pair::second_type mapped_type;
513 operator[](
const _Key& __k);
516 template<
typename _Key,
typename _Pair,
typename _Hashtable>
517 typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
518 true, _Hashtable>::mapped_type&
519 _Map_base<_Key, _Pair, std::_Select1st<_Pair>,
true, _Hashtable>::
520 operator[](
const _Key& __k)
522 _Hashtable* __h =
static_cast<_Hashtable*
>(
this);
523 typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k);
524 std::size_t __n = __h->_M_bucket_index(__k, __code,
525 __h->_M_bucket_count);
527 typename _Hashtable::_Node* __p =
528 __h->_M_find_node(__h->_M_buckets[__n], __k, __code);
530 return __h->_M_insert_bucket(std::make_pair(__k, mapped_type()),
531 __n, __code)->second;
532 return (__p->_M_v).second;
537 template<
typename _RehashPolicy,
typename _Hashtable>
538 struct _Rehash_base { };
540 template<
typename _Hashtable>
541 struct _Rehash_base<_Prime_rehash_policy, _Hashtable>
544 max_load_factor()
const
546 const _Hashtable* __this =
static_cast<const _Hashtable*
>(
this);
547 return __this->__rehash_policy().max_load_factor();
551 max_load_factor(
float __z)
553 _Hashtable* __this =
static_cast<_Hashtable*
>(
this);
554 __this->__rehash_policy(_Prime_rehash_policy(__z));
570 template<
typename _Key,
typename _Value,
571 typename _ExtractKey,
typename _Equal,
572 typename _H1,
typename _H2,
typename _Hash,
573 bool __cache_hash_code>
574 struct _Hash_code_base;
578 template<
typename _Key,
typename _Value,
579 typename _ExtractKey,
typename _Equal,
580 typename _H1,
typename _H2,
typename _Hash>
581 struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2,
585 _Hash_code_base(
const _ExtractKey& __ex,
const _Equal& __eq,
586 const _H1&,
const _H2&,
const _Hash& __h)
587 : _M_extract(__ex), _M_eq(__eq), _M_ranged_hash(__h) { }
589 typedef void* _Hash_code_type;
592 _M_hash_code(
const _Key& __key)
const
596 _M_bucket_index(
const _Key& __k, _Hash_code_type,
598 {
return _M_ranged_hash(__k, __n); }
601 _M_bucket_index(
const _Hash_node<_Value, false>* __p,
603 {
return _M_ranged_hash(_M_extract(__p->_M_v), __n); }
606 _M_compare(
const _Key& __k, _Hash_code_type,
607 _Hash_node<_Value, false>* __n)
const
608 {
return _M_eq(__k, _M_extract(__n->_M_v)); }
611 _M_store_code(_Hash_node<_Value, false>*, _Hash_code_type)
const
615 _M_copy_code(_Hash_node<_Value, false>*,
616 const _Hash_node<_Value, false>*)
const
620 _M_swap(_Hash_code_base& __x)
624 std::swap(_M_ranged_hash, __x._M_ranged_hash);
628 _ExtractKey _M_extract;
630 _Hash _M_ranged_hash;
641 template<
typename _Key,
typename _Value,
642 typename _ExtractKey,
typename _Equal,
643 typename _H1,
typename _H2,
typename _Hash>
644 struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2,
650 template<
typename _Key,
typename _Value,
651 typename _ExtractKey,
typename _Equal,
652 typename _H1,
typename _H2>
653 struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2,
654 _Default_ranged_hash,
false>
659 hash_function()
const
663 _Hash_code_base(
const _ExtractKey& __ex,
const _Equal& __eq,
664 const _H1& __h1,
const _H2& __h2,
665 const _Default_ranged_hash&)
666 : _M_extract(__ex), _M_eq(__eq), _M_h1(__h1), _M_h2(__h2) { }
671 _M_hash_code(
const _Key& __k)
const
672 {
return _M_h1(__k); }
675 _M_bucket_index(
const _Key&, _Hash_code_type __c,
677 {
return _M_h2(__c, __n); }
680 _M_bucket_index(
const _Hash_node<_Value, false>* __p,
682 {
return _M_h2(_M_h1(_M_extract(__p->_M_v)), __n); }
685 _M_compare(
const _Key& __k, _Hash_code_type,
686 _Hash_node<_Value, false>* __n)
const
687 {
return _M_eq(__k, _M_extract(__n->_M_v)); }
690 _M_store_code(_Hash_node<_Value, false>*, _Hash_code_type)
const
694 _M_copy_code(_Hash_node<_Value, false>*,
695 const _Hash_node<_Value, false>*)
const
699 _M_swap(_Hash_code_base& __x)
708 _ExtractKey _M_extract;
717 template<
typename _Key,
typename _Value,
718 typename _ExtractKey,
typename _Equal,
719 typename _H1,
typename _H2>
720 struct _Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, _H2,
721 _Default_ranged_hash,
true>
726 hash_function()
const
730 _Hash_code_base(
const _ExtractKey& __ex,
const _Equal& __eq,
731 const _H1& __h1,
const _H2& __h2,
732 const _Default_ranged_hash&)
733 : _M_extract(__ex), _M_eq(__eq), _M_h1(__h1), _M_h2(__h2) { }
738 _M_hash_code(
const _Key& __k)
const
739 {
return _M_h1(__k); }
742 _M_bucket_index(
const _Key&, _Hash_code_type __c,
744 {
return _M_h2(__c, __n); }
747 _M_bucket_index(
const _Hash_node<_Value, true>* __p,
749 {
return _M_h2(__p->_M_hash_code, __n); }
752 _M_compare(
const _Key& __k, _Hash_code_type __c,
753 _Hash_node<_Value, true>* __n)
const
754 {
return __c == __n->_M_hash_code && _M_eq(__k, _M_extract(__n->_M_v)); }
757 _M_store_code(_Hash_node<_Value, true>* __n, _Hash_code_type __c)
const
758 { __n->_M_hash_code = __c; }
761 _M_copy_code(_Hash_node<_Value, true>* __to,
762 const _Hash_node<_Value, true>* __from)
const
763 { __to->_M_hash_code = __from->_M_hash_code; }
766 _M_swap(_Hash_code_base& __x)
775 _ExtractKey _M_extract;
780 _GLIBCXX_END_NAMESPACE_VERSION
bool operator==(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
#define false
Definition: stdbool.h:35
#define true
Definition: stdbool.h:34
bool operator!=(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
const _Tp & max(const _Tp &__a, const _Tp &__b)
Equivalent to std::max.
Definition: base.h:150
__SIZE_TYPE__ size_t
Definition: stddef.h:212
__PTRDIFF_TYPE__ ptrdiff_t
Definition: stddef.h:147
void swap(exception_ptr &__lhs, exception_ptr &__rhs)
Definition: exception_ptr.h:160