1*700637cbSDimitry Andric// -*- C++ -*- 2*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 3*700637cbSDimitry Andric// 4*700637cbSDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*700637cbSDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 6*700637cbSDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*700637cbSDimitry Andric// 8*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 9*700637cbSDimitry Andric 10*700637cbSDimitry Andric#ifndef _LIBCPP___CXX03___HASH_TABLE 11*700637cbSDimitry Andric#define _LIBCPP___CXX03___HASH_TABLE 12*700637cbSDimitry Andric 13*700637cbSDimitry Andric#include <__cxx03/__algorithm/max.h> 14*700637cbSDimitry Andric#include <__cxx03/__algorithm/min.h> 15*700637cbSDimitry Andric#include <__cxx03/__assert> 16*700637cbSDimitry Andric#include <__cxx03/__bit/countl.h> 17*700637cbSDimitry Andric#include <__cxx03/__config> 18*700637cbSDimitry Andric#include <__cxx03/__functional/hash.h> 19*700637cbSDimitry Andric#include <__cxx03/__iterator/iterator_traits.h> 20*700637cbSDimitry Andric#include <__cxx03/__memory/addressof.h> 21*700637cbSDimitry Andric#include <__cxx03/__memory/allocator_traits.h> 22*700637cbSDimitry Andric#include <__cxx03/__memory/compressed_pair.h> 23*700637cbSDimitry Andric#include <__cxx03/__memory/construct_at.h> 24*700637cbSDimitry Andric#include <__cxx03/__memory/pointer_traits.h> 25*700637cbSDimitry Andric#include <__cxx03/__memory/swap_allocator.h> 26*700637cbSDimitry Andric#include <__cxx03/__memory/unique_ptr.h> 27*700637cbSDimitry Andric#include <__cxx03/__type_traits/can_extract_key.h> 28*700637cbSDimitry Andric#include <__cxx03/__type_traits/conditional.h> 29*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_const.h> 30*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_constructible.h> 31*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_nothrow_assignable.h> 32*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_nothrow_constructible.h> 33*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_pointer.h> 34*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_reference.h> 35*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_swappable.h> 36*700637cbSDimitry Andric#include <__cxx03/__type_traits/remove_const.h> 37*700637cbSDimitry Andric#include <__cxx03/__type_traits/remove_cvref.h> 38*700637cbSDimitry Andric#include <__cxx03/__utility/forward.h> 39*700637cbSDimitry Andric#include <__cxx03/__utility/move.h> 40*700637cbSDimitry Andric#include <__cxx03/__utility/pair.h> 41*700637cbSDimitry Andric#include <__cxx03/__utility/swap.h> 42*700637cbSDimitry Andric#include <__cxx03/cmath> 43*700637cbSDimitry Andric#include <__cxx03/cstring> 44*700637cbSDimitry Andric#include <__cxx03/new> // __launder 45*700637cbSDimitry Andric 46*700637cbSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 47*700637cbSDimitry Andric# pragma GCC system_header 48*700637cbSDimitry Andric#endif 49*700637cbSDimitry Andric 50*700637cbSDimitry Andric_LIBCPP_PUSH_MACROS 51*700637cbSDimitry Andric#include <__cxx03/__undef_macros> 52*700637cbSDimitry Andric 53*700637cbSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 54*700637cbSDimitry Andric 55*700637cbSDimitry Andrictemplate <class _Key, class _Tp> 56*700637cbSDimitry Andricstruct __hash_value_type; 57*700637cbSDimitry Andric 58*700637cbSDimitry Andrictemplate <class _Tp> 59*700637cbSDimitry Andricstruct __is_hash_value_type_imp : false_type {}; 60*700637cbSDimitry Andric 61*700637cbSDimitry Andrictemplate <class _Key, class _Value> 62*700637cbSDimitry Andricstruct __is_hash_value_type_imp<__hash_value_type<_Key, _Value> > : true_type {}; 63*700637cbSDimitry Andric 64*700637cbSDimitry Andrictemplate <class... _Args> 65*700637cbSDimitry Andricstruct __is_hash_value_type : false_type {}; 66*700637cbSDimitry Andric 67*700637cbSDimitry Andrictemplate <class _One> 68*700637cbSDimitry Andricstruct __is_hash_value_type<_One> : __is_hash_value_type_imp<__remove_cvref_t<_One> > {}; 69*700637cbSDimitry Andric 70*700637cbSDimitry Andric_LIBCPP_EXPORTED_FROM_ABI size_t __next_prime(size_t __n); 71*700637cbSDimitry Andric 72*700637cbSDimitry Andrictemplate <class _NodePtr> 73*700637cbSDimitry Andricstruct __hash_node_base { 74*700637cbSDimitry Andric typedef typename pointer_traits<_NodePtr>::element_type __node_type; 75*700637cbSDimitry Andric typedef __hash_node_base __first_node; 76*700637cbSDimitry Andric typedef __rebind_pointer_t<_NodePtr, __first_node> __node_base_pointer; 77*700637cbSDimitry Andric typedef _NodePtr __node_pointer; 78*700637cbSDimitry Andric 79*700637cbSDimitry Andric#if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB) 80*700637cbSDimitry Andric typedef __node_base_pointer __next_pointer; 81*700637cbSDimitry Andric#else 82*700637cbSDimitry Andric typedef __conditional_t<is_pointer<__node_pointer>::value, __node_base_pointer, __node_pointer> __next_pointer; 83*700637cbSDimitry Andric#endif 84*700637cbSDimitry Andric 85*700637cbSDimitry Andric __next_pointer __next_; 86*700637cbSDimitry Andric 87*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __next_pointer __ptr() _NOEXCEPT { 88*700637cbSDimitry Andric return static_cast<__next_pointer>(pointer_traits<__node_base_pointer>::pointer_to(*this)); 89*700637cbSDimitry Andric } 90*700637cbSDimitry Andric 91*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __node_pointer __upcast() _NOEXCEPT { 92*700637cbSDimitry Andric return static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::pointer_to(*this)); 93*700637cbSDimitry Andric } 94*700637cbSDimitry Andric 95*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_t __hash() const _NOEXCEPT { return static_cast<__node_type const&>(*this).__hash_; } 96*700637cbSDimitry Andric 97*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_node_base() _NOEXCEPT : __next_(nullptr) {} 98*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit __hash_node_base(__next_pointer __next) _NOEXCEPT : __next_(__next) {} 99*700637cbSDimitry Andric}; 100*700637cbSDimitry Andric 101*700637cbSDimitry Andrictemplate <class _Tp, class _VoidPtr> 102*700637cbSDimitry Andricstruct __hash_node : public __hash_node_base< __rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > > { 103*700637cbSDimitry Andric typedef _Tp __node_value_type; 104*700637cbSDimitry Andric using _Base = __hash_node_base<__rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > >; 105*700637cbSDimitry Andric using __next_pointer = typename _Base::__next_pointer; 106*700637cbSDimitry Andric 107*700637cbSDimitry Andric size_t __hash_; 108*700637cbSDimitry Andric 109*700637cbSDimitry Andric // We allow starting the lifetime of nodes without initializing the value held by the node, 110*700637cbSDimitry Andric // since that is handled by the hash table itself in order to be allocator-aware. 111*700637cbSDimitry Andric 112*700637cbSDimitry Andricprivate: 113*700637cbSDimitry Andric _ALIGNAS_TYPE(_Tp) char __buffer_[sizeof(_Tp)]; 114*700637cbSDimitry Andric 115*700637cbSDimitry Andricpublic: 116*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return *std::__launder(reinterpret_cast<_Tp*>(&__buffer_)); } 117*700637cbSDimitry Andric 118*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit __hash_node(__next_pointer __next, size_t __hash) : _Base(__next), __hash_(__hash) {} 119*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI ~__hash_node() {} 120*700637cbSDimitry Andric}; 121*700637cbSDimitry Andric 122*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool __is_hash_power2(size_t __bc) { return __bc > 2 && !(__bc & (__bc - 1)); } 123*700637cbSDimitry Andric 124*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI size_t __constrain_hash(size_t __h, size_t __bc) { 125*700637cbSDimitry Andric return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : (__h < __bc ? __h : __h % __bc); 126*700637cbSDimitry Andric} 127*700637cbSDimitry Andric 128*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI size_t __next_hash_pow2(size_t __n) { 129*700637cbSDimitry Andric return __n < 2 ? __n : (size_t(1) << (numeric_limits<size_t>::digits - __libcpp_clz(__n - 1))); 130*700637cbSDimitry Andric} 131*700637cbSDimitry Andric 132*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 133*700637cbSDimitry Andricclass __hash_table; 134*700637cbSDimitry Andric 135*700637cbSDimitry Andrictemplate <class _NodePtr> 136*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __hash_iterator; 137*700637cbSDimitry Andrictemplate <class _ConstNodePtr> 138*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __hash_const_iterator; 139*700637cbSDimitry Andrictemplate <class _NodePtr> 140*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __hash_local_iterator; 141*700637cbSDimitry Andrictemplate <class _ConstNodePtr> 142*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; 143*700637cbSDimitry Andrictemplate <class _HashIterator> 144*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __hash_map_iterator; 145*700637cbSDimitry Andrictemplate <class _HashIterator> 146*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; 147*700637cbSDimitry Andric 148*700637cbSDimitry Andrictemplate <class _Tp> 149*700637cbSDimitry Andricstruct __hash_key_value_types { 150*700637cbSDimitry Andric static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, ""); 151*700637cbSDimitry Andric typedef _Tp key_type; 152*700637cbSDimitry Andric typedef _Tp __node_value_type; 153*700637cbSDimitry Andric typedef _Tp __container_value_type; 154*700637cbSDimitry Andric static const bool __is_map = false; 155*700637cbSDimitry Andric 156*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI static key_type const& __get_key(_Tp const& __v) { return __v; } 157*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(__node_value_type const& __v) { return __v; } 158*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI static __container_value_type* __get_ptr(__node_value_type& __n) { return std::addressof(__n); } 159*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI static __container_value_type&& __move(__node_value_type& __v) { return std::move(__v); } 160*700637cbSDimitry Andric}; 161*700637cbSDimitry Andric 162*700637cbSDimitry Andrictemplate <class _Key, class _Tp> 163*700637cbSDimitry Andricstruct __hash_key_value_types<__hash_value_type<_Key, _Tp> > { 164*700637cbSDimitry Andric typedef _Key key_type; 165*700637cbSDimitry Andric typedef _Tp mapped_type; 166*700637cbSDimitry Andric typedef __hash_value_type<_Key, _Tp> __node_value_type; 167*700637cbSDimitry Andric typedef pair<const _Key, _Tp> __container_value_type; 168*700637cbSDimitry Andric typedef __container_value_type __map_value_type; 169*700637cbSDimitry Andric static const bool __is_map = true; 170*700637cbSDimitry Andric 171*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI static key_type const& __get_key(__container_value_type const& __v) { return __v.first; } 172*700637cbSDimitry Andric 173*700637cbSDimitry Andric template <class _Up, __enable_if_t<__is_same_uncvref<_Up, __node_value_type>::value, int> = 0> 174*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(_Up& __t) { 175*700637cbSDimitry Andric return __t.__get_value(); 176*700637cbSDimitry Andric } 177*700637cbSDimitry Andric 178*700637cbSDimitry Andric template <class _Up, __enable_if_t<__is_same_uncvref<_Up, __container_value_type>::value, int> = 0> 179*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(_Up& __t) { 180*700637cbSDimitry Andric return __t; 181*700637cbSDimitry Andric } 182*700637cbSDimitry Andric 183*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI static __container_value_type* __get_ptr(__node_value_type& __n) { 184*700637cbSDimitry Andric return std::addressof(__n.__get_value()); 185*700637cbSDimitry Andric } 186*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI static pair<key_type&&, mapped_type&&> __move(__node_value_type& __v) { return __v.__move(); } 187*700637cbSDimitry Andric}; 188*700637cbSDimitry Andric 189*700637cbSDimitry Andrictemplate <class _Tp, class _AllocPtr, class _KVTypes = __hash_key_value_types<_Tp>, bool = _KVTypes::__is_map> 190*700637cbSDimitry Andricstruct __hash_map_pointer_types {}; 191*700637cbSDimitry Andric 192*700637cbSDimitry Andrictemplate <class _Tp, class _AllocPtr, class _KVTypes> 193*700637cbSDimitry Andricstruct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { 194*700637cbSDimitry Andric typedef typename _KVTypes::__map_value_type _Mv; 195*700637cbSDimitry Andric typedef __rebind_pointer_t<_AllocPtr, _Mv> __map_value_type_pointer; 196*700637cbSDimitry Andric typedef __rebind_pointer_t<_AllocPtr, const _Mv> __const_map_value_type_pointer; 197*700637cbSDimitry Andric}; 198*700637cbSDimitry Andric 199*700637cbSDimitry Andrictemplate <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type> 200*700637cbSDimitry Andricstruct __hash_node_types; 201*700637cbSDimitry Andric 202*700637cbSDimitry Andrictemplate <class _NodePtr, class _Tp, class _VoidPtr> 203*700637cbSDimitry Andricstruct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> > 204*700637cbSDimitry Andric : public __hash_key_value_types<_Tp>, 205*700637cbSDimitry Andric __hash_map_pointer_types<_Tp, _VoidPtr> 206*700637cbSDimitry Andric 207*700637cbSDimitry Andric{ 208*700637cbSDimitry Andric typedef __hash_key_value_types<_Tp> __base; 209*700637cbSDimitry Andric 210*700637cbSDimitry Andricpublic: 211*700637cbSDimitry Andric typedef ptrdiff_t difference_type; 212*700637cbSDimitry Andric typedef size_t size_type; 213*700637cbSDimitry Andric 214*700637cbSDimitry Andric typedef __rebind_pointer_t<_NodePtr, void> __void_pointer; 215*700637cbSDimitry Andric 216*700637cbSDimitry Andric typedef typename pointer_traits<_NodePtr>::element_type __node_type; 217*700637cbSDimitry Andric typedef _NodePtr __node_pointer; 218*700637cbSDimitry Andric 219*700637cbSDimitry Andric typedef __hash_node_base<__node_pointer> __node_base_type; 220*700637cbSDimitry Andric typedef __rebind_pointer_t<_NodePtr, __node_base_type> __node_base_pointer; 221*700637cbSDimitry Andric 222*700637cbSDimitry Andric typedef typename __node_base_type::__next_pointer __next_pointer; 223*700637cbSDimitry Andric 224*700637cbSDimitry Andric typedef _Tp __node_value_type; 225*700637cbSDimitry Andric typedef __rebind_pointer_t<_VoidPtr, __node_value_type> __node_value_type_pointer; 226*700637cbSDimitry Andric typedef __rebind_pointer_t<_VoidPtr, const __node_value_type> __const_node_value_type_pointer; 227*700637cbSDimitry Andric 228*700637cbSDimitry Andricprivate: 229*700637cbSDimitry Andric static_assert(!is_const<__node_type>::value, "_NodePtr should never be a pointer to const"); 230*700637cbSDimitry Andric static_assert(is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value, 231*700637cbSDimitry Andric "_VoidPtr does not point to unqualified void type"); 232*700637cbSDimitry Andric static_assert(is_same<__rebind_pointer_t<_VoidPtr, __node_type>, _NodePtr>::value, 233*700637cbSDimitry Andric "_VoidPtr does not rebind to _NodePtr."); 234*700637cbSDimitry Andric}; 235*700637cbSDimitry Andric 236*700637cbSDimitry Andrictemplate <class _HashIterator> 237*700637cbSDimitry Andricstruct __hash_node_types_from_iterator; 238*700637cbSDimitry Andrictemplate <class _NodePtr> 239*700637cbSDimitry Andricstruct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; 240*700637cbSDimitry Andrictemplate <class _NodePtr> 241*700637cbSDimitry Andricstruct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; 242*700637cbSDimitry Andrictemplate <class _NodePtr> 243*700637cbSDimitry Andricstruct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; 244*700637cbSDimitry Andrictemplate <class _NodePtr> 245*700637cbSDimitry Andricstruct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; 246*700637cbSDimitry Andric 247*700637cbSDimitry Andrictemplate <class _NodeValueTp, class _VoidPtr> 248*700637cbSDimitry Andricstruct __make_hash_node_types { 249*700637cbSDimitry Andric typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp; 250*700637cbSDimitry Andric typedef __rebind_pointer_t<_VoidPtr, _NodeTp> _NodePtr; 251*700637cbSDimitry Andric typedef __hash_node_types<_NodePtr> type; 252*700637cbSDimitry Andric}; 253*700637cbSDimitry Andric 254*700637cbSDimitry Andrictemplate <class _NodePtr> 255*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __hash_iterator { 256*700637cbSDimitry Andric typedef __hash_node_types<_NodePtr> _NodeTypes; 257*700637cbSDimitry Andric typedef _NodePtr __node_pointer; 258*700637cbSDimitry Andric typedef typename _NodeTypes::__next_pointer __next_pointer; 259*700637cbSDimitry Andric 260*700637cbSDimitry Andric __next_pointer __node_; 261*700637cbSDimitry Andric 262*700637cbSDimitry Andricpublic: 263*700637cbSDimitry Andric typedef forward_iterator_tag iterator_category; 264*700637cbSDimitry Andric typedef typename _NodeTypes::__node_value_type value_type; 265*700637cbSDimitry Andric typedef typename _NodeTypes::difference_type difference_type; 266*700637cbSDimitry Andric typedef value_type& reference; 267*700637cbSDimitry Andric typedef typename _NodeTypes::__node_value_type_pointer pointer; 268*700637cbSDimitry Andric 269*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_iterator() _NOEXCEPT : __node_(nullptr) {} 270*700637cbSDimitry Andric 271*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI reference operator*() const { 272*700637cbSDimitry Andric _LIBCPP_ASSERT_NON_NULL( 273*700637cbSDimitry Andric __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container iterator"); 274*700637cbSDimitry Andric return __node_->__upcast()->__get_value(); 275*700637cbSDimitry Andric } 276*700637cbSDimitry Andric 277*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pointer operator->() const { 278*700637cbSDimitry Andric _LIBCPP_ASSERT_NON_NULL( 279*700637cbSDimitry Andric __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container iterator"); 280*700637cbSDimitry Andric return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__get_value()); 281*700637cbSDimitry Andric } 282*700637cbSDimitry Andric 283*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_iterator& operator++() { 284*700637cbSDimitry Andric _LIBCPP_ASSERT_NON_NULL( 285*700637cbSDimitry Andric __node_ != nullptr, "Attempted to increment a non-incrementable unordered container iterator"); 286*700637cbSDimitry Andric __node_ = __node_->__next_; 287*700637cbSDimitry Andric return *this; 288*700637cbSDimitry Andric } 289*700637cbSDimitry Andric 290*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_iterator operator++(int) { 291*700637cbSDimitry Andric __hash_iterator __t(*this); 292*700637cbSDimitry Andric ++(*this); 293*700637cbSDimitry Andric return __t; 294*700637cbSDimitry Andric } 295*700637cbSDimitry Andric 296*700637cbSDimitry Andric friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __hash_iterator& __x, const __hash_iterator& __y) { 297*700637cbSDimitry Andric return __x.__node_ == __y.__node_; 298*700637cbSDimitry Andric } 299*700637cbSDimitry Andric friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y) { 300*700637cbSDimitry Andric return !(__x == __y); 301*700637cbSDimitry Andric } 302*700637cbSDimitry Andric 303*700637cbSDimitry Andricprivate: 304*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit __hash_iterator(__next_pointer __node) _NOEXCEPT : __node_(__node) {} 305*700637cbSDimitry Andric 306*700637cbSDimitry Andric template <class, class, class, class> 307*700637cbSDimitry Andric friend class __hash_table; 308*700637cbSDimitry Andric template <class> 309*700637cbSDimitry Andric friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; 310*700637cbSDimitry Andric template <class> 311*700637cbSDimitry Andric friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; 312*700637cbSDimitry Andric template <class, class, class, class, class> 313*700637cbSDimitry Andric friend class _LIBCPP_TEMPLATE_VIS unordered_map; 314*700637cbSDimitry Andric template <class, class, class, class, class> 315*700637cbSDimitry Andric friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; 316*700637cbSDimitry Andric}; 317*700637cbSDimitry Andric 318*700637cbSDimitry Andrictemplate <class _NodePtr> 319*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __hash_const_iterator { 320*700637cbSDimitry Andric static_assert(!is_const<typename pointer_traits<_NodePtr>::element_type>::value, ""); 321*700637cbSDimitry Andric typedef __hash_node_types<_NodePtr> _NodeTypes; 322*700637cbSDimitry Andric typedef _NodePtr __node_pointer; 323*700637cbSDimitry Andric typedef typename _NodeTypes::__next_pointer __next_pointer; 324*700637cbSDimitry Andric 325*700637cbSDimitry Andric __next_pointer __node_; 326*700637cbSDimitry Andric 327*700637cbSDimitry Andricpublic: 328*700637cbSDimitry Andric typedef __hash_iterator<_NodePtr> __non_const_iterator; 329*700637cbSDimitry Andric 330*700637cbSDimitry Andric typedef forward_iterator_tag iterator_category; 331*700637cbSDimitry Andric typedef typename _NodeTypes::__node_value_type value_type; 332*700637cbSDimitry Andric typedef typename _NodeTypes::difference_type difference_type; 333*700637cbSDimitry Andric typedef const value_type& reference; 334*700637cbSDimitry Andric typedef typename _NodeTypes::__const_node_value_type_pointer pointer; 335*700637cbSDimitry Andric 336*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_const_iterator() _NOEXCEPT : __node_(nullptr) {} 337*700637cbSDimitry Andric 338*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT : __node_(__x.__node_) {} 339*700637cbSDimitry Andric 340*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI reference operator*() const { 341*700637cbSDimitry Andric _LIBCPP_ASSERT_NON_NULL( 342*700637cbSDimitry Andric __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container const_iterator"); 343*700637cbSDimitry Andric return __node_->__upcast()->__get_value(); 344*700637cbSDimitry Andric } 345*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pointer operator->() const { 346*700637cbSDimitry Andric _LIBCPP_ASSERT_NON_NULL( 347*700637cbSDimitry Andric __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container const_iterator"); 348*700637cbSDimitry Andric return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__get_value()); 349*700637cbSDimitry Andric } 350*700637cbSDimitry Andric 351*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_const_iterator& operator++() { 352*700637cbSDimitry Andric _LIBCPP_ASSERT_NON_NULL( 353*700637cbSDimitry Andric __node_ != nullptr, "Attempted to increment a non-incrementable unordered container const_iterator"); 354*700637cbSDimitry Andric __node_ = __node_->__next_; 355*700637cbSDimitry Andric return *this; 356*700637cbSDimitry Andric } 357*700637cbSDimitry Andric 358*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_const_iterator operator++(int) { 359*700637cbSDimitry Andric __hash_const_iterator __t(*this); 360*700637cbSDimitry Andric ++(*this); 361*700637cbSDimitry Andric return __t; 362*700637cbSDimitry Andric } 363*700637cbSDimitry Andric 364*700637cbSDimitry Andric friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y) { 365*700637cbSDimitry Andric return __x.__node_ == __y.__node_; 366*700637cbSDimitry Andric } 367*700637cbSDimitry Andric friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y) { 368*700637cbSDimitry Andric return !(__x == __y); 369*700637cbSDimitry Andric } 370*700637cbSDimitry Andric 371*700637cbSDimitry Andricprivate: 372*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit __hash_const_iterator(__next_pointer __node) _NOEXCEPT : __node_(__node) {} 373*700637cbSDimitry Andric 374*700637cbSDimitry Andric template <class, class, class, class> 375*700637cbSDimitry Andric friend class __hash_table; 376*700637cbSDimitry Andric template <class> 377*700637cbSDimitry Andric friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; 378*700637cbSDimitry Andric template <class, class, class, class, class> 379*700637cbSDimitry Andric friend class _LIBCPP_TEMPLATE_VIS unordered_map; 380*700637cbSDimitry Andric template <class, class, class, class, class> 381*700637cbSDimitry Andric friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; 382*700637cbSDimitry Andric}; 383*700637cbSDimitry Andric 384*700637cbSDimitry Andrictemplate <class _NodePtr> 385*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __hash_local_iterator { 386*700637cbSDimitry Andric typedef __hash_node_types<_NodePtr> _NodeTypes; 387*700637cbSDimitry Andric typedef _NodePtr __node_pointer; 388*700637cbSDimitry Andric typedef typename _NodeTypes::__next_pointer __next_pointer; 389*700637cbSDimitry Andric 390*700637cbSDimitry Andric __next_pointer __node_; 391*700637cbSDimitry Andric size_t __bucket_; 392*700637cbSDimitry Andric size_t __bucket_count_; 393*700637cbSDimitry Andric 394*700637cbSDimitry Andricpublic: 395*700637cbSDimitry Andric typedef forward_iterator_tag iterator_category; 396*700637cbSDimitry Andric typedef typename _NodeTypes::__node_value_type value_type; 397*700637cbSDimitry Andric typedef typename _NodeTypes::difference_type difference_type; 398*700637cbSDimitry Andric typedef value_type& reference; 399*700637cbSDimitry Andric typedef typename _NodeTypes::__node_value_type_pointer pointer; 400*700637cbSDimitry Andric 401*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_local_iterator() _NOEXCEPT : __node_(nullptr) {} 402*700637cbSDimitry Andric 403*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI reference operator*() const { 404*700637cbSDimitry Andric _LIBCPP_ASSERT_NON_NULL( 405*700637cbSDimitry Andric __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container local_iterator"); 406*700637cbSDimitry Andric return __node_->__upcast()->__get_value(); 407*700637cbSDimitry Andric } 408*700637cbSDimitry Andric 409*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pointer operator->() const { 410*700637cbSDimitry Andric _LIBCPP_ASSERT_NON_NULL( 411*700637cbSDimitry Andric __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container local_iterator"); 412*700637cbSDimitry Andric return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__get_value()); 413*700637cbSDimitry Andric } 414*700637cbSDimitry Andric 415*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_local_iterator& operator++() { 416*700637cbSDimitry Andric _LIBCPP_ASSERT_NON_NULL( 417*700637cbSDimitry Andric __node_ != nullptr, "Attempted to increment a non-incrementable unordered container local_iterator"); 418*700637cbSDimitry Andric __node_ = __node_->__next_; 419*700637cbSDimitry Andric if (__node_ != nullptr && std::__constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) 420*700637cbSDimitry Andric __node_ = nullptr; 421*700637cbSDimitry Andric return *this; 422*700637cbSDimitry Andric } 423*700637cbSDimitry Andric 424*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_local_iterator operator++(int) { 425*700637cbSDimitry Andric __hash_local_iterator __t(*this); 426*700637cbSDimitry Andric ++(*this); 427*700637cbSDimitry Andric return __t; 428*700637cbSDimitry Andric } 429*700637cbSDimitry Andric 430*700637cbSDimitry Andric friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y) { 431*700637cbSDimitry Andric return __x.__node_ == __y.__node_; 432*700637cbSDimitry Andric } 433*700637cbSDimitry Andric friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y) { 434*700637cbSDimitry Andric return !(__x == __y); 435*700637cbSDimitry Andric } 436*700637cbSDimitry Andric 437*700637cbSDimitry Andricprivate: 438*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit __hash_local_iterator( 439*700637cbSDimitry Andric __next_pointer __node, size_t __bucket, size_t __bucket_count) _NOEXCEPT 440*700637cbSDimitry Andric : __node_(__node), 441*700637cbSDimitry Andric __bucket_(__bucket), 442*700637cbSDimitry Andric __bucket_count_(__bucket_count) { 443*700637cbSDimitry Andric if (__node_ != nullptr) 444*700637cbSDimitry Andric __node_ = __node_->__next_; 445*700637cbSDimitry Andric } 446*700637cbSDimitry Andric 447*700637cbSDimitry Andric template <class, class, class, class> 448*700637cbSDimitry Andric friend class __hash_table; 449*700637cbSDimitry Andric template <class> 450*700637cbSDimitry Andric friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; 451*700637cbSDimitry Andric template <class> 452*700637cbSDimitry Andric friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; 453*700637cbSDimitry Andric}; 454*700637cbSDimitry Andric 455*700637cbSDimitry Andrictemplate <class _ConstNodePtr> 456*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator { 457*700637cbSDimitry Andric typedef __hash_node_types<_ConstNodePtr> _NodeTypes; 458*700637cbSDimitry Andric typedef _ConstNodePtr __node_pointer; 459*700637cbSDimitry Andric typedef typename _NodeTypes::__next_pointer __next_pointer; 460*700637cbSDimitry Andric 461*700637cbSDimitry Andric __next_pointer __node_; 462*700637cbSDimitry Andric size_t __bucket_; 463*700637cbSDimitry Andric size_t __bucket_count_; 464*700637cbSDimitry Andric 465*700637cbSDimitry Andric typedef pointer_traits<__node_pointer> __pointer_traits; 466*700637cbSDimitry Andric typedef typename __pointer_traits::element_type __node; 467*700637cbSDimitry Andric typedef __remove_const_t<__node> __non_const_node; 468*700637cbSDimitry Andric typedef __rebind_pointer_t<__node_pointer, __non_const_node> __non_const_node_pointer; 469*700637cbSDimitry Andric 470*700637cbSDimitry Andricpublic: 471*700637cbSDimitry Andric typedef __hash_local_iterator<__non_const_node_pointer> __non_const_iterator; 472*700637cbSDimitry Andric 473*700637cbSDimitry Andric typedef forward_iterator_tag iterator_category; 474*700637cbSDimitry Andric typedef typename _NodeTypes::__node_value_type value_type; 475*700637cbSDimitry Andric typedef typename _NodeTypes::difference_type difference_type; 476*700637cbSDimitry Andric typedef const value_type& reference; 477*700637cbSDimitry Andric typedef typename _NodeTypes::__const_node_value_type_pointer pointer; 478*700637cbSDimitry Andric 479*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) {} 480*700637cbSDimitry Andric 481*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT 482*700637cbSDimitry Andric : __node_(__x.__node_), 483*700637cbSDimitry Andric __bucket_(__x.__bucket_), 484*700637cbSDimitry Andric __bucket_count_(__x.__bucket_count_) {} 485*700637cbSDimitry Andric 486*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI reference operator*() const { 487*700637cbSDimitry Andric _LIBCPP_ASSERT_NON_NULL( 488*700637cbSDimitry Andric __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); 489*700637cbSDimitry Andric return __node_->__upcast()->__get_value(); 490*700637cbSDimitry Andric } 491*700637cbSDimitry Andric 492*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pointer operator->() const { 493*700637cbSDimitry Andric _LIBCPP_ASSERT_NON_NULL( 494*700637cbSDimitry Andric __node_ != nullptr, "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); 495*700637cbSDimitry Andric return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__get_value()); 496*700637cbSDimitry Andric } 497*700637cbSDimitry Andric 498*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_const_local_iterator& operator++() { 499*700637cbSDimitry Andric _LIBCPP_ASSERT_NON_NULL( 500*700637cbSDimitry Andric __node_ != nullptr, "Attempted to increment a non-incrementable unordered container const_local_iterator"); 501*700637cbSDimitry Andric __node_ = __node_->__next_; 502*700637cbSDimitry Andric if (__node_ != nullptr && std::__constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) 503*700637cbSDimitry Andric __node_ = nullptr; 504*700637cbSDimitry Andric return *this; 505*700637cbSDimitry Andric } 506*700637cbSDimitry Andric 507*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_const_local_iterator operator++(int) { 508*700637cbSDimitry Andric __hash_const_local_iterator __t(*this); 509*700637cbSDimitry Andric ++(*this); 510*700637cbSDimitry Andric return __t; 511*700637cbSDimitry Andric } 512*700637cbSDimitry Andric 513*700637cbSDimitry Andric friend _LIBCPP_HIDE_FROM_ABI bool 514*700637cbSDimitry Andric operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) { 515*700637cbSDimitry Andric return __x.__node_ == __y.__node_; 516*700637cbSDimitry Andric } 517*700637cbSDimitry Andric friend _LIBCPP_HIDE_FROM_ABI bool 518*700637cbSDimitry Andric operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) { 519*700637cbSDimitry Andric return !(__x == __y); 520*700637cbSDimitry Andric } 521*700637cbSDimitry Andric 522*700637cbSDimitry Andricprivate: 523*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit __hash_const_local_iterator( 524*700637cbSDimitry Andric __next_pointer __node_ptr, size_t __bucket, size_t __bucket_count) _NOEXCEPT 525*700637cbSDimitry Andric : __node_(__node_ptr), 526*700637cbSDimitry Andric __bucket_(__bucket), 527*700637cbSDimitry Andric __bucket_count_(__bucket_count) { 528*700637cbSDimitry Andric if (__node_ != nullptr) 529*700637cbSDimitry Andric __node_ = __node_->__next_; 530*700637cbSDimitry Andric } 531*700637cbSDimitry Andric 532*700637cbSDimitry Andric template <class, class, class, class> 533*700637cbSDimitry Andric friend class __hash_table; 534*700637cbSDimitry Andric template <class> 535*700637cbSDimitry Andric friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; 536*700637cbSDimitry Andric}; 537*700637cbSDimitry Andric 538*700637cbSDimitry Andrictemplate <class _Alloc> 539*700637cbSDimitry Andricclass __bucket_list_deallocator { 540*700637cbSDimitry Andric typedef _Alloc allocator_type; 541*700637cbSDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 542*700637cbSDimitry Andric typedef typename __alloc_traits::size_type size_type; 543*700637cbSDimitry Andric 544*700637cbSDimitry Andric __compressed_pair<size_type, allocator_type> __data_; 545*700637cbSDimitry Andric 546*700637cbSDimitry Andricpublic: 547*700637cbSDimitry Andric typedef typename __alloc_traits::pointer pointer; 548*700637cbSDimitry Andric 549*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator() : __data_(0, __default_init_tag()) {} 550*700637cbSDimitry Andric 551*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator(const allocator_type& __a, size_type __size) : __data_(__size, __a) {} 552*700637cbSDimitry Andric 553*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator(__bucket_list_deallocator&& __x) : __data_(std::move(__x.__data_)) { 554*700637cbSDimitry Andric __x.size() = 0; 555*700637cbSDimitry Andric } 556*700637cbSDimitry Andric 557*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __data_.first(); } 558*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __data_.first(); } 559*700637cbSDimitry Andric 560*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __data_.second(); } 561*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __data_.second(); } 562*700637cbSDimitry Andric 563*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT { __alloc_traits::deallocate(__alloc(), __p, size()); } 564*700637cbSDimitry Andric}; 565*700637cbSDimitry Andric 566*700637cbSDimitry Andrictemplate <class _Alloc> 567*700637cbSDimitry Andricclass __hash_map_node_destructor; 568*700637cbSDimitry Andric 569*700637cbSDimitry Andrictemplate <class _Alloc> 570*700637cbSDimitry Andricclass __hash_node_destructor { 571*700637cbSDimitry Andric typedef _Alloc allocator_type; 572*700637cbSDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 573*700637cbSDimitry Andric 574*700637cbSDimitry Andricpublic: 575*700637cbSDimitry Andric typedef typename __alloc_traits::pointer pointer; 576*700637cbSDimitry Andric 577*700637cbSDimitry Andricprivate: 578*700637cbSDimitry Andric typedef __hash_node_types<pointer> _NodeTypes; 579*700637cbSDimitry Andric 580*700637cbSDimitry Andric allocator_type& __na_; 581*700637cbSDimitry Andric 582*700637cbSDimitry Andricpublic: 583*700637cbSDimitry Andric bool __value_constructed; 584*700637cbSDimitry Andric 585*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_node_destructor(__hash_node_destructor const&) = default; 586*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_node_destructor& operator=(const __hash_node_destructor&) = delete; 587*700637cbSDimitry Andric 588*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit __hash_node_destructor(allocator_type& __na, bool __constructed = false) _NOEXCEPT 589*700637cbSDimitry Andric : __na_(__na), 590*700637cbSDimitry Andric __value_constructed(__constructed) {} 591*700637cbSDimitry Andric 592*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT { 593*700637cbSDimitry Andric if (__value_constructed) { 594*700637cbSDimitry Andric __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__get_value())); 595*700637cbSDimitry Andric std::__destroy_at(std::addressof(*__p)); 596*700637cbSDimitry Andric } 597*700637cbSDimitry Andric if (__p) 598*700637cbSDimitry Andric __alloc_traits::deallocate(__na_, __p, 1); 599*700637cbSDimitry Andric } 600*700637cbSDimitry Andric 601*700637cbSDimitry Andric template <class> 602*700637cbSDimitry Andric friend class __hash_map_node_destructor; 603*700637cbSDimitry Andric}; 604*700637cbSDimitry Andric 605*700637cbSDimitry Andrictemplate <class _Key, class _Hash, class _Equal> 606*700637cbSDimitry Andricstruct __enforce_unordered_container_requirements { 607*700637cbSDimitry Andric typedef int type; 608*700637cbSDimitry Andric}; 609*700637cbSDimitry Andric 610*700637cbSDimitry Andrictemplate <class _Key, class _Hash, class _Equal> 611*700637cbSDimitry Andrictypename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type 612*700637cbSDimitry Andric__diagnose_unordered_container_requirements(int); 613*700637cbSDimitry Andric 614*700637cbSDimitry Andric// This dummy overload is used so that the compiler won't emit a spurious 615*700637cbSDimitry Andric// "no matching function for call to __diagnose_unordered_xxx" diagnostic 616*700637cbSDimitry Andric// when the overload above causes a hard error. 617*700637cbSDimitry Andrictemplate <class _Key, class _Hash, class _Equal> 618*700637cbSDimitry Andricint __diagnose_unordered_container_requirements(void*); 619*700637cbSDimitry Andric 620*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 621*700637cbSDimitry Andricclass __hash_table { 622*700637cbSDimitry Andricpublic: 623*700637cbSDimitry Andric typedef _Tp value_type; 624*700637cbSDimitry Andric typedef _Hash hasher; 625*700637cbSDimitry Andric typedef _Equal key_equal; 626*700637cbSDimitry Andric typedef _Alloc allocator_type; 627*700637cbSDimitry Andric 628*700637cbSDimitry Andricprivate: 629*700637cbSDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 630*700637cbSDimitry Andric typedef typename __make_hash_node_types<value_type, typename __alloc_traits::void_pointer>::type _NodeTypes; 631*700637cbSDimitry Andric 632*700637cbSDimitry Andricpublic: 633*700637cbSDimitry Andric typedef typename _NodeTypes::__node_value_type __node_value_type; 634*700637cbSDimitry Andric typedef typename _NodeTypes::__container_value_type __container_value_type; 635*700637cbSDimitry Andric typedef typename _NodeTypes::key_type key_type; 636*700637cbSDimitry Andric typedef value_type& reference; 637*700637cbSDimitry Andric typedef const value_type& const_reference; 638*700637cbSDimitry Andric typedef typename __alloc_traits::pointer pointer; 639*700637cbSDimitry Andric typedef typename __alloc_traits::const_pointer const_pointer; 640*700637cbSDimitry Andric#ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE 641*700637cbSDimitry Andric typedef typename __alloc_traits::size_type size_type; 642*700637cbSDimitry Andric#else 643*700637cbSDimitry Andric typedef typename _NodeTypes::size_type size_type; 644*700637cbSDimitry Andric#endif 645*700637cbSDimitry Andric typedef typename _NodeTypes::difference_type difference_type; 646*700637cbSDimitry Andric 647*700637cbSDimitry Andricpublic: 648*700637cbSDimitry Andric // Create __node 649*700637cbSDimitry Andric 650*700637cbSDimitry Andric typedef typename _NodeTypes::__node_type __node; 651*700637cbSDimitry Andric typedef __rebind_alloc<__alloc_traits, __node> __node_allocator; 652*700637cbSDimitry Andric typedef allocator_traits<__node_allocator> __node_traits; 653*700637cbSDimitry Andric typedef typename _NodeTypes::__void_pointer __void_pointer; 654*700637cbSDimitry Andric typedef typename _NodeTypes::__node_pointer __node_pointer; 655*700637cbSDimitry Andric typedef typename _NodeTypes::__node_pointer __node_const_pointer; 656*700637cbSDimitry Andric typedef typename _NodeTypes::__node_base_type __first_node; 657*700637cbSDimitry Andric typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; 658*700637cbSDimitry Andric typedef typename _NodeTypes::__next_pointer __next_pointer; 659*700637cbSDimitry Andric 660*700637cbSDimitry Andricprivate: 661*700637cbSDimitry Andric // check for sane allocator pointer rebinding semantics. Rebinding the 662*700637cbSDimitry Andric // allocator for a new pointer type should be exactly the same as rebinding 663*700637cbSDimitry Andric // the pointer using 'pointer_traits'. 664*700637cbSDimitry Andric static_assert(is_same<__node_pointer, typename __node_traits::pointer>::value, 665*700637cbSDimitry Andric "Allocator does not rebind pointers in a sane manner."); 666*700637cbSDimitry Andric typedef __rebind_alloc<__node_traits, __first_node> __node_base_allocator; 667*700637cbSDimitry Andric typedef allocator_traits<__node_base_allocator> __node_base_traits; 668*700637cbSDimitry Andric static_assert(is_same<__node_base_pointer, typename __node_base_traits::pointer>::value, 669*700637cbSDimitry Andric "Allocator does not rebind pointers in a sane manner."); 670*700637cbSDimitry Andric 671*700637cbSDimitry Andricprivate: 672*700637cbSDimitry Andric typedef __rebind_alloc<__node_traits, __next_pointer> __pointer_allocator; 673*700637cbSDimitry Andric typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; 674*700637cbSDimitry Andric typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list; 675*700637cbSDimitry Andric typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; 676*700637cbSDimitry Andric typedef typename __bucket_list_deleter::pointer __node_pointer_pointer; 677*700637cbSDimitry Andric 678*700637cbSDimitry Andric // --- Member data begin --- 679*700637cbSDimitry Andric __bucket_list __bucket_list_; 680*700637cbSDimitry Andric __compressed_pair<__first_node, __node_allocator> __p1_; 681*700637cbSDimitry Andric __compressed_pair<size_type, hasher> __p2_; 682*700637cbSDimitry Andric __compressed_pair<float, key_equal> __p3_; 683*700637cbSDimitry Andric // --- Member data end --- 684*700637cbSDimitry Andric 685*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __p2_.first(); } 686*700637cbSDimitry Andric 687*700637cbSDimitry Andricpublic: 688*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __p2_.first(); } 689*700637cbSDimitry Andric 690*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI hasher& hash_function() _NOEXCEPT { return __p2_.second(); } 691*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI const hasher& hash_function() const _NOEXCEPT { return __p2_.second(); } 692*700637cbSDimitry Andric 693*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI float& max_load_factor() _NOEXCEPT { return __p3_.first(); } 694*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI float max_load_factor() const _NOEXCEPT { return __p3_.first(); } 695*700637cbSDimitry Andric 696*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI key_equal& key_eq() _NOEXCEPT { return __p3_.second(); } 697*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI const key_equal& key_eq() const _NOEXCEPT { return __p3_.second(); } 698*700637cbSDimitry Andric 699*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __p1_.second(); } 700*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __p1_.second(); } 701*700637cbSDimitry Andric 702*700637cbSDimitry Andricpublic: 703*700637cbSDimitry Andric typedef __hash_iterator<__node_pointer> iterator; 704*700637cbSDimitry Andric typedef __hash_const_iterator<__node_pointer> const_iterator; 705*700637cbSDimitry Andric typedef __hash_local_iterator<__node_pointer> local_iterator; 706*700637cbSDimitry Andric typedef __hash_const_local_iterator<__node_pointer> const_local_iterator; 707*700637cbSDimitry Andric 708*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_table(); 709*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_table(const hasher& __hf, const key_equal& __eql); 710*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_table(const hasher& __hf, const key_equal& __eql, const allocator_type& __a); 711*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit __hash_table(const allocator_type& __a); 712*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_table(const __hash_table& __u); 713*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_table(const __hash_table& __u, const allocator_type& __a); 714*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_table(__hash_table&& __u); 715*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_table(__hash_table&& __u, const allocator_type& __a); 716*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI ~__hash_table(); 717*700637cbSDimitry Andric 718*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_table& operator=(const __hash_table& __u); 719*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __hash_table& operator=(__hash_table&& __u); 720*700637cbSDimitry Andric template <class _InputIterator> 721*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __assign_unique(_InputIterator __first, _InputIterator __last); 722*700637cbSDimitry Andric template <class _InputIterator> 723*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __assign_multi(_InputIterator __first, _InputIterator __last); 724*700637cbSDimitry Andric 725*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { 726*700637cbSDimitry Andric return std::min<size_type>(__node_traits::max_size(__node_alloc()), numeric_limits<difference_type >::max()); 727*700637cbSDimitry Andric } 728*700637cbSDimitry Andric 729*700637cbSDimitry Andricprivate: 730*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __next_pointer __node_insert_multi_prepare(size_t __cp_hash, value_type& __cp_val); 731*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __node_insert_multi_perform(__node_pointer __cp, __next_pointer __pn) _NOEXCEPT; 732*700637cbSDimitry Andric 733*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __next_pointer __node_insert_unique_prepare(size_t __nd_hash, value_type& __nd_val); 734*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __node_insert_unique_perform(__node_pointer __ptr) _NOEXCEPT; 735*700637cbSDimitry Andric 736*700637cbSDimitry Andricpublic: 737*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __node_insert_unique(__node_pointer __nd); 738*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI iterator __node_insert_multi(__node_pointer __nd); 739*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI iterator __node_insert_multi(const_iterator __p, __node_pointer __nd); 740*700637cbSDimitry Andric 741*700637cbSDimitry Andric template <class _Key, class... _Args> 742*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_unique_key_args(_Key const& __k, _Args&&... __args); 743*700637cbSDimitry Andric 744*700637cbSDimitry Andric template <class... _Args> 745*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_unique_impl(_Args&&... __args); 746*700637cbSDimitry Andric 747*700637cbSDimitry Andric template <class _Pp> 748*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_unique(_Pp&& __x) { 749*700637cbSDimitry Andric return __emplace_unique_extract_key(std::forward<_Pp>(__x), __can_extract_key<_Pp, key_type>()); 750*700637cbSDimitry Andric } 751*700637cbSDimitry Andric 752*700637cbSDimitry Andric template <class _First, 753*700637cbSDimitry Andric class _Second, 754*700637cbSDimitry Andric __enable_if_t<__can_extract_map_key<_First, key_type, __container_value_type>::value, int> = 0> 755*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_unique(_First&& __f, _Second&& __s) { 756*700637cbSDimitry Andric return __emplace_unique_key_args(__f, std::forward<_First>(__f), std::forward<_Second>(__s)); 757*700637cbSDimitry Andric } 758*700637cbSDimitry Andric 759*700637cbSDimitry Andric template <class... _Args> 760*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_unique(_Args&&... __args) { 761*700637cbSDimitry Andric return __emplace_unique_impl(std::forward<_Args>(__args)...); 762*700637cbSDimitry Andric } 763*700637cbSDimitry Andric 764*700637cbSDimitry Andric template <class _Pp> 765*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) { 766*700637cbSDimitry Andric return __emplace_unique_impl(std::forward<_Pp>(__x)); 767*700637cbSDimitry Andric } 768*700637cbSDimitry Andric template <class _Pp> 769*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) { 770*700637cbSDimitry Andric return __emplace_unique_key_args(__x, std::forward<_Pp>(__x)); 771*700637cbSDimitry Andric } 772*700637cbSDimitry Andric template <class _Pp> 773*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) { 774*700637cbSDimitry Andric return __emplace_unique_key_args(__x.first, std::forward<_Pp>(__x)); 775*700637cbSDimitry Andric } 776*700637cbSDimitry Andric 777*700637cbSDimitry Andric template <class... _Args> 778*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI iterator __emplace_multi(_Args&&... __args); 779*700637cbSDimitry Andric template <class... _Args> 780*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); 781*700637cbSDimitry Andric 782*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(__container_value_type&& __x) { 783*700637cbSDimitry Andric return __emplace_unique_key_args(_NodeTypes::__get_key(__x), std::move(__x)); 784*700637cbSDimitry Andric } 785*700637cbSDimitry Andric 786*700637cbSDimitry Andric template <class _Pp, __enable_if_t<!__is_same_uncvref<_Pp, __container_value_type>::value, int> = 0> 787*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(_Pp&& __x) { 788*700637cbSDimitry Andric return __emplace_unique(std::forward<_Pp>(__x)); 789*700637cbSDimitry Andric } 790*700637cbSDimitry Andric 791*700637cbSDimitry Andric template <class _Pp> 792*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI iterator __insert_multi(_Pp&& __x) { 793*700637cbSDimitry Andric return __emplace_multi(std::forward<_Pp>(__x)); 794*700637cbSDimitry Andric } 795*700637cbSDimitry Andric 796*700637cbSDimitry Andric template <class _Pp> 797*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI iterator __insert_multi(const_iterator __p, _Pp&& __x) { 798*700637cbSDimitry Andric return __emplace_hint_multi(__p, std::forward<_Pp>(__x)); 799*700637cbSDimitry Andric } 800*700637cbSDimitry Andric 801*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(const __container_value_type& __x) { 802*700637cbSDimitry Andric return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x); 803*700637cbSDimitry Andric } 804*700637cbSDimitry Andric 805*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT; 806*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __rehash_unique(size_type __n) { __rehash<true>(__n); } 807*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __rehash_multi(size_type __n) { __rehash<false>(__n); } 808*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __reserve_unique(size_type __n) { 809*700637cbSDimitry Andric __rehash_unique(static_cast<size_type>(std::ceil(__n / max_load_factor()))); 810*700637cbSDimitry Andric } 811*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __reserve_multi(size_type __n) { 812*700637cbSDimitry Andric __rehash_multi(static_cast<size_type>(std::ceil(__n / max_load_factor()))); 813*700637cbSDimitry Andric } 814*700637cbSDimitry Andric 815*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type bucket_count() const _NOEXCEPT { return __bucket_list_.get_deleter().size(); } 816*700637cbSDimitry Andric 817*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT; 818*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT; 819*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT; 820*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT; 821*700637cbSDimitry Andric 822*700637cbSDimitry Andric template <class _Key> 823*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type bucket(const _Key& __k) const { 824*700637cbSDimitry Andric _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( 825*700637cbSDimitry Andric bucket_count() > 0, "unordered container::bucket(key) called when bucket_count() == 0"); 826*700637cbSDimitry Andric return std::__constrain_hash(hash_function()(__k), bucket_count()); 827*700637cbSDimitry Andric } 828*700637cbSDimitry Andric 829*700637cbSDimitry Andric template <class _Key> 830*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI iterator find(const _Key& __x); 831*700637cbSDimitry Andric template <class _Key> 832*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI const_iterator find(const _Key& __x) const; 833*700637cbSDimitry Andric 834*700637cbSDimitry Andric typedef __hash_node_destructor<__node_allocator> _Dp; 835*700637cbSDimitry Andric typedef unique_ptr<__node, _Dp> __node_holder; 836*700637cbSDimitry Andric 837*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p); 838*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last); 839*700637cbSDimitry Andric template <class _Key> 840*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type __erase_unique(const _Key& __k); 841*700637cbSDimitry Andric template <class _Key> 842*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type __erase_multi(const _Key& __k); 843*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __node_holder remove(const_iterator __p) _NOEXCEPT; 844*700637cbSDimitry Andric 845*700637cbSDimitry Andric template <class _Key> 846*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type __count_unique(const _Key& __k) const; 847*700637cbSDimitry Andric template <class _Key> 848*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type __count_multi(const _Key& __k) const; 849*700637cbSDimitry Andric 850*700637cbSDimitry Andric template <class _Key> 851*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> __equal_range_unique(const _Key& __k); 852*700637cbSDimitry Andric template <class _Key> 853*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> __equal_range_unique(const _Key& __k) const; 854*700637cbSDimitry Andric 855*700637cbSDimitry Andric template <class _Key> 856*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> __equal_range_multi(const _Key& __k); 857*700637cbSDimitry Andric template <class _Key> 858*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> __equal_range_multi(const _Key& __k) const; 859*700637cbSDimitry Andric 860*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void swap(__hash_table& __u); 861*700637cbSDimitry Andric 862*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type max_bucket_count() const _NOEXCEPT { return max_size(); } 863*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_type bucket_size(size_type __n) const; 864*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI float load_factor() const _NOEXCEPT { 865*700637cbSDimitry Andric size_type __bc = bucket_count(); 866*700637cbSDimitry Andric return __bc != 0 ? (float)size() / __bc : 0.f; 867*700637cbSDimitry Andric } 868*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void max_load_factor(float __mlf) _NOEXCEPT { 869*700637cbSDimitry Andric // While passing a non-positive load factor is undefined behavior, in practice the result will be benign (the 870*700637cbSDimitry Andric // call will be equivalent to `max_load_factor(load_factor())`, which is also the case for passing a valid value 871*700637cbSDimitry Andric // less than the current `load_factor`). 872*700637cbSDimitry Andric _LIBCPP_ASSERT_PEDANTIC(__mlf > 0, "unordered container::max_load_factor(lf) called with lf <= 0"); 873*700637cbSDimitry Andric max_load_factor() = std::max(__mlf, load_factor()); 874*700637cbSDimitry Andric } 875*700637cbSDimitry Andric 876*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI local_iterator begin(size_type __n) { 877*700637cbSDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( 878*700637cbSDimitry Andric __n < bucket_count(), "unordered container::begin(n) called with n >= bucket_count()"); 879*700637cbSDimitry Andric return local_iterator(__bucket_list_[__n], __n, bucket_count()); 880*700637cbSDimitry Andric } 881*700637cbSDimitry Andric 882*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI local_iterator end(size_type __n) { 883*700637cbSDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( 884*700637cbSDimitry Andric __n < bucket_count(), "unordered container::end(n) called with n >= bucket_count()"); 885*700637cbSDimitry Andric return local_iterator(nullptr, __n, bucket_count()); 886*700637cbSDimitry Andric } 887*700637cbSDimitry Andric 888*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI const_local_iterator cbegin(size_type __n) const { 889*700637cbSDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( 890*700637cbSDimitry Andric __n < bucket_count(), "unordered container::cbegin(n) called with n >= bucket_count()"); 891*700637cbSDimitry Andric return const_local_iterator(__bucket_list_[__n], __n, bucket_count()); 892*700637cbSDimitry Andric } 893*700637cbSDimitry Andric 894*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI const_local_iterator cend(size_type __n) const { 895*700637cbSDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( 896*700637cbSDimitry Andric __n < bucket_count(), "unordered container::cend(n) called with n >= bucket_count()"); 897*700637cbSDimitry Andric return const_local_iterator(nullptr, __n, bucket_count()); 898*700637cbSDimitry Andric } 899*700637cbSDimitry Andric 900*700637cbSDimitry Andricprivate: 901*700637cbSDimitry Andric template <bool _UniqueKeys> 902*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __rehash(size_type __n); 903*700637cbSDimitry Andric template <bool _UniqueKeys> 904*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __do_rehash(size_type __n); 905*700637cbSDimitry Andric 906*700637cbSDimitry Andric template <class... _Args> 907*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node(_Args&&... __args); 908*700637cbSDimitry Andric 909*700637cbSDimitry Andric template <class _First, class... _Rest> 910*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest); 911*700637cbSDimitry Andric 912*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __hash_table& __u) { 913*700637cbSDimitry Andric __copy_assign_alloc(__u, integral_constant<bool, __node_traits::propagate_on_container_copy_assignment::value>()); 914*700637cbSDimitry Andric } 915*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __hash_table& __u, true_type); 916*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __hash_table&, false_type) {} 917*700637cbSDimitry Andric 918*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __move_assign(__hash_table& __u, false_type); 919*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __move_assign(__hash_table& __u, true_type); 920*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__hash_table& __u) { 921*700637cbSDimitry Andric __move_assign_alloc(__u, integral_constant<bool, __node_traits::propagate_on_container_move_assignment::value>()); 922*700637cbSDimitry Andric } 923*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__hash_table& __u, true_type) { 924*700637cbSDimitry Andric __bucket_list_.get_deleter().__alloc() = std::move(__u.__bucket_list_.get_deleter().__alloc()); 925*700637cbSDimitry Andric __node_alloc() = std::move(__u.__node_alloc()); 926*700637cbSDimitry Andric } 927*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {} 928*700637cbSDimitry Andric 929*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __deallocate_node(__next_pointer __np) _NOEXCEPT; 930*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI __next_pointer __detach() _NOEXCEPT; 931*700637cbSDimitry Andric 932*700637cbSDimitry Andric template <class, class, class, class, class> 933*700637cbSDimitry Andric friend class _LIBCPP_TEMPLATE_VIS unordered_map; 934*700637cbSDimitry Andric template <class, class, class, class, class> 935*700637cbSDimitry Andric friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; 936*700637cbSDimitry Andric}; 937*700637cbSDimitry Andric 938*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 939*700637cbSDimitry Andricinline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() 940*700637cbSDimitry Andric : __p2_(0, __default_init_tag()), __p3_(1.0f, __default_init_tag()) {} 941*700637cbSDimitry Andric 942*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 943*700637cbSDimitry Andricinline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, const key_equal& __eql) 944*700637cbSDimitry Andric : __bucket_list_(nullptr, __bucket_list_deleter()), __p1_(), __p2_(0, __hf), __p3_(1.0f, __eql) {} 945*700637cbSDimitry Andric 946*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 947*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table( 948*700637cbSDimitry Andric const hasher& __hf, const key_equal& __eql, const allocator_type& __a) 949*700637cbSDimitry Andric : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), 950*700637cbSDimitry Andric __p1_(__default_init_tag(), __node_allocator(__a)), 951*700637cbSDimitry Andric __p2_(0, __hf), 952*700637cbSDimitry Andric __p3_(1.0f, __eql) {} 953*700637cbSDimitry Andric 954*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 955*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a) 956*700637cbSDimitry Andric : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), 957*700637cbSDimitry Andric __p1_(__default_init_tag(), __node_allocator(__a)), 958*700637cbSDimitry Andric __p2_(0, __default_init_tag()), 959*700637cbSDimitry Andric __p3_(1.0f, __default_init_tag()) {} 960*700637cbSDimitry Andric 961*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 962*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) 963*700637cbSDimitry Andric : __bucket_list_(nullptr, 964*700637cbSDimitry Andric __bucket_list_deleter(allocator_traits<__pointer_allocator>::select_on_container_copy_construction( 965*700637cbSDimitry Andric __u.__bucket_list_.get_deleter().__alloc()), 966*700637cbSDimitry Andric 0)), 967*700637cbSDimitry Andric __p1_(__default_init_tag(), 968*700637cbSDimitry Andric allocator_traits<__node_allocator>::select_on_container_copy_construction(__u.__node_alloc())), 969*700637cbSDimitry Andric __p2_(0, __u.hash_function()), 970*700637cbSDimitry Andric __p3_(__u.__p3_) {} 971*700637cbSDimitry Andric 972*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 973*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, const allocator_type& __a) 974*700637cbSDimitry Andric : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), 975*700637cbSDimitry Andric __p1_(__default_init_tag(), __node_allocator(__a)), 976*700637cbSDimitry Andric __p2_(0, __u.hash_function()), 977*700637cbSDimitry Andric __p3_(__u.__p3_) {} 978*700637cbSDimitry Andric 979*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 980*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) 981*700637cbSDimitry Andric : __bucket_list_(std::move(__u.__bucket_list_)), 982*700637cbSDimitry Andric __p1_(std::move(__u.__p1_)), 983*700637cbSDimitry Andric __p2_(std::move(__u.__p2_)), 984*700637cbSDimitry Andric __p3_(std::move(__u.__p3_)) { 985*700637cbSDimitry Andric if (size() > 0) { 986*700637cbSDimitry Andric __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); 987*700637cbSDimitry Andric __u.__p1_.first().__next_ = nullptr; 988*700637cbSDimitry Andric __u.size() = 0; 989*700637cbSDimitry Andric } 990*700637cbSDimitry Andric} 991*700637cbSDimitry Andric 992*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 993*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, const allocator_type& __a) 994*700637cbSDimitry Andric : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), 995*700637cbSDimitry Andric __p1_(__default_init_tag(), __node_allocator(__a)), 996*700637cbSDimitry Andric __p2_(0, std::move(__u.hash_function())), 997*700637cbSDimitry Andric __p3_(std::move(__u.__p3_)) { 998*700637cbSDimitry Andric if (__a == allocator_type(__u.__node_alloc())) { 999*700637cbSDimitry Andric __bucket_list_.reset(__u.__bucket_list_.release()); 1000*700637cbSDimitry Andric __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); 1001*700637cbSDimitry Andric __u.__bucket_list_.get_deleter().size() = 0; 1002*700637cbSDimitry Andric if (__u.size() > 0) { 1003*700637cbSDimitry Andric __p1_.first().__next_ = __u.__p1_.first().__next_; 1004*700637cbSDimitry Andric __u.__p1_.first().__next_ = nullptr; 1005*700637cbSDimitry Andric __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); 1006*700637cbSDimitry Andric size() = __u.size(); 1007*700637cbSDimitry Andric __u.size() = 0; 1008*700637cbSDimitry Andric } 1009*700637cbSDimitry Andric } 1010*700637cbSDimitry Andric} 1011*700637cbSDimitry Andric 1012*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1013*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() { 1014*700637cbSDimitry Andric static_assert(is_copy_constructible<key_equal>::value, "Predicate must be copy-constructible."); 1015*700637cbSDimitry Andric static_assert(is_copy_constructible<hasher>::value, "Hasher must be copy-constructible."); 1016*700637cbSDimitry Andric 1017*700637cbSDimitry Andric __deallocate_node(__p1_.first().__next_); 1018*700637cbSDimitry Andric} 1019*700637cbSDimitry Andric 1020*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1021*700637cbSDimitry Andricvoid __hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc(const __hash_table& __u, true_type) { 1022*700637cbSDimitry Andric if (__node_alloc() != __u.__node_alloc()) { 1023*700637cbSDimitry Andric clear(); 1024*700637cbSDimitry Andric __bucket_list_.reset(); 1025*700637cbSDimitry Andric __bucket_list_.get_deleter().size() = 0; 1026*700637cbSDimitry Andric } 1027*700637cbSDimitry Andric __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc(); 1028*700637cbSDimitry Andric __node_alloc() = __u.__node_alloc(); 1029*700637cbSDimitry Andric} 1030*700637cbSDimitry Andric 1031*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1032*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>& __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u) { 1033*700637cbSDimitry Andric if (this != std::addressof(__u)) { 1034*700637cbSDimitry Andric __copy_assign_alloc(__u); 1035*700637cbSDimitry Andric hash_function() = __u.hash_function(); 1036*700637cbSDimitry Andric key_eq() = __u.key_eq(); 1037*700637cbSDimitry Andric max_load_factor() = __u.max_load_factor(); 1038*700637cbSDimitry Andric __assign_multi(__u.begin(), __u.end()); 1039*700637cbSDimitry Andric } 1040*700637cbSDimitry Andric return *this; 1041*700637cbSDimitry Andric} 1042*700637cbSDimitry Andric 1043*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1044*700637cbSDimitry Andricvoid __hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np) _NOEXCEPT { 1045*700637cbSDimitry Andric __node_allocator& __na = __node_alloc(); 1046*700637cbSDimitry Andric while (__np != nullptr) { 1047*700637cbSDimitry Andric __next_pointer __next = __np->__next_; 1048*700637cbSDimitry Andric __node_pointer __real_np = __np->__upcast(); 1049*700637cbSDimitry Andric __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__get_value())); 1050*700637cbSDimitry Andric std::__destroy_at(std::addressof(*__real_np)); 1051*700637cbSDimitry Andric __node_traits::deallocate(__na, __real_np, 1); 1052*700637cbSDimitry Andric __np = __next; 1053*700637cbSDimitry Andric } 1054*700637cbSDimitry Andric} 1055*700637cbSDimitry Andric 1056*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1057*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer 1058*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT { 1059*700637cbSDimitry Andric size_type __bc = bucket_count(); 1060*700637cbSDimitry Andric for (size_type __i = 0; __i < __bc; ++__i) 1061*700637cbSDimitry Andric __bucket_list_[__i] = nullptr; 1062*700637cbSDimitry Andric size() = 0; 1063*700637cbSDimitry Andric __next_pointer __cache = __p1_.first().__next_; 1064*700637cbSDimitry Andric __p1_.first().__next_ = nullptr; 1065*700637cbSDimitry Andric return __cache; 1066*700637cbSDimitry Andric} 1067*700637cbSDimitry Andric 1068*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1069*700637cbSDimitry Andricvoid __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u, true_type) { 1070*700637cbSDimitry Andric clear(); 1071*700637cbSDimitry Andric __bucket_list_.reset(__u.__bucket_list_.release()); 1072*700637cbSDimitry Andric __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); 1073*700637cbSDimitry Andric __u.__bucket_list_.get_deleter().size() = 0; 1074*700637cbSDimitry Andric __move_assign_alloc(__u); 1075*700637cbSDimitry Andric size() = __u.size(); 1076*700637cbSDimitry Andric hash_function() = std::move(__u.hash_function()); 1077*700637cbSDimitry Andric max_load_factor() = __u.max_load_factor(); 1078*700637cbSDimitry Andric key_eq() = std::move(__u.key_eq()); 1079*700637cbSDimitry Andric __p1_.first().__next_ = __u.__p1_.first().__next_; 1080*700637cbSDimitry Andric if (size() > 0) { 1081*700637cbSDimitry Andric __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); 1082*700637cbSDimitry Andric __u.__p1_.first().__next_ = nullptr; 1083*700637cbSDimitry Andric __u.size() = 0; 1084*700637cbSDimitry Andric } 1085*700637cbSDimitry Andric} 1086*700637cbSDimitry Andric 1087*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1088*700637cbSDimitry Andricvoid __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u, false_type) { 1089*700637cbSDimitry Andric if (__node_alloc() == __u.__node_alloc()) 1090*700637cbSDimitry Andric __move_assign(__u, true_type()); 1091*700637cbSDimitry Andric else { 1092*700637cbSDimitry Andric hash_function() = std::move(__u.hash_function()); 1093*700637cbSDimitry Andric key_eq() = std::move(__u.key_eq()); 1094*700637cbSDimitry Andric max_load_factor() = __u.max_load_factor(); 1095*700637cbSDimitry Andric if (bucket_count() != 0) { 1096*700637cbSDimitry Andric __next_pointer __cache = __detach(); 1097*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1098*700637cbSDimitry Andric try { 1099*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1100*700637cbSDimitry Andric const_iterator __i = __u.begin(); 1101*700637cbSDimitry Andric while (__cache != nullptr && __u.size() != 0) { 1102*700637cbSDimitry Andric __cache->__upcast()->__get_value() = std::move(__u.remove(__i++)->__get_value()); 1103*700637cbSDimitry Andric __next_pointer __next = __cache->__next_; 1104*700637cbSDimitry Andric __node_insert_multi(__cache->__upcast()); 1105*700637cbSDimitry Andric __cache = __next; 1106*700637cbSDimitry Andric } 1107*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1108*700637cbSDimitry Andric } catch (...) { 1109*700637cbSDimitry Andric __deallocate_node(__cache); 1110*700637cbSDimitry Andric throw; 1111*700637cbSDimitry Andric } 1112*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1113*700637cbSDimitry Andric __deallocate_node(__cache); 1114*700637cbSDimitry Andric } 1115*700637cbSDimitry Andric const_iterator __i = __u.begin(); 1116*700637cbSDimitry Andric while (__u.size() != 0) { 1117*700637cbSDimitry Andric __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__get_value())); 1118*700637cbSDimitry Andric __node_insert_multi(__h.get()); 1119*700637cbSDimitry Andric __h.release(); 1120*700637cbSDimitry Andric } 1121*700637cbSDimitry Andric } 1122*700637cbSDimitry Andric} 1123*700637cbSDimitry Andric 1124*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1125*700637cbSDimitry Andricinline __hash_table<_Tp, _Hash, _Equal, _Alloc>& 1126*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u) { 1127*700637cbSDimitry Andric __move_assign(__u, integral_constant<bool, __node_traits::propagate_on_container_move_assignment::value>()); 1128*700637cbSDimitry Andric return *this; 1129*700637cbSDimitry Andric} 1130*700637cbSDimitry Andric 1131*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1132*700637cbSDimitry Andrictemplate <class _InputIterator> 1133*700637cbSDimitry Andricvoid __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first, _InputIterator __last) { 1134*700637cbSDimitry Andric typedef iterator_traits<_InputIterator> _ITraits; 1135*700637cbSDimitry Andric typedef typename _ITraits::value_type _ItValueType; 1136*700637cbSDimitry Andric static_assert(is_same<_ItValueType, __container_value_type>::value, 1137*700637cbSDimitry Andric "__assign_unique may only be called with the containers value type"); 1138*700637cbSDimitry Andric 1139*700637cbSDimitry Andric if (bucket_count() != 0) { 1140*700637cbSDimitry Andric __next_pointer __cache = __detach(); 1141*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1142*700637cbSDimitry Andric try { 1143*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1144*700637cbSDimitry Andric for (; __cache != nullptr && __first != __last; ++__first) { 1145*700637cbSDimitry Andric __cache->__upcast()->__get_value() = *__first; 1146*700637cbSDimitry Andric __next_pointer __next = __cache->__next_; 1147*700637cbSDimitry Andric __node_insert_unique(__cache->__upcast()); 1148*700637cbSDimitry Andric __cache = __next; 1149*700637cbSDimitry Andric } 1150*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1151*700637cbSDimitry Andric } catch (...) { 1152*700637cbSDimitry Andric __deallocate_node(__cache); 1153*700637cbSDimitry Andric throw; 1154*700637cbSDimitry Andric } 1155*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1156*700637cbSDimitry Andric __deallocate_node(__cache); 1157*700637cbSDimitry Andric } 1158*700637cbSDimitry Andric for (; __first != __last; ++__first) 1159*700637cbSDimitry Andric __insert_unique(*__first); 1160*700637cbSDimitry Andric} 1161*700637cbSDimitry Andric 1162*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1163*700637cbSDimitry Andrictemplate <class _InputIterator> 1164*700637cbSDimitry Andricvoid __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first, _InputIterator __last) { 1165*700637cbSDimitry Andric typedef iterator_traits<_InputIterator> _ITraits; 1166*700637cbSDimitry Andric typedef typename _ITraits::value_type _ItValueType; 1167*700637cbSDimitry Andric static_assert( 1168*700637cbSDimitry Andric (is_same<_ItValueType, __container_value_type>::value || is_same<_ItValueType, __node_value_type>::value), 1169*700637cbSDimitry Andric "__assign_multi may only be called with the containers value type" 1170*700637cbSDimitry Andric " or the nodes value type"); 1171*700637cbSDimitry Andric if (bucket_count() != 0) { 1172*700637cbSDimitry Andric __next_pointer __cache = __detach(); 1173*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1174*700637cbSDimitry Andric try { 1175*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1176*700637cbSDimitry Andric for (; __cache != nullptr && __first != __last; ++__first) { 1177*700637cbSDimitry Andric __cache->__upcast()->__get_value() = *__first; 1178*700637cbSDimitry Andric __next_pointer __next = __cache->__next_; 1179*700637cbSDimitry Andric __node_insert_multi(__cache->__upcast()); 1180*700637cbSDimitry Andric __cache = __next; 1181*700637cbSDimitry Andric } 1182*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1183*700637cbSDimitry Andric } catch (...) { 1184*700637cbSDimitry Andric __deallocate_node(__cache); 1185*700637cbSDimitry Andric throw; 1186*700637cbSDimitry Andric } 1187*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1188*700637cbSDimitry Andric __deallocate_node(__cache); 1189*700637cbSDimitry Andric } 1190*700637cbSDimitry Andric for (; __first != __last; ++__first) 1191*700637cbSDimitry Andric __insert_multi(_NodeTypes::__get_value(*__first)); 1192*700637cbSDimitry Andric} 1193*700637cbSDimitry Andric 1194*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1195*700637cbSDimitry Andricinline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator 1196*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT { 1197*700637cbSDimitry Andric return iterator(__p1_.first().__next_); 1198*700637cbSDimitry Andric} 1199*700637cbSDimitry Andric 1200*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1201*700637cbSDimitry Andricinline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator 1202*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT { 1203*700637cbSDimitry Andric return iterator(nullptr); 1204*700637cbSDimitry Andric} 1205*700637cbSDimitry Andric 1206*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1207*700637cbSDimitry Andricinline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator 1208*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT { 1209*700637cbSDimitry Andric return const_iterator(__p1_.first().__next_); 1210*700637cbSDimitry Andric} 1211*700637cbSDimitry Andric 1212*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1213*700637cbSDimitry Andricinline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator 1214*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT { 1215*700637cbSDimitry Andric return const_iterator(nullptr); 1216*700637cbSDimitry Andric} 1217*700637cbSDimitry Andric 1218*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1219*700637cbSDimitry Andricvoid __hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT { 1220*700637cbSDimitry Andric if (size() > 0) { 1221*700637cbSDimitry Andric __deallocate_node(__p1_.first().__next_); 1222*700637cbSDimitry Andric __p1_.first().__next_ = nullptr; 1223*700637cbSDimitry Andric size_type __bc = bucket_count(); 1224*700637cbSDimitry Andric for (size_type __i = 0; __i < __bc; ++__i) 1225*700637cbSDimitry Andric __bucket_list_[__i] = nullptr; 1226*700637cbSDimitry Andric size() = 0; 1227*700637cbSDimitry Andric } 1228*700637cbSDimitry Andric} 1229*700637cbSDimitry Andric 1230*700637cbSDimitry Andric// Prepare the container for an insertion of the value __value with the hash 1231*700637cbSDimitry Andric// __hash. This does a lookup into the container to see if __value is already 1232*700637cbSDimitry Andric// present, and performs a rehash if necessary. Returns a pointer to the 1233*700637cbSDimitry Andric// existing element if it exists, otherwise nullptr. 1234*700637cbSDimitry Andric// 1235*700637cbSDimitry Andric// Note that this function does forward exceptions if key_eq() throws, and never 1236*700637cbSDimitry Andric// mutates __value or actually inserts into the map. 1237*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1238*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer 1239*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare(size_t __hash, value_type& __value) { 1240*700637cbSDimitry Andric size_type __bc = bucket_count(); 1241*700637cbSDimitry Andric 1242*700637cbSDimitry Andric if (__bc != 0) { 1243*700637cbSDimitry Andric size_t __chash = std::__constrain_hash(__hash, __bc); 1244*700637cbSDimitry Andric __next_pointer __ndptr = __bucket_list_[__chash]; 1245*700637cbSDimitry Andric if (__ndptr != nullptr) { 1246*700637cbSDimitry Andric for (__ndptr = __ndptr->__next_; 1247*700637cbSDimitry Andric __ndptr != nullptr && 1248*700637cbSDimitry Andric (__ndptr->__hash() == __hash || std::__constrain_hash(__ndptr->__hash(), __bc) == __chash); 1249*700637cbSDimitry Andric __ndptr = __ndptr->__next_) { 1250*700637cbSDimitry Andric if ((__ndptr->__hash() == __hash) && key_eq()(__ndptr->__upcast()->__get_value(), __value)) 1251*700637cbSDimitry Andric return __ndptr; 1252*700637cbSDimitry Andric } 1253*700637cbSDimitry Andric } 1254*700637cbSDimitry Andric } 1255*700637cbSDimitry Andric if (size() + 1 > __bc * max_load_factor() || __bc == 0) { 1256*700637cbSDimitry Andric __rehash_unique(std::max<size_type>( 1257*700637cbSDimitry Andric 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor())))); 1258*700637cbSDimitry Andric } 1259*700637cbSDimitry Andric return nullptr; 1260*700637cbSDimitry Andric} 1261*700637cbSDimitry Andric 1262*700637cbSDimitry Andric// Insert the node __nd into the container by pushing it into the right bucket, 1263*700637cbSDimitry Andric// and updating size(). Assumes that __nd->__hash is up-to-date, and that 1264*700637cbSDimitry Andric// rehashing has already occurred and that no element with the same key exists 1265*700637cbSDimitry Andric// in the map. 1266*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1267*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI void 1268*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform(__node_pointer __nd) _NOEXCEPT { 1269*700637cbSDimitry Andric size_type __bc = bucket_count(); 1270*700637cbSDimitry Andric size_t __chash = std::__constrain_hash(__nd->__hash(), __bc); 1271*700637cbSDimitry Andric // insert_after __bucket_list_[__chash], or __first_node if bucket is null 1272*700637cbSDimitry Andric __next_pointer __pn = __bucket_list_[__chash]; 1273*700637cbSDimitry Andric if (__pn == nullptr) { 1274*700637cbSDimitry Andric __pn = __p1_.first().__ptr(); 1275*700637cbSDimitry Andric __nd->__next_ = __pn->__next_; 1276*700637cbSDimitry Andric __pn->__next_ = __nd->__ptr(); 1277*700637cbSDimitry Andric // fix up __bucket_list_ 1278*700637cbSDimitry Andric __bucket_list_[__chash] = __pn; 1279*700637cbSDimitry Andric if (__nd->__next_ != nullptr) 1280*700637cbSDimitry Andric __bucket_list_[std::__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr(); 1281*700637cbSDimitry Andric } else { 1282*700637cbSDimitry Andric __nd->__next_ = __pn->__next_; 1283*700637cbSDimitry Andric __pn->__next_ = __nd->__ptr(); 1284*700637cbSDimitry Andric } 1285*700637cbSDimitry Andric ++size(); 1286*700637cbSDimitry Andric} 1287*700637cbSDimitry Andric 1288*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1289*700637cbSDimitry Andricpair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> 1290*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd) { 1291*700637cbSDimitry Andric __nd->__hash_ = hash_function()(__nd->__get_value()); 1292*700637cbSDimitry Andric __next_pointer __existing_node = __node_insert_unique_prepare(__nd->__hash(), __nd->__get_value()); 1293*700637cbSDimitry Andric 1294*700637cbSDimitry Andric // Insert the node, unless it already exists in the container. 1295*700637cbSDimitry Andric bool __inserted = false; 1296*700637cbSDimitry Andric if (__existing_node == nullptr) { 1297*700637cbSDimitry Andric __node_insert_unique_perform(__nd); 1298*700637cbSDimitry Andric __existing_node = __nd->__ptr(); 1299*700637cbSDimitry Andric __inserted = true; 1300*700637cbSDimitry Andric } 1301*700637cbSDimitry Andric return pair<iterator, bool>(iterator(__existing_node), __inserted); 1302*700637cbSDimitry Andric} 1303*700637cbSDimitry Andric 1304*700637cbSDimitry Andric// Prepare the container for an insertion of the value __cp_val with the hash 1305*700637cbSDimitry Andric// __cp_hash. This does a lookup into the container to see if __cp_value is 1306*700637cbSDimitry Andric// already present, and performs a rehash if necessary. Returns a pointer to the 1307*700637cbSDimitry Andric// last occurrence of __cp_val in the map. 1308*700637cbSDimitry Andric// 1309*700637cbSDimitry Andric// Note that this function does forward exceptions if key_eq() throws, and never 1310*700637cbSDimitry Andric// mutates __value or actually inserts into the map. 1311*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1312*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer 1313*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_prepare(size_t __cp_hash, value_type& __cp_val) { 1314*700637cbSDimitry Andric size_type __bc = bucket_count(); 1315*700637cbSDimitry Andric if (size() + 1 > __bc * max_load_factor() || __bc == 0) { 1316*700637cbSDimitry Andric __rehash_multi(std::max<size_type>( 1317*700637cbSDimitry Andric 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor())))); 1318*700637cbSDimitry Andric __bc = bucket_count(); 1319*700637cbSDimitry Andric } 1320*700637cbSDimitry Andric size_t __chash = std::__constrain_hash(__cp_hash, __bc); 1321*700637cbSDimitry Andric __next_pointer __pn = __bucket_list_[__chash]; 1322*700637cbSDimitry Andric if (__pn != nullptr) { 1323*700637cbSDimitry Andric for (bool __found = false; 1324*700637cbSDimitry Andric __pn->__next_ != nullptr && std::__constrain_hash(__pn->__next_->__hash(), __bc) == __chash; 1325*700637cbSDimitry Andric __pn = __pn->__next_) { 1326*700637cbSDimitry Andric // __found key_eq() action 1327*700637cbSDimitry Andric // false false loop 1328*700637cbSDimitry Andric // true true loop 1329*700637cbSDimitry Andric // false true set __found to true 1330*700637cbSDimitry Andric // true false break 1331*700637cbSDimitry Andric if (__found != 1332*700637cbSDimitry Andric (__pn->__next_->__hash() == __cp_hash && key_eq()(__pn->__next_->__upcast()->__get_value(), __cp_val))) { 1333*700637cbSDimitry Andric if (!__found) 1334*700637cbSDimitry Andric __found = true; 1335*700637cbSDimitry Andric else 1336*700637cbSDimitry Andric break; 1337*700637cbSDimitry Andric } 1338*700637cbSDimitry Andric } 1339*700637cbSDimitry Andric } 1340*700637cbSDimitry Andric return __pn; 1341*700637cbSDimitry Andric} 1342*700637cbSDimitry Andric 1343*700637cbSDimitry Andric// Insert the node __cp into the container after __pn (which is the last node in 1344*700637cbSDimitry Andric// the bucket that compares equal to __cp). Rehashing, and checking for 1345*700637cbSDimitry Andric// uniqueness has already been performed (in __node_insert_multi_prepare), so 1346*700637cbSDimitry Andric// all we need to do is update the bucket and size(). Assumes that __cp->__hash 1347*700637cbSDimitry Andric// is up-to-date. 1348*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1349*700637cbSDimitry Andricvoid __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform( 1350*700637cbSDimitry Andric __node_pointer __cp, __next_pointer __pn) _NOEXCEPT { 1351*700637cbSDimitry Andric size_type __bc = bucket_count(); 1352*700637cbSDimitry Andric size_t __chash = std::__constrain_hash(__cp->__hash_, __bc); 1353*700637cbSDimitry Andric if (__pn == nullptr) { 1354*700637cbSDimitry Andric __pn = __p1_.first().__ptr(); 1355*700637cbSDimitry Andric __cp->__next_ = __pn->__next_; 1356*700637cbSDimitry Andric __pn->__next_ = __cp->__ptr(); 1357*700637cbSDimitry Andric // fix up __bucket_list_ 1358*700637cbSDimitry Andric __bucket_list_[__chash] = __pn; 1359*700637cbSDimitry Andric if (__cp->__next_ != nullptr) 1360*700637cbSDimitry Andric __bucket_list_[std::__constrain_hash(__cp->__next_->__hash(), __bc)] = __cp->__ptr(); 1361*700637cbSDimitry Andric } else { 1362*700637cbSDimitry Andric __cp->__next_ = __pn->__next_; 1363*700637cbSDimitry Andric __pn->__next_ = __cp->__ptr(); 1364*700637cbSDimitry Andric if (__cp->__next_ != nullptr) { 1365*700637cbSDimitry Andric size_t __nhash = std::__constrain_hash(__cp->__next_->__hash(), __bc); 1366*700637cbSDimitry Andric if (__nhash != __chash) 1367*700637cbSDimitry Andric __bucket_list_[__nhash] = __cp->__ptr(); 1368*700637cbSDimitry Andric } 1369*700637cbSDimitry Andric } 1370*700637cbSDimitry Andric ++size(); 1371*700637cbSDimitry Andric} 1372*700637cbSDimitry Andric 1373*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1374*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator 1375*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp) { 1376*700637cbSDimitry Andric __cp->__hash_ = hash_function()(__cp->__get_value()); 1377*700637cbSDimitry Andric __next_pointer __pn = __node_insert_multi_prepare(__cp->__hash(), __cp->__get_value()); 1378*700637cbSDimitry Andric __node_insert_multi_perform(__cp, __pn); 1379*700637cbSDimitry Andric 1380*700637cbSDimitry Andric return iterator(__cp->__ptr()); 1381*700637cbSDimitry Andric} 1382*700637cbSDimitry Andric 1383*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1384*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator 1385*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(const_iterator __p, __node_pointer __cp) { 1386*700637cbSDimitry Andric if (__p != end() && key_eq()(*__p, __cp->__get_value())) { 1387*700637cbSDimitry Andric __next_pointer __np = __p.__node_; 1388*700637cbSDimitry Andric __cp->__hash_ = __np->__hash(); 1389*700637cbSDimitry Andric size_type __bc = bucket_count(); 1390*700637cbSDimitry Andric if (size() + 1 > __bc * max_load_factor() || __bc == 0) { 1391*700637cbSDimitry Andric __rehash_multi(std::max<size_type>( 1392*700637cbSDimitry Andric 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor())))); 1393*700637cbSDimitry Andric __bc = bucket_count(); 1394*700637cbSDimitry Andric } 1395*700637cbSDimitry Andric size_t __chash = std::__constrain_hash(__cp->__hash_, __bc); 1396*700637cbSDimitry Andric __next_pointer __pp = __bucket_list_[__chash]; 1397*700637cbSDimitry Andric while (__pp->__next_ != __np) 1398*700637cbSDimitry Andric __pp = __pp->__next_; 1399*700637cbSDimitry Andric __cp->__next_ = __np; 1400*700637cbSDimitry Andric __pp->__next_ = static_cast<__next_pointer>(__cp); 1401*700637cbSDimitry Andric ++size(); 1402*700637cbSDimitry Andric return iterator(static_cast<__next_pointer>(__cp)); 1403*700637cbSDimitry Andric } 1404*700637cbSDimitry Andric return __node_insert_multi(__cp); 1405*700637cbSDimitry Andric} 1406*700637cbSDimitry Andric 1407*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1408*700637cbSDimitry Andrictemplate <class _Key, class... _Args> 1409*700637cbSDimitry Andricpair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> 1410*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) { 1411*700637cbSDimitry Andric size_t __hash = hash_function()(__k); 1412*700637cbSDimitry Andric size_type __bc = bucket_count(); 1413*700637cbSDimitry Andric bool __inserted = false; 1414*700637cbSDimitry Andric __next_pointer __nd; 1415*700637cbSDimitry Andric size_t __chash; 1416*700637cbSDimitry Andric if (__bc != 0) { 1417*700637cbSDimitry Andric __chash = std::__constrain_hash(__hash, __bc); 1418*700637cbSDimitry Andric __nd = __bucket_list_[__chash]; 1419*700637cbSDimitry Andric if (__nd != nullptr) { 1420*700637cbSDimitry Andric for (__nd = __nd->__next_; 1421*700637cbSDimitry Andric __nd != nullptr && (__nd->__hash() == __hash || std::__constrain_hash(__nd->__hash(), __bc) == __chash); 1422*700637cbSDimitry Andric __nd = __nd->__next_) { 1423*700637cbSDimitry Andric if ((__nd->__hash() == __hash) && key_eq()(__nd->__upcast()->__get_value(), __k)) 1424*700637cbSDimitry Andric goto __done; 1425*700637cbSDimitry Andric } 1426*700637cbSDimitry Andric } 1427*700637cbSDimitry Andric } 1428*700637cbSDimitry Andric { 1429*700637cbSDimitry Andric __node_holder __h = __construct_node_hash(__hash, std::forward<_Args>(__args)...); 1430*700637cbSDimitry Andric if (size() + 1 > __bc * max_load_factor() || __bc == 0) { 1431*700637cbSDimitry Andric __rehash_unique(std::max<size_type>( 1432*700637cbSDimitry Andric 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor())))); 1433*700637cbSDimitry Andric __bc = bucket_count(); 1434*700637cbSDimitry Andric __chash = std::__constrain_hash(__hash, __bc); 1435*700637cbSDimitry Andric } 1436*700637cbSDimitry Andric // insert_after __bucket_list_[__chash], or __first_node if bucket is null 1437*700637cbSDimitry Andric __next_pointer __pn = __bucket_list_[__chash]; 1438*700637cbSDimitry Andric if (__pn == nullptr) { 1439*700637cbSDimitry Andric __pn = __p1_.first().__ptr(); 1440*700637cbSDimitry Andric __h->__next_ = __pn->__next_; 1441*700637cbSDimitry Andric __pn->__next_ = __h.get()->__ptr(); 1442*700637cbSDimitry Andric // fix up __bucket_list_ 1443*700637cbSDimitry Andric __bucket_list_[__chash] = __pn; 1444*700637cbSDimitry Andric if (__h->__next_ != nullptr) 1445*700637cbSDimitry Andric __bucket_list_[std::__constrain_hash(__h->__next_->__hash(), __bc)] = __h.get()->__ptr(); 1446*700637cbSDimitry Andric } else { 1447*700637cbSDimitry Andric __h->__next_ = __pn->__next_; 1448*700637cbSDimitry Andric __pn->__next_ = static_cast<__next_pointer>(__h.get()); 1449*700637cbSDimitry Andric } 1450*700637cbSDimitry Andric __nd = static_cast<__next_pointer>(__h.release()); 1451*700637cbSDimitry Andric // increment size 1452*700637cbSDimitry Andric ++size(); 1453*700637cbSDimitry Andric __inserted = true; 1454*700637cbSDimitry Andric } 1455*700637cbSDimitry Andric__done: 1456*700637cbSDimitry Andric return pair<iterator, bool>(iterator(__nd), __inserted); 1457*700637cbSDimitry Andric} 1458*700637cbSDimitry Andric 1459*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1460*700637cbSDimitry Andrictemplate <class... _Args> 1461*700637cbSDimitry Andricpair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> 1462*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args) { 1463*700637cbSDimitry Andric __node_holder __h = __construct_node(std::forward<_Args>(__args)...); 1464*700637cbSDimitry Andric pair<iterator, bool> __r = __node_insert_unique(__h.get()); 1465*700637cbSDimitry Andric if (__r.second) 1466*700637cbSDimitry Andric __h.release(); 1467*700637cbSDimitry Andric return __r; 1468*700637cbSDimitry Andric} 1469*700637cbSDimitry Andric 1470*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1471*700637cbSDimitry Andrictemplate <class... _Args> 1472*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator 1473*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args) { 1474*700637cbSDimitry Andric __node_holder __h = __construct_node(std::forward<_Args>(__args)...); 1475*700637cbSDimitry Andric iterator __r = __node_insert_multi(__h.get()); 1476*700637cbSDimitry Andric __h.release(); 1477*700637cbSDimitry Andric return __r; 1478*700637cbSDimitry Andric} 1479*700637cbSDimitry Andric 1480*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1481*700637cbSDimitry Andrictemplate <class... _Args> 1482*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator 1483*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(const_iterator __p, _Args&&... __args) { 1484*700637cbSDimitry Andric __node_holder __h = __construct_node(std::forward<_Args>(__args)...); 1485*700637cbSDimitry Andric iterator __r = __node_insert_multi(__p, __h.get()); 1486*700637cbSDimitry Andric __h.release(); 1487*700637cbSDimitry Andric return __r; 1488*700637cbSDimitry Andric} 1489*700637cbSDimitry Andric 1490*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1491*700637cbSDimitry Andrictemplate <bool _UniqueKeys> 1492*700637cbSDimitry Andricvoid __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __n) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { 1493*700637cbSDimitry Andric if (__n == 1) 1494*700637cbSDimitry Andric __n = 2; 1495*700637cbSDimitry Andric else if (__n & (__n - 1)) 1496*700637cbSDimitry Andric __n = std::__next_prime(__n); 1497*700637cbSDimitry Andric size_type __bc = bucket_count(); 1498*700637cbSDimitry Andric if (__n > __bc) 1499*700637cbSDimitry Andric __do_rehash<_UniqueKeys>(__n); 1500*700637cbSDimitry Andric else if (__n < __bc) { 1501*700637cbSDimitry Andric __n = std::max<size_type>( 1502*700637cbSDimitry Andric __n, 1503*700637cbSDimitry Andric std::__is_hash_power2(__bc) ? std::__next_hash_pow2(size_t(std::ceil(float(size()) / max_load_factor()))) 1504*700637cbSDimitry Andric : std::__next_prime(size_t(std::ceil(float(size()) / max_load_factor())))); 1505*700637cbSDimitry Andric if (__n < __bc) 1506*700637cbSDimitry Andric __do_rehash<_UniqueKeys>(__n); 1507*700637cbSDimitry Andric } 1508*700637cbSDimitry Andric} 1509*700637cbSDimitry Andric 1510*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1511*700637cbSDimitry Andrictemplate <bool _UniqueKeys> 1512*700637cbSDimitry Andricvoid __hash_table<_Tp, _Hash, _Equal, _Alloc>::__do_rehash(size_type __nbc) { 1513*700637cbSDimitry Andric __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc(); 1514*700637cbSDimitry Andric __bucket_list_.reset(__nbc > 0 ? __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr); 1515*700637cbSDimitry Andric __bucket_list_.get_deleter().size() = __nbc; 1516*700637cbSDimitry Andric if (__nbc > 0) { 1517*700637cbSDimitry Andric for (size_type __i = 0; __i < __nbc; ++__i) 1518*700637cbSDimitry Andric __bucket_list_[__i] = nullptr; 1519*700637cbSDimitry Andric __next_pointer __pp = __p1_.first().__ptr(); 1520*700637cbSDimitry Andric __next_pointer __cp = __pp->__next_; 1521*700637cbSDimitry Andric if (__cp != nullptr) { 1522*700637cbSDimitry Andric size_type __chash = std::__constrain_hash(__cp->__hash(), __nbc); 1523*700637cbSDimitry Andric __bucket_list_[__chash] = __pp; 1524*700637cbSDimitry Andric size_type __phash = __chash; 1525*700637cbSDimitry Andric for (__pp = __cp, void(), __cp = __cp->__next_; __cp != nullptr; __cp = __pp->__next_) { 1526*700637cbSDimitry Andric __chash = std::__constrain_hash(__cp->__hash(), __nbc); 1527*700637cbSDimitry Andric if (__chash == __phash) 1528*700637cbSDimitry Andric __pp = __cp; 1529*700637cbSDimitry Andric else { 1530*700637cbSDimitry Andric if (__bucket_list_[__chash] == nullptr) { 1531*700637cbSDimitry Andric __bucket_list_[__chash] = __pp; 1532*700637cbSDimitry Andric __pp = __cp; 1533*700637cbSDimitry Andric __phash = __chash; 1534*700637cbSDimitry Andric } else { 1535*700637cbSDimitry Andric __next_pointer __np = __cp; 1536*700637cbSDimitry Andric if (!_UniqueKeys) { 1537*700637cbSDimitry Andric for (; __np->__next_ != nullptr && 1538*700637cbSDimitry Andric key_eq()(__cp->__upcast()->__get_value(), __np->__next_->__upcast()->__get_value()); 1539*700637cbSDimitry Andric __np = __np->__next_) 1540*700637cbSDimitry Andric ; 1541*700637cbSDimitry Andric } 1542*700637cbSDimitry Andric __pp->__next_ = __np->__next_; 1543*700637cbSDimitry Andric __np->__next_ = __bucket_list_[__chash]->__next_; 1544*700637cbSDimitry Andric __bucket_list_[__chash]->__next_ = __cp; 1545*700637cbSDimitry Andric } 1546*700637cbSDimitry Andric } 1547*700637cbSDimitry Andric } 1548*700637cbSDimitry Andric } 1549*700637cbSDimitry Andric } 1550*700637cbSDimitry Andric} 1551*700637cbSDimitry Andric 1552*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1553*700637cbSDimitry Andrictemplate <class _Key> 1554*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator 1555*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) { 1556*700637cbSDimitry Andric size_t __hash = hash_function()(__k); 1557*700637cbSDimitry Andric size_type __bc = bucket_count(); 1558*700637cbSDimitry Andric if (__bc != 0) { 1559*700637cbSDimitry Andric size_t __chash = std::__constrain_hash(__hash, __bc); 1560*700637cbSDimitry Andric __next_pointer __nd = __bucket_list_[__chash]; 1561*700637cbSDimitry Andric if (__nd != nullptr) { 1562*700637cbSDimitry Andric for (__nd = __nd->__next_; 1563*700637cbSDimitry Andric __nd != nullptr && (__nd->__hash() == __hash || std::__constrain_hash(__nd->__hash(), __bc) == __chash); 1564*700637cbSDimitry Andric __nd = __nd->__next_) { 1565*700637cbSDimitry Andric if ((__nd->__hash() == __hash) && key_eq()(__nd->__upcast()->__get_value(), __k)) 1566*700637cbSDimitry Andric return iterator(__nd); 1567*700637cbSDimitry Andric } 1568*700637cbSDimitry Andric } 1569*700637cbSDimitry Andric } 1570*700637cbSDimitry Andric return end(); 1571*700637cbSDimitry Andric} 1572*700637cbSDimitry Andric 1573*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1574*700637cbSDimitry Andrictemplate <class _Key> 1575*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator 1576*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const { 1577*700637cbSDimitry Andric size_t __hash = hash_function()(__k); 1578*700637cbSDimitry Andric size_type __bc = bucket_count(); 1579*700637cbSDimitry Andric if (__bc != 0) { 1580*700637cbSDimitry Andric size_t __chash = std::__constrain_hash(__hash, __bc); 1581*700637cbSDimitry Andric __next_pointer __nd = __bucket_list_[__chash]; 1582*700637cbSDimitry Andric if (__nd != nullptr) { 1583*700637cbSDimitry Andric for (__nd = __nd->__next_; 1584*700637cbSDimitry Andric __nd != nullptr && (__hash == __nd->__hash() || std::__constrain_hash(__nd->__hash(), __bc) == __chash); 1585*700637cbSDimitry Andric __nd = __nd->__next_) { 1586*700637cbSDimitry Andric if ((__nd->__hash() == __hash) && key_eq()(__nd->__upcast()->__get_value(), __k)) 1587*700637cbSDimitry Andric return const_iterator(__nd); 1588*700637cbSDimitry Andric } 1589*700637cbSDimitry Andric } 1590*700637cbSDimitry Andric } 1591*700637cbSDimitry Andric return end(); 1592*700637cbSDimitry Andric} 1593*700637cbSDimitry Andric 1594*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1595*700637cbSDimitry Andrictemplate <class... _Args> 1596*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder 1597*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&&... __args) { 1598*700637cbSDimitry Andric static_assert(!__is_hash_value_type<_Args...>::value, "Construct cannot be called with a hash value type"); 1599*700637cbSDimitry Andric __node_allocator& __na = __node_alloc(); 1600*700637cbSDimitry Andric __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); 1601*700637cbSDimitry Andric 1602*700637cbSDimitry Andric // Begin the lifetime of the node itself. Note that this doesn't begin the lifetime of the value 1603*700637cbSDimitry Andric // held inside the node, since we need to use the allocator's construct() method for that. 1604*700637cbSDimitry Andric // 1605*700637cbSDimitry Andric // We don't use the allocator's construct() method to construct the node itself since the 1606*700637cbSDimitry Andric // Cpp17FooInsertable named requirements don't require the allocator's construct() method 1607*700637cbSDimitry Andric // to work on anything other than the value_type. 1608*700637cbSDimitry Andric std::__construct_at(std::addressof(*__h), /* next = */ nullptr, /* hash = */ 0); 1609*700637cbSDimitry Andric 1610*700637cbSDimitry Andric // Now construct the value_type using the allocator's construct() method. 1611*700637cbSDimitry Andric __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__get_value()), std::forward<_Args>(__args)...); 1612*700637cbSDimitry Andric __h.get_deleter().__value_constructed = true; 1613*700637cbSDimitry Andric 1614*700637cbSDimitry Andric __h->__hash_ = hash_function()(__h->__get_value()); 1615*700637cbSDimitry Andric return __h; 1616*700637cbSDimitry Andric} 1617*700637cbSDimitry Andric 1618*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1619*700637cbSDimitry Andrictemplate <class _First, class... _Rest> 1620*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder 1621*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest) { 1622*700637cbSDimitry Andric static_assert(!__is_hash_value_type<_First, _Rest...>::value, "Construct cannot be called with a hash value type"); 1623*700637cbSDimitry Andric __node_allocator& __na = __node_alloc(); 1624*700637cbSDimitry Andric __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); 1625*700637cbSDimitry Andric std::__construct_at(std::addressof(*__h), /* next = */ nullptr, /* hash = */ __hash); 1626*700637cbSDimitry Andric __node_traits::construct( 1627*700637cbSDimitry Andric __na, _NodeTypes::__get_ptr(__h->__get_value()), std::forward<_First>(__f), std::forward<_Rest>(__rest)...); 1628*700637cbSDimitry Andric __h.get_deleter().__value_constructed = true; 1629*700637cbSDimitry Andric return __h; 1630*700637cbSDimitry Andric} 1631*700637cbSDimitry Andric 1632*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1633*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator 1634*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p) { 1635*700637cbSDimitry Andric __next_pointer __np = __p.__node_; 1636*700637cbSDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( 1637*700637cbSDimitry Andric __p != end(), "unordered container::erase(iterator) called with a non-dereferenceable iterator"); 1638*700637cbSDimitry Andric iterator __r(__np); 1639*700637cbSDimitry Andric ++__r; 1640*700637cbSDimitry Andric remove(__p); 1641*700637cbSDimitry Andric return __r; 1642*700637cbSDimitry Andric} 1643*700637cbSDimitry Andric 1644*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1645*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator 1646*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, const_iterator __last) { 1647*700637cbSDimitry Andric for (const_iterator __p = __first; __first != __last; __p = __first) { 1648*700637cbSDimitry Andric ++__first; 1649*700637cbSDimitry Andric erase(__p); 1650*700637cbSDimitry Andric } 1651*700637cbSDimitry Andric __next_pointer __np = __last.__node_; 1652*700637cbSDimitry Andric return iterator(__np); 1653*700637cbSDimitry Andric} 1654*700637cbSDimitry Andric 1655*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1656*700637cbSDimitry Andrictemplate <class _Key> 1657*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type 1658*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k) { 1659*700637cbSDimitry Andric iterator __i = find(__k); 1660*700637cbSDimitry Andric if (__i == end()) 1661*700637cbSDimitry Andric return 0; 1662*700637cbSDimitry Andric erase(__i); 1663*700637cbSDimitry Andric return 1; 1664*700637cbSDimitry Andric} 1665*700637cbSDimitry Andric 1666*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1667*700637cbSDimitry Andrictemplate <class _Key> 1668*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type 1669*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k) { 1670*700637cbSDimitry Andric size_type __r = 0; 1671*700637cbSDimitry Andric iterator __i = find(__k); 1672*700637cbSDimitry Andric if (__i != end()) { 1673*700637cbSDimitry Andric iterator __e = end(); 1674*700637cbSDimitry Andric do { 1675*700637cbSDimitry Andric erase(__i++); 1676*700637cbSDimitry Andric ++__r; 1677*700637cbSDimitry Andric } while (__i != __e && key_eq()(*__i, __k)); 1678*700637cbSDimitry Andric } 1679*700637cbSDimitry Andric return __r; 1680*700637cbSDimitry Andric} 1681*700637cbSDimitry Andric 1682*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1683*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder 1684*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT { 1685*700637cbSDimitry Andric // current node 1686*700637cbSDimitry Andric __next_pointer __cn = __p.__node_; 1687*700637cbSDimitry Andric size_type __bc = bucket_count(); 1688*700637cbSDimitry Andric size_t __chash = std::__constrain_hash(__cn->__hash(), __bc); 1689*700637cbSDimitry Andric // find previous node 1690*700637cbSDimitry Andric __next_pointer __pn = __bucket_list_[__chash]; 1691*700637cbSDimitry Andric for (; __pn->__next_ != __cn; __pn = __pn->__next_) 1692*700637cbSDimitry Andric ; 1693*700637cbSDimitry Andric // Fix up __bucket_list_ 1694*700637cbSDimitry Andric // if __pn is not in same bucket (before begin is not in same bucket) && 1695*700637cbSDimitry Andric // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) 1696*700637cbSDimitry Andric if (__pn == __p1_.first().__ptr() || std::__constrain_hash(__pn->__hash(), __bc) != __chash) { 1697*700637cbSDimitry Andric if (__cn->__next_ == nullptr || std::__constrain_hash(__cn->__next_->__hash(), __bc) != __chash) 1698*700637cbSDimitry Andric __bucket_list_[__chash] = nullptr; 1699*700637cbSDimitry Andric } 1700*700637cbSDimitry Andric // if __cn->__next_ is not in same bucket (nullptr is in same bucket) 1701*700637cbSDimitry Andric if (__cn->__next_ != nullptr) { 1702*700637cbSDimitry Andric size_t __nhash = std::__constrain_hash(__cn->__next_->__hash(), __bc); 1703*700637cbSDimitry Andric if (__nhash != __chash) 1704*700637cbSDimitry Andric __bucket_list_[__nhash] = __pn; 1705*700637cbSDimitry Andric } 1706*700637cbSDimitry Andric // remove __cn 1707*700637cbSDimitry Andric __pn->__next_ = __cn->__next_; 1708*700637cbSDimitry Andric __cn->__next_ = nullptr; 1709*700637cbSDimitry Andric --size(); 1710*700637cbSDimitry Andric return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true)); 1711*700637cbSDimitry Andric} 1712*700637cbSDimitry Andric 1713*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1714*700637cbSDimitry Andrictemplate <class _Key> 1715*700637cbSDimitry Andricinline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type 1716*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const { 1717*700637cbSDimitry Andric return static_cast<size_type>(find(__k) != end()); 1718*700637cbSDimitry Andric} 1719*700637cbSDimitry Andric 1720*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1721*700637cbSDimitry Andrictemplate <class _Key> 1722*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type 1723*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const { 1724*700637cbSDimitry Andric size_type __r = 0; 1725*700637cbSDimitry Andric const_iterator __i = find(__k); 1726*700637cbSDimitry Andric if (__i != end()) { 1727*700637cbSDimitry Andric const_iterator __e = end(); 1728*700637cbSDimitry Andric do { 1729*700637cbSDimitry Andric ++__i; 1730*700637cbSDimitry Andric ++__r; 1731*700637cbSDimitry Andric } while (__i != __e && key_eq()(*__i, __k)); 1732*700637cbSDimitry Andric } 1733*700637cbSDimitry Andric return __r; 1734*700637cbSDimitry Andric} 1735*700637cbSDimitry Andric 1736*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1737*700637cbSDimitry Andrictemplate <class _Key> 1738*700637cbSDimitry Andricpair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, 1739*700637cbSDimitry Andric typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> 1740*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(const _Key& __k) { 1741*700637cbSDimitry Andric iterator __i = find(__k); 1742*700637cbSDimitry Andric iterator __j = __i; 1743*700637cbSDimitry Andric if (__i != end()) 1744*700637cbSDimitry Andric ++__j; 1745*700637cbSDimitry Andric return pair<iterator, iterator>(__i, __j); 1746*700637cbSDimitry Andric} 1747*700637cbSDimitry Andric 1748*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1749*700637cbSDimitry Andrictemplate <class _Key> 1750*700637cbSDimitry Andricpair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator, 1751*700637cbSDimitry Andric typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> 1752*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(const _Key& __k) const { 1753*700637cbSDimitry Andric const_iterator __i = find(__k); 1754*700637cbSDimitry Andric const_iterator __j = __i; 1755*700637cbSDimitry Andric if (__i != end()) 1756*700637cbSDimitry Andric ++__j; 1757*700637cbSDimitry Andric return pair<const_iterator, const_iterator>(__i, __j); 1758*700637cbSDimitry Andric} 1759*700637cbSDimitry Andric 1760*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1761*700637cbSDimitry Andrictemplate <class _Key> 1762*700637cbSDimitry Andricpair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, 1763*700637cbSDimitry Andric typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> 1764*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(const _Key& __k) { 1765*700637cbSDimitry Andric iterator __i = find(__k); 1766*700637cbSDimitry Andric iterator __j = __i; 1767*700637cbSDimitry Andric if (__i != end()) { 1768*700637cbSDimitry Andric iterator __e = end(); 1769*700637cbSDimitry Andric do { 1770*700637cbSDimitry Andric ++__j; 1771*700637cbSDimitry Andric } while (__j != __e && key_eq()(*__j, __k)); 1772*700637cbSDimitry Andric } 1773*700637cbSDimitry Andric return pair<iterator, iterator>(__i, __j); 1774*700637cbSDimitry Andric} 1775*700637cbSDimitry Andric 1776*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1777*700637cbSDimitry Andrictemplate <class _Key> 1778*700637cbSDimitry Andricpair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator, 1779*700637cbSDimitry Andric typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> 1780*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(const _Key& __k) const { 1781*700637cbSDimitry Andric const_iterator __i = find(__k); 1782*700637cbSDimitry Andric const_iterator __j = __i; 1783*700637cbSDimitry Andric if (__i != end()) { 1784*700637cbSDimitry Andric const_iterator __e = end(); 1785*700637cbSDimitry Andric do { 1786*700637cbSDimitry Andric ++__j; 1787*700637cbSDimitry Andric } while (__j != __e && key_eq()(*__j, __k)); 1788*700637cbSDimitry Andric } 1789*700637cbSDimitry Andric return pair<const_iterator, const_iterator>(__i, __j); 1790*700637cbSDimitry Andric} 1791*700637cbSDimitry Andric 1792*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1793*700637cbSDimitry Andricvoid __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) { 1794*700637cbSDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR( 1795*700637cbSDimitry Andric __node_traits::propagate_on_container_swap::value || this->__node_alloc() == __u.__node_alloc(), 1796*700637cbSDimitry Andric "unordered container::swap: Either propagate_on_container_swap " 1797*700637cbSDimitry Andric "must be true or the allocators must compare equal"); 1798*700637cbSDimitry Andric { 1799*700637cbSDimitry Andric __node_pointer_pointer __npp = __bucket_list_.release(); 1800*700637cbSDimitry Andric __bucket_list_.reset(__u.__bucket_list_.release()); 1801*700637cbSDimitry Andric __u.__bucket_list_.reset(__npp); 1802*700637cbSDimitry Andric } 1803*700637cbSDimitry Andric std::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size()); 1804*700637cbSDimitry Andric std::__swap_allocator(__bucket_list_.get_deleter().__alloc(), __u.__bucket_list_.get_deleter().__alloc()); 1805*700637cbSDimitry Andric std::__swap_allocator(__node_alloc(), __u.__node_alloc()); 1806*700637cbSDimitry Andric std::swap(__p1_.first().__next_, __u.__p1_.first().__next_); 1807*700637cbSDimitry Andric __p2_.swap(__u.__p2_); 1808*700637cbSDimitry Andric __p3_.swap(__u.__p3_); 1809*700637cbSDimitry Andric if (size() > 0) 1810*700637cbSDimitry Andric __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); 1811*700637cbSDimitry Andric if (__u.size() > 0) 1812*700637cbSDimitry Andric __u.__bucket_list_[std::__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = 1813*700637cbSDimitry Andric __u.__p1_.first().__ptr(); 1814*700637cbSDimitry Andric} 1815*700637cbSDimitry Andric 1816*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1817*700637cbSDimitry Andrictypename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type 1818*700637cbSDimitry Andric__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const { 1819*700637cbSDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( 1820*700637cbSDimitry Andric __n < bucket_count(), "unordered container::bucket_size(n) called with n >= bucket_count()"); 1821*700637cbSDimitry Andric __next_pointer __np = __bucket_list_[__n]; 1822*700637cbSDimitry Andric size_type __bc = bucket_count(); 1823*700637cbSDimitry Andric size_type __r = 0; 1824*700637cbSDimitry Andric if (__np != nullptr) { 1825*700637cbSDimitry Andric for (__np = __np->__next_; __np != nullptr && std::__constrain_hash(__np->__hash(), __bc) == __n; 1826*700637cbSDimitry Andric __np = __np->__next_, (void)++__r) 1827*700637cbSDimitry Andric ; 1828*700637cbSDimitry Andric } 1829*700637cbSDimitry Andric return __r; 1830*700637cbSDimitry Andric} 1831*700637cbSDimitry Andric 1832*700637cbSDimitry Andrictemplate <class _Tp, class _Hash, class _Equal, class _Alloc> 1833*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void 1834*700637cbSDimitry Andricswap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x, __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y) { 1835*700637cbSDimitry Andric __x.swap(__y); 1836*700637cbSDimitry Andric} 1837*700637cbSDimitry Andric 1838*700637cbSDimitry Andric_LIBCPP_END_NAMESPACE_STD 1839*700637cbSDimitry Andric 1840*700637cbSDimitry Andric_LIBCPP_POP_MACROS 1841*700637cbSDimitry Andric 1842*700637cbSDimitry Andric#endif // _LIBCPP___CXX03___HASH_TABLE 1843