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