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