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