Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP__HASH_TABLE |
| 12 | #define _LIBCPP__HASH_TABLE |
| 13 | |
| 14 | #include <__config> |
| 15 | #include <initializer_list> |
| 16 | #include <memory> |
| 17 | #include <iterator> |
| 18 | #include <algorithm> |
| 19 | #include <cmath> |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 20 | #include <utility> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | |
Howard Hinnant | 66c6f97 | 2011-11-29 16:45:27 +0000 | [diff] [blame] | 22 | #include <__undef_min_max> |
Saleem Abdulrasool | f1b30c4 | 2015-02-13 22:15:32 +0000 | [diff] [blame] | 23 | #include <__undef___deallocate> |
Howard Hinnant | 66c6f97 | 2011-11-29 16:45:27 +0000 | [diff] [blame] | 24 | |
Eric Fiselier | b953610 | 2014-08-10 23:53:08 +0000 | [diff] [blame] | 25 | #include <__debug> |
Howard Hinnant | 8b00e6c | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 26 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 27 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 28 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 29 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 30 | |
| 31 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 32 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 33 | |
| 34 | #ifndef _LIBCPP_CXX03_LANG |
| 35 | template <class _Key, class _Tp> |
| 36 | union __hash_value_type; |
| 37 | #else |
| 38 | template <class _Key, class _Tp> |
| 39 | struct __hash_value_type; |
| 40 | #endif |
| 41 | |
| 42 | #ifndef _LIBCPP_CXX03_LANG |
| 43 | template <class _Tp> |
| 44 | struct __is_hash_value_type_imp : false_type {}; |
| 45 | |
| 46 | template <class _Key, class _Value> |
| 47 | struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {}; |
| 48 | |
| 49 | template <class ..._Args> |
| 50 | struct __is_hash_value_type : false_type {}; |
| 51 | |
| 52 | template <class _One> |
| 53 | struct __is_hash_value_type<_One> : __is_hash_value_type_imp<typename __uncvref<_One>::type> {}; |
| 54 | #endif |
| 55 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 56 | _LIBCPP_FUNC_VIS |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 57 | size_t __next_prime(size_t __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 58 | |
| 59 | template <class _NodePtr> |
| 60 | struct __hash_node_base |
| 61 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 62 | typedef typename pointer_traits<_NodePtr>::element_type __node_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 63 | typedef __hash_node_base __first_node; |
Eric Fiselier | f653588 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 | |
Eric Fiselier | f653588 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 94 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 95 | _LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {} |
Howard Hinnant | bc8d3f9 | 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 | 5cf84e0 | 2015-12-30 21:52:00 +0000 | [diff] [blame] | 102 | typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 103 | > |
| 104 | { |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 105 | typedef _Tp __node_value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 106 | |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 107 | size_t __hash_; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 108 | __node_value_type __value_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 111 | inline _LIBCPP_INLINE_VISIBILITY |
| 112 | bool |
Eric Fiselier | 57947ca | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 113 | __is_hash_power2(size_t __bc) |
Howard Hinnant | 7a44515 | 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 | 5766391 | 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 | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | inline _LIBCPP_INLINE_VISIBILITY |
| 127 | size_t |
Eric Fiselier | 57947ca | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 128 | __next_hash_pow2(size_t __n) |
Howard Hinnant | 7a44515 | 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 | 798ec84 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 133 | |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 134 | template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 135 | |
| 136 | template <class _NodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_iterator; |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 137 | template <class _ConstNodePtr> class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; |
Eric Fiselier | 774c7c5 | 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 | 0f678bd | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 142 | |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 143 | template <class _Tp> |
Eric Fiselier | 66e344f | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 144 | struct __hash_key_value_types { |
Eric Fiselier | 774c7c5 | 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 | 2960ae2 | 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 | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | template <class _Key, class _Tp> |
Eric Fiselier | 66e344f | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 172 | struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > { |
Eric Fiselier | 774c7c5 | 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 | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 177 | typedef pair<_Key, _Tp> __nc_value_type; |
Eric Fiselier | 774c7c5 | 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 | 2960ae2 | 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 | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 213 | }; |
| 214 | |
Eric Fiselier | 66e344f | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 215 | template <class _Tp, class _AllocPtr, class _KVTypes = __hash_key_value_types<_Tp>, |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 216 | bool = _KVTypes::__is_map> |
Eric Fiselier | 66e344f | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 217 | struct __hash_map_pointer_types {}; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 218 | |
| 219 | template <class _Tp, class _AllocPtr, class _KVTypes> |
Eric Fiselier | 66e344f | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 220 | struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { |
Eric Fiselier | 774c7c5 | 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 | 66e344f | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 233 | : public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr> |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 234 | |
| 235 | { |
Eric Fiselier | 66e344f | 2016-02-20 07:59:16 +0000 | [diff] [blame] | 236 | typedef __hash_key_value_types<_Tp> __base; |
Eric Fiselier | 774c7c5 | 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 | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 251 | typedef typename __node_base_type::__next_pointer __next_pointer; |
| 252 | |
Eric Fiselier | 774c7c5 | 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 | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 258 | |
Eric Fiselier | 774c7c5 | 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 | 774c7c5 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 287 | template <class _NodePtr> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 288 | class _LIBCPP_TYPE_VIS_ONLY __hash_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 289 | { |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 290 | typedef __hash_node_types<_NodePtr> _NodeTypes; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 291 | typedef _NodePtr __node_pointer; |
| 292 | typedef typename _NodeTypes::__next_pointer __next_pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 293 | |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 294 | __next_pointer __node_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 295 | |
| 296 | public: |
Eric Fiselier | 774c7c5 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 302 | |
Eric Fiselier | f653588 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 308 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3921364 | 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 | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 315 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3921364 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 331 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 332 | |
| 333 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 339 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 340 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 350 | "Attempted to increment non-incrementable unordered container iterator"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 351 | __node_ = __node_->__next_; |
| 352 | return *this; |
| 353 | } |
| 354 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 355 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 356 | __hash_iterator operator++(int) |
| 357 | { |
| 358 | __hash_iterator __t(*this); |
| 359 | ++(*this); |
| 360 | return __t; |
| 361 | } |
| 362 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 363 | friend _LIBCPP_INLINE_VISIBILITY |
| 364 | bool operator==(const __hash_iterator& __x, const __hash_iterator& __y) |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 365 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 366 | return __x.__node_ == __y.__node_; |
| 367 | } |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 368 | friend _LIBCPP_INLINE_VISIBILITY |
| 369 | bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y) |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 370 | {return !(__x == __y);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 371 | |
| 372 | private: |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 373 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 374 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 375 | __hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT |
Howard Hinnant | 3921364 | 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 | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 381 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 382 | __hash_iterator(__next_pointer __node) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 383 | : __node_(__node) |
| 384 | {} |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 385 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 386 | template <class, class, class, class> friend class __hash_table; |
Howard Hinnant | 0f678bd | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 391 | }; |
| 392 | |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 393 | template <class _NodePtr> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 394 | class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 395 | { |
Eric Fiselier | 774c7c5 | 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 | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 398 | typedef _NodePtr __node_pointer; |
| 399 | typedef typename _NodeTypes::__next_pointer __next_pointer; |
Eric Fiselier | 0493d02 | 2016-02-18 00:20:34 +0000 | [diff] [blame] | 400 | |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 401 | __next_pointer __node_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 402 | |
| 403 | public: |
Eric Fiselier | 0493d02 | 2016-02-18 00:20:34 +0000 | [diff] [blame] | 404 | typedef __hash_iterator<_NodePtr> __non_const_iterator; |
| 405 | |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 406 | typedef forward_iterator_tag iterator_category; |
| 407 | typedef typename _NodeTypes::__node_value_type value_type; |
| 408 | typedef typename _NodeTypes::difference_type difference_type; |
| 409 | typedef const value_type& reference; |
| 410 | typedef typename _NodeTypes::__const_node_value_type_pointer pointer; |
| 411 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 412 | |
Eric Fiselier | f653588 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 415 | } |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 416 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 417 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 418 | __hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 419 | : __node_(__x.__node_) |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 420 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 421 | _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 425 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3921364 | 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 | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 432 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3921364 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 448 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 449 | |
| 450 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 451 | reference operator*() const { |
| 452 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 453 | "Attempted to dereference a non-dereferenceable unordered container const_iterator"); |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 454 | return __node_->__upcast()->__value_; |
| 455 | } |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 456 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 457 | pointer operator->() const { |
| 458 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 459 | "Attempted to dereference a non-dereferenceable unordered container const_iterator"); |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 460 | return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_); |
| 461 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 462 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 463 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 467 | __node_ = __node_->__next_; |
| 468 | return *this; |
| 469 | } |
| 470 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 471 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 99acc50 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 481 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 482 | return __x.__node_ == __y.__node_; |
| 483 | } |
Howard Hinnant | 99acc50 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 486 | {return !(__x == __y);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 487 | |
| 488 | private: |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 489 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 490 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 491 | __hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT |
Howard Hinnant | 3921364 | 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 | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 497 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 498 | __hash_const_iterator(__next_pointer __node) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 499 | : __node_(__node) |
| 500 | {} |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 501 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 502 | template <class, class, class, class> friend class __hash_table; |
Howard Hinnant | 0f678bd | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 506 | }; |
| 507 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 508 | template <class _NodePtr> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 509 | class _LIBCPP_TYPE_VIS_ONLY __hash_local_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | { |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 511 | typedef __hash_node_types<_NodePtr> _NodeTypes; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 512 | typedef _NodePtr __node_pointer; |
| 513 | typedef typename _NodeTypes::__next_pointer __next_pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 514 | |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 515 | __next_pointer __node_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 516 | size_t __bucket_; |
| 517 | size_t __bucket_count_; |
| 518 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 519 | public: |
| 520 | typedef forward_iterator_tag iterator_category; |
Eric Fiselier | 774c7c5 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 523 | typedef value_type& reference; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 524 | typedef typename _NodeTypes::__node_value_type_pointer pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 525 | |
Eric Fiselier | f653588 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 531 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3921364 | 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 | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 540 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3921364 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 558 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 559 | |
| 560 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 561 | reference operator*() const { |
| 562 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 563 | "Attempted to dereference a non-dereferenceable unordered container local_iterator"); |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 564 | return __node_->__upcast()->__value_; |
| 565 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 566 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 567 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 577 | "Attempted to increment non-incrementable unordered container local_iterator"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 578 | __node_ = __node_->__next_; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 579 | if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 580 | __node_ = nullptr; |
| 581 | return *this; |
| 582 | } |
| 583 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 584 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 99acc50 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 594 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 595 | return __x.__node_ == __y.__node_; |
| 596 | } |
Howard Hinnant | 99acc50 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 599 | {return !(__x == __y);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 600 | |
| 601 | private: |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 602 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 603 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 604 | __hash_local_iterator(__next_pointer __node, size_t __bucket, |
Howard Hinnant | 3921364 | 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 | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 615 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 616 | __hash_local_iterator(__next_pointer __node, size_t __bucket, |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 617 | size_t __bucket_count) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 625 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 626 | template <class, class, class, class> friend class __hash_table; |
Howard Hinnant | 0f678bd | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 629 | }; |
| 630 | |
| 631 | template <class _ConstNodePtr> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 632 | class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 633 | { |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 634 | typedef __hash_node_types<_ConstNodePtr> _NodeTypes; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 635 | typedef _ConstNodePtr __node_pointer; |
| 636 | typedef typename _NodeTypes::__next_pointer __next_pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 637 | |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 638 | __next_pointer __node_; |
Howard Hinnant | bc8d3f9 | 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 | 5cf84e0 | 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 | 0493d02 | 2016-02-18 00:20:34 +0000 | [diff] [blame] | 647 | public: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 648 | typedef __hash_local_iterator<__non_const_node_pointer> |
| 649 | __non_const_iterator; |
Eric Fiselier | 0493d02 | 2016-02-18 00:20:34 +0000 | [diff] [blame] | 650 | |
Eric Fiselier | 774c7c5 | 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 | 5cf84e0 | 2015-12-30 21:52:00 +0000 | [diff] [blame] | 656 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 657 | |
Eric Fiselier | f653588 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 662 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 663 | __hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 667 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 668 | _LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x)); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 672 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3921364 | 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 | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 681 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3921364 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 699 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 700 | |
| 701 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 702 | reference operator*() const { |
| 703 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this), |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 704 | "Attempted to dereference a non-dereferenceable unordered container const_local_iterator"); |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 705 | return __node_->__upcast()->__value_; |
| 706 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 707 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 708 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 718 | "Attempted to increment non-incrementable unordered container const_local_iterator"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 719 | __node_ = __node_->__next_; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 720 | if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 721 | __node_ = nullptr; |
| 722 | return *this; |
| 723 | } |
| 724 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 725 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 99acc50 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 735 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 736 | return __x.__node_ == __y.__node_; |
| 737 | } |
Howard Hinnant | 99acc50 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 740 | {return !(__x == __y);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 741 | |
| 742 | private: |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 743 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 744 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 745 | __hash_const_local_iterator(__next_pointer __node, size_t __bucket, |
Howard Hinnant | 3921364 | 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 | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 756 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 757 | __hash_const_local_iterator(__next_pointer __node, size_t __bucket, |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 758 | size_t __bucket_count) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 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 | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 766 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 767 | template <class, class, class, class> friend class __hash_table; |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 768 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator; |
Howard Hinnant | bc8d3f9 | 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 | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 782 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 783 | __bucket_list_deallocator() |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 784 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 785 | : __data_(0) {} |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 786 | |
| 787 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 788 | __bucket_list_deallocator(const allocator_type& __a, size_type __size) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 789 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 790 | : __data_(__size, __a) {} |
| 791 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 792 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 793 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 794 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 795 | __bucket_list_deallocator(__bucket_list_deallocator&& __x) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 796 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 797 | : __data_(_VSTD::move(__x.__data_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 798 | { |
| 799 | __x.size() = 0; |
| 800 | } |
| 801 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 802 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 803 | |
Howard Hinnant | 5f2f14c | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 808 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 809 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 816 | { |
| 817 | __alloc_traits::deallocate(__alloc(), __p, size()); |
| 818 | } |
| 819 | }; |
| 820 | |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 821 | template <class _Alloc> class __hash_map_node_destructor; |
Howard Hinnant | bc8d3f9 | 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 | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 828 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 829 | public: |
| 830 | typedef typename __alloc_traits::pointer pointer; |
| 831 | private: |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 832 | typedef __hash_node_types<pointer> _NodeTypes; |
Howard Hinnant | bc8d3f9 | 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 | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 841 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 199d0ae | 2011-07-31 17:04:30 +0000 | [diff] [blame] | 842 | explicit __hash_node_destructor(allocator_type& __na, |
| 843 | bool __constructed = false) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 844 | : __na_(__na), |
Howard Hinnant | 199d0ae | 2011-07-31 17:04:30 +0000 | [diff] [blame] | 845 | __value_constructed(__constructed) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 846 | {} |
| 847 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 848 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 849 | void operator()(pointer __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 850 | { |
| 851 | if (__value_constructed) |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 852 | __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_)); |
Howard Hinnant | bc8d3f9 | 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 | 774c7c5 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 874 | public: |
Eric Fiselier | 2960ae2 | 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 | 798ec84 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 878 | typedef typename _NodeTypes::key_type key_type; |
Howard Hinnant | bc8d3f9 | 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 | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 883 | #ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 884 | typedef typename __alloc_traits::size_type size_type; |
Eric Fiselier | 774c7c5 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 889 | public: |
| 890 | // Create __node |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 891 | |
| 892 | typedef typename _NodeTypes::__node_type __node; |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 893 | typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 894 | typedef allocator_traits<__node_allocator> __node_traits; |
Eric Fiselier | 9e9f42e | 2016-02-11 15:22:37 +0000 | [diff] [blame] | 895 | typedef typename _NodeTypes::__void_pointer __void_pointer; |
Eric Fiselier | 774c7c5 | 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 | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 900 | typedef typename _NodeTypes::__next_pointer __next_pointer; |
Eric Fiselier | 774c7c5 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 913 | |
| 914 | private: |
| 915 | |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 916 | typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 917 | typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 918 | typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 919 | typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 920 | typedef typename __bucket_list_deleter::pointer __node_pointer_pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 921 | |
| 922 | // --- Member data begin --- |
Eric Fiselier | 774c7c5 | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 927 | // --- Member data end --- |
| 928 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 929 | _LIBCPP_INLINE_VISIBILITY |
| 930 | size_type& size() _NOEXCEPT {return __p2_.first();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 931 | public: |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 932 | _LIBCPP_INLINE_VISIBILITY |
| 933 | size_type size() const _NOEXCEPT {return __p2_.first();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 934 | |
Howard Hinnant | 5f2f14c | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 939 | |
Howard Hinnant | 5f2f14c | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 944 | |
Howard Hinnant | 5f2f14c | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 949 | |
Howard Hinnant | 5f2f14c | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 955 | |
| 956 | public: |
| 957 | typedef __hash_iterator<__node_pointer> iterator; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 958 | typedef __hash_const_iterator<__node_pointer> const_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 959 | typedef __hash_local_iterator<__node_pointer> local_iterator; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 960 | typedef __hash_const_local_iterator<__node_pointer> const_local_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 961 | |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 962 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 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 | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 970 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 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 | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 977 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 5f2f14c | 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 985 | __hash_table(__hash_table&& __u, const allocator_type& __a); |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 986 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 987 | ~__hash_table(); |
| 988 | |
| 989 | __hash_table& operator=(const __hash_table& __u); |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 990 | #ifndef _LIBCPP_CXX03_LANG |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 991 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 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 | bc8d3f9 | 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 | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1004 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1005 | size_type max_size() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1006 | { |
| 1007 | return allocator_traits<__pointer_allocator>::max_size( |
| 1008 | __bucket_list_.get_deleter().__alloc()); |
| 1009 | } |
| 1010 | |
| 1011 | pair<iterator, bool> __node_insert_unique(__node_pointer __nd); |
| 1012 | iterator __node_insert_multi(__node_pointer __nd); |
| 1013 | iterator __node_insert_multi(const_iterator __p, |
| 1014 | __node_pointer __nd); |
| 1015 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1016 | #ifndef _LIBCPP_CXX03_LANG |
| 1017 | template <class _Key, class ..._Args> |
Duncan P. N. Exon Smith | 798ec84 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 1018 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1019 | pair<iterator, bool> __emplace_unique_key_args(_Key const& __k, _Args&&... __args); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1020 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1021 | template <class... _Args> |
Duncan P. N. Exon Smith | 798ec84 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 1022 | _LIBCPP_INLINE_VISIBILITY |
| 1023 | pair<iterator, bool> __emplace_unique_impl(_Args&&... __args); |
| 1024 | |
| 1025 | template <class _Pp> |
| 1026 | _LIBCPP_INLINE_VISIBILITY |
| 1027 | pair<iterator, bool> __emplace_unique(_Pp&& __x) { |
| 1028 | return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x), |
| 1029 | __can_extract_key<_Pp, key_type>()); |
| 1030 | } |
Eric Fiselier | dc414cd | 2016-04-16 00:23:12 +0000 | [diff] [blame] | 1031 | |
| 1032 | template <class _First, class _Second> |
| 1033 | _LIBCPP_INLINE_VISIBILITY |
| 1034 | typename enable_if< |
| 1035 | __can_extract_map_key<_First, key_type, __container_value_type>::value, |
| 1036 | pair<iterator, bool> |
| 1037 | >::type __emplace_unique(_First&& __f, _Second&& __s) { |
| 1038 | return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f), |
| 1039 | _VSTD::forward<_Second>(__s)); |
| 1040 | } |
| 1041 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1042 | template <class... _Args> |
Duncan P. N. Exon Smith | 798ec84 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 1043 | _LIBCPP_INLINE_VISIBILITY |
| 1044 | pair<iterator, bool> __emplace_unique(_Args&&... __args) { |
| 1045 | return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...); |
| 1046 | } |
| 1047 | |
| 1048 | template <class _Pp> |
| 1049 | _LIBCPP_INLINE_VISIBILITY |
| 1050 | pair<iterator, bool> |
| 1051 | __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) { |
| 1052 | return __emplace_unique_impl(_VSTD::forward<_Pp>(__x)); |
| 1053 | } |
| 1054 | template <class _Pp> |
| 1055 | _LIBCPP_INLINE_VISIBILITY |
| 1056 | pair<iterator, bool> |
| 1057 | __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) { |
| 1058 | return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x)); |
| 1059 | } |
| 1060 | template <class _Pp> |
| 1061 | _LIBCPP_INLINE_VISIBILITY |
| 1062 | pair<iterator, bool> |
| 1063 | __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) { |
| 1064 | return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x)); |
| 1065 | } |
| 1066 | |
| 1067 | template <class... _Args> |
| 1068 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1069 | iterator __emplace_multi(_Args&&... __args); |
| 1070 | template <class... _Args> |
Duncan P. N. Exon Smith | 798ec84 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 1071 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1072 | iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); |
| 1073 | |
| 1074 | |
Eric Fiselier | fdae69a | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1075 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1076 | pair<iterator, bool> |
| 1077 | __insert_unique(__container_value_type&& __x) { |
| 1078 | return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _VSTD::move(__x)); |
| 1079 | } |
| 1080 | |
| 1081 | template <class _Pp, class = typename enable_if< |
| 1082 | !__is_same_uncvref<_Pp, __container_value_type>::value |
| 1083 | >::type> |
Eric Fiselier | fdae69a | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1084 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1085 | pair<iterator, bool> __insert_unique(_Pp&& __x) { |
| 1086 | return __emplace_unique(_VSTD::forward<_Pp>(__x)); |
| 1087 | } |
| 1088 | |
| 1089 | template <class _Pp> |
| 1090 | _LIBCPP_INLINE_VISIBILITY |
| 1091 | iterator __insert_multi(_Pp&& __x) { |
| 1092 | return __emplace_multi(_VSTD::forward<_Pp>(__x)); |
| 1093 | } |
| 1094 | |
| 1095 | template <class _Pp> |
| 1096 | _LIBCPP_INLINE_VISIBILITY |
| 1097 | iterator __insert_multi(const_iterator __p, _Pp&& __x) { |
| 1098 | return __emplace_hint_multi(__p, _VSTD::forward<_Pp>(__x)); |
| 1099 | } |
| 1100 | |
| 1101 | #else // !defined(_LIBCPP_CXX03_LANG) |
| 1102 | template <class _Key, class _Args> |
| 1103 | pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args); |
| 1104 | |
| 1105 | iterator __insert_multi(const __container_value_type& __x); |
| 1106 | iterator __insert_multi(const_iterator __p, const __container_value_type& __x); |
Eric Fiselier | fdae69a | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1107 | #endif |
| 1108 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1109 | _LIBCPP_INLINE_VISIBILITY |
| 1110 | pair<iterator, bool> __insert_unique(const __container_value_type& __x) { |
| 1111 | return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x); |
| 1112 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1113 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1114 | void clear() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1115 | void rehash(size_type __n); |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1116 | _LIBCPP_INLINE_VISIBILITY void reserve(size_type __n) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1117 | {rehash(static_cast<size_type>(ceil(__n / max_load_factor())));} |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1118 | |
| 1119 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1120 | size_type bucket_count() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1121 | { |
| 1122 | return __bucket_list_.get_deleter().size(); |
| 1123 | } |
| 1124 | |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1125 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1126 | iterator begin() _NOEXCEPT; |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1127 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1128 | iterator end() _NOEXCEPT; |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1129 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1130 | const_iterator begin() const _NOEXCEPT; |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1131 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1132 | const_iterator end() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1133 | |
| 1134 | template <class _Key> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1135 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1136 | size_type bucket(const _Key& __k) const |
Howard Hinnant | 0bb0a7c | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 1137 | { |
| 1138 | _LIBCPP_ASSERT(bucket_count() > 0, |
| 1139 | "unordered container::bucket(key) called when bucket_count() == 0"); |
| 1140 | return __constrain_hash(hash_function()(__k), bucket_count()); |
| 1141 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1142 | |
| 1143 | template <class _Key> |
| 1144 | iterator find(const _Key& __x); |
| 1145 | template <class _Key> |
| 1146 | const_iterator find(const _Key& __x) const; |
| 1147 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1148 | typedef __hash_node_destructor<__node_allocator> _Dp; |
| 1149 | typedef unique_ptr<__node, _Dp> __node_holder; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1150 | |
| 1151 | iterator erase(const_iterator __p); |
| 1152 | iterator erase(const_iterator __first, const_iterator __last); |
| 1153 | template <class _Key> |
| 1154 | size_type __erase_unique(const _Key& __k); |
| 1155 | template <class _Key> |
| 1156 | size_type __erase_multi(const _Key& __k); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1157 | __node_holder remove(const_iterator __p) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1158 | |
| 1159 | template <class _Key> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1160 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1161 | size_type __count_unique(const _Key& __k) const; |
| 1162 | template <class _Key> |
| 1163 | size_type __count_multi(const _Key& __k) const; |
| 1164 | |
| 1165 | template <class _Key> |
| 1166 | pair<iterator, iterator> |
| 1167 | __equal_range_unique(const _Key& __k); |
| 1168 | template <class _Key> |
| 1169 | pair<const_iterator, const_iterator> |
| 1170 | __equal_range_unique(const _Key& __k) const; |
| 1171 | |
| 1172 | template <class _Key> |
| 1173 | pair<iterator, iterator> |
| 1174 | __equal_range_multi(const _Key& __k); |
| 1175 | template <class _Key> |
| 1176 | pair<const_iterator, const_iterator> |
| 1177 | __equal_range_multi(const _Key& __k) const; |
| 1178 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1179 | void swap(__hash_table& __u) |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 1180 | #if _LIBCPP_STD_VER <= 11 |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1181 | _NOEXCEPT_( |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1182 | __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1183 | && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value |
| 1184 | || __is_nothrow_swappable<__pointer_allocator>::value) |
| 1185 | && (!__node_traits::propagate_on_container_swap::value |
| 1186 | || __is_nothrow_swappable<__node_allocator>::value) |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1187 | ); |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 1188 | #else |
| 1189 | _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value); |
| 1190 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1191 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1192 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1193 | size_type max_bucket_count() const _NOEXCEPT |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1194 | {return __pointer_alloc_traits::max_size(__bucket_list_.get_deleter().__alloc());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1195 | size_type bucket_size(size_type __n) const; |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1196 | _LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1197 | { |
| 1198 | size_type __bc = bucket_count(); |
| 1199 | return __bc != 0 ? (float)size() / __bc : 0.f; |
| 1200 | } |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1201 | _LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT |
Howard Hinnant | 0bb0a7c | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 1202 | { |
| 1203 | _LIBCPP_ASSERT(__mlf > 0, |
| 1204 | "unordered container::max_load_factor(lf) called with lf <= 0"); |
| 1205 | max_load_factor() = _VSTD::max(__mlf, load_factor()); |
| 1206 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1207 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1208 | _LIBCPP_INLINE_VISIBILITY |
| 1209 | local_iterator |
| 1210 | begin(size_type __n) |
| 1211 | { |
Howard Hinnant | 0bb0a7c | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 1212 | _LIBCPP_ASSERT(__n < bucket_count(), |
| 1213 | "unordered container::begin(n) called with n >= bucket_count()"); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1214 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1215 | return local_iterator(__bucket_list_[__n], __n, bucket_count(), this); |
| 1216 | #else |
| 1217 | return local_iterator(__bucket_list_[__n], __n, bucket_count()); |
| 1218 | #endif |
| 1219 | } |
| 1220 | |
| 1221 | _LIBCPP_INLINE_VISIBILITY |
| 1222 | local_iterator |
| 1223 | end(size_type __n) |
| 1224 | { |
Howard Hinnant | 0bb0a7c | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 1225 | _LIBCPP_ASSERT(__n < bucket_count(), |
| 1226 | "unordered container::end(n) called with n >= bucket_count()"); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1227 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1228 | return local_iterator(nullptr, __n, bucket_count(), this); |
| 1229 | #else |
| 1230 | return local_iterator(nullptr, __n, bucket_count()); |
| 1231 | #endif |
| 1232 | } |
| 1233 | |
| 1234 | _LIBCPP_INLINE_VISIBILITY |
| 1235 | const_local_iterator |
| 1236 | cbegin(size_type __n) const |
| 1237 | { |
Howard Hinnant | 0bb0a7c | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 1238 | _LIBCPP_ASSERT(__n < bucket_count(), |
| 1239 | "unordered container::cbegin(n) called with n >= bucket_count()"); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1240 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1241 | return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this); |
| 1242 | #else |
| 1243 | return const_local_iterator(__bucket_list_[__n], __n, bucket_count()); |
| 1244 | #endif |
| 1245 | } |
| 1246 | |
| 1247 | _LIBCPP_INLINE_VISIBILITY |
| 1248 | const_local_iterator |
| 1249 | cend(size_type __n) const |
| 1250 | { |
Howard Hinnant | 0bb0a7c | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 1251 | _LIBCPP_ASSERT(__n < bucket_count(), |
| 1252 | "unordered container::cend(n) called with n >= bucket_count()"); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1253 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1254 | return const_local_iterator(nullptr, __n, bucket_count(), this); |
| 1255 | #else |
| 1256 | return const_local_iterator(nullptr, __n, bucket_count()); |
| 1257 | #endif |
| 1258 | } |
| 1259 | |
| 1260 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1261 | |
| 1262 | bool __dereferenceable(const const_iterator* __i) const; |
| 1263 | bool __decrementable(const const_iterator* __i) const; |
| 1264 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1265 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1266 | |
| 1267 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 1268 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1269 | private: |
| 1270 | void __rehash(size_type __n); |
| 1271 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1272 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1273 | template <class ..._Args> |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1274 | __node_holder __construct_node(_Args&& ...__args); |
| 1275 | |
| 1276 | template <class _First, class ..._Rest> |
| 1277 | __node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest); |
| 1278 | #else // _LIBCPP_CXX03_LANG |
| 1279 | __node_holder __construct_node(const __container_value_type& __v); |
| 1280 | __node_holder __construct_node_hash(size_t __hash, const __container_value_type& __v); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1281 | #endif |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1282 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1283 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1284 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1285 | void __copy_assign_alloc(const __hash_table& __u) |
| 1286 | {__copy_assign_alloc(__u, integral_constant<bool, |
| 1287 | __node_traits::propagate_on_container_copy_assignment::value>());} |
| 1288 | void __copy_assign_alloc(const __hash_table& __u, true_type); |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1289 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1290 | void __copy_assign_alloc(const __hash_table&, false_type) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1291 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1292 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1293 | void __move_assign(__hash_table& __u, false_type); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1294 | void __move_assign(__hash_table& __u, true_type) |
| 1295 | _NOEXCEPT_( |
| 1296 | is_nothrow_move_assignable<__node_allocator>::value && |
| 1297 | is_nothrow_move_assignable<hasher>::value && |
| 1298 | is_nothrow_move_assignable<key_equal>::value); |
| 1299 | _LIBCPP_INLINE_VISIBILITY |
| 1300 | void __move_assign_alloc(__hash_table& __u) |
| 1301 | _NOEXCEPT_( |
| 1302 | !__node_traits::propagate_on_container_move_assignment::value || |
| 1303 | (is_nothrow_move_assignable<__pointer_allocator>::value && |
| 1304 | is_nothrow_move_assignable<__node_allocator>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1305 | {__move_assign_alloc(__u, integral_constant<bool, |
| 1306 | __node_traits::propagate_on_container_move_assignment::value>());} |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1307 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1308 | void __move_assign_alloc(__hash_table& __u, true_type) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1309 | _NOEXCEPT_( |
| 1310 | is_nothrow_move_assignable<__pointer_allocator>::value && |
| 1311 | is_nothrow_move_assignable<__node_allocator>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1312 | { |
| 1313 | __bucket_list_.get_deleter().__alloc() = |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1314 | _VSTD::move(__u.__bucket_list_.get_deleter().__alloc()); |
| 1315 | __node_alloc() = _VSTD::move(__u.__node_alloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1316 | } |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1317 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1318 | void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {} |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1319 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1320 | |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1321 | void __deallocate(__next_pointer __np) _NOEXCEPT; |
| 1322 | __next_pointer __detach() _NOEXCEPT; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1323 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1324 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map; |
| 1325 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1326 | }; |
| 1327 | |
| 1328 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1329 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1330 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1331 | _NOEXCEPT_( |
| 1332 | is_nothrow_default_constructible<__bucket_list>::value && |
| 1333 | is_nothrow_default_constructible<__first_node>::value && |
Eric Fiselier | c8f54c2 | 2015-12-16 00:53:04 +0000 | [diff] [blame] | 1334 | is_nothrow_default_constructible<__node_allocator>::value && |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1335 | is_nothrow_default_constructible<hasher>::value && |
| 1336 | is_nothrow_default_constructible<key_equal>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1337 | : __p2_(0), |
| 1338 | __p3_(1.0f) |
| 1339 | { |
| 1340 | } |
| 1341 | |
| 1342 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1343 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1344 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, |
| 1345 | const key_equal& __eql) |
| 1346 | : __bucket_list_(nullptr, __bucket_list_deleter()), |
| 1347 | __p1_(), |
| 1348 | __p2_(0, __hf), |
| 1349 | __p3_(1.0f, __eql) |
| 1350 | { |
| 1351 | } |
| 1352 | |
| 1353 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1354 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, |
| 1355 | const key_equal& __eql, |
| 1356 | const allocator_type& __a) |
| 1357 | : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), |
| 1358 | __p1_(__node_allocator(__a)), |
| 1359 | __p2_(0, __hf), |
| 1360 | __p3_(1.0f, __eql) |
| 1361 | { |
| 1362 | } |
| 1363 | |
| 1364 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1365 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a) |
| 1366 | : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), |
| 1367 | __p1_(__node_allocator(__a)), |
| 1368 | __p2_(0), |
| 1369 | __p3_(1.0f) |
| 1370 | { |
| 1371 | } |
| 1372 | |
| 1373 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1374 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) |
| 1375 | : __bucket_list_(nullptr, |
| 1376 | __bucket_list_deleter(allocator_traits<__pointer_allocator>:: |
| 1377 | select_on_container_copy_construction( |
| 1378 | __u.__bucket_list_.get_deleter().__alloc()), 0)), |
| 1379 | __p1_(allocator_traits<__node_allocator>:: |
| 1380 | select_on_container_copy_construction(__u.__node_alloc())), |
| 1381 | __p2_(0, __u.hash_function()), |
| 1382 | __p3_(__u.__p3_) |
| 1383 | { |
| 1384 | } |
| 1385 | |
| 1386 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1387 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, |
| 1388 | const allocator_type& __a) |
| 1389 | : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), |
| 1390 | __p1_(__node_allocator(__a)), |
| 1391 | __p2_(0, __u.hash_function()), |
| 1392 | __p3_(__u.__p3_) |
| 1393 | { |
| 1394 | } |
| 1395 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1396 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1397 | |
| 1398 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1399 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1400 | _NOEXCEPT_( |
| 1401 | is_nothrow_move_constructible<__bucket_list>::value && |
| 1402 | is_nothrow_move_constructible<__first_node>::value && |
Eric Fiselier | c8f54c2 | 2015-12-16 00:53:04 +0000 | [diff] [blame] | 1403 | is_nothrow_move_constructible<__node_allocator>::value && |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1404 | is_nothrow_move_constructible<hasher>::value && |
| 1405 | is_nothrow_move_constructible<key_equal>::value) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1406 | : __bucket_list_(_VSTD::move(__u.__bucket_list_)), |
| 1407 | __p1_(_VSTD::move(__u.__p1_)), |
| 1408 | __p2_(_VSTD::move(__u.__p2_)), |
| 1409 | __p3_(_VSTD::move(__u.__p3_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1410 | { |
| 1411 | if (size() > 0) |
| 1412 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1413 | __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = |
| 1414 | __p1_.first().__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1415 | __u.__p1_.first().__next_ = nullptr; |
| 1416 | __u.size() = 0; |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1421 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, |
| 1422 | const allocator_type& __a) |
| 1423 | : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), |
| 1424 | __p1_(__node_allocator(__a)), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1425 | __p2_(0, _VSTD::move(__u.hash_function())), |
| 1426 | __p3_(_VSTD::move(__u.__p3_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1427 | { |
| 1428 | if (__a == allocator_type(__u.__node_alloc())) |
| 1429 | { |
| 1430 | __bucket_list_.reset(__u.__bucket_list_.release()); |
| 1431 | __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); |
| 1432 | __u.__bucket_list_.get_deleter().size() = 0; |
| 1433 | if (__u.size() > 0) |
| 1434 | { |
| 1435 | __p1_.first().__next_ = __u.__p1_.first().__next_; |
| 1436 | __u.__p1_.first().__next_ = nullptr; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1437 | __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = |
| 1438 | __p1_.first().__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1439 | size() = __u.size(); |
| 1440 | __u.size() = 0; |
| 1441 | } |
| 1442 | } |
| 1443 | } |
| 1444 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1445 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1446 | |
| 1447 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1448 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() |
| 1449 | { |
Marshall Clow | 1a93312 | 2016-06-30 22:05:45 +0000 | [diff] [blame] | 1450 | static_assert((is_copy_constructible<key_equal>::value), |
| 1451 | "Predicate must be copy-constructible."); |
| 1452 | static_assert((is_copy_constructible<hasher>::value), |
| 1453 | "Hasher must be copy-constructible."); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1454 | __deallocate(__p1_.first().__next_); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1455 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1456 | __get_db()->__erase_c(this); |
| 1457 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1461 | void |
| 1462 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc( |
| 1463 | const __hash_table& __u, true_type) |
| 1464 | { |
| 1465 | if (__node_alloc() != __u.__node_alloc()) |
| 1466 | { |
| 1467 | clear(); |
| 1468 | __bucket_list_.reset(); |
| 1469 | __bucket_list_.get_deleter().size() = 0; |
| 1470 | } |
| 1471 | __bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc(); |
| 1472 | __node_alloc() = __u.__node_alloc(); |
| 1473 | } |
| 1474 | |
| 1475 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1476 | __hash_table<_Tp, _Hash, _Equal, _Alloc>& |
| 1477 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u) |
| 1478 | { |
| 1479 | if (this != &__u) |
| 1480 | { |
| 1481 | __copy_assign_alloc(__u); |
| 1482 | hash_function() = __u.hash_function(); |
| 1483 | key_eq() = __u.key_eq(); |
| 1484 | max_load_factor() = __u.max_load_factor(); |
| 1485 | __assign_multi(__u.begin(), __u.end()); |
| 1486 | } |
| 1487 | return *this; |
| 1488 | } |
| 1489 | |
| 1490 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1491 | void |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1492 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate(__next_pointer __np) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1493 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1494 | { |
| 1495 | __node_allocator& __na = __node_alloc(); |
| 1496 | while (__np != nullptr) |
| 1497 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1498 | __next_pointer __next = __np->__next_; |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1499 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1500 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 1501 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
| 1502 | { |
| 1503 | --__p; |
| 1504 | iterator* __i = static_cast<iterator*>((*__p)->__i_); |
| 1505 | if (__i->__node_ == __np) |
| 1506 | { |
| 1507 | (*__p)->__c_ = nullptr; |
| 1508 | if (--__c->end_ != __p) |
| 1509 | memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
| 1510 | } |
| 1511 | } |
| 1512 | __get_db()->unlock(); |
| 1513 | #endif |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1514 | __node_pointer __real_np = __np->__upcast(); |
| 1515 | __node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__value_)); |
| 1516 | __node_traits::deallocate(__na, __real_np, 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1517 | __np = __next; |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1522 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1523 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1524 | { |
| 1525 | size_type __bc = bucket_count(); |
| 1526 | for (size_type __i = 0; __i < __bc; ++__i) |
| 1527 | __bucket_list_[__i] = nullptr; |
| 1528 | size() = 0; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1529 | __next_pointer __cache = __p1_.first().__next_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1530 | __p1_.first().__next_ = nullptr; |
| 1531 | return __cache; |
| 1532 | } |
| 1533 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1534 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1535 | |
| 1536 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1537 | void |
| 1538 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( |
| 1539 | __hash_table& __u, true_type) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1540 | _NOEXCEPT_( |
| 1541 | is_nothrow_move_assignable<__node_allocator>::value && |
| 1542 | is_nothrow_move_assignable<hasher>::value && |
| 1543 | is_nothrow_move_assignable<key_equal>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1544 | { |
| 1545 | clear(); |
| 1546 | __bucket_list_.reset(__u.__bucket_list_.release()); |
| 1547 | __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); |
| 1548 | __u.__bucket_list_.get_deleter().size() = 0; |
| 1549 | __move_assign_alloc(__u); |
| 1550 | size() = __u.size(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1551 | hash_function() = _VSTD::move(__u.hash_function()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1552 | max_load_factor() = __u.max_load_factor(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1553 | key_eq() = _VSTD::move(__u.key_eq()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1554 | __p1_.first().__next_ = __u.__p1_.first().__next_; |
| 1555 | if (size() > 0) |
| 1556 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1557 | __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = |
| 1558 | __p1_.first().__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1559 | __u.__p1_.first().__next_ = nullptr; |
| 1560 | __u.size() = 0; |
| 1561 | } |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1562 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1563 | __get_db()->swap(this, &__u); |
| 1564 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1568 | void |
| 1569 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( |
| 1570 | __hash_table& __u, false_type) |
| 1571 | { |
| 1572 | if (__node_alloc() == __u.__node_alloc()) |
| 1573 | __move_assign(__u, true_type()); |
| 1574 | else |
| 1575 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1576 | hash_function() = _VSTD::move(__u.hash_function()); |
| 1577 | key_eq() = _VSTD::move(__u.key_eq()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1578 | max_load_factor() = __u.max_load_factor(); |
| 1579 | if (bucket_count() != 0) |
| 1580 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1581 | __next_pointer __cache = __detach(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1582 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1583 | try |
| 1584 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1585 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1586 | const_iterator __i = __u.begin(); |
| 1587 | while (__cache != nullptr && __u.size() != 0) |
| 1588 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1589 | __cache->__upcast()->__value_ = |
| 1590 | _VSTD::move(__u.remove(__i++)->__value_); |
| 1591 | __next_pointer __next = __cache->__next_; |
| 1592 | __node_insert_multi(__cache->__upcast()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1593 | __cache = __next; |
| 1594 | } |
| 1595 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1596 | } |
| 1597 | catch (...) |
| 1598 | { |
| 1599 | __deallocate(__cache); |
| 1600 | throw; |
| 1601 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1602 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1603 | __deallocate(__cache); |
| 1604 | } |
| 1605 | const_iterator __i = __u.begin(); |
| 1606 | while (__u.size() != 0) |
| 1607 | { |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1608 | __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1609 | __node_insert_multi(__h.get()); |
| 1610 | __h.release(); |
| 1611 | } |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1616 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1617 | __hash_table<_Tp, _Hash, _Equal, _Alloc>& |
| 1618 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1619 | _NOEXCEPT_( |
| 1620 | __node_traits::propagate_on_container_move_assignment::value && |
| 1621 | is_nothrow_move_assignable<__node_allocator>::value && |
| 1622 | is_nothrow_move_assignable<hasher>::value && |
| 1623 | is_nothrow_move_assignable<key_equal>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1624 | { |
| 1625 | __move_assign(__u, integral_constant<bool, |
| 1626 | __node_traits::propagate_on_container_move_assignment::value>()); |
| 1627 | return *this; |
| 1628 | } |
| 1629 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1630 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1631 | |
| 1632 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1633 | template <class _InputIterator> |
| 1634 | void |
| 1635 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first, |
| 1636 | _InputIterator __last) |
| 1637 | { |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1638 | typedef iterator_traits<_InputIterator> _ITraits; |
| 1639 | typedef typename _ITraits::value_type _ItValueType; |
| 1640 | static_assert((is_same<_ItValueType, __container_value_type>::value), |
| 1641 | "__assign_unique may only be called with the containers value type"); |
| 1642 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1643 | if (bucket_count() != 0) |
| 1644 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1645 | __next_pointer __cache = __detach(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1646 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1647 | try |
| 1648 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1649 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1650 | for (; __cache != nullptr && __first != __last; ++__first) |
| 1651 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1652 | __cache->__upcast()->__value_ = *__first; |
| 1653 | __next_pointer __next = __cache->__next_; |
| 1654 | __node_insert_unique(__cache->__upcast()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1655 | __cache = __next; |
| 1656 | } |
| 1657 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1658 | } |
| 1659 | catch (...) |
| 1660 | { |
| 1661 | __deallocate(__cache); |
| 1662 | throw; |
| 1663 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1664 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1665 | __deallocate(__cache); |
| 1666 | } |
| 1667 | for (; __first != __last; ++__first) |
| 1668 | __insert_unique(*__first); |
| 1669 | } |
| 1670 | |
| 1671 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1672 | template <class _InputIterator> |
| 1673 | void |
| 1674 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first, |
| 1675 | _InputIterator __last) |
| 1676 | { |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1677 | typedef iterator_traits<_InputIterator> _ITraits; |
| 1678 | typedef typename _ITraits::value_type _ItValueType; |
| 1679 | static_assert((is_same<_ItValueType, __container_value_type>::value || |
| 1680 | is_same<_ItValueType, __node_value_type>::value), |
| 1681 | "__assign_multi may only be called with the containers value type" |
| 1682 | " or the nodes value type"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1683 | if (bucket_count() != 0) |
| 1684 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1685 | __next_pointer __cache = __detach(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1686 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1687 | try |
| 1688 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1689 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1690 | for (; __cache != nullptr && __first != __last; ++__first) |
| 1691 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1692 | __cache->__upcast()->__value_ = *__first; |
| 1693 | __next_pointer __next = __cache->__next_; |
| 1694 | __node_insert_multi(__cache->__upcast()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1695 | __cache = __next; |
| 1696 | } |
| 1697 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1698 | } |
| 1699 | catch (...) |
| 1700 | { |
| 1701 | __deallocate(__cache); |
| 1702 | throw; |
| 1703 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1704 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1705 | __deallocate(__cache); |
| 1706 | } |
| 1707 | for (; __first != __last; ++__first) |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1708 | __insert_multi(_NodeTypes::__get_value(*__first)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1712 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1713 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1714 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1715 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1716 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1717 | return iterator(__p1_.first().__next_, this); |
| 1718 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1719 | return iterator(__p1_.first().__next_); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1720 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1724 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1725 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1726 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1727 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1728 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1729 | return iterator(nullptr, this); |
| 1730 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1731 | return iterator(nullptr); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1732 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1736 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1737 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1738 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1739 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1740 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1741 | return const_iterator(__p1_.first().__next_, this); |
| 1742 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1743 | return const_iterator(__p1_.first().__next_); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1744 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1748 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1749 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1750 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1751 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1752 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1753 | return const_iterator(nullptr, this); |
| 1754 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1755 | return const_iterator(nullptr); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1756 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1760 | void |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1761 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1762 | { |
| 1763 | if (size() > 0) |
| 1764 | { |
| 1765 | __deallocate(__p1_.first().__next_); |
| 1766 | __p1_.first().__next_ = nullptr; |
| 1767 | size_type __bc = bucket_count(); |
Howard Hinnant | 9f66bff | 2011-07-05 14:14:17 +0000 | [diff] [blame] | 1768 | for (size_type __i = 0; __i < __bc; ++__i) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1769 | __bucket_list_[__i] = nullptr; |
| 1770 | size() = 0; |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1775 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> |
| 1776 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd) |
| 1777 | { |
| 1778 | __nd->__hash_ = hash_function()(__nd->__value_); |
| 1779 | size_type __bc = bucket_count(); |
| 1780 | bool __inserted = false; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1781 | __next_pointer __ndptr; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1782 | size_t __chash; |
| 1783 | if (__bc != 0) |
| 1784 | { |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 1785 | __chash = __constrain_hash(__nd->__hash_, __bc); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1786 | __ndptr = __bucket_list_[__chash]; |
| 1787 | if (__ndptr != nullptr) |
| 1788 | { |
| 1789 | for (__ndptr = __ndptr->__next_; __ndptr != nullptr && |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1790 | __constrain_hash(__ndptr->__hash(), __bc) == __chash; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1791 | __ndptr = __ndptr->__next_) |
| 1792 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1793 | if (key_eq()(__ndptr->__upcast()->__value_, __nd->__value_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1794 | goto __done; |
| 1795 | } |
| 1796 | } |
| 1797 | } |
| 1798 | { |
| 1799 | if (size()+1 > __bc * max_load_factor() || __bc == 0) |
| 1800 | { |
Eric Fiselier | 57947ca | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 1801 | rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1802 | size_type(ceil(float(size() + 1) / max_load_factor())))); |
| 1803 | __bc = bucket_count(); |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 1804 | __chash = __constrain_hash(__nd->__hash_, __bc); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1805 | } |
| 1806 | // insert_after __bucket_list_[__chash], or __first_node if bucket is null |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1807 | __next_pointer __pn = __bucket_list_[__chash]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1808 | if (__pn == nullptr) |
| 1809 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1810 | __pn =__p1_.first().__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1811 | __nd->__next_ = __pn->__next_; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1812 | __pn->__next_ = __nd->__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1813 | // fix up __bucket_list_ |
| 1814 | __bucket_list_[__chash] = __pn; |
| 1815 | if (__nd->__next_ != nullptr) |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1816 | __bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1817 | } |
| 1818 | else |
| 1819 | { |
| 1820 | __nd->__next_ = __pn->__next_; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1821 | __pn->__next_ = __nd->__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1822 | } |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1823 | __ndptr = __nd->__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1824 | // increment size |
| 1825 | ++size(); |
| 1826 | __inserted = true; |
| 1827 | } |
| 1828 | __done: |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1829 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1830 | return pair<iterator, bool>(iterator(__ndptr, this), __inserted); |
| 1831 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1832 | return pair<iterator, bool>(iterator(__ndptr), __inserted); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1833 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1837 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 1838 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp) |
| 1839 | { |
| 1840 | __cp->__hash_ = hash_function()(__cp->__value_); |
| 1841 | size_type __bc = bucket_count(); |
| 1842 | if (size()+1 > __bc * max_load_factor() || __bc == 0) |
| 1843 | { |
Eric Fiselier | 57947ca | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 1844 | rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1845 | size_type(ceil(float(size() + 1) / max_load_factor())))); |
| 1846 | __bc = bucket_count(); |
| 1847 | } |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 1848 | size_t __chash = __constrain_hash(__cp->__hash_, __bc); |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1849 | __next_pointer __pn = __bucket_list_[__chash]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1850 | if (__pn == nullptr) |
| 1851 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1852 | __pn =__p1_.first().__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1853 | __cp->__next_ = __pn->__next_; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1854 | __pn->__next_ = __cp->__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1855 | // fix up __bucket_list_ |
| 1856 | __bucket_list_[__chash] = __pn; |
| 1857 | if (__cp->__next_ != nullptr) |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1858 | __bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)] |
| 1859 | = __cp->__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1860 | } |
| 1861 | else |
| 1862 | { |
| 1863 | for (bool __found = false; __pn->__next_ != nullptr && |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1864 | __constrain_hash(__pn->__next_->__hash(), __bc) == __chash; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1865 | __pn = __pn->__next_) |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1866 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1867 | // __found key_eq() action |
| 1868 | // false false loop |
| 1869 | // true true loop |
| 1870 | // false true set __found to true |
| 1871 | // true false break |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1872 | if (__found != (__pn->__next_->__hash() == __cp->__hash_ && |
| 1873 | key_eq()(__pn->__next_->__upcast()->__value_, __cp->__value_))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1874 | { |
| 1875 | if (!__found) |
| 1876 | __found = true; |
| 1877 | else |
| 1878 | break; |
| 1879 | } |
| 1880 | } |
| 1881 | __cp->__next_ = __pn->__next_; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1882 | __pn->__next_ = __cp->__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1883 | if (__cp->__next_ != nullptr) |
| 1884 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1885 | size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1886 | if (__nhash != __chash) |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1887 | __bucket_list_[__nhash] = __cp->__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1888 | } |
| 1889 | } |
| 1890 | ++size(); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1891 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1892 | return iterator(__cp->__ptr(), this); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1893 | #else |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1894 | return iterator(__cp->__ptr()); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1895 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 1899 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 1900 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi( |
| 1901 | const_iterator __p, __node_pointer __cp) |
| 1902 | { |
Howard Hinnant | 824c199 | 2013-08-02 17:50:49 +0000 | [diff] [blame] | 1903 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1904 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1905 | "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" |
| 1906 | " referring to this unordered container"); |
| 1907 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1908 | if (__p != end() && key_eq()(*__p, __cp->__value_)) |
| 1909 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1910 | __next_pointer __np = __p.__node_; |
| 1911 | __cp->__hash_ = __np->__hash(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1912 | size_type __bc = bucket_count(); |
| 1913 | if (size()+1 > __bc * max_load_factor() || __bc == 0) |
| 1914 | { |
Eric Fiselier | 57947ca | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 1915 | rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1916 | size_type(ceil(float(size() + 1) / max_load_factor())))); |
| 1917 | __bc = bucket_count(); |
| 1918 | } |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 1919 | size_t __chash = __constrain_hash(__cp->__hash_, __bc); |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1920 | __next_pointer __pp = __bucket_list_[__chash]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1921 | while (__pp->__next_ != __np) |
| 1922 | __pp = __pp->__next_; |
| 1923 | __cp->__next_ = __np; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1924 | __pp->__next_ = static_cast<__next_pointer>(__cp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1925 | ++size(); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1926 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1927 | return iterator(static_cast<__next_pointer>(__cp), this); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1928 | #else |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1929 | return iterator(static_cast<__next_pointer>(__cp)); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1930 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1931 | } |
| 1932 | return __node_insert_multi(__cp); |
| 1933 | } |
| 1934 | |
Eric Fiselier | fdae69a | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1935 | |
| 1936 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1937 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | fdae69a | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1938 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1939 | template <class _Key, class ..._Args> |
Eric Fiselier | fdae69a | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1940 | _LIBCPP_INLINE_VISIBILITY |
| 1941 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1942 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) |
Eric Fiselier | fdae69a | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1943 | #else |
| 1944 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1945 | template <class _Key, class _Args> |
Eric Fiselier | fdae69a | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1946 | _LIBCPP_INLINE_VISIBILITY |
| 1947 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1948 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args) |
Eric Fiselier | fdae69a | 2015-06-13 07:18:32 +0000 | [diff] [blame] | 1949 | #endif |
| 1950 | { |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1951 | |
| 1952 | size_t __hash = hash_function()(__k); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1953 | size_type __bc = bucket_count(); |
| 1954 | bool __inserted = false; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1955 | __next_pointer __nd; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1956 | size_t __chash; |
| 1957 | if (__bc != 0) |
| 1958 | { |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 1959 | __chash = __constrain_hash(__hash, __bc); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1960 | __nd = __bucket_list_[__chash]; |
| 1961 | if (__nd != nullptr) |
| 1962 | { |
| 1963 | for (__nd = __nd->__next_; __nd != nullptr && |
Eric Fiselier | d757090 | 2016-07-24 06:22:25 +0000 | [diff] [blame^] | 1964 | (__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1965 | __nd = __nd->__next_) |
| 1966 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1967 | if (key_eq()(__nd->__upcast()->__value_, __k)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1968 | goto __done; |
| 1969 | } |
| 1970 | } |
| 1971 | } |
| 1972 | { |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1973 | #ifndef _LIBCPP_CXX03_LANG |
| 1974 | __node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...); |
| 1975 | #else |
| 1976 | __node_holder __h = __construct_node_hash(__hash, __args); |
| 1977 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1978 | if (size()+1 > __bc * max_load_factor() || __bc == 0) |
| 1979 | { |
Eric Fiselier | 57947ca | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 1980 | rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1981 | size_type(ceil(float(size() + 1) / max_load_factor())))); |
| 1982 | __bc = bucket_count(); |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 1983 | __chash = __constrain_hash(__hash, __bc); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1984 | } |
| 1985 | // insert_after __bucket_list_[__chash], or __first_node if bucket is null |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1986 | __next_pointer __pn = __bucket_list_[__chash]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1987 | if (__pn == nullptr) |
| 1988 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1989 | __pn = __p1_.first().__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1990 | __h->__next_ = __pn->__next_; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1991 | __pn->__next_ = __h.get()->__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1992 | // fix up __bucket_list_ |
| 1993 | __bucket_list_[__chash] = __pn; |
| 1994 | if (__h->__next_ != nullptr) |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 1995 | __bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)] |
| 1996 | = __h.get()->__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1997 | } |
| 1998 | else |
| 1999 | { |
| 2000 | __h->__next_ = __pn->__next_; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2001 | __pn->__next_ = static_cast<__next_pointer>(__h.get()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2002 | } |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2003 | __nd = static_cast<__next_pointer>(__h.release()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2004 | // increment size |
| 2005 | ++size(); |
| 2006 | __inserted = true; |
| 2007 | } |
| 2008 | __done: |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2009 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2010 | return pair<iterator, bool>(iterator(__nd, this), __inserted); |
| 2011 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2012 | return pair<iterator, bool>(iterator(__nd), __inserted); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2013 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2016 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2017 | |
| 2018 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2019 | template <class... _Args> |
| 2020 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool> |
Duncan P. N. Exon Smith | 798ec84 | 2016-03-17 20:45:20 +0000 | [diff] [blame] | 2021 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2022 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2023 | __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2024 | pair<iterator, bool> __r = __node_insert_unique(__h.get()); |
| 2025 | if (__r.second) |
| 2026 | __h.release(); |
| 2027 | return __r; |
| 2028 | } |
| 2029 | |
| 2030 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2031 | template <class... _Args> |
| 2032 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 2033 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args) |
| 2034 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2035 | __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2036 | iterator __r = __node_insert_multi(__h.get()); |
| 2037 | __h.release(); |
| 2038 | return __r; |
| 2039 | } |
| 2040 | |
| 2041 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2042 | template <class... _Args> |
| 2043 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 2044 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi( |
| 2045 | const_iterator __p, _Args&&... __args) |
| 2046 | { |
Howard Hinnant | 0bb0a7c | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 2047 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2048 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 2049 | "unordered container::emplace_hint(const_iterator, args...) called with an iterator not" |
| 2050 | " referring to this unordered container"); |
| 2051 | #endif |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2052 | __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2053 | iterator __r = __node_insert_multi(__p, __h.get()); |
| 2054 | __h.release(); |
| 2055 | return __r; |
| 2056 | } |
| 2057 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2058 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2059 | |
| 2060 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2061 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2062 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const __container_value_type& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2063 | { |
| 2064 | __node_holder __h = __construct_node(__x); |
| 2065 | iterator __r = __node_insert_multi(__h.get()); |
| 2066 | __h.release(); |
| 2067 | return __r; |
| 2068 | } |
| 2069 | |
| 2070 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2071 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 2072 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p, |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2073 | const __container_value_type& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2074 | { |
Howard Hinnant | 0bb0a7c | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 2075 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2076 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 2077 | "unordered container::insert(const_iterator, lvalue) called with an iterator not" |
| 2078 | " referring to this unordered container"); |
| 2079 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2080 | __node_holder __h = __construct_node(__x); |
| 2081 | iterator __r = __node_insert_multi(__p, __h.get()); |
| 2082 | __h.release(); |
| 2083 | return __r; |
| 2084 | } |
| 2085 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2086 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2087 | |
| 2088 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2089 | void |
| 2090 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n) |
| 2091 | { |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 2092 | if (__n == 1) |
| 2093 | __n = 2; |
| 2094 | else if (__n & (__n - 1)) |
| 2095 | __n = __next_prime(__n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2096 | size_type __bc = bucket_count(); |
| 2097 | if (__n > __bc) |
| 2098 | __rehash(__n); |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 2099 | else if (__n < __bc) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2100 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2101 | __n = _VSTD::max<size_type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2102 | ( |
| 2103 | __n, |
Eric Fiselier | 57947ca | 2015-02-02 21:31:48 +0000 | [diff] [blame] | 2104 | __is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) : |
| 2105 | __next_prime(size_t(ceil(float(size()) / max_load_factor()))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2106 | ); |
| 2107 | if (__n < __bc) |
| 2108 | __rehash(__n); |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2113 | void |
| 2114 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc) |
| 2115 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2116 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2117 | __get_db()->__invalidate_all(this); |
| 2118 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2119 | __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc(); |
| 2120 | __bucket_list_.reset(__nbc > 0 ? |
| 2121 | __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr); |
| 2122 | __bucket_list_.get_deleter().size() = __nbc; |
| 2123 | if (__nbc > 0) |
| 2124 | { |
| 2125 | for (size_type __i = 0; __i < __nbc; ++__i) |
| 2126 | __bucket_list_[__i] = nullptr; |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2127 | __next_pointer __pp = __p1_.first().__ptr(); |
| 2128 | __next_pointer __cp = __pp->__next_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2129 | if (__cp != nullptr) |
| 2130 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2131 | size_type __chash = __constrain_hash(__cp->__hash(), __nbc); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2132 | __bucket_list_[__chash] = __pp; |
| 2133 | size_type __phash = __chash; |
| 2134 | for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr; |
| 2135 | __cp = __pp->__next_) |
| 2136 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2137 | __chash = __constrain_hash(__cp->__hash(), __nbc); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2138 | if (__chash == __phash) |
| 2139 | __pp = __cp; |
| 2140 | else |
| 2141 | { |
| 2142 | if (__bucket_list_[__chash] == nullptr) |
| 2143 | { |
| 2144 | __bucket_list_[__chash] = __pp; |
| 2145 | __pp = __cp; |
| 2146 | __phash = __chash; |
| 2147 | } |
| 2148 | else |
| 2149 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2150 | __next_pointer __np = __cp; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2151 | for (; __np->__next_ != nullptr && |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2152 | key_eq()(__cp->__upcast()->__value_, |
| 2153 | __np->__next_->__upcast()->__value_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2154 | __np = __np->__next_) |
| 2155 | ; |
| 2156 | __pp->__next_ = __np->__next_; |
| 2157 | __np->__next_ = __bucket_list_[__chash]->__next_; |
| 2158 | __bucket_list_[__chash]->__next_ = __cp; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2159 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2160 | } |
| 2161 | } |
| 2162 | } |
| 2163 | } |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2168 | template <class _Key> |
| 2169 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 2170 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) |
| 2171 | { |
| 2172 | size_t __hash = hash_function()(__k); |
| 2173 | size_type __bc = bucket_count(); |
| 2174 | if (__bc != 0) |
| 2175 | { |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 2176 | size_t __chash = __constrain_hash(__hash, __bc); |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2177 | __next_pointer __nd = __bucket_list_[__chash]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2178 | if (__nd != nullptr) |
| 2179 | { |
| 2180 | for (__nd = __nd->__next_; __nd != nullptr && |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2181 | (__nd->__hash() == __hash |
| 2182 | || __constrain_hash(__nd->__hash(), __bc) == __chash); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2183 | __nd = __nd->__next_) |
| 2184 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2185 | if ((__nd->__hash() == __hash) |
| 2186 | && key_eq()(__nd->__upcast()->__value_, __k)) |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2187 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2188 | return iterator(__nd, this); |
| 2189 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2190 | return iterator(__nd); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2191 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2192 | } |
| 2193 | } |
| 2194 | } |
| 2195 | return end(); |
| 2196 | } |
| 2197 | |
| 2198 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2199 | template <class _Key> |
| 2200 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator |
| 2201 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const |
| 2202 | { |
| 2203 | size_t __hash = hash_function()(__k); |
| 2204 | size_type __bc = bucket_count(); |
| 2205 | if (__bc != 0) |
| 2206 | { |
Howard Hinnant | 7a44515 | 2012-07-06 17:31:14 +0000 | [diff] [blame] | 2207 | size_t __chash = __constrain_hash(__hash, __bc); |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2208 | __next_pointer __nd = __bucket_list_[__chash]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2209 | if (__nd != nullptr) |
| 2210 | { |
| 2211 | for (__nd = __nd->__next_; __nd != nullptr && |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2212 | (__hash == __nd->__hash() |
| 2213 | || __constrain_hash(__nd->__hash(), __bc) == __chash); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2214 | __nd = __nd->__next_) |
| 2215 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2216 | if ((__nd->__hash() == __hash) |
| 2217 | && key_eq()(__nd->__upcast()->__value_, __k)) |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2218 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2219 | return const_iterator(__nd, this); |
| 2220 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2221 | return const_iterator(__nd); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2222 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2223 | } |
| 2224 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2225 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2226 | } |
| 2227 | return end(); |
| 2228 | } |
| 2229 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2230 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2231 | |
| 2232 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2233 | template <class ..._Args> |
| 2234 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder |
| 2235 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args) |
| 2236 | { |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2237 | static_assert(!__is_hash_value_type<_Args...>::value, |
| 2238 | "Construct cannot be called with a hash value type"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2239 | __node_allocator& __na = __node_alloc(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2240 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2241 | __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2242 | __h.get_deleter().__value_constructed = true; |
| 2243 | __h->__hash_ = hash_function()(__h->__value_); |
| 2244 | __h->__next_ = nullptr; |
| 2245 | return __h; |
| 2246 | } |
| 2247 | |
| 2248 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2249 | template <class _First, class ..._Rest> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2250 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2251 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash( |
| 2252 | size_t __hash, _First&& __f, _Rest&& ...__rest) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2253 | { |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2254 | static_assert(!__is_hash_value_type<_First, _Rest...>::value, |
| 2255 | "Construct cannot be called with a hash value type"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2256 | __node_allocator& __na = __node_alloc(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2257 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2258 | __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), |
| 2259 | _VSTD::forward<_First>(__f), |
| 2260 | _VSTD::forward<_Rest>(__rest)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2261 | __h.get_deleter().__value_constructed = true; |
| 2262 | __h->__hash_ = __hash; |
| 2263 | __h->__next_ = nullptr; |
Howard Hinnant | 9a894d9 | 2013-08-22 18:29:50 +0000 | [diff] [blame] | 2264 | return __h; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2265 | } |
| 2266 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2267 | #else // _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2268 | |
| 2269 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2270 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2271 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const __container_value_type& __v) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2272 | { |
| 2273 | __node_allocator& __na = __node_alloc(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2274 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2275 | __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2276 | __h.get_deleter().__value_constructed = true; |
| 2277 | __h->__hash_ = hash_function()(__h->__value_); |
| 2278 | __h->__next_ = nullptr; |
Dimitry Andric | 8966350 | 2015-08-19 06:43:33 +0000 | [diff] [blame] | 2279 | return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2280 | } |
| 2281 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2282 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2283 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2284 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash, |
| 2285 | const __container_value_type& __v) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2286 | { |
| 2287 | __node_allocator& __na = __node_alloc(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2288 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2289 | __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2290 | __h.get_deleter().__value_constructed = true; |
| 2291 | __h->__hash_ = __hash; |
| 2292 | __h->__next_ = nullptr; |
Dimitry Andric | 8966350 | 2015-08-19 06:43:33 +0000 | [diff] [blame] | 2293 | return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2294 | } |
| 2295 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 2296 | #endif // _LIBCPP_CXX03_LANG |
| 2297 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2298 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2299 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 2300 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p) |
| 2301 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2302 | __next_pointer __np = __p.__node_; |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2303 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2304 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 2305 | "unordered container erase(iterator) called with an iterator not" |
| 2306 | " referring to this container"); |
| 2307 | _LIBCPP_ASSERT(__p != end(), |
| 2308 | "unordered container erase(iterator) called with a non-dereferenceable iterator"); |
| 2309 | iterator __r(__np, this); |
| 2310 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2311 | iterator __r(__np); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2312 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2313 | ++__r; |
| 2314 | remove(__p); |
| 2315 | return __r; |
| 2316 | } |
| 2317 | |
| 2318 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2319 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator |
| 2320 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, |
| 2321 | const_iterator __last) |
| 2322 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2323 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2324 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, |
| 2325 | "unodered container::erase(iterator, iterator) called with an iterator not" |
| 2326 | " referring to this unodered container"); |
| 2327 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, |
| 2328 | "unodered container::erase(iterator, iterator) called with an iterator not" |
| 2329 | " referring to this unodered container"); |
| 2330 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2331 | for (const_iterator __p = __first; __first != __last; __p = __first) |
| 2332 | { |
| 2333 | ++__first; |
| 2334 | erase(__p); |
| 2335 | } |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2336 | __next_pointer __np = __last.__node_; |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2337 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2338 | return iterator (__np, this); |
| 2339 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2340 | return iterator (__np); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2341 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2345 | template <class _Key> |
| 2346 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type |
| 2347 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k) |
| 2348 | { |
| 2349 | iterator __i = find(__k); |
| 2350 | if (__i == end()) |
| 2351 | return 0; |
| 2352 | erase(__i); |
| 2353 | return 1; |
| 2354 | } |
| 2355 | |
| 2356 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2357 | template <class _Key> |
| 2358 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type |
| 2359 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k) |
| 2360 | { |
| 2361 | size_type __r = 0; |
| 2362 | iterator __i = find(__k); |
| 2363 | if (__i != end()) |
| 2364 | { |
| 2365 | iterator __e = end(); |
| 2366 | do |
| 2367 | { |
| 2368 | erase(__i++); |
| 2369 | ++__r; |
| 2370 | } while (__i != __e && key_eq()(*__i, __k)); |
| 2371 | } |
| 2372 | return __r; |
| 2373 | } |
| 2374 | |
| 2375 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2376 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 2377 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2378 | { |
| 2379 | // current node |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2380 | __next_pointer __cn = __p.__node_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2381 | size_type __bc = bucket_count(); |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2382 | size_t __chash = __constrain_hash(__cn->__hash(), __bc); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2383 | // find previous node |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2384 | __next_pointer __pn = __bucket_list_[__chash]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2385 | for (; __pn->__next_ != __cn; __pn = __pn->__next_) |
| 2386 | ; |
| 2387 | // Fix up __bucket_list_ |
| 2388 | // if __pn is not in same bucket (before begin is not in same bucket) && |
| 2389 | // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2390 | if (__pn == __p1_.first().__ptr() |
| 2391 | || __constrain_hash(__pn->__hash(), __bc) != __chash) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2392 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2393 | if (__cn->__next_ == nullptr |
| 2394 | || __constrain_hash(__cn->__next_->__hash(), __bc) != __chash) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2395 | __bucket_list_[__chash] = nullptr; |
| 2396 | } |
| 2397 | // if __cn->__next_ is not in same bucket (nullptr is in same bucket) |
| 2398 | if (__cn->__next_ != nullptr) |
| 2399 | { |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2400 | size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2401 | if (__nhash != __chash) |
| 2402 | __bucket_list_[__nhash] = __pn; |
| 2403 | } |
| 2404 | // remove __cn |
| 2405 | __pn->__next_ = __cn->__next_; |
| 2406 | __cn->__next_ = nullptr; |
| 2407 | --size(); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2408 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2409 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 2410 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
| 2411 | { |
| 2412 | --__p; |
| 2413 | iterator* __i = static_cast<iterator*>((*__p)->__i_); |
| 2414 | if (__i->__node_ == __cn) |
| 2415 | { |
| 2416 | (*__p)->__c_ = nullptr; |
| 2417 | if (--__c->end_ != __p) |
| 2418 | memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
| 2419 | } |
| 2420 | } |
| 2421 | __get_db()->unlock(); |
| 2422 | #endif |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2423 | return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2427 | template <class _Key> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 2428 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2429 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type |
| 2430 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const |
| 2431 | { |
| 2432 | return static_cast<size_type>(find(__k) != end()); |
| 2433 | } |
| 2434 | |
| 2435 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2436 | template <class _Key> |
| 2437 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type |
| 2438 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const |
| 2439 | { |
| 2440 | size_type __r = 0; |
| 2441 | const_iterator __i = find(__k); |
| 2442 | if (__i != end()) |
| 2443 | { |
| 2444 | const_iterator __e = end(); |
| 2445 | do |
| 2446 | { |
| 2447 | ++__i; |
| 2448 | ++__r; |
| 2449 | } while (__i != __e && key_eq()(*__i, __k)); |
| 2450 | } |
| 2451 | return __r; |
| 2452 | } |
| 2453 | |
| 2454 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2455 | template <class _Key> |
| 2456 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, |
| 2457 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> |
| 2458 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( |
| 2459 | const _Key& __k) |
| 2460 | { |
| 2461 | iterator __i = find(__k); |
| 2462 | iterator __j = __i; |
| 2463 | if (__i != end()) |
| 2464 | ++__j; |
| 2465 | return pair<iterator, iterator>(__i, __j); |
| 2466 | } |
| 2467 | |
| 2468 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2469 | template <class _Key> |
| 2470 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator, |
| 2471 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> |
| 2472 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique( |
| 2473 | const _Key& __k) const |
| 2474 | { |
| 2475 | const_iterator __i = find(__k); |
| 2476 | const_iterator __j = __i; |
| 2477 | if (__i != end()) |
| 2478 | ++__j; |
| 2479 | return pair<const_iterator, const_iterator>(__i, __j); |
| 2480 | } |
| 2481 | |
| 2482 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2483 | template <class _Key> |
| 2484 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, |
| 2485 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator> |
| 2486 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( |
| 2487 | const _Key& __k) |
| 2488 | { |
| 2489 | iterator __i = find(__k); |
| 2490 | iterator __j = __i; |
| 2491 | if (__i != end()) |
| 2492 | { |
| 2493 | iterator __e = end(); |
| 2494 | do |
| 2495 | { |
| 2496 | ++__j; |
| 2497 | } while (__j != __e && key_eq()(*__j, __k)); |
| 2498 | } |
| 2499 | return pair<iterator, iterator>(__i, __j); |
| 2500 | } |
| 2501 | |
| 2502 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2503 | template <class _Key> |
| 2504 | pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator, |
| 2505 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator> |
| 2506 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( |
| 2507 | const _Key& __k) const |
| 2508 | { |
| 2509 | const_iterator __i = find(__k); |
| 2510 | const_iterator __j = __i; |
| 2511 | if (__i != end()) |
| 2512 | { |
| 2513 | const_iterator __e = end(); |
| 2514 | do |
| 2515 | { |
| 2516 | ++__j; |
| 2517 | } while (__j != __e && key_eq()(*__j, __k)); |
| 2518 | } |
| 2519 | return pair<const_iterator, const_iterator>(__i, __j); |
| 2520 | } |
| 2521 | |
| 2522 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2523 | void |
| 2524 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 2525 | #if _LIBCPP_STD_VER <= 11 |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 2526 | _NOEXCEPT_( |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2527 | __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2528 | && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value |
| 2529 | || __is_nothrow_swappable<__pointer_allocator>::value) |
| 2530 | && (!__node_traits::propagate_on_container_swap::value |
| 2531 | || __is_nothrow_swappable<__node_allocator>::value) |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2532 | ) |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 2533 | #else |
| 2534 | _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value) |
| 2535 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2536 | { |
| 2537 | { |
| 2538 | __node_pointer_pointer __npp = __bucket_list_.release(); |
| 2539 | __bucket_list_.reset(__u.__bucket_list_.release()); |
| 2540 | __u.__bucket_list_.reset(__npp); |
| 2541 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2542 | _VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size()); |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2543 | __swap_allocator(__bucket_list_.get_deleter().__alloc(), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2544 | __u.__bucket_list_.get_deleter().__alloc()); |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2545 | __swap_allocator(__node_alloc(), __u.__node_alloc()); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2546 | _VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2547 | __p2_.swap(__u.__p2_); |
| 2548 | __p3_.swap(__u.__p3_); |
| 2549 | if (size() > 0) |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2550 | __bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = |
| 2551 | __p1_.first().__ptr(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2552 | if (__u.size() > 0) |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2553 | __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = |
| 2554 | __u.__p1_.first().__ptr(); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2555 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2556 | __get_db()->swap(this, &__u); |
| 2557 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2561 | typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type |
| 2562 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const |
| 2563 | { |
Howard Hinnant | 0bb0a7c | 2013-07-29 19:05:47 +0000 | [diff] [blame] | 2564 | _LIBCPP_ASSERT(__n < bucket_count(), |
| 2565 | "unordered container::bucket_size(n) called with n >= bucket_count()"); |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2566 | __next_pointer __np = __bucket_list_[__n]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2567 | size_type __bc = bucket_count(); |
| 2568 | size_type __r = 0; |
| 2569 | if (__np != nullptr) |
| 2570 | { |
| 2571 | for (__np = __np->__next_; __np != nullptr && |
Eric Fiselier | f653588 | 2016-07-23 20:36:55 +0000 | [diff] [blame] | 2572 | __constrain_hash(__np->__hash(), __bc) == __n; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2573 | __np = __np->__next_, ++__r) |
| 2574 | ; |
| 2575 | } |
| 2576 | return __r; |
| 2577 | } |
| 2578 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 2579 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2580 | inline _LIBCPP_INLINE_VISIBILITY |
| 2581 | void |
| 2582 | swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x, |
| 2583 | __hash_table<_Tp, _Hash, _Equal, _Alloc>& __y) |
| 2584 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
| 2585 | { |
| 2586 | __x.swap(__y); |
| 2587 | } |
| 2588 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2589 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2590 | |
| 2591 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2592 | bool |
| 2593 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const |
| 2594 | { |
| 2595 | return __i->__node_ != nullptr; |
| 2596 | } |
| 2597 | |
| 2598 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2599 | bool |
| 2600 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const |
| 2601 | { |
| 2602 | return false; |
| 2603 | } |
| 2604 | |
| 2605 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2606 | bool |
| 2607 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const |
| 2608 | { |
| 2609 | return false; |
| 2610 | } |
| 2611 | |
| 2612 | template <class _Tp, class _Hash, class _Equal, class _Alloc> |
| 2613 | bool |
| 2614 | __hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const |
| 2615 | { |
| 2616 | return false; |
| 2617 | } |
| 2618 | |
| 2619 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2620 | _LIBCPP_END_NAMESPACE_STD |
| 2621 | |
| 2622 | #endif // _LIBCPP__HASH_TABLE |