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