32 #define _HASHTABLE_H 1
34 #pragma GCC system_header
38 namespace std _GLIBCXX_VISIBILITY(default)
40 _GLIBCXX_BEGIN_NAMESPACE_VERSION
141 template<
typename _Key,
typename _Value,
typename _Allocator,
142 typename _ExtractKey,
typename _Equal,
143 typename _H1,
typename _H2,
typename _Hash,
144 typename _RehashPolicy,
145 bool __cache_hash_code,
146 bool __constant_iterators,
149 :
public __detail::_Rehash_base<_RehashPolicy,
150 _Hashtable<_Key, _Value, _Allocator,
152 _Equal, _H1, _H2, _Hash,
155 __constant_iterators,
157 public __detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal,
158 _H1, _H2, _Hash, __cache_hash_code>,
159 public __detail::_Map_base<_Key, _Value, _ExtractKey, __unique_keys,
160 _Hashtable<_Key, _Value, _Allocator,
162 _Equal, _H1, _H2, _Hash,
165 __constant_iterators,
167 public __detail::_Equality_base<_ExtractKey, __unique_keys,
168 _Hashtable<_Key, _Value, _Allocator,
170 _Equal, _H1, _H2, _Hash,
173 __constant_iterators,
176 template<
typename _Cond>
177 using __if_hash_code_cached
178 = __or_<__not_<integral_constant<bool, __cache_hash_code>>, _Cond>;
180 template<
typename _Cond>
181 using __if_hash_code_not_cached
182 = __or_<integral_constant<bool, __cache_hash_code>, _Cond>;
186 static_assert(__if_hash_code_not_cached<__detail::__is_noexcept_hash<_Key,
188 "Cache the hash code or qualify your hash functor with noexcept");
197 "Functor used to map hash code to bucket index must be empty");
199 typedef __detail::_Hash_code_base<_Key, _Value, _ExtractKey,
201 __cache_hash_code> _HCBase;
206 "Cache the hash code or make functors involved in hash code"
207 " and bucket index computation empty");
210 typedef _Allocator allocator_type;
211 typedef _Value value_type;
212 typedef _Key key_type;
213 typedef _Equal key_equal;
216 typedef typename _Allocator::pointer pointer;
217 typedef typename _Allocator::const_pointer const_pointer;
218 typedef typename _Allocator::reference reference;
219 typedef typename _Allocator::const_reference const_reference;
221 typedef std::size_t size_type;
222 typedef std::ptrdiff_t difference_type;
223 typedef __detail::_Local_iterator<key_type, value_type, _ExtractKey,
225 __constant_iterators,
228 typedef __detail::_Local_const_iterator<key_type, value_type, _ExtractKey,
230 __constant_iterators,
232 const_local_iterator;
233 typedef __detail::_Node_iterator<value_type, __constant_iterators,
236 typedef __detail::_Node_const_iterator<value_type,
237 __constant_iterators,
241 template<
typename _Key2,
typename _Value2,
typename _Ex2,
bool __unique2,
242 typename _Hashtable2>
243 friend struct __detail::_Map_base;
246 typedef typename _RehashPolicy::_State _RehashPolicyState;
247 typedef __detail::_Hash_node<_Value, __cache_hash_code> _Node;
248 typedef typename _Allocator::template rebind<_Node>::other
249 _Node_allocator_type;
250 typedef __detail::_Hash_node_base _BaseNode;
251 typedef _BaseNode* _Bucket;
252 typedef typename _Allocator::template rebind<_Bucket>::other
253 _Bucket_allocator_type;
255 typedef typename _Allocator::template rebind<_Value>::other
256 _Value_allocator_type;
258 _Node_allocator_type _M_node_allocator;
260 size_type _M_bucket_count;
261 _BaseNode _M_before_begin;
262 size_type _M_element_count;
263 _RehashPolicy _M_rehash_policy;
265 template<
typename... _Args>
267 _M_allocate_node(_Args&&... __args);
270 _M_deallocate_node(_Node* __n);
274 _M_deallocate_nodes(_Node* __n);
277 _M_allocate_buckets(size_type __n);
280 _M_deallocate_buckets(_Bucket*, size_type __n);
285 _M_bucket_begin(size_type __bkt)
const;
289 {
return static_cast<_Node*
>(_M_before_begin._M_nxt); }
294 const _H1&,
const _H2&,
const _Hash&,
295 const _Equal&,
const _ExtractKey&,
296 const allocator_type&);
298 template<
typename _InputIterator>
299 _Hashtable(_InputIterator __first, _InputIterator __last,
300 size_type __bucket_hint,
301 const _H1&,
const _H2&,
const _Hash&,
302 const _Equal&,
const _ExtractKey&,
303 const allocator_type&);
334 {
return iterator(_M_begin()); }
337 begin()
const noexcept
338 {
return const_iterator(_M_begin()); }
342 {
return iterator(
nullptr); }
346 {
return const_iterator(
nullptr); }
349 cbegin()
const noexcept
350 {
return const_iterator(_M_begin()); }
353 cend()
const noexcept
354 {
return const_iterator(
nullptr); }
357 size()
const noexcept
358 {
return _M_element_count; }
361 empty()
const noexcept
362 {
return size() == 0; }
365 get_allocator()
const noexcept
366 {
return allocator_type(_M_node_allocator); }
369 max_size()
const noexcept
370 {
return _M_node_allocator.max_size(); }
375 {
return this->_M_eq(); }
381 bucket_count()
const noexcept
382 {
return _M_bucket_count; }
385 max_bucket_count()
const noexcept
386 {
return max_size(); }
389 bucket_size(size_type __n)
const
393 bucket(
const key_type& __k)
const
394 {
return _M_bucket_index(__k, this->_M_hash_code(__k)); }
398 {
return local_iterator(_M_bucket_begin(__n), __n,
403 {
return local_iterator(
nullptr, __n, _M_bucket_count); }
406 begin(size_type __n)
const
407 {
return const_local_iterator(_M_bucket_begin(__n), __n,
411 end(size_type __n)
const
412 {
return const_local_iterator(
nullptr, __n, _M_bucket_count); }
416 cbegin(size_type __n)
const
417 {
return const_local_iterator(_M_bucket_begin(__n), __n,
421 cend(size_type __n)
const
422 {
return const_local_iterator(
nullptr, __n, _M_bucket_count); }
425 load_factor()
const noexcept
427 return static_cast<float>(
size()) / static_cast<float>(bucket_count());
435 __rehash_policy()
const
436 {
return _M_rehash_policy; }
439 __rehash_policy(
const _RehashPolicy&);
443 find(
const key_type& __k);
446 find(
const key_type& __k)
const;
449 count(
const key_type& __k)
const;
452 equal_range(
const key_type& __k);
455 equal_range(
const key_type& __k)
const;
460 _M_bucket_index(_Node* __n)
const
461 {
return _HCBase::_M_bucket_index(__n, _M_bucket_count); }
464 _M_bucket_index(
const key_type& __k,
465 typename _Hashtable::_Hash_code_type __c)
const
466 {
return _HCBase::_M_bucket_index(__k, __c, _M_bucket_count); }
471 _M_find_before_node(size_type,
const key_type&,
472 typename _Hashtable::_Hash_code_type)
const;
475 _M_find_node(size_type __bkt,
const key_type& __key,
476 typename _Hashtable::_Hash_code_type __c)
const
478 _BaseNode* __before_n = _M_find_before_node(__bkt, __key, __c);
480 return static_cast<_Node*
>(__before_n->_M_nxt);
486 _M_insert_bucket_begin(size_type, _Node*);
490 _M_remove_bucket_begin(size_type __bkt, _Node* __next_n,
491 size_type __next_bkt);
495 _M_get_previous_node(size_type __bkt, _BaseNode* __n);
497 template<
typename _Arg>
499 _M_insert_bucket(_Arg&&, size_type,
500 typename _Hashtable::_Hash_code_type);
508 std::_Select1st<_Insert_Return_Type>,
509 std::_Identity<_Insert_Return_Type>
514 template<
typename... _Args>
518 template<
typename... _Args>
522 template<
typename _Arg>
526 template<
typename _Arg>
532 template<
typename... _Args>
534 emplace(_Args&&... __args)
536 std::forward<_Args>(__args)...); }
538 template<
typename... _Args>
540 emplace_hint(const_iterator, _Args&&... __args)
544 insert(
const value_type& __v)
548 insert(const_iterator,
const value_type& __v)
551 template<
typename _Pair,
typename =
typename
554 _Pair&&>>::value>::type>
557 {
return _M_insert(std::forward<_Pair>(__v),
560 template<
typename _Pair,
typename =
typename
563 _Pair&&>>::value>::type>
565 insert(const_iterator, _Pair&& __v)
568 template<
typename _InputIterator>
570 insert(_InputIterator __first, _InputIterator __last);
574 { this->insert(__l.begin(), __l.end()); }
577 erase(const_iterator);
582 {
return erase(const_iterator(__it)); }
585 erase(
const key_type&);
588 erase(const_iterator, const_iterator);
594 void rehash(size_type __n);
608 void _M_rehash(size_type __n,
const _RehashPolicyState& __state);
613 template<
typename _Key,
typename _Value,
614 typename _Allocator,
typename _ExtractKey,
typename _Equal,
615 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
616 bool __chc,
bool __cit,
bool __uk>
617 template<
typename... _Args>
618 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
619 _H1, _H2, _Hash, _RehashPolicy,
620 __chc, __cit, __uk>::_Node*
621 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
622 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
623 _M_allocate_node(_Args&&... __args)
625 _Node* __n = _M_node_allocator.allocate(1);
628 _M_node_allocator.construct(__n, std::forward<_Args>(__args)...);
633 _M_node_allocator.deallocate(__n, 1);
634 __throw_exception_again;
638 template<
typename _Key,
typename _Value,
639 typename _Allocator,
typename _ExtractKey,
typename _Equal,
640 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
641 bool __chc,
bool __cit,
bool __uk>
643 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
644 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
645 _M_deallocate_node(_Node* __n)
647 _M_node_allocator.destroy(__n);
648 _M_node_allocator.deallocate(__n, 1);
651 template<
typename _Key,
typename _Value,
652 typename _Allocator,
typename _ExtractKey,
typename _Equal,
653 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
654 bool __chc,
bool __cit,
bool __uk>
656 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
657 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
658 _M_deallocate_nodes(_Node* __n)
663 __n = __n->_M_next();
664 _M_deallocate_node(__tmp);
668 template<
typename _Key,
typename _Value,
669 typename _Allocator,
typename _ExtractKey,
typename _Equal,
670 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
671 bool __chc,
bool __cit,
bool __uk>
672 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
673 _H1, _H2, _Hash, _RehashPolicy,
674 __chc, __cit, __uk>::_Bucket*
675 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
676 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
677 _M_allocate_buckets(size_type __n)
679 _Bucket_allocator_type __alloc(_M_node_allocator);
681 _Bucket* __p = __alloc.allocate(__n);
682 __builtin_memset(__p, 0, __n *
sizeof(_Bucket));
686 template<
typename _Key,
typename _Value,
687 typename _Allocator,
typename _ExtractKey,
typename _Equal,
688 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
689 bool __chc,
bool __cit,
bool __uk>
691 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
692 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
693 _M_deallocate_buckets(_Bucket* __p, size_type __n)
695 _Bucket_allocator_type __alloc(_M_node_allocator);
696 __alloc.deallocate(__p, __n);
699 template<
typename _Key,
typename _Value,
700 typename _Allocator,
typename _ExtractKey,
typename _Equal,
701 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
702 bool __chc,
bool __cit,
bool __uk>
703 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey,
704 _Equal, _H1, _H2, _Hash, _RehashPolicy,
705 __chc, __cit, __uk>::_Node*
706 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
707 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
708 _M_bucket_begin(size_type __bkt)
const
710 _BaseNode* __n = _M_buckets[__bkt];
711 return __n ?
static_cast<_Node*
>(__n->_M_nxt) :
nullptr;
714 template<
typename _Key,
typename _Value,
715 typename _Allocator,
typename _ExtractKey,
typename _Equal,
716 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
717 bool __chc,
bool __cit,
bool __uk>
718 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
719 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
720 _Hashtable(size_type __bucket_hint,
721 const _H1& __h1,
const _H2& __h2,
const _Hash& __h,
722 const _Equal& __eq,
const _ExtractKey& __exk,
723 const allocator_type& __a)
724 : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(),
725 __detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal,
726 _H1, _H2, _Hash, __chc>(__exk, __h1, __h2, __h,
728 __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(),
729 _M_node_allocator(__a),
734 _M_bucket_count = _M_rehash_policy._M_next_bkt(__bucket_hint);
737 _M_rehash_policy._M_prev_resize = 0;
738 _M_buckets = _M_allocate_buckets(_M_bucket_count);
741 template<
typename _Key,
typename _Value,
742 typename _Allocator,
typename _ExtractKey,
typename _Equal,
743 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
744 bool __chc,
bool __cit,
bool __uk>
745 template<
typename _InputIterator>
746 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
747 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
748 _Hashtable(_InputIterator __f, _InputIterator __l,
749 size_type __bucket_hint,
750 const _H1& __h1,
const _H2& __h2,
const _Hash& __h,
751 const _Equal& __eq,
const _ExtractKey& __exk,
752 const allocator_type& __a)
753 : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(),
754 __detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal,
755 _H1, _H2, _Hash, __chc>(__exk, __h1, __h2, __h,
757 __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(),
758 _M_node_allocator(__a),
764 _M_rehash_policy._M_bkt_for_elements(__detail::__distance_fw(__f,
766 if (_M_bucket_count <= __bucket_hint)
767 _M_bucket_count = _M_rehash_policy._M_next_bkt(__bucket_hint);
772 _M_rehash_policy._M_prev_resize = 0;
773 _M_buckets = _M_allocate_buckets(_M_bucket_count);
776 for (; __f != __l; ++__f)
782 _M_deallocate_buckets(_M_buckets, _M_bucket_count);
783 __throw_exception_again;
787 template<
typename _Key,
typename _Value,
788 typename _Allocator,
typename _ExtractKey,
typename _Equal,
789 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
790 bool __chc,
bool __cit,
bool __uk>
791 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
792 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
793 _Hashtable(
const _Hashtable& __ht)
794 : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(__ht),
795 __detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal,
796 _H1, _H2, _Hash, __chc>(__ht),
797 __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(__ht),
798 _M_node_allocator(__ht._M_node_allocator),
799 _M_bucket_count(__ht._M_bucket_count),
800 _M_element_count(__ht._M_element_count),
801 _M_rehash_policy(__ht._M_rehash_policy)
803 _M_buckets = _M_allocate_buckets(_M_bucket_count);
806 if (!__ht._M_before_begin._M_nxt)
811 const _Node* __ht_n = __ht._M_begin();
812 _Node* __this_n = _M_allocate_node(__ht_n->_M_v);
813 this->_M_copy_code(__this_n, __ht_n);
814 _M_before_begin._M_nxt = __this_n;
815 _M_buckets[_M_bucket_index(__this_n)] = &_M_before_begin;
818 _BaseNode* __prev_n = __this_n;
819 for (__ht_n = __ht_n->_M_next(); __ht_n; __ht_n = __ht_n->_M_next())
821 __this_n = _M_allocate_node(__ht_n->_M_v);
822 __prev_n->_M_nxt = __this_n;
823 this->_M_copy_code(__this_n, __ht_n);
824 size_type __bkt = _M_bucket_index(__this_n);
825 if (!_M_buckets[__bkt])
826 _M_buckets[__bkt] = __prev_n;
833 _M_deallocate_buckets(_M_buckets, _M_bucket_count);
834 __throw_exception_again;
838 template<
typename _Key,
typename _Value,
839 typename _Allocator,
typename _ExtractKey,
typename _Equal,
840 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
841 bool __chc,
bool __cit,
bool __uk>
842 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
843 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
844 _Hashtable(_Hashtable&& __ht)
845 : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(__ht),
846 __detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal,
847 _H1, _H2, _Hash, __chc>(__ht),
848 __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(__ht),
849 _M_node_allocator(std::move(__ht._M_node_allocator)),
850 _M_buckets(__ht._M_buckets),
851 _M_bucket_count(__ht._M_bucket_count),
852 _M_before_begin(__ht._M_before_begin._M_nxt),
853 _M_element_count(__ht._M_element_count),
854 _M_rehash_policy(__ht._M_rehash_policy)
858 _M_buckets[_M_bucket_index(_M_begin())] = &_M_before_begin;
859 __ht._M_rehash_policy = _RehashPolicy();
860 __ht._M_bucket_count = __ht._M_rehash_policy._M_next_bkt(0);
861 __ht._M_buckets = __ht._M_allocate_buckets(__ht._M_bucket_count);
862 __ht._M_before_begin._M_nxt =
nullptr;
863 __ht._M_element_count = 0;
866 template<
typename _Key,
typename _Value,
867 typename _Allocator,
typename _ExtractKey,
typename _Equal,
868 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
869 bool __chc,
bool __cit,
bool __uk>
870 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
871 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
872 ~_Hashtable() noexcept
875 _M_deallocate_buckets(_M_buckets, _M_bucket_count);
878 template<
typename _Key,
typename _Value,
879 typename _Allocator,
typename _ExtractKey,
typename _Equal,
880 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
881 bool __chc,
bool __cit,
bool __uk>
883 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
884 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
885 swap(_Hashtable& __x)
894 std::__alloc_swap<_Node_allocator_type>::_S_do_it(_M_node_allocator,
895 __x._M_node_allocator);
897 std::swap(_M_rehash_policy, __x._M_rehash_policy);
898 std::swap(_M_buckets, __x._M_buckets);
899 std::swap(_M_bucket_count, __x._M_bucket_count);
900 std::swap(_M_before_begin._M_nxt, __x._M_before_begin._M_nxt);
901 std::swap(_M_element_count, __x._M_element_count);
905 _M_buckets[_M_bucket_index(_M_begin())] = &_M_before_begin;
907 __x._M_buckets[__x._M_bucket_index(__x._M_begin())]
908 = &(__x._M_before_begin);
911 template<
typename _Key,
typename _Value,
912 typename _Allocator,
typename _ExtractKey,
typename _Equal,
913 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
914 bool __chc,
bool __cit,
bool __uk>
916 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
917 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
918 __rehash_policy(
const _RehashPolicy& __pol)
920 size_type __n_bkt = __pol._M_bkt_for_elements(_M_element_count);
921 if (__n_bkt != _M_bucket_count)
922 _M_rehash(__n_bkt, _M_rehash_policy._M_state());
923 _M_rehash_policy = __pol;
926 template<
typename _Key,
typename _Value,
927 typename _Allocator,
typename _ExtractKey,
typename _Equal,
928 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
929 bool __chc,
bool __cit,
bool __uk>
930 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
931 _H1, _H2, _Hash, _RehashPolicy,
932 __chc, __cit, __uk>::iterator
933 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
934 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
935 find(
const key_type& __k)
937 typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
938 std::size_t __n = _M_bucket_index(__k, __code);
939 _Node* __p = _M_find_node(__n, __k, __code);
940 return __p ? iterator(__p) : this->
end();
943 template<
typename _Key,
typename _Value,
944 typename _Allocator,
typename _ExtractKey,
typename _Equal,
945 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
946 bool __chc,
bool __cit,
bool __uk>
947 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
948 _H1, _H2, _Hash, _RehashPolicy,
949 __chc, __cit, __uk>::const_iterator
950 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
951 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
952 find(
const key_type& __k)
const
954 typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
955 std::size_t __n = _M_bucket_index(__k, __code);
956 _Node* __p = _M_find_node(__n, __k, __code);
957 return __p ? const_iterator(__p) : this->
end();
960 template<
typename _Key,
typename _Value,
961 typename _Allocator,
typename _ExtractKey,
typename _Equal,
962 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
963 bool __chc,
bool __cit,
bool __uk>
964 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
965 _H1, _H2, _Hash, _RehashPolicy,
966 __chc, __cit, __uk>::size_type
967 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
968 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>
::
969 count(
const key_type& __k)
const
971 typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
972 std::size_t __n = _M_bucket_index(__k, __code);
973 _Node* __p = _M_bucket_begin(__n);
977 std::size_t __result = 0;
978 for (;; __p = __p->_M_next())
980 if (this->_M_equals(__k, __code, __p))
987 if (!__p->_M_nxt || _M_bucket_index(__p->_M_next()) != __n)
993 template<
typename _Key,
typename _Value,
994 typename _Allocator,
typename _ExtractKey,
typename _Equal,
995 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
996 bool __chc,
bool __cit,
bool __uk>
997 std::pair<
typename _Hashtable<_Key, _Value, _Allocator,
998 _ExtractKey, _Equal, _H1,
999 _H2, _Hash, _RehashPolicy,
1000 __chc, __cit, __uk>::iterator,
1001 typename _Hashtable<_Key, _Value, _Allocator,
1002 _ExtractKey, _Equal, _H1,
1003 _H2, _Hash, _RehashPolicy,
1004 __chc, __cit, __uk>::iterator>
1005 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1006 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1007 equal_range(
const key_type& __k)
1009 typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
1010 std::size_t __n = _M_bucket_index(__k, __code);
1011 _Node* __p = _M_find_node(__n, __k, __code);
1015 _Node* __p1 = __p->_M_next();
1016 while (__p1 && _M_bucket_index(__p1) == __n
1017 && this->_M_equals(__k, __code, __p1))
1018 __p1 = __p1->_M_next();
1026 template<
typename _Key,
typename _Value,
1027 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1028 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1029 bool __chc,
bool __cit,
bool __uk>
1030 std::pair<
typename _Hashtable<_Key, _Value, _Allocator,
1031 _ExtractKey, _Equal, _H1,
1032 _H2, _Hash, _RehashPolicy,
1033 __chc, __cit, __uk>::const_iterator,
1034 typename _Hashtable<_Key, _Value, _Allocator,
1035 _ExtractKey, _Equal, _H1,
1036 _H2, _Hash, _RehashPolicy,
1037 __chc, __cit, __uk>::const_iterator>
1038 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1039 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1040 equal_range(
const key_type& __k)
const
1042 typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
1043 std::size_t __n = _M_bucket_index(__k, __code);
1044 _Node* __p = _M_find_node(__n, __k, __code);
1048 _Node* __p1 = __p->_M_next();
1049 while (__p1 && _M_bucket_index(__p1) == __n
1050 && this->_M_equals(__k, __code, __p1))
1051 __p1 = __p1->_M_next();
1053 return std::make_pair(const_iterator(__p), const_iterator(__p1));
1061 template<
typename _Key,
typename _Value,
1062 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1063 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1064 bool __chc,
bool __cit,
bool __uk>
1065 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey,
1066 _Equal, _H1, _H2, _Hash, _RehashPolicy,
1067 __chc, __cit, __uk>::_BaseNode*
1068 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1069 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1070 _M_find_before_node(size_type __n,
const key_type& __k,
1071 typename _Hashtable::_Hash_code_type __code)
const
1073 _BaseNode* __prev_p = _M_buckets[__n];
1076 _Node* __p =
static_cast<_Node*
>(__prev_p->_M_nxt);
1077 for (;; __p = __p->_M_next())
1079 if (this->_M_equals(__k, __code, __p))
1081 if (!(__p->_M_nxt) || _M_bucket_index(__p->_M_next()) != __n)
1088 template<
typename _Key,
typename _Value,
1089 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1090 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1091 bool __chc,
bool __cit,
bool __uk>
1093 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1094 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1095 _M_insert_bucket_begin(size_type __bkt, _Node* __new_node)
1097 if (_M_buckets[__bkt])
1101 __new_node->_M_nxt = _M_buckets[__bkt]->_M_nxt;
1102 _M_buckets[__bkt]->_M_nxt = __new_node;
1109 __new_node->_M_nxt = _M_before_begin._M_nxt;
1110 _M_before_begin._M_nxt = __new_node;
1111 if (__new_node->_M_nxt)
1114 _M_buckets[_M_bucket_index(__new_node->_M_next())] = __new_node;
1115 _M_buckets[__bkt] = &_M_before_begin;
1119 template<
typename _Key,
typename _Value,
1120 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1121 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1122 bool __chc,
bool __cit,
bool __uk>
1124 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1125 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1126 _M_remove_bucket_begin(size_type __bkt, _Node* __next, size_type __next_bkt)
1128 if (!__next || __next_bkt != __bkt)
1133 _M_buckets[__next_bkt] = _M_buckets[__bkt];
1135 if (&_M_before_begin == _M_buckets[__bkt])
1136 _M_before_begin._M_nxt = __next;
1137 _M_buckets[__bkt] =
nullptr;
1141 template<
typename _Key,
typename _Value,
1142 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1143 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1144 bool __chc,
bool __cit,
bool __uk>
1145 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey,
1146 _Equal, _H1, _H2, _Hash, _RehashPolicy,
1147 __chc, __cit, __uk>::_BaseNode*
1148 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1149 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1150 _M_get_previous_node(size_type __bkt, _BaseNode* __n)
1152 _BaseNode* __prev_n = _M_buckets[__bkt];
1153 while (__prev_n->_M_nxt != __n)
1154 __prev_n = __prev_n->_M_nxt;
1158 template<
typename _Key,
typename _Value,
1159 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1160 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1161 bool __chc,
bool __cit,
bool __uk>
1162 template<
typename... _Args>
1163 std::pair<
typename _Hashtable<_Key, _Value, _Allocator,
1164 _ExtractKey, _Equal, _H1,
1165 _H2, _Hash, _RehashPolicy,
1166 __chc, __cit, __uk>::iterator,
bool>
1167 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1168 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1172 _Node* __new_node = _M_allocate_node(std::forward<_Args>(__args)...);
1175 const key_type& __k = this->_M_extract()(__new_node->_M_v);
1176 typename _Hashtable::_Hash_code_type __code
1177 = this->_M_hash_code(__k);
1178 size_type __bkt = _M_bucket_index(__k, __code);
1180 if (_Node* __p = _M_find_node(__bkt, __k, __code))
1183 _M_deallocate_node(__new_node);
1188 this->_M_store_code(__new_node, __code);
1189 const _RehashPolicyState& __saved_state
1190 = _M_rehash_policy._M_state();
1192 = _M_rehash_policy._M_need_rehash(_M_bucket_count,
1193 _M_element_count, 1);
1195 if (__do_rehash.
first)
1197 _M_rehash(__do_rehash.
second, __saved_state);
1198 __bkt = _M_bucket_index(__k, __code);
1201 _M_insert_bucket_begin(__bkt, __new_node);
1207 _M_deallocate_node(__new_node);
1208 __throw_exception_again;
1212 template<
typename _Key,
typename _Value,
1213 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1214 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1215 bool __chc,
bool __cit,
bool __uk>
1216 template<
typename... _Args>
1217 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1218 _H1, _H2, _Hash, _RehashPolicy,
1219 __chc, __cit, __uk>::iterator
1220 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1221 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1224 const _RehashPolicyState& __saved_state = _M_rehash_policy._M_state();
1226 = _M_rehash_policy._M_need_rehash(_M_bucket_count,
1227 _M_element_count, 1);
1230 _Node* __new_node = _M_allocate_node(std::forward<_Args>(__args)...);
1233 const key_type& __k = this->_M_extract()(__new_node->_M_v);
1234 typename _Hashtable::_Hash_code_type __code
1235 = this->_M_hash_code(__k);
1236 this->_M_store_code(__new_node, __code);
1239 if (__do_rehash.
first)
1240 _M_rehash(__do_rehash.
second, __saved_state);
1243 size_type __bkt = _M_bucket_index(__k, __code);
1244 _BaseNode* __prev = _M_find_before_node(__bkt, __k, __code);
1249 __new_node->_M_nxt = __prev->_M_nxt;
1250 __prev->_M_nxt = __new_node;
1256 _M_insert_bucket_begin(__bkt, __new_node);
1258 return iterator(__new_node);
1262 _M_deallocate_node(__new_node);
1263 __throw_exception_again;
1268 template<
typename _Key,
typename _Value,
1269 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1270 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1271 bool __chc,
bool __cit,
bool __uk>
1272 template<
typename _Arg>
1273 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1274 _H1, _H2, _Hash, _RehashPolicy,
1275 __chc, __cit, __uk>::iterator
1276 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1277 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1278 _M_insert_bucket(_Arg&& __v, size_type __n,
1279 typename _Hashtable::_Hash_code_type __code)
1281 const _RehashPolicyState& __saved_state = _M_rehash_policy._M_state();
1283 = _M_rehash_policy._M_need_rehash(_M_bucket_count,
1284 _M_element_count, 1);
1286 if (__do_rehash.
first)
1288 const key_type& __k = this->_M_extract()(__v);
1289 __n = _HCBase::_M_bucket_index(__k, __code, __do_rehash.
second);
1292 _Node* __new_node =
nullptr;
1297 __new_node = _M_allocate_node(std::forward<_Arg>(__v));
1298 this->_M_store_code(__new_node, __code);
1299 if (__do_rehash.
first)
1300 _M_rehash(__do_rehash.
second, __saved_state);
1302 _M_insert_bucket_begin(__n, __new_node);
1304 return iterator(__new_node);
1309 _M_rehash_policy._M_reset(__saved_state);
1311 _M_deallocate_node(__new_node);
1312 __throw_exception_again;
1317 template<
typename _Key,
typename _Value,
1318 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1319 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1320 bool __chc,
bool __cit,
bool __uk>
1321 template<
typename _Arg>
1322 std::pair<
typename _Hashtable<_Key, _Value, _Allocator,
1323 _ExtractKey, _Equal, _H1,
1324 _H2, _Hash, _RehashPolicy,
1325 __chc, __cit, __uk>::iterator,
bool>
1326 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1327 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1330 const key_type& __k = this->_M_extract()(__v);
1331 typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
1332 size_type __n = _M_bucket_index(__k, __code);
1334 if (_Node* __p = _M_find_node(__n, __k, __code))
1337 __n, __code),
true);
1341 template<
typename _Key,
typename _Value,
1342 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1343 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1344 bool __chc,
bool __cit,
bool __uk>
1345 template<
typename _Arg>
1346 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1347 _H1, _H2, _Hash, _RehashPolicy,
1348 __chc, __cit, __uk>::iterator
1349 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1350 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1353 const _RehashPolicyState& __saved_state = _M_rehash_policy._M_state();
1355 = _M_rehash_policy._M_need_rehash(_M_bucket_count,
1356 _M_element_count, 1);
1359 typename _Hashtable::_Hash_code_type __code
1360 = this->_M_hash_code(this->_M_extract()(__v));
1362 _Node* __new_node =
nullptr;
1366 __new_node = _M_allocate_node(std::forward<_Arg>(__v));
1367 this->_M_store_code(__new_node, __code);
1368 if (__do_rehash.
first)
1369 _M_rehash(__do_rehash.
second, __saved_state);
1372 size_type __bkt = _M_bucket_index(__new_node);
1374 = _M_find_before_node(__bkt, this->_M_extract()(__new_node->_M_v),
1379 __new_node->_M_nxt = __prev->_M_nxt;
1380 __prev->_M_nxt = __new_node;
1386 _M_insert_bucket_begin(__bkt, __new_node);
1388 return iterator(__new_node);
1393 _M_rehash_policy._M_reset(__saved_state);
1395 _M_deallocate_node(__new_node);
1396 __throw_exception_again;
1400 template<
typename _Key,
typename _Value,
1401 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1402 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1403 bool __chc,
bool __cit,
bool __uk>
1404 template<
typename _InputIterator>
1406 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1407 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1408 insert(_InputIterator __first, _InputIterator __last)
1410 size_type __n_elt = __detail::__distance_fw(__first, __last);
1411 const _RehashPolicyState& __saved_state = _M_rehash_policy._M_state();
1413 = _M_rehash_policy._M_need_rehash(_M_bucket_count,
1414 _M_element_count, __n_elt);
1415 if (__do_rehash.
first)
1416 _M_rehash(__do_rehash.
second, __saved_state);
1418 for (; __first != __last; ++__first)
1419 this->insert(*__first);
1422 template<
typename _Key,
typename _Value,
1423 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1424 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1425 bool __chc,
bool __cit,
bool __uk>
1426 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1427 _H1, _H2, _Hash, _RehashPolicy,
1428 __chc, __cit, __uk>::iterator
1429 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1430 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1431 erase(const_iterator __it)
1433 _Node* __n = __it._M_cur;
1434 std::size_t __bkt = _M_bucket_index(__n);
1438 _BaseNode* __prev_n = _M_get_previous_node(__bkt, __n);
1439 if (__n == _M_bucket_begin(__bkt))
1440 _M_remove_bucket_begin(__bkt, __n->_M_next(),
1441 __n->_M_nxt ? _M_bucket_index(__n->_M_next()) : 0);
1442 else if (__n->_M_nxt)
1444 size_type __next_bkt = _M_bucket_index(__n->_M_next());
1445 if (__next_bkt != __bkt)
1446 _M_buckets[__next_bkt] = __prev_n;
1449 __prev_n->_M_nxt = __n->_M_nxt;
1450 iterator __result(__n->_M_next());
1451 _M_deallocate_node(__n);
1457 template<
typename _Key,
typename _Value,
1458 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1459 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1460 bool __chc,
bool __cit,
bool __uk>
1461 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1462 _H1, _H2, _Hash, _RehashPolicy,
1463 __chc, __cit, __uk>::size_type
1464 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1465 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1466 erase(
const key_type& __k)
1468 typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k);
1469 std::size_t __bkt = _M_bucket_index(__k, __code);
1471 _BaseNode* __prev_n = _M_find_before_node(__bkt, __k, __code);
1474 _Node* __n =
static_cast<_Node*
>(__prev_n->_M_nxt);
1475 bool __is_bucket_begin = _M_buckets[__bkt] == __prev_n;
1478 std::size_t __next_bkt = __bkt;
1479 _Node* __next_n = __n;
1480 size_type __result = 0;
1481 _Node* __saved_n =
nullptr;
1484 _Node* __p = __next_n;
1485 __next_n = __p->_M_next();
1491 _M_deallocate_node(__p);
1498 __next_bkt = _M_bucket_index(__next_n);
1500 while (__next_bkt == __bkt && this->_M_equals(__k, __code, __next_n));
1503 _M_deallocate_node(__saved_n);
1504 if (__is_bucket_begin)
1505 _M_remove_bucket_begin(__bkt, __next_n, __next_bkt);
1506 else if (__next_n && __next_bkt != __bkt)
1507 _M_buckets[__next_bkt] = __prev_n;
1509 __prev_n->_M_nxt = __next_n;
1513 template<
typename _Key,
typename _Value,
1514 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1515 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1516 bool __chc,
bool __cit,
bool __uk>
1517 typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1518 _H1, _H2, _Hash, _RehashPolicy,
1519 __chc, __cit, __uk>::iterator
1520 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1521 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1522 erase(const_iterator __first, const_iterator __last)
1524 _Node* __n = __first._M_cur;
1525 _Node* __last_n = __last._M_cur;
1526 if (__n == __last_n)
1527 return iterator(__n);
1529 std::size_t __bkt = _M_bucket_index(__n);
1531 _BaseNode* __prev_n = _M_get_previous_node(__bkt, __n);
1532 bool __is_bucket_begin = __n == _M_bucket_begin(__bkt);
1533 std::size_t __n_bkt = __bkt;
1539 __n = __n->_M_next();
1540 _M_deallocate_node(__tmp);
1544 __n_bkt = _M_bucket_index(__n);
1546 while (__n != __last_n && __n_bkt == __bkt);
1547 if (__is_bucket_begin)
1548 _M_remove_bucket_begin(__bkt, __n, __n_bkt);
1549 if (__n == __last_n)
1551 __is_bucket_begin =
true;
1555 if (__n && (__n_bkt != __bkt || __is_bucket_begin))
1556 _M_buckets[__n_bkt] = __prev_n;
1557 __prev_n->_M_nxt = __n;
1558 return iterator(__n);
1561 template<
typename _Key,
typename _Value,
1562 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1563 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1564 bool __chc,
bool __cit,
bool __uk>
1566 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1567 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1570 _M_deallocate_nodes(_M_begin());
1571 __builtin_memset(_M_buckets, 0, _M_bucket_count *
sizeof(_Bucket));
1572 _M_element_count = 0;
1573 _M_before_begin._M_nxt =
nullptr;
1576 template<
typename _Key,
typename _Value,
1577 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1578 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1579 bool __chc,
bool __cit,
bool __uk>
1581 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1582 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1583 rehash(size_type __n)
1585 const _RehashPolicyState& __saved_state = _M_rehash_policy._M_state();
1586 std::size_t __buckets
1587 = _M_rehash_policy._M_bkt_for_elements(_M_element_count + 1);
1588 if (__buckets <= __n)
1589 __buckets = _M_rehash_policy._M_next_bkt(__n);
1591 if (__buckets != _M_bucket_count)
1593 _M_rehash(__buckets, __saved_state);
1598 _M_rehash_policy._M_prev_resize = 0;
1602 _M_rehash_policy._M_reset(__saved_state);
1605 template<
typename _Key,
typename _Value,
1606 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1607 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1608 bool __chc,
bool __cit,
bool __uk>
1610 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1611 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1612 _M_rehash(size_type __n,
const _RehashPolicyState& __state)
1616 _M_rehash_aux(__n, integral_constant<bool, __uk>());
1622 _M_rehash_policy._M_reset(__state);
1623 __throw_exception_again;
1628 template<
typename _Key,
typename _Value,
1629 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1630 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1631 bool __chc,
bool __cit,
bool __uk>
1633 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1634 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1637 _Bucket* __new_buckets = _M_allocate_buckets(__n);
1638 _Node* __p = _M_begin();
1639 _M_before_begin._M_nxt =
nullptr;
1640 std::size_t __bbegin_bkt;
1643 _Node* __next = __p->_M_next();
1644 std::size_t __bkt = _HCBase::_M_bucket_index(__p, __n);
1645 if (!__new_buckets[__bkt])
1647 __p->_M_nxt = _M_before_begin._M_nxt;
1648 _M_before_begin._M_nxt = __p;
1649 __new_buckets[__bkt] = &_M_before_begin;
1651 __new_buckets[__bbegin_bkt] = __p;
1652 __bbegin_bkt = __bkt;
1656 __p->_M_nxt = __new_buckets[__bkt]->_M_nxt;
1657 __new_buckets[__bkt]->_M_nxt = __p;
1661 _M_deallocate_buckets(_M_buckets, _M_bucket_count);
1662 _M_bucket_count = __n;
1663 _M_buckets = __new_buckets;
1668 template<
typename _Key,
typename _Value,
1669 typename _Allocator,
typename _ExtractKey,
typename _Equal,
1670 typename _H1,
typename _H2,
typename _Hash,
typename _RehashPolicy,
1671 bool __chc,
bool __cit,
bool __uk>
1673 _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal,
1674 _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::
1677 _Bucket* __new_buckets = _M_allocate_buckets(__n);
1679 _Node* __p = _M_begin();
1680 _M_before_begin._M_nxt =
nullptr;
1681 std::size_t __bbegin_bkt;
1682 std::size_t __prev_bkt;
1683 _Node* __prev_p =
nullptr;
1684 bool __check_bucket =
false;
1688 _Node* __next = __p->_M_next();
1689 std::size_t __bkt = _HCBase::_M_bucket_index(__p, __n);
1691 if (__prev_p && __prev_bkt == __bkt)
1696 __p->_M_nxt = __prev_p->_M_nxt;
1697 __prev_p->_M_nxt = __p;
1704 __check_bucket =
true;
1712 if (__prev_p->_M_nxt)
1714 std::size_t __next_bkt
1715 = _HCBase::_M_bucket_index(__prev_p->_M_next(), __n);
1716 if (__next_bkt != __prev_bkt)
1717 __new_buckets[__next_bkt] = __prev_p;
1719 __check_bucket =
false;
1721 if (!__new_buckets[__bkt])
1723 __p->_M_nxt = _M_before_begin._M_nxt;
1724 _M_before_begin._M_nxt = __p;
1725 __new_buckets[__bkt] = &_M_before_begin;
1727 __new_buckets[__bbegin_bkt] = __p;
1728 __bbegin_bkt = __bkt;
1732 __p->_M_nxt = __new_buckets[__bkt]->_M_nxt;
1733 __new_buckets[__bkt]->_M_nxt = __p;
1742 if (__check_bucket && __prev_p->_M_nxt)
1744 std::size_t __next_bkt
1745 = _HCBase::_M_bucket_index(__prev_p->_M_next(), __n);
1746 if (__next_bkt != __prev_bkt)
1747 __new_buckets[__next_bkt] = __prev_p;
1750 _M_deallocate_buckets(_M_buckets, _M_bucket_count);
1751 _M_bucket_count = __n;
1752 _M_buckets = __new_buckets;
1755 _GLIBCXX_END_NAMESPACE_VERSION
1758 #endif // _HASHTABLE_H