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