Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP__HASH_TABLE |
| 12 | #define _LIBCPP__HASH_TABLE |
| 13 | |
| 14 | #include <__config> |
| 15 | #include <initializer_list> |
| 16 | #include <memory> |
| 17 | #include <iterator> |
| 18 | #include <algorithm> |
| 19 | #include <cmath> |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 20 | #include <utility> |
Eric Fiselier | 04333f9 | 2017-01-13 22:42:53 +0000 | [diff] [blame] | 21 | #include <type_traits> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | |
Eric Fiselier | c1bd919 | 2014-08-10 23:53:08 +0000 | [diff] [blame] | 23 | #include <__debug> |
Howard Hinnant | 42a3046 | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 24 | |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 25 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | #pragma GCC system_header |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 27 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 28 | |
Eric Fiselier | a016efb | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 29 | _LIBCPP_PUSH_MACROS |
| 30 | #include <__undef_macros> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 31 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 32 | |
Eric Fiselier | a016efb | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 33 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 34 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 35 | template <class _Key, class _Tp> |
| 36 | struct __hash_value_type; |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 37 | |
Eric Fiselier | 04333f9 | 2017-01-13 22:42:53 +0000 | [diff] [blame] | 38 | template <class _Key, class _Cp, class _Hash, |
| 39 | bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value> |
| 40 | class __unordered_map_hasher; |
| 41 | |
| 42 | template <class _Key, class _Cp, class _Pred, |
| 43 | bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value |
| 44 | > |
| 45 | class __unordered_map_equal; |
| 46 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 47 | #ifndef _LIBCPP_CXX03_LANG |
| 48 | template <class _Tp> |
| 49 | struct __is_hash_value_type_imp : false_type {}; |
| 50 | |
| 51 | template <class _Key, class _Value> |
| 52 | struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {}; |
| 53 | |
| 54 | template <class ..._Args> |
| 55 | struct __is_hash_value_type : false_type {}; |
| 56 | |
| 57 | template <class _One> |
| 58 | struct __is_hash_value_type<_One> : __is_hash_value_type_imp<typename __uncvref<_One>::type> {}; |
| 59 | #endif |
| 60 | |
Howard Hinnant | 6e41256 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 61 | _LIBCPP_FUNC_VIS |
Howard Hinnant | ce53420 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 62 | size_t __next_prime(size_t __n); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 63 | |
| 64 | template <class _NodePtr> |
| 65 | struct __hash_node_base |
| 66 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 67 | typedef typename pointer_traits<_NodePtr>::element_type __node_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | typedef __hash_node_base __first_node; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 69 | typedef typename __rebind_pointer<_NodePtr, __first_node>::type __node_base_pointer; |
| 70 | typedef _NodePtr __node_pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 71 | |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 72 | #if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB) |
| 73 | typedef __node_base_pointer __next_pointer; |
| 74 | #else |
| 75 | typedef typename conditional< |
| 76 | is_pointer<__node_pointer>::value, |
| 77 | __node_base_pointer, |
| 78 | __node_pointer>::type __next_pointer; |
| 79 | #endif |
| 80 | |
| 81 | __next_pointer __next_; |
| 82 | |
| 83 | _LIBCPP_INLINE_VISIBILITY |
| 84 | __next_pointer __ptr() _NOEXCEPT { |
| 85 | return static_cast<__next_pointer>( |
| 86 | pointer_traits<__node_base_pointer>::pointer_to(*this)); |
| 87 | } |
| 88 | |
| 89 | _LIBCPP_INLINE_VISIBILITY |
| 90 | __node_pointer __upcast() _NOEXCEPT { |
| 91 | return static_cast<__node_pointer>( |
| 92 | pointer_traits<__node_base_pointer>::pointer_to(*this)); |
| 93 | } |
| 94 | |
| 95 | _LIBCPP_INLINE_VISIBILITY |
| 96 | size_t __hash() const _NOEXCEPT { |
| 97 | return static_cast<__node_type const&>(*this).__hash_; |
| 98 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 99 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 100 | _LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | template <class _Tp, class _VoidPtr> |
| 104 | struct __hash_node |
| 105 | : public __hash_node_base |
| 106 | < |
Eric Fiselier | 934b092 | 2015-12-30 21:52:00 +0000 | [diff] [blame] | 107 | typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 108 | > |
| 109 | { |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 110 | typedef _Tp __node_value_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 111 | |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 112 | size_t __hash_; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 113 | __node_value_type __value_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 116 | inline _LIBCPP_INLINE_VISIBILITY |
| 117 | bool |
Eric Fiselier | 9ba5c11 | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 118 | __is_hash_power2(size_t __bc) |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 119 | { |
| 120 | return __bc > 2 && !(__bc & (__bc - 1)); |
| 121 | } |
| 122 | |
| 123 | inline _LIBCPP_INLINE_VISIBILITY |
| 124 | size_t |
| 125 | __constrain_hash(size_t __h, size_t __bc) |
| 126 | { |
Eric Fiselier | 118cb41 | 2016-07-11 22:02:02 +0000 | [diff] [blame] | 127 | return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : |
| 128 | (__h < __bc ? __h : __h % __bc); |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | inline _LIBCPP_INLINE_VISIBILITY |
| 132 | size_t |
Eric Fiselier | 9ba5c11 | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 133 | __next_hash_pow2(size_t __n) |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 134 | { |
Marshall Clow | 87af646 | 2017-06-03 00:08:32 +0000 | [diff] [blame] | 135 | return __n < 2 ? __n : (size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1))); |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Duncan P. N. Exon Smith | fde79b4 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 138 | |
Howard Hinnant | ce53420 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 139 | template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 140 | |
Eric Fiselier | e2f2d1e | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 141 | template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_iterator; |
| 142 | template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; |
| 143 | template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_local_iterator; |
| 144 | template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; |
| 145 | template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; |
| 146 | template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 147 | |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 148 | template <class _Tp> |
Eric Fiselier | 43b121d | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 149 | struct __hash_key_value_types { |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 150 | static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, ""); |
| 151 | typedef _Tp key_type; |
| 152 | typedef _Tp __node_value_type; |
| 153 | typedef _Tp __container_value_type; |
| 154 | static const bool __is_map = false; |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 155 | |
| 156 | _LIBCPP_INLINE_VISIBILITY |
| 157 | static key_type const& __get_key(_Tp const& __v) { |
| 158 | return __v; |
| 159 | } |
| 160 | _LIBCPP_INLINE_VISIBILITY |
| 161 | static __container_value_type const& __get_value(__node_value_type const& __v) { |
| 162 | return __v; |
| 163 | } |
| 164 | _LIBCPP_INLINE_VISIBILITY |
| 165 | static __container_value_type* __get_ptr(__node_value_type& __n) { |
| 166 | return _VSTD::addressof(__n); |
| 167 | } |
| 168 | #ifndef _LIBCPP_CXX03_LANG |
| 169 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 170 | static __container_value_type&& __move(__node_value_type& __v) { |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 171 | return _VSTD::move(__v); |
| 172 | } |
| 173 | #endif |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | template <class _Key, class _Tp> |
Eric Fiselier | 43b121d | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 177 | struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > { |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 178 | typedef _Key key_type; |
| 179 | typedef _Tp mapped_type; |
| 180 | typedef __hash_value_type<_Key, _Tp> __node_value_type; |
| 181 | typedef pair<const _Key, _Tp> __container_value_type; |
| 182 | typedef __container_value_type __map_value_type; |
| 183 | static const bool __is_map = true; |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 184 | |
| 185 | _LIBCPP_INLINE_VISIBILITY |
| 186 | static key_type const& __get_key(__container_value_type const& __v) { |
| 187 | return __v.first; |
| 188 | } |
| 189 | |
| 190 | template <class _Up> |
| 191 | _LIBCPP_INLINE_VISIBILITY |
| 192 | static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value, |
| 193 | __container_value_type const&>::type |
| 194 | __get_value(_Up& __t) { |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 195 | return __t.__get_value(); |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | template <class _Up> |
| 199 | _LIBCPP_INLINE_VISIBILITY |
| 200 | static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, |
| 201 | __container_value_type const&>::type |
| 202 | __get_value(_Up& __t) { |
| 203 | return __t; |
| 204 | } |
| 205 | |
| 206 | _LIBCPP_INLINE_VISIBILITY |
| 207 | static __container_value_type* __get_ptr(__node_value_type& __n) { |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 208 | return _VSTD::addressof(__n.__get_value()); |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 209 | } |
| 210 | #ifndef _LIBCPP_CXX03_LANG |
| 211 | _LIBCPP_INLINE_VISIBILITY |
Erik Pilkington | f52318b | 2018-06-04 20:38:23 +0000 | [diff] [blame] | 212 | static pair<key_type&&, mapped_type&&> __move(__node_value_type& __v) { |
| 213 | return __v.__move(); |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 214 | } |
| 215 | #endif |
| 216 | |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 217 | }; |
| 218 | |
Eric Fiselier | 43b121d | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 219 | template <class _Tp, class _AllocPtr, class _KVTypes = __hash_key_value_types<_Tp>, |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 220 | bool = _KVTypes::__is_map> |
Eric Fiselier | 43b121d | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 221 | struct __hash_map_pointer_types {}; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 222 | |
| 223 | template <class _Tp, class _AllocPtr, class _KVTypes> |
Eric Fiselier | 43b121d | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 224 | struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 225 | typedef typename _KVTypes::__map_value_type _Mv; |
| 226 | typedef typename __rebind_pointer<_AllocPtr, _Mv>::type |
| 227 | __map_value_type_pointer; |
| 228 | typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type |
| 229 | __const_map_value_type_pointer; |
| 230 | }; |
| 231 | |
| 232 | template <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type> |
| 233 | struct __hash_node_types; |
| 234 | |
| 235 | template <class _NodePtr, class _Tp, class _VoidPtr> |
| 236 | struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> > |
Eric Fiselier | 43b121d | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 237 | : public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr> |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 238 | |
| 239 | { |
Eric Fiselier | 43b121d | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 240 | typedef __hash_key_value_types<_Tp> __base; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 241 | |
| 242 | public: |
| 243 | typedef ptrdiff_t difference_type; |
| 244 | typedef size_t size_type; |
| 245 | |
| 246 | typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer; |
| 247 | |
| 248 | typedef typename pointer_traits<_NodePtr>::element_type __node_type; |
| 249 | typedef _NodePtr __node_pointer; |
| 250 | |
| 251 | typedef __hash_node_base<__node_pointer> __node_base_type; |
| 252 | typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type |
| 253 | __node_base_pointer; |
| 254 | |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 255 | typedef typename __node_base_type::__next_pointer __next_pointer; |
| 256 | |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 257 | typedef _Tp __node_value_type; |
| 258 | typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type |
| 259 | __node_value_type_pointer; |
| 260 | typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type |
| 261 | __const_node_value_type_pointer; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 262 | |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 263 | private: |
| 264 | static_assert(!is_const<__node_type>::value, |
| 265 | "_NodePtr should never be a pointer to const"); |
| 266 | static_assert((is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value), |
| 267 | "_VoidPtr does not point to unqualified void type"); |
| 268 | static_assert((is_same<typename __rebind_pointer<_VoidPtr, __node_type>::type, |
| 269 | _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr."); |
| 270 | }; |
| 271 | |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 272 | template <class _HashIterator> |
| 273 | struct __hash_node_types_from_iterator; |
| 274 | template <class _NodePtr> |
| 275 | struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; |
| 276 | template <class _NodePtr> |
| 277 | struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; |
| 278 | template <class _NodePtr> |
| 279 | struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; |
| 280 | template <class _NodePtr> |
| 281 | struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {}; |
| 282 | |
| 283 | |
| 284 | template <class _NodeValueTp, class _VoidPtr> |
| 285 | struct __make_hash_node_types { |
| 286 | typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp; |
| 287 | typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr; |
| 288 | typedef __hash_node_types<_NodePtr> type; |
| 289 | }; |
| 290 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 291 | template <class _NodePtr> |
Eric Fiselier | e2f2d1e | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 292 | class _LIBCPP_TEMPLATE_VIS __hash_iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 293 | { |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 294 | typedef __hash_node_types<_NodePtr> _NodeTypes; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 295 | typedef _NodePtr __node_pointer; |
| 296 | typedef typename _NodeTypes::__next_pointer __next_pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 297 | |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 298 | __next_pointer __node_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 299 | |
| 300 | public: |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 301 | typedef forward_iterator_tag iterator_category; |
| 302 | typedef typename _NodeTypes::__node_value_type value_type; |
| 303 | typedef typename _NodeTypes::difference_type difference_type; |
| 304 | typedef value_type& reference; |
| 305 | typedef typename _NodeTypes::__node_value_type_pointer pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 306 | |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 307 | _LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT : __node_(nullptr) { |
| 308 | _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 312 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 313 | __hash_iterator(const __hash_iterator& __i) |
| 314 | : __node_(__i.__node_) |
| 315 | { |
| 316 | __get_db()->__iterator_copy(this, &__i); |
| 317 | } |
| 318 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 319 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 320 | ~__hash_iterator() |
| 321 | { |
| 322 | __get_db()->__erase_i(this); |
| 323 | } |
| 324 | |
| 325 | _LIBCPP_INLINE_VISIBILITY |
| 326 | __hash_iterator& operator=(const __hash_iterator& __i) |
| 327 | { |
| 328 | if (this != &__i) |
| 329 | { |
| 330 | __get_db()->__iterator_copy(this, &__i); |
| 331 | __node_ = __i.__node_; |
| 332 | } |
| 333 | return *this; |
| 334 | } |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 335 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 336 | |
| 337 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 338 | reference operator*() const { |
| 339 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
| 340 | "Attempted to dereference a non-dereferenceable unordered container iterator"); |
| 341 | return __node_->__upcast()->__value_; |
| 342 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 343 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 344 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 345 | pointer operator->() const { |
| 346 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
| 347 | "Attempted to dereference a non-dereferenceable unordered container iterator"); |
| 348 | return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); |
| 349 | } |
| 350 | |
| 351 | _LIBCPP_INLINE_VISIBILITY |
| 352 | __hash_iterator& operator++() { |
| 353 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 354 | "Attempted to increment non-incrementable unordered container iterator"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 355 | __node_ = __node_->__next_; |
| 356 | return *this; |
| 357 | } |
| 358 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 359 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 360 | __hash_iterator operator++(int) |
| 361 | { |
| 362 | __hash_iterator __t(*this); |
| 363 | ++(*this); |
| 364 | return __t; |
| 365 | } |
| 366 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 367 | friend _LIBCPP_INLINE_VISIBILITY |
| 368 | bool operator==(const __hash_iterator& __x, const __hash_iterator& __y) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 369 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 370 | return __x.__node_ == __y.__node_; |
| 371 | } |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 372 | friend _LIBCPP_INLINE_VISIBILITY |
| 373 | bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 374 | {return !(__x == __y);} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 375 | |
| 376 | private: |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 377 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 378 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 379 | __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 380 | : __node_(__node) |
| 381 | { |
| 382 | __get_db()->__insert_ic(this, __c); |
| 383 | } |
| 384 | #else |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 385 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 386 | __hash_iterator(__next_pointer __node) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 387 | : __node_(__node) |
| 388 | {} |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 389 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | template <class, class, class, class> friend class __hash_table; |
Eric Fiselier | e2f2d1e | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 391 | template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; |
| 392 | template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; |
| 393 | template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; |
| 394 | template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 395 | }; |
| 396 | |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 397 | template <class _NodePtr> |
Eric Fiselier | e2f2d1e | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 398 | class _LIBCPP_TEMPLATE_VIS __hash_const_iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 399 | { |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 400 | static_assert(!is_const<typename pointer_traits<_NodePtr>::element_type>::value, ""); |
| 401 | typedef __hash_node_types<_NodePtr> _NodeTypes; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 402 | typedef _NodePtr __node_pointer; |
| 403 | typedef typename _NodeTypes::__next_pointer __next_pointer; |
Eric Fiselier | 757373e | 2016-02-18 00:20:34 +0000 | [diff] [blame] | 404 | |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 405 | __next_pointer __node_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 406 | |
| 407 | public: |
Eric Fiselier | 757373e | 2016-02-18 00:20:34 +0000 | [diff] [blame] | 408 | typedef __hash_iterator<_NodePtr> __non_const_iterator; |
| 409 | |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 410 | typedef forward_iterator_tag iterator_category; |
| 411 | typedef typename _NodeTypes::__node_value_type value_type; |
| 412 | typedef typename _NodeTypes::difference_type difference_type; |
| 413 | typedef const value_type& reference; |
| 414 | typedef typename _NodeTypes::__const_node_value_type_pointer pointer; |
| 415 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 416 | |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 417 | _LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT : __node_(nullptr) { |
| 418 | _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 419 | } |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 420 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 421 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 422 | __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 423 | : __node_(__x.__node_) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 424 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 425 | _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 429 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 430 | __hash_const_iterator(const __hash_const_iterator& __i) |
| 431 | : __node_(__i.__node_) |
| 432 | { |
| 433 | __get_db()->__iterator_copy(this, &__i); |
| 434 | } |
| 435 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 436 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 437 | ~__hash_const_iterator() |
| 438 | { |
| 439 | __get_db()->__erase_i(this); |
| 440 | } |
| 441 | |
| 442 | _LIBCPP_INLINE_VISIBILITY |
| 443 | __hash_const_iterator& operator=(const __hash_const_iterator& __i) |
| 444 | { |
| 445 | if (this != &__i) |
| 446 | { |
| 447 | __get_db()->__iterator_copy(this, &__i); |
| 448 | __node_ = __i.__node_; |
| 449 | } |
| 450 | return *this; |
| 451 | } |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 452 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 453 | |
| 454 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 455 | reference operator*() const { |
| 456 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 457 | "Attempted to dereference a non-dereferenceable unordered container const_iterator"); |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 458 | return __node_->__upcast()->__value_; |
| 459 | } |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 460 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 461 | pointer operator->() const { |
| 462 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 463 | "Attempted to dereference a non-dereferenceable unordered container const_iterator"); |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 464 | return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); |
| 465 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 466 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 467 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 468 | __hash_const_iterator& operator++() { |
| 469 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
| 470 | "Attempted to increment non-incrementable unordered container const_iterator"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 471 | __node_ = __node_->__next_; |
| 472 | return *this; |
| 473 | } |
| 474 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 475 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 476 | __hash_const_iterator operator++(int) |
| 477 | { |
| 478 | __hash_const_iterator __t(*this); |
| 479 | ++(*this); |
| 480 | return __t; |
| 481 | } |
| 482 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 483 | friend _LIBCPP_INLINE_VISIBILITY |
| 484 | bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 485 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 486 | return __x.__node_ == __y.__node_; |
| 487 | } |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 488 | friend _LIBCPP_INLINE_VISIBILITY |
| 489 | bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 490 | {return !(__x == __y);} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 491 | |
| 492 | private: |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 493 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 494 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 495 | __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 496 | : __node_(__node) |
| 497 | { |
| 498 | __get_db()->__insert_ic(this, __c); |
| 499 | } |
| 500 | #else |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 501 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 502 | __hash_const_iterator(__next_pointer __node) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 503 | : __node_(__node) |
| 504 | {} |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 505 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 506 | template <class, class, class, class> friend class __hash_table; |
Eric Fiselier | e2f2d1e | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 507 | template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; |
| 508 | template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; |
| 509 | template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | }; |
| 511 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 512 | template <class _NodePtr> |
Eric Fiselier | e2f2d1e | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 513 | class _LIBCPP_TEMPLATE_VIS __hash_local_iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 514 | { |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 515 | typedef __hash_node_types<_NodePtr> _NodeTypes; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 516 | typedef _NodePtr __node_pointer; |
| 517 | typedef typename _NodeTypes::__next_pointer __next_pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 518 | |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 519 | __next_pointer __node_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 520 | size_t __bucket_; |
| 521 | size_t __bucket_count_; |
| 522 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 523 | public: |
| 524 | typedef forward_iterator_tag iterator_category; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 525 | typedef typename _NodeTypes::__node_value_type value_type; |
| 526 | typedef typename _NodeTypes::difference_type difference_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 527 | typedef value_type& reference; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 528 | typedef typename _NodeTypes::__node_value_type_pointer pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 529 | |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 530 | _LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT : __node_(nullptr) { |
| 531 | _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 535 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 536 | __hash_local_iterator(const __hash_local_iterator& __i) |
| 537 | : __node_(__i.__node_), |
| 538 | __bucket_(__i.__bucket_), |
| 539 | __bucket_count_(__i.__bucket_count_) |
| 540 | { |
| 541 | __get_db()->__iterator_copy(this, &__i); |
| 542 | } |
| 543 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 544 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 545 | ~__hash_local_iterator() |
| 546 | { |
| 547 | __get_db()->__erase_i(this); |
| 548 | } |
| 549 | |
| 550 | _LIBCPP_INLINE_VISIBILITY |
| 551 | __hash_local_iterator& operator=(const __hash_local_iterator& __i) |
| 552 | { |
| 553 | if (this != &__i) |
| 554 | { |
| 555 | __get_db()->__iterator_copy(this, &__i); |
| 556 | __node_ = __i.__node_; |
| 557 | __bucket_ = __i.__bucket_; |
| 558 | __bucket_count_ = __i.__bucket_count_; |
| 559 | } |
| 560 | return *this; |
| 561 | } |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 562 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 563 | |
| 564 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 565 | reference operator*() const { |
| 566 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 567 | "Attempted to dereference a non-dereferenceable unordered container local_iterator"); |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 568 | return __node_->__upcast()->__value_; |
| 569 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 570 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 571 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 572 | pointer operator->() const { |
| 573 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
| 574 | "Attempted to dereference a non-dereferenceable unordered container local_iterator"); |
| 575 | return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); |
| 576 | } |
| 577 | |
| 578 | _LIBCPP_INLINE_VISIBILITY |
| 579 | __hash_local_iterator& operator++() { |
| 580 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 581 | "Attempted to increment non-incrementable unordered container local_iterator"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 582 | __node_ = __node_->__next_; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 583 | if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 584 | __node_ = nullptr; |
| 585 | return *this; |
| 586 | } |
| 587 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 588 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 589 | __hash_local_iterator operator++(int) |
| 590 | { |
| 591 | __hash_local_iterator __t(*this); |
| 592 | ++(*this); |
| 593 | return __t; |
| 594 | } |
| 595 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 596 | friend _LIBCPP_INLINE_VISIBILITY |
| 597 | bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 598 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 599 | return __x.__node_ == __y.__node_; |
| 600 | } |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 601 | friend _LIBCPP_INLINE_VISIBILITY |
| 602 | bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 603 | {return !(__x == __y);} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 604 | |
| 605 | private: |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 606 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 607 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 608 | __hash_local_iterator(__next_pointer __node, size_t __bucket, |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 609 | size_t __bucket_count, const void* __c) _NOEXCEPT |
| 610 | : __node_(__node), |
| 611 | __bucket_(__bucket), |
| 612 | __bucket_count_(__bucket_count) |
| 613 | { |
| 614 | __get_db()->__insert_ic(this, __c); |
| 615 | if (__node_ != nullptr) |
| 616 | __node_ = __node_->__next_; |
| 617 | } |
| 618 | #else |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 619 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 620 | __hash_local_iterator(__next_pointer __node, size_t __bucket, |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 621 | size_t __bucket_count) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 622 | : __node_(__node), |
| 623 | __bucket_(__bucket), |
| 624 | __bucket_count_(__bucket_count) |
| 625 | { |
| 626 | if (__node_ != nullptr) |
| 627 | __node_ = __node_->__next_; |
| 628 | } |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 629 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 630 | template <class, class, class, class> friend class __hash_table; |
Eric Fiselier | e2f2d1e | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 631 | template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; |
| 632 | template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 633 | }; |
| 634 | |
| 635 | template <class _ConstNodePtr> |
Eric Fiselier | e2f2d1e | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 636 | class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 637 | { |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 638 | typedef __hash_node_types<_ConstNodePtr> _NodeTypes; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 639 | typedef _ConstNodePtr __node_pointer; |
| 640 | typedef typename _NodeTypes::__next_pointer __next_pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 641 | |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 642 | __next_pointer __node_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 643 | size_t __bucket_; |
| 644 | size_t __bucket_count_; |
| 645 | |
| 646 | typedef pointer_traits<__node_pointer> __pointer_traits; |
| 647 | typedef typename __pointer_traits::element_type __node; |
| 648 | typedef typename remove_const<__node>::type __non_const_node; |
Eric Fiselier | 934b092 | 2015-12-30 21:52:00 +0000 | [diff] [blame] | 649 | typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type |
| 650 | __non_const_node_pointer; |
Eric Fiselier | 757373e | 2016-02-18 00:20:34 +0000 | [diff] [blame] | 651 | public: |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 652 | typedef __hash_local_iterator<__non_const_node_pointer> |
| 653 | __non_const_iterator; |
Eric Fiselier | 757373e | 2016-02-18 00:20:34 +0000 | [diff] [blame] | 654 | |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 655 | typedef forward_iterator_tag iterator_category; |
| 656 | typedef typename _NodeTypes::__node_value_type value_type; |
| 657 | typedef typename _NodeTypes::difference_type difference_type; |
| 658 | typedef const value_type& reference; |
| 659 | typedef typename _NodeTypes::__const_node_value_type_pointer pointer; |
Eric Fiselier | 934b092 | 2015-12-30 21:52:00 +0000 | [diff] [blame] | 660 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 661 | |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 662 | _LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) { |
| 663 | _LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this)); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 666 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 667 | __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 668 | : __node_(__x.__node_), |
| 669 | __bucket_(__x.__bucket_), |
| 670 | __bucket_count_(__x.__bucket_count_) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 671 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 672 | _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 676 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 677 | __hash_const_local_iterator(const __hash_const_local_iterator& __i) |
| 678 | : __node_(__i.__node_), |
| 679 | __bucket_(__i.__bucket_), |
| 680 | __bucket_count_(__i.__bucket_count_) |
| 681 | { |
| 682 | __get_db()->__iterator_copy(this, &__i); |
| 683 | } |
| 684 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 685 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 686 | ~__hash_const_local_iterator() |
| 687 | { |
| 688 | __get_db()->__erase_i(this); |
| 689 | } |
| 690 | |
| 691 | _LIBCPP_INLINE_VISIBILITY |
| 692 | __hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i) |
| 693 | { |
| 694 | if (this != &__i) |
| 695 | { |
| 696 | __get_db()->__iterator_copy(this, &__i); |
| 697 | __node_ = __i.__node_; |
| 698 | __bucket_ = __i.__bucket_; |
| 699 | __bucket_count_ = __i.__bucket_count_; |
| 700 | } |
| 701 | return *this; |
| 702 | } |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 703 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 704 | |
| 705 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 706 | reference operator*() const { |
| 707 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 708 | "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 709 | return __node_->__upcast()->__value_; |
| 710 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 711 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 712 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 713 | pointer operator->() const { |
| 714 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
| 715 | "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); |
| 716 | return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); |
| 717 | } |
| 718 | |
| 719 | _LIBCPP_INLINE_VISIBILITY |
| 720 | __hash_const_local_iterator& operator++() { |
| 721 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 722 | "Attempted to increment non-incrementable unordered container const_local_iterator"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 723 | __node_ = __node_->__next_; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 724 | if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 725 | __node_ = nullptr; |
| 726 | return *this; |
| 727 | } |
| 728 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 729 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 730 | __hash_const_local_iterator operator++(int) |
| 731 | { |
| 732 | __hash_const_local_iterator __t(*this); |
| 733 | ++(*this); |
| 734 | return __t; |
| 735 | } |
| 736 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 737 | friend _LIBCPP_INLINE_VISIBILITY |
| 738 | bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 739 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 740 | return __x.__node_ == __y.__node_; |
| 741 | } |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 742 | friend _LIBCPP_INLINE_VISIBILITY |
| 743 | bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 744 | {return !(__x == __y);} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 745 | |
| 746 | private: |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 747 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 748 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 749 | __hash_const_local_iterator(__next_pointer __node, size_t __bucket, |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 750 | size_t __bucket_count, const void* __c) _NOEXCEPT |
| 751 | : __node_(__node), |
| 752 | __bucket_(__bucket), |
| 753 | __bucket_count_(__bucket_count) |
| 754 | { |
| 755 | __get_db()->__insert_ic(this, __c); |
| 756 | if (__node_ != nullptr) |
| 757 | __node_ = __node_->__next_; |
| 758 | } |
| 759 | #else |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 760 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 761 | __hash_const_local_iterator(__next_pointer __node, size_t __bucket, |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 762 | size_t __bucket_count) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 763 | : __node_(__node), |
| 764 | __bucket_(__bucket), |
| 765 | __bucket_count_(__bucket_count) |
| 766 | { |
| 767 | if (__node_ != nullptr) |
| 768 | __node_ = __node_->__next_; |
| 769 | } |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 770 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 771 | template <class, class, class, class> friend class __hash_table; |
Eric Fiselier | e2f2d1e | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 772 | template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 773 | }; |
| 774 | |
| 775 | template <class _Alloc> |
| 776 | class __bucket_list_deallocator |
| 777 | { |
| 778 | typedef _Alloc allocator_type; |
| 779 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 780 | typedef typename __alloc_traits::size_type size_type; |
| 781 | |
| 782 | __compressed_pair<size_type, allocator_type> __data_; |
| 783 | public: |
| 784 | typedef typename __alloc_traits::pointer pointer; |
| 785 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 786 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 787 | __bucket_list_deallocator() |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 788 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 789 | : __data_(0) {} |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 790 | |
| 791 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 792 | __bucket_list_deallocator(const allocator_type& __a, size_type __size) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 793 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 794 | : __data_(__size, __a) {} |
| 795 | |
Eric Fiselier | afa7a95 | 2017-04-19 01:23:04 +0000 | [diff] [blame] | 796 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 797 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 798 | __bucket_list_deallocator(__bucket_list_deallocator&& __x) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 799 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 800 | : __data_(_VSTD::move(__x.__data_)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 801 | { |
| 802 | __x.size() = 0; |
| 803 | } |
Eric Fiselier | afa7a95 | 2017-04-19 01:23:04 +0000 | [diff] [blame] | 804 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 805 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 806 | _LIBCPP_INLINE_VISIBILITY |
| 807 | size_type& size() _NOEXCEPT {return __data_.first();} |
| 808 | _LIBCPP_INLINE_VISIBILITY |
| 809 | size_type size() const _NOEXCEPT {return __data_.first();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 810 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 811 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 812 | allocator_type& __alloc() _NOEXCEPT {return __data_.second();} |
| 813 | _LIBCPP_INLINE_VISIBILITY |
| 814 | const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();} |
| 815 | |
| 816 | _LIBCPP_INLINE_VISIBILITY |
| 817 | void operator()(pointer __p) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 818 | { |
| 819 | __alloc_traits::deallocate(__alloc(), __p, size()); |
| 820 | } |
| 821 | }; |
| 822 | |
Howard Hinnant | ce53420 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 823 | template <class _Alloc> class __hash_map_node_destructor; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 824 | |
| 825 | template <class _Alloc> |
| 826 | class __hash_node_destructor |
| 827 | { |
| 828 | typedef _Alloc allocator_type; |
| 829 | typedef allocator_traits<allocator_type> __alloc_traits; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 830 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 831 | public: |
| 832 | typedef typename __alloc_traits::pointer pointer; |
| 833 | private: |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 834 | typedef __hash_node_types<pointer> _NodeTypes; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 835 | |
| 836 | allocator_type& __na_; |
| 837 | |
| 838 | __hash_node_destructor& operator=(const __hash_node_destructor&); |
| 839 | |
| 840 | public: |
| 841 | bool __value_constructed; |
| 842 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 843 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f622b58 | 2011-07-31 17:04:30 +0000 | [diff] [blame] | 844 | explicit __hash_node_destructor(allocator_type& __na, |
| 845 | bool __constructed = false) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 846 | : __na_(__na), |
Howard Hinnant | f622b58 | 2011-07-31 17:04:30 +0000 | [diff] [blame] | 847 | __value_constructed(__constructed) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 848 | {} |
| 849 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 850 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 851 | void operator()(pointer __p) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 852 | { |
| 853 | if (__value_constructed) |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 854 | __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 855 | if (__p) |
| 856 | __alloc_traits::deallocate(__na_, __p, 1); |
| 857 | } |
| 858 | |
| 859 | template <class> friend class __hash_map_node_destructor; |
| 860 | }; |
| 861 | |
Eric Fiselier | 04333f9 | 2017-01-13 22:42:53 +0000 | [diff] [blame] | 862 | |
| 863 | #ifndef _LIBCPP_CXX03_LANG |
| 864 | template <class _Key, class _Hash, class _Equal, class _Alloc> |
| 865 | struct __diagnose_hash_table_helper { |
| 866 | static constexpr bool __trigger_diagnostics() |
Eric Fiselier | bd6a2d8 | 2017-03-03 22:35:58 +0000 | [diff] [blame] | 867 | _LIBCPP_DIAGNOSE_WARNING(__check_hash_requirements<_Key, _Hash>::value |
Eric Fiselier | acb2158 | 2017-03-01 02:02:28 +0000 | [diff] [blame] | 868 | && !__invokable<_Hash const&, _Key const&>::value, |
| 869 | "the specified hash functor does not provide a const call operator") |
| 870 | _LIBCPP_DIAGNOSE_WARNING(is_copy_constructible<_Equal>::value |
| 871 | && !__invokable<_Equal const&, _Key const&, _Key const&>::value, |
| 872 | "the specified comparator type does not provide a const call operator") |
| 873 | { |
Eric Fiselier | bd6a2d8 | 2017-03-03 22:35:58 +0000 | [diff] [blame] | 874 | static_assert(__check_hash_requirements<_Key, _Hash>::value, |
| 875 | "the specified hash does not meet the Hash requirements"); |
Eric Fiselier | acb2158 | 2017-03-01 02:02:28 +0000 | [diff] [blame] | 876 | static_assert(is_copy_constructible<_Equal>::value, |
| 877 | "the specified comparator is required to be copy constructible"); |
| 878 | return true; |
| 879 | } |
Eric Fiselier | 04333f9 | 2017-01-13 22:42:53 +0000 | [diff] [blame] | 880 | }; |
| 881 | |
| 882 | template <class _Key, class _Value, class _Hash, class _Equal, class _Alloc> |
| 883 | struct __diagnose_hash_table_helper< |
| 884 | __hash_value_type<_Key, _Value>, |
| 885 | __unordered_map_hasher<_Key, __hash_value_type<_Key, _Value>, _Hash>, |
| 886 | __unordered_map_equal<_Key, __hash_value_type<_Key, _Value>, _Equal>, |
| 887 | _Alloc> |
| 888 | : __diagnose_hash_table_helper<_Key, _Hash, _Equal, _Alloc> |
| 889 | { |
| 890 | }; |
| 891 | #endif // _LIBCPP_CXX03_LANG |
| 892 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 893 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 894 | class __hash_table |
| 895 | { |
| 896 | public: |
| 897 | typedef _Tp value_type; |
| 898 | typedef _Hash hasher; |
| 899 | typedef _Equal key_equal; |
| 900 | typedef _Alloc allocator_type; |
| 901 | |
| 902 | private: |
| 903 | typedef allocator_traits<allocator_type> __alloc_traits; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 904 | typedef typename |
| 905 | __make_hash_node_types<value_type, typename __alloc_traits::void_pointer>::type |
| 906 | _NodeTypes; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 907 | public: |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 908 | |
| 909 | typedef typename _NodeTypes::__node_value_type __node_value_type; |
| 910 | typedef typename _NodeTypes::__container_value_type __container_value_type; |
Duncan P. N. Exon Smith | fde79b4 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 911 | typedef typename _NodeTypes::key_type key_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 912 | typedef value_type& reference; |
| 913 | typedef const value_type& const_reference; |
| 914 | typedef typename __alloc_traits::pointer pointer; |
| 915 | typedef typename __alloc_traits::const_pointer const_pointer; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 916 | #ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 917 | typedef typename __alloc_traits::size_type size_type; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 918 | #else |
| 919 | typedef typename _NodeTypes::size_type size_type; |
| 920 | #endif |
| 921 | typedef typename _NodeTypes::difference_type difference_type; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 922 | public: |
| 923 | // Create __node |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 924 | |
| 925 | typedef typename _NodeTypes::__node_type __node; |
Marshall Clow | 1f50801 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 926 | typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 927 | typedef allocator_traits<__node_allocator> __node_traits; |
Eric Fiselier | 8e39768 | 2016-02-11 15:22:37 +0000 | [diff] [blame] | 928 | typedef typename _NodeTypes::__void_pointer __void_pointer; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 929 | typedef typename _NodeTypes::__node_pointer __node_pointer; |
| 930 | typedef typename _NodeTypes::__node_pointer __node_const_pointer; |
| 931 | typedef typename _NodeTypes::__node_base_type __first_node; |
| 932 | typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 933 | typedef typename _NodeTypes::__next_pointer __next_pointer; |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 934 | |
| 935 | private: |
| 936 | // check for sane allocator pointer rebinding semantics. Rebinding the |
| 937 | // allocator for a new pointer type should be exactly the same as rebinding |
| 938 | // the pointer using 'pointer_traits'. |
| 939 | static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value), |
| 940 | "Allocator does not rebind pointers in a sane manner."); |
| 941 | typedef typename __rebind_alloc_helper<__node_traits, __first_node>::type |
| 942 | __node_base_allocator; |
| 943 | typedef allocator_traits<__node_base_allocator> __node_base_traits; |
| 944 | static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value), |
| 945 | "Allocator does not rebind pointers in a sane manner."); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 946 | |
| 947 | private: |
| 948 | |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 949 | typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 950 | typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 951 | typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 952 | typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 953 | typedef typename __bucket_list_deleter::pointer __node_pointer_pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 954 | |
Eric Fiselier | acb2158 | 2017-03-01 02:02:28 +0000 | [diff] [blame] | 955 | #ifndef _LIBCPP_CXX03_LANG |
| 956 | static_assert(__diagnose_hash_table_helper<_Tp, _Hash, _Equal, _Alloc>::__trigger_diagnostics(), ""); |
| 957 | #endif |
| 958 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 959 | // --- Member data begin --- |
Eric Fiselier | 75d0dcf | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 960 | __bucket_list __bucket_list_; |
| 961 | __compressed_pair<__first_node, __node_allocator> __p1_; |
| 962 | __compressed_pair<size_type, hasher> __p2_; |
| 963 | __compressed_pair<float, key_equal> __p3_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 964 | // --- Member data end --- |
| 965 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 966 | _LIBCPP_INLINE_VISIBILITY |
| 967 | size_type& size() _NOEXCEPT {return __p2_.first();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 968 | public: |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 969 | _LIBCPP_INLINE_VISIBILITY |
| 970 | size_type size() const _NOEXCEPT {return __p2_.first();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 971 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 972 | _LIBCPP_INLINE_VISIBILITY |
| 973 | hasher& hash_function() _NOEXCEPT {return __p2_.second();} |
| 974 | _LIBCPP_INLINE_VISIBILITY |
| 975 | const hasher& hash_function() const _NOEXCEPT {return __p2_.second();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 976 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 977 | _LIBCPP_INLINE_VISIBILITY |
| 978 | float& max_load_factor() _NOEXCEPT {return __p3_.first();} |
| 979 | _LIBCPP_INLINE_VISIBILITY |
| 980 | float max_load_factor() const _NOEXCEPT {return __p3_.first();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 981 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 982 | _LIBCPP_INLINE_VISIBILITY |
| 983 | key_equal& key_eq() _NOEXCEPT {return __p3_.second();} |
| 984 | _LIBCPP_INLINE_VISIBILITY |
| 985 | const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 986 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 987 | _LIBCPP_INLINE_VISIBILITY |
| 988 | __node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();} |
| 989 | _LIBCPP_INLINE_VISIBILITY |
| 990 | const __node_allocator& __node_alloc() const _NOEXCEPT |
| 991 | {return __p1_.second();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 992 | |
| 993 | public: |
| 994 | typedef __hash_iterator<__node_pointer> iterator; |
Howard Hinnant | 307f814 | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 995 | typedef __hash_const_iterator<__node_pointer> const_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 996 | typedef __hash_local_iterator<__node_pointer> local_iterator; |
Howard Hinnant | 307f814 | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 997 | typedef __hash_const_local_iterator<__node_pointer> const_local_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 998 | |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 999 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1000 | __hash_table() |
| 1001 | _NOEXCEPT_( |
| 1002 | is_nothrow_default_constructible<__bucket_list>::value && |
| 1003 | is_nothrow_default_constructible<__first_node>::value && |
| 1004 | is_nothrow_default_constructible<__node_allocator>::value && |
| 1005 | is_nothrow_default_constructible<hasher>::value && |
| 1006 | is_nothrow_default_constructible<key_equal>::value); |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1007 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1008 | __hash_table(const hasher& __hf, const key_equal& __eql); |
| 1009 | __hash_table(const hasher& __hf, const key_equal& __eql, |
| 1010 | const allocator_type& __a); |
| 1011 | explicit __hash_table(const allocator_type& __a); |
| 1012 | __hash_table(const __hash_table& __u); |
| 1013 | __hash_table(const __hash_table& __u, const allocator_type& __a); |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1014 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1015 | __hash_table(__hash_table&& __u) |
| 1016 | _NOEXCEPT_( |
| 1017 | is_nothrow_move_constructible<__bucket_list>::value && |
| 1018 | is_nothrow_move_constructible<__first_node>::value && |
| 1019 | is_nothrow_move_constructible<__node_allocator>::value && |
| 1020 | is_nothrow_move_constructible<hasher>::value && |
| 1021 | is_nothrow_move_constructible<key_equal>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1022 | __hash_table(__hash_table&& __u, const allocator_type& __a); |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1023 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1024 | ~__hash_table(); |
| 1025 | |
| 1026 | __hash_table& operator=(const __hash_table& __u); |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1027 | #ifndef _LIBCPP_CXX03_LANG |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1028 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1029 | __hash_table& operator=(__hash_table&& __u) |
| 1030 | _NOEXCEPT_( |
| 1031 | __node_traits::propagate_on_container_move_assignment::value && |
| 1032 | is_nothrow_move_assignable<__node_allocator>::value && |
| 1033 | is_nothrow_move_assignable<hasher>::value && |
| 1034 | is_nothrow_move_assignable<key_equal>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1035 | #endif |
| 1036 | template <class _InputIterator> |
| 1037 | void __assign_unique(_InputIterator __first, _InputIterator __last); |
| 1038 | template <class _InputIterator> |
| 1039 | void __assign_multi(_InputIterator __first, _InputIterator __last); |
| 1040 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1041 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1042 | size_type max_size() const _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1043 | { |
Eric Fiselier | 55b31b4e | 2016-11-23 01:18:56 +0000 | [diff] [blame] | 1044 | return std::min<size_type>( |
Eric Fiselier | 341c9dd | 2016-11-23 09:16:12 +0000 | [diff] [blame] | 1045 | __node_traits::max_size(__node_alloc()), |
Eric Fiselier | 55b31b4e | 2016-11-23 01:18:56 +0000 | [diff] [blame] | 1046 | numeric_limits<difference_type >::max() |
| 1047 | ); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | pair<iterator, bool> __node_insert_unique(__node_pointer __nd); |
| 1051 | iterator __node_insert_multi(__node_pointer __nd); |
| 1052 | iterator __node_insert_multi(const_iterator __p, |
| 1053 | __node_pointer __nd); |
| 1054 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1055 | #ifndef _LIBCPP_CXX03_LANG |
| 1056 | template <class _Key, class ..._Args> |
Duncan P. N. Exon Smith | fde79b4 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 1057 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1058 | pair<iterator, bool> __emplace_unique_key_args(_Key const& __k, _Args&&... __args); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1059 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1060 | template <class... _Args> |
Duncan P. N. Exon Smith | fde79b4 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 1061 | _LIBCPP_INLINE_VISIBILITY |
| 1062 | pair<iterator, bool> __emplace_unique_impl(_Args&&... __args); |
| 1063 | |
| 1064 | template <class _Pp> |
| 1065 | _LIBCPP_INLINE_VISIBILITY |
| 1066 | pair<iterator, bool> __emplace_unique(_Pp&& __x) { |
| 1067 | return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x), |
| 1068 | __can_extract_key<_Pp, key_type>()); |
| 1069 | } |
Eric Fiselier | 5008868 | 2016-04-16 00:23:12 +0000 | [diff] [blame] | 1070 | |
| 1071 | template <class _First, class _Second> |
| 1072 | _LIBCPP_INLINE_VISIBILITY |
| 1073 | typename enable_if< |
| 1074 | __can_extract_map_key<_First, key_type, __container_value_type>::value, |
| 1075 | pair<iterator, bool> |
| 1076 | >::type __emplace_unique(_First&& __f, _Second&& __s) { |
| 1077 | return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f), |
| 1078 | _VSTD::forward<_Second>(__s)); |
| 1079 | } |
| 1080 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1081 | template <class... _Args> |
Duncan P. N. Exon Smith | fde79b4 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 1082 | _LIBCPP_INLINE_VISIBILITY |
| 1083 | pair<iterator, bool> __emplace_unique(_Args&&... __args) { |
| 1084 | return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...); |
| 1085 | } |
| 1086 | |
| 1087 | template <class _Pp> |
| 1088 | _LIBCPP_INLINE_VISIBILITY |
| 1089 | pair<iterator, bool> |
| 1090 | __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) { |
| 1091 | return __emplace_unique_impl(_VSTD::forward<_Pp>(__x)); |
| 1092 | } |
| 1093 | template <class _Pp> |
| 1094 | _LIBCPP_INLINE_VISIBILITY |
| 1095 | pair<iterator, bool> |
| 1096 | __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) { |
| 1097 | return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x)); |
| 1098 | } |
| 1099 | template <class _Pp> |
| 1100 | _LIBCPP_INLINE_VISIBILITY |
| 1101 | pair<iterator, bool> |
| 1102 | __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) { |
| 1103 | return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x)); |
| 1104 | } |
| 1105 | |
| 1106 | template <class... _Args> |
| 1107 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1108 | iterator __emplace_multi(_Args&&... __args); |
| 1109 | template <class... _Args> |
Duncan P. N. Exon Smith | fde79b4 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 1110 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1111 | iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); |
| 1112 | |
| 1113 | |
Eric Fiselier | de3f2b3 | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1114 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1115 | pair<iterator, bool> |
| 1116 | __insert_unique(__container_value_type&& __x) { |
| 1117 | return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _VSTD::move(__x)); |
| 1118 | } |
| 1119 | |
| 1120 | template <class _Pp, class = typename enable_if< |
| 1121 | !__is_same_uncvref<_Pp, __container_value_type>::value |
| 1122 | >::type> |
Eric Fiselier | de3f2b3 | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1123 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1124 | pair<iterator, bool> __insert_unique(_Pp&& __x) { |
| 1125 | return __emplace_unique(_VSTD::forward<_Pp>(__x)); |
| 1126 | } |
| 1127 | |
| 1128 | template <class _Pp> |
| 1129 | _LIBCPP_INLINE_VISIBILITY |
| 1130 | iterator __insert_multi(_Pp&& __x) { |
| 1131 | return __emplace_multi(_VSTD::forward<_Pp>(__x)); |
| 1132 | } |
| 1133 | |
| 1134 | template <class _Pp> |
| 1135 | _LIBCPP_INLINE_VISIBILITY |
| 1136 | iterator __insert_multi(const_iterator __p, _Pp&& __x) { |
| 1137 | return __emplace_hint_multi(__p, _VSTD::forward<_Pp>(__x)); |
| 1138 | } |
| 1139 | |
| 1140 | #else // !defined(_LIBCPP_CXX03_LANG) |
| 1141 | template <class _Key, class _Args> |
Eric Fiselier | 4271d01 | 2016-09-25 04:05:46 +0000 | [diff] [blame] | 1142 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1143 | pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args); |
| 1144 | |
| 1145 | iterator __insert_multi(const __container_value_type& __x); |
| 1146 | iterator __insert_multi(const_iterator __p, const __container_value_type& __x); |
Eric Fiselier | de3f2b3 | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1147 | #endif |
| 1148 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1149 | _LIBCPP_INLINE_VISIBILITY |
| 1150 | pair<iterator, bool> __insert_unique(const __container_value_type& __x) { |
| 1151 | return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x); |
| 1152 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1153 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1154 | void clear() _NOEXCEPT; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1155 | void rehash(size_type __n); |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1156 | _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1157 | {rehash(static_cast<size_type>(ceil(__n / max_load_factor())));} |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1158 | |
| 1159 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1160 | size_type bucket_count() const _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1161 | { |
| 1162 | return __bucket_list_.get_deleter().size(); |
| 1163 | } |
| 1164 | |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1165 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1166 | iterator begin() _NOEXCEPT; |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1167 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1168 | iterator end() _NOEXCEPT; |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1169 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1170 | const_iterator begin() const _NOEXCEPT; |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1171 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1172 | const_iterator end() const _NOEXCEPT; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1173 | |
| 1174 | template <class _Key> |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1175 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1176 | size_type bucket(const _Key& __k) const |
Howard Hinnant | e5c13de | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 1177 | { |
| 1178 | _LIBCPP_ASSERT(bucket_count() > 0, |
| 1179 | "unordered container::bucket(key) called when bucket_count() == 0"); |
| 1180 | return __constrain_hash(hash_function()(__k), bucket_count()); |
| 1181 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1182 | |
| 1183 | template <class _Key> |
| 1184 | iterator find(const _Key& __x); |
| 1185 | template <class _Key> |
| 1186 | const_iterator find(const _Key& __x) const; |
| 1187 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1188 | typedef __hash_node_destructor<__node_allocator> _Dp; |
| 1189 | typedef unique_ptr<__node, _Dp> __node_holder; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1190 | |
| 1191 | iterator erase(const_iterator __p); |
| 1192 | iterator erase(const_iterator __first, const_iterator __last); |
| 1193 | template <class _Key> |
| 1194 | size_type __erase_unique(const _Key& __k); |
| 1195 | template <class _Key> |
| 1196 | size_type __erase_multi(const _Key& __k); |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1197 | __node_holder remove(const_iterator __p) _NOEXCEPT; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1198 | |
| 1199 | template <class _Key> |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1200 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1201 | size_type __count_unique(const _Key& __k) const; |
| 1202 | template <class _Key> |
| 1203 | size_type __count_multi(const _Key& __k) const; |
| 1204 | |
| 1205 | template <class _Key> |
| 1206 | pair<iterator, iterator> |
| 1207 | __equal_range_unique(const _Key& __k); |
| 1208 | template <class _Key> |
| 1209 | pair<const_iterator, const_iterator> |
| 1210 | __equal_range_unique(const _Key& __k) const; |
| 1211 | |
| 1212 | template <class _Key> |
| 1213 | pair<iterator, iterator> |
| 1214 | __equal_range_multi(const _Key& __k); |
| 1215 | template <class _Key> |
| 1216 | pair<const_iterator, const_iterator> |
| 1217 | __equal_range_multi(const _Key& __k) const; |
| 1218 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1219 | void swap(__hash_table& __u) |
Eric Fiselier | 87a8249 | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 1220 | #if _LIBCPP_STD_VER <= 11 |
Eric Fiselier | 780b51d | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 1221 | _NOEXCEPT_DEBUG_( |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1222 | __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1223 | && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value |
| 1224 | || __is_nothrow_swappable<__pointer_allocator>::value) |
| 1225 | && (!__node_traits::propagate_on_container_swap::value |
| 1226 | || __is_nothrow_swappable<__node_allocator>::value) |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1227 | ); |
Eric Fiselier | 87a8249 | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 1228 | #else |
Eric Fiselier | 780b51d | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 1229 | _NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value); |
Eric Fiselier | 87a8249 | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 1230 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1231 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1232 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1233 | size_type max_bucket_count() const _NOEXCEPT |
Eric Fiselier | 55b31b4e | 2016-11-23 01:18:56 +0000 | [diff] [blame] | 1234 | {return max_size(); } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1235 | size_type bucket_size(size_type __n) const; |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1236 | _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1237 | { |
| 1238 | size_type __bc = bucket_count(); |
| 1239 | return __bc != 0 ? (float)size() / __bc : 0.f; |
| 1240 | } |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1241 | _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT |
Howard Hinnant | e5c13de | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 1242 | { |
| 1243 | _LIBCPP_ASSERT(__mlf > 0, |
| 1244 | "unordered container::max_load_factor(lf) called with lf <= 0"); |
| 1245 | max_load_factor() = _VSTD::max(__mlf, load_factor()); |
| 1246 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1247 | |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1248 | _LIBCPP_INLINE_VISIBILITY |
| 1249 | local_iterator |
| 1250 | begin(size_type __n) |
| 1251 | { |
Howard Hinnant | e5c13de | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 1252 | _LIBCPP_ASSERT(__n < bucket_count(), |
| 1253 | "unordered container::begin(n) called with n >= bucket_count()"); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1254 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1255 | return local_iterator(__bucket_list_[__n], __n, bucket_count(), this); |
| 1256 | #else |
| 1257 | return local_iterator(__bucket_list_[__n], __n, bucket_count()); |
| 1258 | #endif |
| 1259 | } |
| 1260 | |
| 1261 | _LIBCPP_INLINE_VISIBILITY |
| 1262 | local_iterator |
| 1263 | end(size_type __n) |
| 1264 | { |
Howard Hinnant | e5c13de | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 1265 | _LIBCPP_ASSERT(__n < bucket_count(), |
| 1266 | "unordered container::end(n) called with n >= bucket_count()"); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1267 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1268 | return local_iterator(nullptr, __n, bucket_count(), this); |
| 1269 | #else |
| 1270 | return local_iterator(nullptr, __n, bucket_count()); |
| 1271 | #endif |
| 1272 | } |
| 1273 | |
| 1274 | _LIBCPP_INLINE_VISIBILITY |
| 1275 | const_local_iterator |
| 1276 | cbegin(size_type __n) const |
| 1277 | { |
Howard Hinnant | e5c13de | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 1278 | _LIBCPP_ASSERT(__n < bucket_count(), |
| 1279 | "unordered container::cbegin(n) called with n >= bucket_count()"); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1280 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1281 | return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this); |
| 1282 | #else |
| 1283 | return const_local_iterator(__bucket_list_[__n], __n, bucket_count()); |
| 1284 | #endif |
| 1285 | } |
| 1286 | |
| 1287 | _LIBCPP_INLINE_VISIBILITY |
| 1288 | const_local_iterator |
| 1289 | cend(size_type __n) const |
| 1290 | { |
Howard Hinnant | e5c13de | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 1291 | _LIBCPP_ASSERT(__n < bucket_count(), |
| 1292 | "unordered container::cend(n) called with n >= bucket_count()"); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1293 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1294 | return const_local_iterator(nullptr, __n, bucket_count(), this); |
| 1295 | #else |
| 1296 | return const_local_iterator(nullptr, __n, bucket_count()); |
| 1297 | #endif |
| 1298 | } |
| 1299 | |
| 1300 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1301 | |
| 1302 | bool __dereferenceable(const const_iterator* __i) const; |
| 1303 | bool __decrementable(const const_iterator* __i) const; |
| 1304 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1305 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1306 | |
| 1307 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 1308 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1309 | private: |
| 1310 | void __rehash(size_type __n); |
| 1311 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1312 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1313 | template <class ..._Args> |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1314 | __node_holder __construct_node(_Args&& ...__args); |
| 1315 | |
| 1316 | template <class _First, class ..._Rest> |
| 1317 | __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest); |
| 1318 | #else // _LIBCPP_CXX03_LANG |
| 1319 | __node_holder __construct_node(const __container_value_type& __v); |
| 1320 | __node_holder __construct_node_hash(size_t __hash, const __container_value_type& __v); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1321 | #endif |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1322 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1323 | |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1324 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1325 | void __copy_assign_alloc(const __hash_table& __u) |
| 1326 | {__copy_assign_alloc(__u, integral_constant<bool, |
| 1327 | __node_traits::propagate_on_container_copy_assignment::value>());} |
| 1328 | void __copy_assign_alloc(const __hash_table& __u, true_type); |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1329 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c206366 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1330 | void __copy_assign_alloc(const __hash_table&, false_type) {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1331 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1332 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1333 | void __move_assign(__hash_table& __u, false_type); |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1334 | void __move_assign(__hash_table& __u, true_type) |
| 1335 | _NOEXCEPT_( |
| 1336 | is_nothrow_move_assignable<__node_allocator>::value && |
| 1337 | is_nothrow_move_assignable<hasher>::value && |
| 1338 | is_nothrow_move_assignable<key_equal>::value); |
| 1339 | _LIBCPP_INLINE_VISIBILITY |
| 1340 | void __move_assign_alloc(__hash_table& __u) |
| 1341 | _NOEXCEPT_( |
| 1342 | !__node_traits::propagate_on_container_move_assignment::value || |
| 1343 | (is_nothrow_move_assignable<__pointer_allocator>::value && |
| 1344 | is_nothrow_move_assignable<__node_allocator>::value)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1345 | {__move_assign_alloc(__u, integral_constant<bool, |
| 1346 | __node_traits::propagate_on_container_move_assignment::value>());} |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1347 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1348 | void __move_assign_alloc(__hash_table& __u, true_type) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1349 | _NOEXCEPT_( |
| 1350 | is_nothrow_move_assignable<__pointer_allocator>::value && |
| 1351 | is_nothrow_move_assignable<__node_allocator>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1352 | { |
| 1353 | __bucket_list_.get_deleter().__alloc() = |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1354 | _VSTD::move(__u.__bucket_list_.get_deleter().__alloc()); |
| 1355 | __node_alloc() = _VSTD::move(__u.__node_alloc()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1356 | } |
Howard Hinnant | 43d9923 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1357 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1358 | void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {} |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1359 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1360 | |
Eric Fiselier | cd71f44 | 2017-01-07 03:01:24 +0000 | [diff] [blame] | 1361 | void __deallocate_node(__next_pointer __np) _NOEXCEPT; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1362 | __next_pointer __detach() _NOEXCEPT; |
Howard Hinnant | 307f814 | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1363 | |
Eric Fiselier | e2f2d1e | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1364 | template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map; |
| 1365 | template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1366 | }; |
| 1367 | |
| 1368 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1369 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1370 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1371 | _NOEXCEPT_( |
| 1372 | is_nothrow_default_constructible<__bucket_list>::value && |
| 1373 | is_nothrow_default_constructible<__first_node>::value && |
Eric Fiselier | e2e332a | 2015-12-16 00:53:04 +0000 | [diff] [blame] | 1374 | is_nothrow_default_constructible<__node_allocator>::value && |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1375 | is_nothrow_default_constructible<hasher>::value && |
| 1376 | is_nothrow_default_constructible<key_equal>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1377 | : __p2_(0), |
| 1378 | __p3_(1.0f) |
| 1379 | { |
| 1380 | } |
| 1381 | |
| 1382 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1383 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1384 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, |
| 1385 | const key_equal& __eql) |
| 1386 | : __bucket_list_(nullptr, __bucket_list_deleter()), |
| 1387 | __p1_(), |
| 1388 | __p2_(0, __hf), |
| 1389 | __p3_(1.0f, __eql) |
| 1390 | { |
| 1391 | } |
| 1392 | |
| 1393 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1394 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, |
| 1395 | const key_equal& __eql, |
| 1396 | const allocator_type& __a) |
| 1397 | : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), |
Eric Fiselier | c88580c | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 1398 | __p1_(__second_tag(), __node_allocator(__a)), |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1399 | __p2_(0, __hf), |
| 1400 | __p3_(1.0f, __eql) |
| 1401 | { |
| 1402 | } |
| 1403 | |
| 1404 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1405 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a) |
| 1406 | : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), |
Eric Fiselier | c88580c | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 1407 | __p1_(__second_tag(), __node_allocator(__a)), |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1408 | __p2_(0), |
| 1409 | __p3_(1.0f) |
| 1410 | { |
| 1411 | } |
| 1412 | |
| 1413 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1414 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) |
| 1415 | : __bucket_list_(nullptr, |
| 1416 | __bucket_list_deleter(allocator_traits<__pointer_allocator>:: |
| 1417 | select_on_container_copy_construction( |
| 1418 | __u.__bucket_list_.get_deleter().__alloc()), 0)), |
Eric Fiselier | c88580c | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 1419 | __p1_(__second_tag(), allocator_traits<__node_allocator>:: |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1420 | select_on_container_copy_construction(__u.__node_alloc())), |
| 1421 | __p2_(0, __u.hash_function()), |
| 1422 | __p3_(__u.__p3_) |
| 1423 | { |
| 1424 | } |
| 1425 | |
| 1426 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1427 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, |
| 1428 | const allocator_type& __a) |
| 1429 | : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), |
Eric Fiselier | c88580c | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 1430 | __p1_(__second_tag(), __node_allocator(__a)), |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1431 | __p2_(0, __u.hash_function()), |
| 1432 | __p3_(__u.__p3_) |
| 1433 | { |
| 1434 | } |
| 1435 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1436 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1437 | |
| 1438 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1439 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1440 | _NOEXCEPT_( |
| 1441 | is_nothrow_move_constructible<__bucket_list>::value && |
| 1442 | is_nothrow_move_constructible<__first_node>::value && |
Eric Fiselier | e2e332a | 2015-12-16 00:53:04 +0000 | [diff] [blame] | 1443 | is_nothrow_move_constructible<__node_allocator>::value && |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1444 | is_nothrow_move_constructible<hasher>::value && |
| 1445 | is_nothrow_move_constructible<key_equal>::value) |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1446 | : __bucket_list_(_VSTD::move(__u.__bucket_list_)), |
| 1447 | __p1_(_VSTD::move(__u.__p1_)), |
| 1448 | __p2_(_VSTD::move(__u.__p2_)), |
| 1449 | __p3_(_VSTD::move(__u.__p3_)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1450 | { |
| 1451 | if (size() > 0) |
| 1452 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1453 | __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = |
| 1454 | __p1_.first().__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1455 | __u.__p1_.first().__next_ = nullptr; |
| 1456 | __u.size() = 0; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1461 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, |
| 1462 | const allocator_type& __a) |
| 1463 | : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), |
Eric Fiselier | c88580c | 2017-04-12 23:45:53 +0000 | [diff] [blame] | 1464 | __p1_(__second_tag(), __node_allocator(__a)), |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1465 | __p2_(0, _VSTD::move(__u.hash_function())), |
| 1466 | __p3_(_VSTD::move(__u.__p3_)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1467 | { |
| 1468 | if (__a == allocator_type(__u.__node_alloc())) |
| 1469 | { |
| 1470 | __bucket_list_.reset(__u.__bucket_list_.release()); |
| 1471 | __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); |
| 1472 | __u.__bucket_list_.get_deleter().size() = 0; |
| 1473 | if (__u.size() > 0) |
| 1474 | { |
| 1475 | __p1_.first().__next_ = __u.__p1_.first().__next_; |
| 1476 | __u.__p1_.first().__next_ = nullptr; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1477 | __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = |
| 1478 | __p1_.first().__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1479 | size() = __u.size(); |
| 1480 | __u.size() = 0; |
| 1481 | } |
| 1482 | } |
| 1483 | } |
| 1484 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1485 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1486 | |
| 1487 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1488 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() |
| 1489 | { |
Eric Fiselier | acb2158 | 2017-03-01 02:02:28 +0000 | [diff] [blame] | 1490 | #if defined(_LIBCPP_CXX03_LANG) |
Marshall Clow | 3b8669e | 2016-06-30 22:05:45 +0000 | [diff] [blame] | 1491 | static_assert((is_copy_constructible<key_equal>::value), |
| 1492 | "Predicate must be copy-constructible."); |
| 1493 | static_assert((is_copy_constructible<hasher>::value), |
| 1494 | "Hasher must be copy-constructible."); |
Eric Fiselier | 04333f9 | 2017-01-13 22:42:53 +0000 | [diff] [blame] | 1495 | #endif |
Eric Fiselier | acb2158 | 2017-03-01 02:02:28 +0000 | [diff] [blame] | 1496 | |
Eric Fiselier | cd71f44 | 2017-01-07 03:01:24 +0000 | [diff] [blame] | 1497 | __deallocate_node(__p1_.first().__next_); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1498 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1499 | __get_db()->__erase_c(this); |
| 1500 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1504 | void |
| 1505 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc( |
| 1506 | const __hash_table& __u, true_type) |
| 1507 | { |
| 1508 | if (__node_alloc() != __u.__node_alloc()) |
| 1509 | { |
| 1510 | clear(); |
| 1511 | __bucket_list_.reset(); |
| 1512 | __bucket_list_.get_deleter().size() = 0; |
| 1513 | } |
| 1514 | __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc(); |
| 1515 | __node_alloc() = __u.__node_alloc(); |
| 1516 | } |
| 1517 | |
| 1518 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1519 | __hash_table<_Tp, _Hash, _Equal, _Alloc>& |
| 1520 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u) |
| 1521 | { |
| 1522 | if (this != &__u) |
| 1523 | { |
| 1524 | __copy_assign_alloc(__u); |
| 1525 | hash_function() = __u.hash_function(); |
| 1526 | key_eq() = __u.key_eq(); |
| 1527 | max_load_factor() = __u.max_load_factor(); |
| 1528 | __assign_multi(__u.begin(), __u.end()); |
| 1529 | } |
| 1530 | return *this; |
| 1531 | } |
| 1532 | |
| 1533 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1534 | void |
Eric Fiselier | cd71f44 | 2017-01-07 03:01:24 +0000 | [diff] [blame] | 1535 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1536 | _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1537 | { |
| 1538 | __node_allocator& __na = __node_alloc(); |
| 1539 | while (__np != nullptr) |
| 1540 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1541 | __next_pointer __next = __np->__next_; |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1542 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1543 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 1544 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
| 1545 | { |
| 1546 | --__p; |
| 1547 | iterator* __i = static_cast<iterator*>((*__p)->__i_); |
| 1548 | if (__i->__node_ == __np) |
| 1549 | { |
| 1550 | (*__p)->__c_ = nullptr; |
| 1551 | if (--__c->end_ != __p) |
| 1552 | memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
| 1553 | } |
| 1554 | } |
| 1555 | __get_db()->unlock(); |
| 1556 | #endif |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1557 | __node_pointer __real_np = __np->__upcast(); |
| 1558 | __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__value_)); |
| 1559 | __node_traits::deallocate(__na, __real_np, 1); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1560 | __np = __next; |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1565 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1566 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1567 | { |
| 1568 | size_type __bc = bucket_count(); |
| 1569 | for (size_type __i = 0; __i < __bc; ++__i) |
| 1570 | __bucket_list_[__i] = nullptr; |
| 1571 | size() = 0; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1572 | __next_pointer __cache = __p1_.first().__next_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1573 | __p1_.first().__next_ = nullptr; |
| 1574 | return __cache; |
| 1575 | } |
| 1576 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1577 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1578 | |
| 1579 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1580 | void |
| 1581 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( |
| 1582 | __hash_table& __u, true_type) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1583 | _NOEXCEPT_( |
| 1584 | is_nothrow_move_assignable<__node_allocator>::value && |
| 1585 | is_nothrow_move_assignable<hasher>::value && |
| 1586 | is_nothrow_move_assignable<key_equal>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1587 | { |
| 1588 | clear(); |
| 1589 | __bucket_list_.reset(__u.__bucket_list_.release()); |
| 1590 | __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); |
| 1591 | __u.__bucket_list_.get_deleter().size() = 0; |
| 1592 | __move_assign_alloc(__u); |
| 1593 | size() = __u.size(); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1594 | hash_function() = _VSTD::move(__u.hash_function()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1595 | max_load_factor() = __u.max_load_factor(); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1596 | key_eq() = _VSTD::move(__u.key_eq()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1597 | __p1_.first().__next_ = __u.__p1_.first().__next_; |
| 1598 | if (size() > 0) |
| 1599 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1600 | __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = |
| 1601 | __p1_.first().__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1602 | __u.__p1_.first().__next_ = nullptr; |
| 1603 | __u.size() = 0; |
| 1604 | } |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1605 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1606 | __get_db()->swap(this, &__u); |
| 1607 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1611 | void |
| 1612 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( |
| 1613 | __hash_table& __u, false_type) |
| 1614 | { |
| 1615 | if (__node_alloc() == __u.__node_alloc()) |
| 1616 | __move_assign(__u, true_type()); |
| 1617 | else |
| 1618 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1619 | hash_function() = _VSTD::move(__u.hash_function()); |
| 1620 | key_eq() = _VSTD::move(__u.key_eq()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1621 | max_load_factor() = __u.max_load_factor(); |
| 1622 | if (bucket_count() != 0) |
| 1623 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1624 | __next_pointer __cache = __detach(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1625 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1626 | try |
| 1627 | { |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1628 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1629 | const_iterator __i = __u.begin(); |
| 1630 | while (__cache != nullptr && __u.size() != 0) |
| 1631 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1632 | __cache->__upcast()->__value_ = |
| 1633 | _VSTD::move(__u.remove(__i++)->__value_); |
| 1634 | __next_pointer __next = __cache->__next_; |
| 1635 | __node_insert_multi(__cache->__upcast()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1636 | __cache = __next; |
| 1637 | } |
| 1638 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1639 | } |
| 1640 | catch (...) |
| 1641 | { |
Eric Fiselier | cd71f44 | 2017-01-07 03:01:24 +0000 | [diff] [blame] | 1642 | __deallocate_node(__cache); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1643 | throw; |
| 1644 | } |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1645 | #endif // _LIBCPP_NO_EXCEPTIONS |
Eric Fiselier | cd71f44 | 2017-01-07 03:01:24 +0000 | [diff] [blame] | 1646 | __deallocate_node(__cache); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1647 | } |
| 1648 | const_iterator __i = __u.begin(); |
| 1649 | while (__u.size() != 0) |
| 1650 | { |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1651 | __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1652 | __node_insert_multi(__h.get()); |
| 1653 | __h.release(); |
| 1654 | } |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1659 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1660 | __hash_table<_Tp, _Hash, _Equal, _Alloc>& |
| 1661 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u) |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1662 | _NOEXCEPT_( |
| 1663 | __node_traits::propagate_on_container_move_assignment::value && |
| 1664 | is_nothrow_move_assignable<__node_allocator>::value && |
| 1665 | is_nothrow_move_assignable<hasher>::value && |
| 1666 | is_nothrow_move_assignable<key_equal>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1667 | { |
| 1668 | __move_assign(__u, integral_constant<bool, |
| 1669 | __node_traits::propagate_on_container_move_assignment::value>()); |
| 1670 | return *this; |
| 1671 | } |
| 1672 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1673 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1674 | |
| 1675 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1676 | template <class _InputIterator> |
| 1677 | void |
| 1678 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first, |
| 1679 | _InputIterator __last) |
| 1680 | { |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1681 | typedef iterator_traits<_InputIterator> _ITraits; |
| 1682 | typedef typename _ITraits::value_type _ItValueType; |
| 1683 | static_assert((is_same<_ItValueType, __container_value_type>::value), |
| 1684 | "__assign_unique may only be called with the containers value type"); |
| 1685 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1686 | if (bucket_count() != 0) |
| 1687 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1688 | __next_pointer __cache = __detach(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1689 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1690 | try |
| 1691 | { |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1692 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1693 | for (; __cache != nullptr && __first != __last; ++__first) |
| 1694 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1695 | __cache->__upcast()->__value_ = *__first; |
| 1696 | __next_pointer __next = __cache->__next_; |
| 1697 | __node_insert_unique(__cache->__upcast()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1698 | __cache = __next; |
| 1699 | } |
| 1700 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1701 | } |
| 1702 | catch (...) |
| 1703 | { |
Eric Fiselier | cd71f44 | 2017-01-07 03:01:24 +0000 | [diff] [blame] | 1704 | __deallocate_node(__cache); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1705 | throw; |
| 1706 | } |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1707 | #endif // _LIBCPP_NO_EXCEPTIONS |
Eric Fiselier | cd71f44 | 2017-01-07 03:01:24 +0000 | [diff] [blame] | 1708 | __deallocate_node(__cache); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1709 | } |
| 1710 | for (; __first != __last; ++__first) |
| 1711 | __insert_unique(*__first); |
| 1712 | } |
| 1713 | |
| 1714 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1715 | template <class _InputIterator> |
| 1716 | void |
| 1717 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first, |
| 1718 | _InputIterator __last) |
| 1719 | { |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1720 | typedef iterator_traits<_InputIterator> _ITraits; |
| 1721 | typedef typename _ITraits::value_type _ItValueType; |
| 1722 | static_assert((is_same<_ItValueType, __container_value_type>::value || |
| 1723 | is_same<_ItValueType, __node_value_type>::value), |
| 1724 | "__assign_multi may only be called with the containers value type" |
| 1725 | " or the nodes value type"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1726 | if (bucket_count() != 0) |
| 1727 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1728 | __next_pointer __cache = __detach(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1729 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1730 | try |
| 1731 | { |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1732 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1733 | for (; __cache != nullptr && __first != __last; ++__first) |
| 1734 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1735 | __cache->__upcast()->__value_ = *__first; |
| 1736 | __next_pointer __next = __cache->__next_; |
| 1737 | __node_insert_multi(__cache->__upcast()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1738 | __cache = __next; |
| 1739 | } |
| 1740 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1741 | } |
| 1742 | catch (...) |
| 1743 | { |
Eric Fiselier | cd71f44 | 2017-01-07 03:01:24 +0000 | [diff] [blame] | 1744 | __deallocate_node(__cache); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1745 | throw; |
| 1746 | } |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1747 | #endif // _LIBCPP_NO_EXCEPTIONS |
Eric Fiselier | cd71f44 | 2017-01-07 03:01:24 +0000 | [diff] [blame] | 1748 | __deallocate_node(__cache); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1749 | } |
| 1750 | for (; __first != __last; ++__first) |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1751 | __insert_multi(_NodeTypes::__get_value(*__first)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1755 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1756 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1757 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1758 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1759 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1760 | return iterator(__p1_.first().__next_, this); |
| 1761 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1762 | return iterator(__p1_.first().__next_); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1763 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1767 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1768 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1769 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1770 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1771 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1772 | return iterator(nullptr, this); |
| 1773 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1774 | return iterator(nullptr); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1775 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1779 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1780 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1781 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1782 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1783 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1784 | return const_iterator(__p1_.first().__next_, this); |
| 1785 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1786 | return const_iterator(__p1_.first().__next_); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1787 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1791 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1792 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1793 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1794 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1795 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1796 | return const_iterator(nullptr, this); |
| 1797 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1798 | return const_iterator(nullptr); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1799 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1803 | void |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1804 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1805 | { |
| 1806 | if (size() > 0) |
| 1807 | { |
Eric Fiselier | cd71f44 | 2017-01-07 03:01:24 +0000 | [diff] [blame] | 1808 | __deallocate_node(__p1_.first().__next_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1809 | __p1_.first().__next_ = nullptr; |
| 1810 | size_type __bc = bucket_count(); |
Howard Hinnant | 1f8da84 | 2011-07-05 14:14:17 +0000 | [diff] [blame] | 1811 | for (size_type __i = 0; __i < __bc; ++__i) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1812 | __bucket_list_[__i] = nullptr; |
| 1813 | size() = 0; |
| 1814 | } |
| 1815 | } |
| 1816 | |
| 1817 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1818 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> |
| 1819 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd) |
| 1820 | { |
| 1821 | __nd->__hash_ = hash_function()(__nd->__value_); |
| 1822 | size_type __bc = bucket_count(); |
| 1823 | bool __inserted = false; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1824 | __next_pointer __ndptr; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1825 | size_t __chash; |
| 1826 | if (__bc != 0) |
| 1827 | { |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 1828 | __chash = __constrain_hash(__nd->__hash_, __bc); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1829 | __ndptr = __bucket_list_[__chash]; |
| 1830 | if (__ndptr != nullptr) |
| 1831 | { |
| 1832 | for (__ndptr = __ndptr->__next_; __ndptr != nullptr && |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1833 | __constrain_hash(__ndptr->__hash(), __bc) == __chash; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1834 | __ndptr = __ndptr->__next_) |
| 1835 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1836 | if (key_eq()(__ndptr->__upcast()->__value_, __nd->__value_)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1837 | goto __done; |
| 1838 | } |
| 1839 | } |
| 1840 | } |
| 1841 | { |
| 1842 | if (size()+1 > __bc * max_load_factor() || __bc == 0) |
| 1843 | { |
Eric Fiselier | 9ba5c11 | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 1844 | rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc), |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1845 | size_type(ceil(float(size() + 1) / max_load_factor())))); |
| 1846 | __bc = bucket_count(); |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 1847 | __chash = __constrain_hash(__nd->__hash_, __bc); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1848 | } |
| 1849 | // insert_after __bucket_list_[__chash], or __first_node if bucket is null |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1850 | __next_pointer __pn = __bucket_list_[__chash]; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1851 | if (__pn == nullptr) |
| 1852 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1853 | __pn =__p1_.first().__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1854 | __nd->__next_ = __pn->__next_; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1855 | __pn->__next_ = __nd->__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1856 | // fix up __bucket_list_ |
| 1857 | __bucket_list_[__chash] = __pn; |
| 1858 | if (__nd->__next_ != nullptr) |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1859 | __bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1860 | } |
| 1861 | else |
| 1862 | { |
| 1863 | __nd->__next_ = __pn->__next_; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1864 | __pn->__next_ = __nd->__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1865 | } |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1866 | __ndptr = __nd->__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1867 | // increment size |
| 1868 | ++size(); |
| 1869 | __inserted = true; |
| 1870 | } |
| 1871 | __done: |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1872 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1873 | return pair<iterator, bool>(iterator(__ndptr, this), __inserted); |
| 1874 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1875 | return pair<iterator, bool>(iterator(__ndptr), __inserted); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1876 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1880 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 1881 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp) |
| 1882 | { |
| 1883 | __cp->__hash_ = hash_function()(__cp->__value_); |
| 1884 | size_type __bc = bucket_count(); |
| 1885 | if (size()+1 > __bc * max_load_factor() || __bc == 0) |
| 1886 | { |
Eric Fiselier | 9ba5c11 | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 1887 | rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc), |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1888 | size_type(ceil(float(size() + 1) / max_load_factor())))); |
| 1889 | __bc = bucket_count(); |
| 1890 | } |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 1891 | size_t __chash = __constrain_hash(__cp->__hash_, __bc); |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1892 | __next_pointer __pn = __bucket_list_[__chash]; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1893 | if (__pn == nullptr) |
| 1894 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1895 | __pn =__p1_.first().__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1896 | __cp->__next_ = __pn->__next_; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1897 | __pn->__next_ = __cp->__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1898 | // fix up __bucket_list_ |
| 1899 | __bucket_list_[__chash] = __pn; |
| 1900 | if (__cp->__next_ != nullptr) |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1901 | __bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)] |
| 1902 | = __cp->__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1903 | } |
| 1904 | else |
| 1905 | { |
| 1906 | for (bool __found = false; __pn->__next_ != nullptr && |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1907 | __constrain_hash(__pn->__next_->__hash(), __bc) == __chash; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1908 | __pn = __pn->__next_) |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1909 | { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1910 | // __found key_eq() action |
| 1911 | // false false loop |
| 1912 | // true true loop |
| 1913 | // false true set __found to true |
| 1914 | // true false break |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1915 | if (__found != (__pn->__next_->__hash() == __cp->__hash_ && |
| 1916 | key_eq()(__pn->__next_->__upcast()->__value_, __cp->__value_))) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1917 | { |
| 1918 | if (!__found) |
| 1919 | __found = true; |
| 1920 | else |
| 1921 | break; |
| 1922 | } |
| 1923 | } |
| 1924 | __cp->__next_ = __pn->__next_; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1925 | __pn->__next_ = __cp->__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1926 | if (__cp->__next_ != nullptr) |
| 1927 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1928 | size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1929 | if (__nhash != __chash) |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1930 | __bucket_list_[__nhash] = __cp->__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1931 | } |
| 1932 | } |
| 1933 | ++size(); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1934 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1935 | return iterator(__cp->__ptr(), this); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1936 | #else |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1937 | return iterator(__cp->__ptr()); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1938 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1942 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 1943 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( |
| 1944 | const_iterator __p, __node_pointer __cp) |
| 1945 | { |
Howard Hinnant | 2f51de5 | 2013-08-02 17:50:49 +0000 | [diff] [blame] | 1946 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1947 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1948 | "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" |
| 1949 | " referring to this unordered container"); |
| 1950 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1951 | if (__p != end() && key_eq()(*__p, __cp->__value_)) |
| 1952 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1953 | __next_pointer __np = __p.__node_; |
| 1954 | __cp->__hash_ = __np->__hash(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1955 | size_type __bc = bucket_count(); |
| 1956 | if (size()+1 > __bc * max_load_factor() || __bc == 0) |
| 1957 | { |
Eric Fiselier | 9ba5c11 | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 1958 | rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc), |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1959 | size_type(ceil(float(size() + 1) / max_load_factor())))); |
| 1960 | __bc = bucket_count(); |
| 1961 | } |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 1962 | size_t __chash = __constrain_hash(__cp->__hash_, __bc); |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1963 | __next_pointer __pp = __bucket_list_[__chash]; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1964 | while (__pp->__next_ != __np) |
| 1965 | __pp = __pp->__next_; |
| 1966 | __cp->__next_ = __np; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1967 | __pp->__next_ = static_cast<__next_pointer>(__cp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1968 | ++size(); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1969 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1970 | return iterator(static_cast<__next_pointer>(__cp), this); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1971 | #else |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1972 | return iterator(static_cast<__next_pointer>(__cp)); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1973 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1974 | } |
| 1975 | return __node_insert_multi(__cp); |
| 1976 | } |
| 1977 | |
Eric Fiselier | de3f2b3 | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1978 | |
| 1979 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1980 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | de3f2b3 | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1981 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1982 | template <class _Key, class ..._Args> |
Eric Fiselier | de3f2b3 | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1983 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1984 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) |
Eric Fiselier | de3f2b3 | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1985 | #else |
| 1986 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1987 | template <class _Key, class _Args> |
Eric Fiselier | de3f2b3 | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1988 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1989 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args) |
Eric Fiselier | de3f2b3 | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1990 | #endif |
| 1991 | { |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1992 | |
| 1993 | size_t __hash = hash_function()(__k); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1994 | size_type __bc = bucket_count(); |
| 1995 | bool __inserted = false; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1996 | __next_pointer __nd; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1997 | size_t __chash; |
| 1998 | if (__bc != 0) |
| 1999 | { |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 2000 | __chash = __constrain_hash(__hash, __bc); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2001 | __nd = __bucket_list_[__chash]; |
| 2002 | if (__nd != nullptr) |
| 2003 | { |
| 2004 | for (__nd = __nd->__next_; __nd != nullptr && |
Eric Fiselier | 1a06fe5 | 2016-07-24 06:22:25 +0000 | [diff] [blame] | 2005 | (__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2006 | __nd = __nd->__next_) |
| 2007 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2008 | if (key_eq()(__nd->__upcast()->__value_, __k)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2009 | goto __done; |
| 2010 | } |
| 2011 | } |
| 2012 | } |
| 2013 | { |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2014 | #ifndef _LIBCPP_CXX03_LANG |
| 2015 | __node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...); |
| 2016 | #else |
| 2017 | __node_holder __h = __construct_node_hash(__hash, __args); |
| 2018 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2019 | if (size()+1 > __bc * max_load_factor() || __bc == 0) |
| 2020 | { |
Eric Fiselier | 9ba5c11 | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 2021 | rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc), |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2022 | size_type(ceil(float(size() + 1) / max_load_factor())))); |
| 2023 | __bc = bucket_count(); |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 2024 | __chash = __constrain_hash(__hash, __bc); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2025 | } |
| 2026 | // insert_after __bucket_list_[__chash], or __first_node if bucket is null |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2027 | __next_pointer __pn = __bucket_list_[__chash]; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2028 | if (__pn == nullptr) |
| 2029 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2030 | __pn = __p1_.first().__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2031 | __h->__next_ = __pn->__next_; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2032 | __pn->__next_ = __h.get()->__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2033 | // fix up __bucket_list_ |
| 2034 | __bucket_list_[__chash] = __pn; |
| 2035 | if (__h->__next_ != nullptr) |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2036 | __bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)] |
| 2037 | = __h.get()->__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2038 | } |
| 2039 | else |
| 2040 | { |
| 2041 | __h->__next_ = __pn->__next_; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2042 | __pn->__next_ = static_cast<__next_pointer>(__h.get()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2043 | } |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2044 | __nd = static_cast<__next_pointer>(__h.release()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2045 | // increment size |
| 2046 | ++size(); |
| 2047 | __inserted = true; |
| 2048 | } |
| 2049 | __done: |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2050 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2051 | return pair<iterator, bool>(iterator(__nd, this), __inserted); |
| 2052 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2053 | return pair<iterator, bool>(iterator(__nd), __inserted); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2054 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2057 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2058 | |
| 2059 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2060 | template <class... _Args> |
| 2061 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> |
Duncan P. N. Exon Smith | fde79b4 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 2062 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2063 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2064 | __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2065 | pair<iterator, bool> __r = __node_insert_unique(__h.get()); |
| 2066 | if (__r.second) |
| 2067 | __h.release(); |
| 2068 | return __r; |
| 2069 | } |
| 2070 | |
| 2071 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2072 | template <class... _Args> |
| 2073 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 2074 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args) |
| 2075 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2076 | __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2077 | iterator __r = __node_insert_multi(__h.get()); |
| 2078 | __h.release(); |
| 2079 | return __r; |
| 2080 | } |
| 2081 | |
| 2082 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2083 | template <class... _Args> |
| 2084 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 2085 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi( |
| 2086 | const_iterator __p, _Args&&... __args) |
| 2087 | { |
Howard Hinnant | e5c13de | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 2088 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2089 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 2090 | "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" |
| 2091 | " referring to this unordered container"); |
| 2092 | #endif |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2093 | __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2094 | iterator __r = __node_insert_multi(__p, __h.get()); |
| 2095 | __h.release(); |
| 2096 | return __r; |
| 2097 | } |
| 2098 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2099 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2100 | |
| 2101 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2102 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2103 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const __container_value_type& __x) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2104 | { |
| 2105 | __node_holder __h = __construct_node(__x); |
| 2106 | iterator __r = __node_insert_multi(__h.get()); |
| 2107 | __h.release(); |
| 2108 | return __r; |
| 2109 | } |
| 2110 | |
| 2111 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2112 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 2113 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p, |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2114 | const __container_value_type& __x) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2115 | { |
Howard Hinnant | e5c13de | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 2116 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2117 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 2118 | "unordered container::insert(const_iterator, lvalue) called with an iterator not" |
| 2119 | " referring to this unordered container"); |
| 2120 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2121 | __node_holder __h = __construct_node(__x); |
| 2122 | iterator __r = __node_insert_multi(__p, __h.get()); |
| 2123 | __h.release(); |
| 2124 | return __r; |
| 2125 | } |
| 2126 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2127 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2128 | |
| 2129 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2130 | void |
| 2131 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n) |
| 2132 | { |
Dan Albert | 553b09b | 2018-01-08 22:57:12 +0000 | [diff] [blame] | 2133 | if (__n == 1) |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 2134 | __n = 2; |
| 2135 | else if (__n & (__n - 1)) |
| 2136 | __n = __next_prime(__n); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2137 | size_type __bc = bucket_count(); |
| 2138 | if (__n > __bc) |
| 2139 | __rehash(__n); |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 2140 | else if (__n < __bc) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2141 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2142 | __n = _VSTD::max<size_type> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2143 | ( |
| 2144 | __n, |
Eric Fiselier | 9ba5c11 | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 2145 | __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) : |
| 2146 | __next_prime(size_t(ceil(float(size()) / max_load_factor()))) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2147 | ); |
| 2148 | if (__n < __bc) |
| 2149 | __rehash(__n); |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2154 | void |
| 2155 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc) |
| 2156 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2157 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2158 | __get_db()->__invalidate_all(this); |
| 2159 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2160 | __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc(); |
| 2161 | __bucket_list_.reset(__nbc > 0 ? |
| 2162 | __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr); |
| 2163 | __bucket_list_.get_deleter().size() = __nbc; |
| 2164 | if (__nbc > 0) |
| 2165 | { |
| 2166 | for (size_type __i = 0; __i < __nbc; ++__i) |
| 2167 | __bucket_list_[__i] = nullptr; |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2168 | __next_pointer __pp = __p1_.first().__ptr(); |
| 2169 | __next_pointer __cp = __pp->__next_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2170 | if (__cp != nullptr) |
| 2171 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2172 | size_type __chash = __constrain_hash(__cp->__hash(), __nbc); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2173 | __bucket_list_[__chash] = __pp; |
| 2174 | size_type __phash = __chash; |
| 2175 | for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr; |
| 2176 | __cp = __pp->__next_) |
| 2177 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2178 | __chash = __constrain_hash(__cp->__hash(), __nbc); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2179 | if (__chash == __phash) |
| 2180 | __pp = __cp; |
| 2181 | else |
| 2182 | { |
| 2183 | if (__bucket_list_[__chash] == nullptr) |
| 2184 | { |
| 2185 | __bucket_list_[__chash] = __pp; |
| 2186 | __pp = __cp; |
| 2187 | __phash = __chash; |
| 2188 | } |
| 2189 | else |
| 2190 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2191 | __next_pointer __np = __cp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2192 | for (; __np->__next_ != nullptr && |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2193 | key_eq()(__cp->__upcast()->__value_, |
| 2194 | __np->__next_->__upcast()->__value_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2195 | __np = __np->__next_) |
| 2196 | ; |
| 2197 | __pp->__next_ = __np->__next_; |
| 2198 | __np->__next_ = __bucket_list_[__chash]->__next_; |
| 2199 | __bucket_list_[__chash]->__next_ = __cp; |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2200 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2201 | } |
| 2202 | } |
| 2203 | } |
| 2204 | } |
| 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2209 | template <class _Key> |
| 2210 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 2211 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) |
| 2212 | { |
| 2213 | size_t __hash = hash_function()(__k); |
| 2214 | size_type __bc = bucket_count(); |
| 2215 | if (__bc != 0) |
| 2216 | { |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 2217 | size_t __chash = __constrain_hash(__hash, __bc); |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2218 | __next_pointer __nd = __bucket_list_[__chash]; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2219 | if (__nd != nullptr) |
| 2220 | { |
| 2221 | for (__nd = __nd->__next_; __nd != nullptr && |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2222 | (__nd->__hash() == __hash |
| 2223 | || __constrain_hash(__nd->__hash(), __bc) == __chash); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2224 | __nd = __nd->__next_) |
| 2225 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2226 | if ((__nd->__hash() == __hash) |
| 2227 | && key_eq()(__nd->__upcast()->__value_, __k)) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2228 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2229 | return iterator(__nd, this); |
| 2230 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2231 | return iterator(__nd); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2232 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2233 | } |
| 2234 | } |
| 2235 | } |
| 2236 | return end(); |
| 2237 | } |
| 2238 | |
| 2239 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2240 | template <class _Key> |
| 2241 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator |
| 2242 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const |
| 2243 | { |
| 2244 | size_t __hash = hash_function()(__k); |
| 2245 | size_type __bc = bucket_count(); |
| 2246 | if (__bc != 0) |
| 2247 | { |
Howard Hinnant | 4cb38a8 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 2248 | size_t __chash = __constrain_hash(__hash, __bc); |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2249 | __next_pointer __nd = __bucket_list_[__chash]; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2250 | if (__nd != nullptr) |
| 2251 | { |
| 2252 | for (__nd = __nd->__next_; __nd != nullptr && |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2253 | (__hash == __nd->__hash() |
| 2254 | || __constrain_hash(__nd->__hash(), __bc) == __chash); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2255 | __nd = __nd->__next_) |
| 2256 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2257 | if ((__nd->__hash() == __hash) |
| 2258 | && key_eq()(__nd->__upcast()->__value_, __k)) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2259 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2260 | return const_iterator(__nd, this); |
| 2261 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2262 | return const_iterator(__nd); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2263 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2264 | } |
| 2265 | } |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2266 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2267 | } |
| 2268 | return end(); |
| 2269 | } |
| 2270 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2271 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2272 | |
| 2273 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2274 | template <class ..._Args> |
| 2275 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder |
| 2276 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args) |
| 2277 | { |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2278 | static_assert(!__is_hash_value_type<_Args...>::value, |
| 2279 | "Construct cannot be called with a hash value type"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2280 | __node_allocator& __na = __node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2281 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2282 | __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2283 | __h.get_deleter().__value_constructed = true; |
| 2284 | __h->__hash_ = hash_function()(__h->__value_); |
| 2285 | __h->__next_ = nullptr; |
| 2286 | return __h; |
| 2287 | } |
| 2288 | |
| 2289 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2290 | template <class _First, class ..._Rest> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2291 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2292 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash( |
| 2293 | size_t __hash, _First&& __f, _Rest&& ...__rest) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2294 | { |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2295 | static_assert(!__is_hash_value_type<_First, _Rest...>::value, |
| 2296 | "Construct cannot be called with a hash value type"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2297 | __node_allocator& __na = __node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2298 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2299 | __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), |
| 2300 | _VSTD::forward<_First>(__f), |
| 2301 | _VSTD::forward<_Rest>(__rest)...); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2302 | __h.get_deleter().__value_constructed = true; |
| 2303 | __h->__hash_ = __hash; |
| 2304 | __h->__next_ = nullptr; |
Howard Hinnant | 179b1f8 | 2013-08-22 18:29:50 +0000 | [diff] [blame] | 2305 | return __h; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2306 | } |
| 2307 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2308 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2309 | |
| 2310 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2311 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2312 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const __container_value_type& __v) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2313 | { |
| 2314 | __node_allocator& __na = __node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2315 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2316 | __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2317 | __h.get_deleter().__value_constructed = true; |
| 2318 | __h->__hash_ = hash_function()(__h->__value_); |
| 2319 | __h->__next_ = nullptr; |
Dimitry Andric | 251c629 | 2015-08-19 06:43:33 +0000 | [diff] [blame] | 2320 | return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2323 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2324 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2325 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash, |
| 2326 | const __container_value_type& __v) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2327 | { |
| 2328 | __node_allocator& __na = __node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2329 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2330 | __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2331 | __h.get_deleter().__value_constructed = true; |
| 2332 | __h->__hash_ = __hash; |
| 2333 | __h->__next_ = nullptr; |
Dimitry Andric | 251c629 | 2015-08-19 06:43:33 +0000 | [diff] [blame] | 2334 | return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2337 | #endif // _LIBCPP_CXX03_LANG |
| 2338 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2339 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2340 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 2341 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p) |
| 2342 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2343 | __next_pointer __np = __p.__node_; |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2344 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2345 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 2346 | "unordered container erase(iterator) called with an iterator not" |
| 2347 | " referring to this container"); |
| 2348 | _LIBCPP_ASSERT(__p != end(), |
| 2349 | "unordered container erase(iterator) called with a non-dereferenceable iterator"); |
| 2350 | iterator __r(__np, this); |
| 2351 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2352 | iterator __r(__np); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2353 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2354 | ++__r; |
| 2355 | remove(__p); |
| 2356 | return __r; |
| 2357 | } |
| 2358 | |
| 2359 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2360 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 2361 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, |
| 2362 | const_iterator __last) |
| 2363 | { |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2364 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2365 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, |
| 2366 | "unodered container::erase(iterator, iterator) called with an iterator not" |
| 2367 | " referring to this unodered container"); |
| 2368 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, |
| 2369 | "unodered container::erase(iterator, iterator) called with an iterator not" |
| 2370 | " referring to this unodered container"); |
| 2371 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2372 | for (const_iterator __p = __first; __first != __last; __p = __first) |
| 2373 | { |
| 2374 | ++__first; |
| 2375 | erase(__p); |
| 2376 | } |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2377 | __next_pointer __np = __last.__node_; |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2378 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2379 | return iterator (__np, this); |
| 2380 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2381 | return iterator (__np); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2382 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2386 | template <class _Key> |
| 2387 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type |
| 2388 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k) |
| 2389 | { |
| 2390 | iterator __i = find(__k); |
| 2391 | if (__i == end()) |
| 2392 | return 0; |
| 2393 | erase(__i); |
| 2394 | return 1; |
| 2395 | } |
| 2396 | |
| 2397 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2398 | template <class _Key> |
| 2399 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type |
| 2400 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k) |
| 2401 | { |
| 2402 | size_type __r = 0; |
| 2403 | iterator __i = find(__k); |
| 2404 | if (__i != end()) |
| 2405 | { |
| 2406 | iterator __e = end(); |
| 2407 | do |
| 2408 | { |
| 2409 | erase(__i++); |
| 2410 | ++__r; |
| 2411 | } while (__i != __e && key_eq()(*__i, __k)); |
| 2412 | } |
| 2413 | return __r; |
| 2414 | } |
| 2415 | |
| 2416 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2417 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 2418 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2419 | { |
| 2420 | // current node |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2421 | __next_pointer __cn = __p.__node_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2422 | size_type __bc = bucket_count(); |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2423 | size_t __chash = __constrain_hash(__cn->__hash(), __bc); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2424 | // find previous node |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2425 | __next_pointer __pn = __bucket_list_[__chash]; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2426 | for (; __pn->__next_ != __cn; __pn = __pn->__next_) |
| 2427 | ; |
| 2428 | // Fix up __bucket_list_ |
| 2429 | // if __pn is not in same bucket (before begin is not in same bucket) && |
| 2430 | // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2431 | if (__pn == __p1_.first().__ptr() |
| 2432 | || __constrain_hash(__pn->__hash(), __bc) != __chash) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2433 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2434 | if (__cn->__next_ == nullptr |
| 2435 | || __constrain_hash(__cn->__next_->__hash(), __bc) != __chash) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2436 | __bucket_list_[__chash] = nullptr; |
| 2437 | } |
| 2438 | // if __cn->__next_ is not in same bucket (nullptr is in same bucket) |
| 2439 | if (__cn->__next_ != nullptr) |
| 2440 | { |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2441 | size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2442 | if (__nhash != __chash) |
| 2443 | __bucket_list_[__nhash] = __pn; |
| 2444 | } |
| 2445 | // remove __cn |
| 2446 | __pn->__next_ = __cn->__next_; |
| 2447 | __cn->__next_ = nullptr; |
| 2448 | --size(); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2449 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2450 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
Eric Fiselier | 780b51d | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 2451 | for (__i_node** __dp = __c->end_; __dp != __c->beg_; ) |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2452 | { |
Eric Fiselier | 780b51d | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 2453 | --__dp; |
| 2454 | iterator* __i = static_cast<iterator*>((*__dp)->__i_); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2455 | if (__i->__node_ == __cn) |
| 2456 | { |
Eric Fiselier | 780b51d | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 2457 | (*__dp)->__c_ = nullptr; |
| 2458 | if (--__c->end_ != __dp) |
| 2459 | memmove(__dp, __dp+1, (__c->end_ - __dp)*sizeof(__i_node*)); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2460 | } |
| 2461 | } |
| 2462 | __get_db()->unlock(); |
| 2463 | #endif |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2464 | return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2468 | template <class _Key> |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 2469 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2470 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type |
| 2471 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const |
| 2472 | { |
| 2473 | return static_cast<size_type>(find(__k) != end()); |
| 2474 | } |
| 2475 | |
| 2476 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2477 | template <class _Key> |
| 2478 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type |
| 2479 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const |
| 2480 | { |
| 2481 | size_type __r = 0; |
| 2482 | const_iterator __i = find(__k); |
| 2483 | if (__i != end()) |
| 2484 | { |
| 2485 | const_iterator __e = end(); |
| 2486 | do |
| 2487 | { |
| 2488 | ++__i; |
| 2489 | ++__r; |
| 2490 | } while (__i != __e && key_eq()(*__i, __k)); |
| 2491 | } |
| 2492 | return __r; |
| 2493 | } |
| 2494 | |
| 2495 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2496 | template <class _Key> |
| 2497 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, |
| 2498 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> |
| 2499 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( |
| 2500 | const _Key& __k) |
| 2501 | { |
| 2502 | iterator __i = find(__k); |
| 2503 | iterator __j = __i; |
| 2504 | if (__i != end()) |
| 2505 | ++__j; |
| 2506 | return pair<iterator, iterator>(__i, __j); |
| 2507 | } |
| 2508 | |
| 2509 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2510 | template <class _Key> |
| 2511 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator, |
| 2512 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> |
| 2513 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( |
| 2514 | const _Key& __k) const |
| 2515 | { |
| 2516 | const_iterator __i = find(__k); |
| 2517 | const_iterator __j = __i; |
| 2518 | if (__i != end()) |
| 2519 | ++__j; |
| 2520 | return pair<const_iterator, const_iterator>(__i, __j); |
| 2521 | } |
| 2522 | |
| 2523 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2524 | template <class _Key> |
| 2525 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, |
| 2526 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> |
| 2527 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( |
| 2528 | const _Key& __k) |
| 2529 | { |
| 2530 | iterator __i = find(__k); |
| 2531 | iterator __j = __i; |
| 2532 | if (__i != end()) |
| 2533 | { |
| 2534 | iterator __e = end(); |
| 2535 | do |
| 2536 | { |
| 2537 | ++__j; |
| 2538 | } while (__j != __e && key_eq()(*__j, __k)); |
| 2539 | } |
| 2540 | return pair<iterator, iterator>(__i, __j); |
| 2541 | } |
| 2542 | |
| 2543 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2544 | template <class _Key> |
| 2545 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator, |
| 2546 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> |
| 2547 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( |
| 2548 | const _Key& __k) const |
| 2549 | { |
| 2550 | const_iterator __i = find(__k); |
| 2551 | const_iterator __j = __i; |
| 2552 | if (__i != end()) |
| 2553 | { |
| 2554 | const_iterator __e = end(); |
| 2555 | do |
| 2556 | { |
| 2557 | ++__j; |
| 2558 | } while (__j != __e && key_eq()(*__j, __k)); |
| 2559 | } |
| 2560 | return pair<const_iterator, const_iterator>(__i, __j); |
| 2561 | } |
| 2562 | |
| 2563 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2564 | void |
| 2565 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) |
Eric Fiselier | 87a8249 | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 2566 | #if _LIBCPP_STD_VER <= 11 |
Eric Fiselier | 780b51d | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 2567 | _NOEXCEPT_DEBUG_( |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2568 | __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2569 | && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value |
| 2570 | || __is_nothrow_swappable<__pointer_allocator>::value) |
| 2571 | && (!__node_traits::propagate_on_container_swap::value |
| 2572 | || __is_nothrow_swappable<__node_allocator>::value) |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2573 | ) |
Eric Fiselier | 87a8249 | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 2574 | #else |
Eric Fiselier | 780b51d | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 2575 | _NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value) |
Eric Fiselier | 87a8249 | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 2576 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2577 | { |
Eric Fiselier | 780b51d | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 2578 | _LIBCPP_ASSERT(__node_traits::propagate_on_container_swap::value || |
| 2579 | this->__node_alloc() == __u.__node_alloc(), |
| 2580 | "list::swap: Either propagate_on_container_swap must be true" |
| 2581 | " or the allocators must compare equal"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2582 | { |
| 2583 | __node_pointer_pointer __npp = __bucket_list_.release(); |
| 2584 | __bucket_list_.reset(__u.__bucket_list_.release()); |
| 2585 | __u.__bucket_list_.reset(__npp); |
| 2586 | } |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2587 | _VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size()); |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2588 | __swap_allocator(__bucket_list_.get_deleter().__alloc(), |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2589 | __u.__bucket_list_.get_deleter().__alloc()); |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2590 | __swap_allocator(__node_alloc(), __u.__node_alloc()); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2591 | _VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2592 | __p2_.swap(__u.__p2_); |
| 2593 | __p3_.swap(__u.__p3_); |
| 2594 | if (size() > 0) |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2595 | __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = |
| 2596 | __p1_.first().__ptr(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2597 | if (__u.size() > 0) |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2598 | __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = |
| 2599 | __u.__p1_.first().__ptr(); |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2600 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2601 | __get_db()->swap(this, &__u); |
| 2602 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2606 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type |
| 2607 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const |
| 2608 | { |
Howard Hinnant | e5c13de | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 2609 | _LIBCPP_ASSERT(__n < bucket_count(), |
| 2610 | "unordered container::bucket_size(n) called with n >= bucket_count()"); |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2611 | __next_pointer __np = __bucket_list_[__n]; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2612 | size_type __bc = bucket_count(); |
| 2613 | size_type __r = 0; |
| 2614 | if (__np != nullptr) |
| 2615 | { |
| 2616 | for (__np = __np->__next_; __np != nullptr && |
Eric Fiselier | 40492ba | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2617 | __constrain_hash(__np->__hash(), __bc) == __n; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2618 | __np = __np->__next_, ++__r) |
| 2619 | ; |
| 2620 | } |
| 2621 | return __r; |
| 2622 | } |
| 2623 | |
Howard Hinnant | 3714107 | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 2624 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2625 | inline _LIBCPP_INLINE_VISIBILITY |
| 2626 | void |
| 2627 | swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x, |
| 2628 | __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y) |
| 2629 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
| 2630 | { |
| 2631 | __x.swap(__y); |
| 2632 | } |
| 2633 | |
Howard Hinnant | b24c802 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2634 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2635 | |
| 2636 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2637 | bool |
| 2638 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const |
| 2639 | { |
| 2640 | return __i->__node_ != nullptr; |
| 2641 | } |
| 2642 | |
| 2643 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2644 | bool |
| 2645 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const |
| 2646 | { |
| 2647 | return false; |
| 2648 | } |
| 2649 | |
| 2650 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2651 | bool |
| 2652 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const |
| 2653 | { |
| 2654 | return false; |
| 2655 | } |
| 2656 | |
| 2657 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2658 | bool |
| 2659 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const |
| 2660 | { |
| 2661 | return false; |
| 2662 | } |
| 2663 | |
| 2664 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | a016efb | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 2665 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2666 | _LIBCPP_END_NAMESPACE_STD |
| 2667 | |
Eric Fiselier | a016efb | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 2668 | _LIBCPP_POP_MACROS |
| 2669 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2670 | #endif // _LIBCPP__HASH_TABLE |