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