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