2010-05-12 03:42:16 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP__HASH_TABLE
|
|
|
|
#define _LIBCPP__HASH_TABLE
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <initializer_list>
|
|
|
|
#include <memory>
|
|
|
|
#include <iterator>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cmath>
|
2016-02-11 04:46:23 +08:00
|
|
|
#include <utility>
|
2017-01-14 06:42:53 +08:00
|
|
|
#include <type_traits>
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2014-08-11 07:53:08 +08:00
|
|
|
#include <__debug>
|
Ok, 3 major changes for debug mode in one commit:
1. I had been detecting and trapping iterator == and \!= among iterators
in different containers as an error. But the trapping itself is actually
an error.
Consider:
#include <iostream>
#include <vector>
#include <algorithm>
template <class C>
void
display(const C& c)
{
std::cout << "{";
bool first = true;
for (const auto& x : c)
{
if (\!first)
std::cout << ", ";
first = false;
std::cout << x;
}
std::cout << "}\n";
}
int
main()
{
typedef std::vector<int> V;
V v1 = {1, 3, 5};
V v2 = {2, 4, 6};
display(v1);
display(v2);
V::iterator i = std::find(v1.begin(), v1.end(), 1);
V::iterator j = std::find(v2.begin(), v2.end(), 2);
if (*i == *j)
i = j; // perfectly legal
// ...
if (i \!= j) // the only way to check
v2.push_back(*i);
display(v1);
display(v2);
}
It is legal to assign an iterator from one container to another of the
same type. This is required to work. One might want to test whether or
not such an assignment had been made. The way one performs such a check
is using the iterator's ==, \!= operator. This is a logical and necessary
function and does not constitute an error.
2. I had a header circular dependence bug when _LIBCPP_DEBUG2 is defined.
This caused a problem in several of the libc++ tests.
Fixed.
3. There is a serious problem when _LIBCPP_DEBUG2=1 at the moment in that
std::basic_string is inoperable. std::basic_string uses __wrap_iterator
to implement its iterators. __wrap_iterator has been rigged up in debug
mode to support vector. But string hasn't been rigged up yet. This means
that one gets false positives when using std::string in debug mode. I've
upped std::string's priority in www/debug_mode.html.
llvm-svn: 187636
2013-08-02 08:26:35 +08:00
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2010-05-12 03:42:16 +08:00
|
|
|
#pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-06-01 06:07:49 +08:00
|
|
|
_LIBCPP_PUSH_MACROS
|
|
|
|
#include <__undef_macros>
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-06-01 06:07:49 +08:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
2016-02-11 19:59:44 +08:00
|
|
|
|
|
|
|
template <class _Key, class _Tp>
|
|
|
|
struct __hash_value_type;
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
|
|
|
template <class _Tp>
|
|
|
|
struct __is_hash_value_type_imp : false_type {};
|
|
|
|
|
|
|
|
template <class _Key, class _Value>
|
|
|
|
struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {};
|
|
|
|
|
|
|
|
template <class ..._Args>
|
|
|
|
struct __is_hash_value_type : false_type {};
|
|
|
|
|
|
|
|
template <class _One>
|
|
|
|
struct __is_hash_value_type<_One> : __is_hash_value_type_imp<typename __uncvref<_One>::type> {};
|
|
|
|
#endif
|
|
|
|
|
2013-03-07 07:30:19 +08:00
|
|
|
_LIBCPP_FUNC_VIS
|
2011-06-15 03:58:17 +08:00
|
|
|
size_t __next_prime(size_t __n);
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _NodePtr>
|
|
|
|
struct __hash_node_base
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
typedef typename pointer_traits<_NodePtr>::element_type __node_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef __hash_node_base __first_node;
|
2016-07-24 04:36:55 +08:00
|
|
|
typedef typename __rebind_pointer<_NodePtr, __first_node>::type __node_base_pointer;
|
|
|
|
typedef _NodePtr __node_pointer;
|
|
|
|
|
|
|
|
#if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB)
|
|
|
|
typedef __node_base_pointer __next_pointer;
|
|
|
|
#else
|
|
|
|
typedef typename conditional<
|
|
|
|
is_pointer<__node_pointer>::value,
|
|
|
|
__node_base_pointer,
|
|
|
|
__node_pointer>::type __next_pointer;
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __next_;
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__next_pointer __ptr() _NOEXCEPT {
|
|
|
|
return static_cast<__next_pointer>(
|
|
|
|
pointer_traits<__node_base_pointer>::pointer_to(*this));
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__node_pointer __upcast() _NOEXCEPT {
|
|
|
|
return static_cast<__node_pointer>(
|
|
|
|
pointer_traits<__node_base_pointer>::pointer_to(*this));
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
size_t __hash() const _NOEXCEPT {
|
|
|
|
return static_cast<__node_type const&>(*this).__hash_;
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-05 02:54:24 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _VoidPtr>
|
|
|
|
struct __hash_node
|
|
|
|
: public __hash_node_base
|
|
|
|
<
|
2015-12-31 05:52:00 +08:00
|
|
|
typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type
|
2010-05-12 03:42:16 +08:00
|
|
|
>
|
|
|
|
{
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef _Tp __node_value_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-24 04:36:55 +08:00
|
|
|
size_t __hash_;
|
2016-02-11 04:46:23 +08:00
|
|
|
__node_value_type __value_;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2012-07-07 01:31:14 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
2015-02-03 05:31:48 +08:00
|
|
|
__is_hash_power2(size_t __bc)
|
2012-07-07 01:31:14 +08:00
|
|
|
{
|
|
|
|
return __bc > 2 && !(__bc & (__bc - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
size_t
|
|
|
|
__constrain_hash(size_t __h, size_t __bc)
|
|
|
|
{
|
2016-07-12 06:02:02 +08:00
|
|
|
return !(__bc & (__bc - 1)) ? __h & (__bc - 1) :
|
|
|
|
(__h < __bc ? __h : __h % __bc);
|
2012-07-07 01:31:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
size_t
|
2015-02-03 05:31:48 +08:00
|
|
|
__next_hash_pow2(size_t __n)
|
2012-07-07 01:31:14 +08:00
|
|
|
{
|
2017-06-03 08:08:32 +08:00
|
|
|
return __n < 2 ? __n : (size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1)));
|
2012-07-07 01:31:14 +08:00
|
|
|
}
|
|
|
|
|
2016-03-18 04:45:20 +08:00
|
|
|
|
2011-06-15 03:58:17 +08:00
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table;
|
2016-02-11 04:46:23 +08:00
|
|
|
|
2017-01-05 07:56:00 +08:00
|
|
|
template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_iterator;
|
|
|
|
template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
|
|
|
|
template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_local_iterator;
|
|
|
|
template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
|
|
|
|
template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
|
|
|
|
template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-02-11 04:46:23 +08:00
|
|
|
template <class _Tp>
|
2016-02-20 15:59:16 +08:00
|
|
|
struct __hash_key_value_types {
|
2016-02-11 04:46:23 +08:00
|
|
|
static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, "");
|
|
|
|
typedef _Tp key_type;
|
|
|
|
typedef _Tp __node_value_type;
|
|
|
|
typedef _Tp __container_value_type;
|
|
|
|
static const bool __is_map = false;
|
2016-02-11 19:59:44 +08:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static key_type const& __get_key(_Tp const& __v) {
|
|
|
|
return __v;
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static __container_value_type const& __get_value(__node_value_type const& __v) {
|
|
|
|
return __v;
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static __container_value_type* __get_ptr(__node_value_type& __n) {
|
|
|
|
return _VSTD::addressof(__n);
|
|
|
|
}
|
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2018-06-05 04:38:23 +08:00
|
|
|
static __container_value_type&& __move(__node_value_type& __v) {
|
2016-02-11 19:59:44 +08:00
|
|
|
return _VSTD::move(__v);
|
|
|
|
}
|
|
|
|
#endif
|
2016-02-11 04:46:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Key, class _Tp>
|
2016-02-20 15:59:16 +08:00
|
|
|
struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > {
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef _Key key_type;
|
|
|
|
typedef _Tp mapped_type;
|
|
|
|
typedef __hash_value_type<_Key, _Tp> __node_value_type;
|
|
|
|
typedef pair<const _Key, _Tp> __container_value_type;
|
|
|
|
typedef __container_value_type __map_value_type;
|
|
|
|
static const bool __is_map = true;
|
2016-02-11 19:59:44 +08:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static key_type const& __get_key(__container_value_type const& __v) {
|
|
|
|
return __v.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Up>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value,
|
|
|
|
__container_value_type const&>::type
|
|
|
|
__get_value(_Up& __t) {
|
2018-06-05 04:38:23 +08:00
|
|
|
return __t.__get_value();
|
2016-02-11 19:59:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Up>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value,
|
|
|
|
__container_value_type const&>::type
|
|
|
|
__get_value(_Up& __t) {
|
|
|
|
return __t;
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static __container_value_type* __get_ptr(__node_value_type& __n) {
|
2018-06-05 04:38:23 +08:00
|
|
|
return _VSTD::addressof(__n.__get_value());
|
2016-02-11 19:59:44 +08:00
|
|
|
}
|
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2018-06-05 04:38:23 +08:00
|
|
|
static pair<key_type&&, mapped_type&&> __move(__node_value_type& __v) {
|
|
|
|
return __v.__move();
|
2016-02-11 19:59:44 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-11 04:46:23 +08:00
|
|
|
};
|
|
|
|
|
2016-02-20 15:59:16 +08:00
|
|
|
template <class _Tp, class _AllocPtr, class _KVTypes = __hash_key_value_types<_Tp>,
|
2016-02-11 04:46:23 +08:00
|
|
|
bool = _KVTypes::__is_map>
|
2016-02-20 15:59:16 +08:00
|
|
|
struct __hash_map_pointer_types {};
|
2016-02-11 04:46:23 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _AllocPtr, class _KVTypes>
|
2016-02-20 15:59:16 +08:00
|
|
|
struct __hash_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> {
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef typename _KVTypes::__map_value_type _Mv;
|
|
|
|
typedef typename __rebind_pointer<_AllocPtr, _Mv>::type
|
|
|
|
__map_value_type_pointer;
|
|
|
|
typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type
|
|
|
|
__const_map_value_type_pointer;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type>
|
|
|
|
struct __hash_node_types;
|
|
|
|
|
|
|
|
template <class _NodePtr, class _Tp, class _VoidPtr>
|
|
|
|
struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> >
|
2016-02-20 15:59:16 +08:00
|
|
|
: public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr>
|
2016-02-11 04:46:23 +08:00
|
|
|
|
|
|
|
{
|
2016-02-20 15:59:16 +08:00
|
|
|
typedef __hash_key_value_types<_Tp> __base;
|
2016-02-11 04:46:23 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef size_t size_type;
|
|
|
|
|
|
|
|
typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer;
|
|
|
|
|
|
|
|
typedef typename pointer_traits<_NodePtr>::element_type __node_type;
|
|
|
|
typedef _NodePtr __node_pointer;
|
|
|
|
|
|
|
|
typedef __hash_node_base<__node_pointer> __node_base_type;
|
|
|
|
typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type
|
|
|
|
__node_base_pointer;
|
|
|
|
|
2016-07-24 04:36:55 +08:00
|
|
|
typedef typename __node_base_type::__next_pointer __next_pointer;
|
|
|
|
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef _Tp __node_value_type;
|
|
|
|
typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type
|
|
|
|
__node_value_type_pointer;
|
|
|
|
typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type
|
|
|
|
__const_node_value_type_pointer;
|
2016-07-24 04:36:55 +08:00
|
|
|
|
2016-02-11 04:46:23 +08:00
|
|
|
private:
|
|
|
|
static_assert(!is_const<__node_type>::value,
|
|
|
|
"_NodePtr should never be a pointer to const");
|
|
|
|
static_assert((is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value),
|
|
|
|
"_VoidPtr does not point to unqualified void type");
|
|
|
|
static_assert((is_same<typename __rebind_pointer<_VoidPtr, __node_type>::type,
|
|
|
|
_NodePtr>::value), "_VoidPtr does not rebind to _NodePtr.");
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _HashIterator>
|
|
|
|
struct __hash_node_types_from_iterator;
|
|
|
|
template <class _NodePtr>
|
|
|
|
struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
|
|
|
|
template <class _NodePtr>
|
|
|
|
struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
|
|
|
|
template <class _NodePtr>
|
|
|
|
struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
|
|
|
|
template <class _NodePtr>
|
|
|
|
struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
|
|
|
|
|
|
|
|
|
|
|
|
template <class _NodeValueTp, class _VoidPtr>
|
|
|
|
struct __make_hash_node_types {
|
|
|
|
typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp;
|
|
|
|
typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr;
|
|
|
|
typedef __hash_node_types<_NodePtr> type;
|
|
|
|
};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _NodePtr>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS __hash_iterator
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef __hash_node_types<_NodePtr> _NodeTypes;
|
2016-07-24 04:36:55 +08:00
|
|
|
typedef _NodePtr __node_pointer;
|
|
|
|
typedef typename _NodeTypes::__next_pointer __next_pointer;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __node_;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
public:
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef forward_iterator_tag iterator_category;
|
|
|
|
typedef typename _NodeTypes::__node_value_type value_type;
|
|
|
|
typedef typename _NodeTypes::difference_type difference_type;
|
|
|
|
typedef value_type& reference;
|
|
|
|
typedef typename _NodeTypes::__node_value_type_pointer pointer;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-24 04:36:55 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT : __node_(nullptr) {
|
|
|
|
_LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__hash_iterator(const __hash_iterator& __i)
|
|
|
|
: __node_(__i.__node_)
|
|
|
|
{
|
|
|
|
__get_db()->__iterator_copy(this, &__i);
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
~__hash_iterator()
|
|
|
|
{
|
|
|
|
__get_db()->__erase_i(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__hash_iterator& operator=(const __hash_iterator& __i)
|
|
|
|
{
|
|
|
|
if (this != &__i)
|
|
|
|
{
|
|
|
|
__get_db()->__iterator_copy(this, &__i);
|
|
|
|
__node_ = __i.__node_;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_DEBUG_LEVEL >= 2
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
reference operator*() const {
|
|
|
|
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
|
|
|
|
"Attempted to dereference a non-dereferenceable unordered container iterator");
|
|
|
|
return __node_->__upcast()->__value_;
|
|
|
|
}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
pointer operator->() const {
|
|
|
|
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
"Attempted to dereference a non-dereferenceable unordered container iterator");
|
2016-07-24 04:36:55 +08:00
|
|
|
return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
__hash_iterator& operator++() {
|
|
|
|
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
"Attempted to increment non-incrementable unordered container iterator");
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_ = __node_->__next_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__hash_iterator operator++(int)
|
|
|
|
{
|
|
|
|
__hash_iterator __t(*this);
|
|
|
|
++(*this);
|
|
|
|
return __t;
|
|
|
|
}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator==(const __hash_iterator& __x, const __hash_iterator& __y)
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
{
|
|
|
|
return __x.__node_ == __y.__node_;
|
|
|
|
}
|
2010-09-22 01:32:39 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y)
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
{return !(__x == __y);}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
private:
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
__hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
: __node_(__node)
|
|
|
|
{
|
|
|
|
__get_db()->__insert_ic(this, __c);
|
|
|
|
}
|
|
|
|
#else
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
__hash_iterator(__next_pointer __node) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __node_(__node)
|
|
|
|
{}
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class, class, class, class> friend class __hash_table;
|
2017-01-05 07:56:00 +08:00
|
|
|
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
|
|
|
|
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
|
|
|
|
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
|
|
|
|
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2016-02-11 04:46:23 +08:00
|
|
|
template <class _NodePtr>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS __hash_const_iterator
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-02-11 04:46:23 +08:00
|
|
|
static_assert(!is_const<typename pointer_traits<_NodePtr>::element_type>::value, "");
|
|
|
|
typedef __hash_node_types<_NodePtr> _NodeTypes;
|
2016-07-24 04:36:55 +08:00
|
|
|
typedef _NodePtr __node_pointer;
|
|
|
|
typedef typename _NodeTypes::__next_pointer __next_pointer;
|
2016-02-18 08:20:34 +08:00
|
|
|
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __node_;
|
2016-02-09 07:47:13 +08:00
|
|
|
|
|
|
|
public:
|
2016-02-18 08:20:34 +08:00
|
|
|
typedef __hash_iterator<_NodePtr> __non_const_iterator;
|
|
|
|
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef forward_iterator_tag iterator_category;
|
|
|
|
typedef typename _NodeTypes::__node_value_type value_type;
|
|
|
|
typedef typename _NodeTypes::difference_type difference_type;
|
|
|
|
typedef const value_type& reference;
|
|
|
|
typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-24 04:36:55 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT : __node_(nullptr) {
|
|
|
|
_LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
}
|
2016-07-24 04:36:55 +08:00
|
|
|
|
2018-12-07 05:46:17 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
__hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __node_(__x.__node_)
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
_LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x));
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__hash_const_iterator(const __hash_const_iterator& __i)
|
|
|
|
: __node_(__i.__node_)
|
|
|
|
{
|
|
|
|
__get_db()->__iterator_copy(this, &__i);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
~__hash_const_iterator()
|
|
|
|
{
|
|
|
|
__get_db()->__erase_i(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__hash_const_iterator& operator=(const __hash_const_iterator& __i)
|
|
|
|
{
|
|
|
|
if (this != &__i)
|
|
|
|
{
|
|
|
|
__get_db()->__iterator_copy(this, &__i);
|
|
|
|
__node_ = __i.__node_;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
reference operator*() const {
|
|
|
|
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
"Attempted to dereference a non-dereferenceable unordered container const_iterator");
|
2016-07-24 04:36:55 +08:00
|
|
|
return __node_->__upcast()->__value_;
|
|
|
|
}
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
pointer operator->() const {
|
|
|
|
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
"Attempted to dereference a non-dereferenceable unordered container const_iterator");
|
2016-07-24 04:36:55 +08:00
|
|
|
return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
__hash_const_iterator& operator++() {
|
|
|
|
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
|
|
|
|
"Attempted to increment non-incrementable unordered container const_iterator");
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_ = __node_->__next_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__hash_const_iterator operator++(int)
|
|
|
|
{
|
|
|
|
__hash_const_iterator __t(*this);
|
|
|
|
++(*this);
|
|
|
|
return __t;
|
|
|
|
}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
{
|
|
|
|
return __x.__node_ == __y.__node_;
|
|
|
|
}
|
2010-09-22 01:32:39 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
{return !(__x == __y);}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
private:
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
__hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
: __node_(__node)
|
|
|
|
{
|
|
|
|
__get_db()->__insert_ic(this, __c);
|
|
|
|
}
|
|
|
|
#else
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
__hash_const_iterator(__next_pointer __node) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __node_(__node)
|
|
|
|
{}
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class, class, class, class> friend class __hash_table;
|
2017-01-05 07:56:00 +08:00
|
|
|
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
|
|
|
|
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
|
|
|
|
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _NodePtr>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS __hash_local_iterator
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef __hash_node_types<_NodePtr> _NodeTypes;
|
2016-07-24 04:36:55 +08:00
|
|
|
typedef _NodePtr __node_pointer;
|
|
|
|
typedef typename _NodeTypes::__next_pointer __next_pointer;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __node_;
|
2010-05-12 03:42:16 +08:00
|
|
|
size_t __bucket_;
|
|
|
|
size_t __bucket_count_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef forward_iterator_tag iterator_category;
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef typename _NodeTypes::__node_value_type value_type;
|
|
|
|
typedef typename _NodeTypes::difference_type difference_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef value_type& reference;
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef typename _NodeTypes::__node_value_type_pointer pointer;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-24 04:36:55 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT : __node_(nullptr) {
|
|
|
|
_LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__hash_local_iterator(const __hash_local_iterator& __i)
|
|
|
|
: __node_(__i.__node_),
|
|
|
|
__bucket_(__i.__bucket_),
|
|
|
|
__bucket_count_(__i.__bucket_count_)
|
|
|
|
{
|
|
|
|
__get_db()->__iterator_copy(this, &__i);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
~__hash_local_iterator()
|
|
|
|
{
|
|
|
|
__get_db()->__erase_i(this);
|
|
|
|
}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
__hash_local_iterator& operator=(const __hash_local_iterator& __i)
|
|
|
|
{
|
|
|
|
if (this != &__i)
|
|
|
|
{
|
|
|
|
__get_db()->__iterator_copy(this, &__i);
|
|
|
|
__node_ = __i.__node_;
|
|
|
|
__bucket_ = __i.__bucket_;
|
|
|
|
__bucket_count_ = __i.__bucket_count_;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
reference operator*() const {
|
|
|
|
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
"Attempted to dereference a non-dereferenceable unordered container local_iterator");
|
2016-07-24 04:36:55 +08:00
|
|
|
return __node_->__upcast()->__value_;
|
|
|
|
}
|
|
|
|
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
pointer operator->() const {
|
|
|
|
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
|
|
|
|
"Attempted to dereference a non-dereferenceable unordered container local_iterator");
|
|
|
|
return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
__hash_local_iterator& operator++() {
|
|
|
|
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
"Attempted to increment non-incrementable unordered container local_iterator");
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_ = __node_->__next_;
|
2016-07-24 04:36:55 +08:00
|
|
|
if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_)
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_ = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__hash_local_iterator operator++(int)
|
|
|
|
{
|
|
|
|
__hash_local_iterator __t(*this);
|
|
|
|
++(*this);
|
|
|
|
return __t;
|
|
|
|
}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
{
|
|
|
|
return __x.__node_ == __y.__node_;
|
|
|
|
}
|
2010-09-22 01:32:39 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
{return !(__x == __y);}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
private:
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
__hash_local_iterator(__next_pointer __node, size_t __bucket,
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
size_t __bucket_count, const void* __c) _NOEXCEPT
|
|
|
|
: __node_(__node),
|
|
|
|
__bucket_(__bucket),
|
|
|
|
__bucket_count_(__bucket_count)
|
|
|
|
{
|
|
|
|
__get_db()->__insert_ic(this, __c);
|
|
|
|
if (__node_ != nullptr)
|
|
|
|
__node_ = __node_->__next_;
|
|
|
|
}
|
|
|
|
#else
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
__hash_local_iterator(__next_pointer __node, size_t __bucket,
|
2011-06-05 02:54:24 +08:00
|
|
|
size_t __bucket_count) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __node_(__node),
|
|
|
|
__bucket_(__bucket),
|
|
|
|
__bucket_count_(__bucket_count)
|
|
|
|
{
|
|
|
|
if (__node_ != nullptr)
|
|
|
|
__node_ = __node_->__next_;
|
|
|
|
}
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class, class, class, class> friend class __hash_table;
|
2017-01-05 07:56:00 +08:00
|
|
|
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
|
|
|
|
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _ConstNodePtr>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef __hash_node_types<_ConstNodePtr> _NodeTypes;
|
2016-07-24 04:36:55 +08:00
|
|
|
typedef _ConstNodePtr __node_pointer;
|
|
|
|
typedef typename _NodeTypes::__next_pointer __next_pointer;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __node_;
|
2010-05-12 03:42:16 +08:00
|
|
|
size_t __bucket_;
|
|
|
|
size_t __bucket_count_;
|
|
|
|
|
|
|
|
typedef pointer_traits<__node_pointer> __pointer_traits;
|
|
|
|
typedef typename __pointer_traits::element_type __node;
|
|
|
|
typedef typename remove_const<__node>::type __non_const_node;
|
2015-12-31 05:52:00 +08:00
|
|
|
typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type
|
|
|
|
__non_const_node_pointer;
|
2016-02-18 08:20:34 +08:00
|
|
|
public:
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef __hash_local_iterator<__non_const_node_pointer>
|
|
|
|
__non_const_iterator;
|
2016-02-18 08:20:34 +08:00
|
|
|
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef forward_iterator_tag iterator_category;
|
|
|
|
typedef typename _NodeTypes::__node_value_type value_type;
|
|
|
|
typedef typename _NodeTypes::difference_type difference_type;
|
|
|
|
typedef const value_type& reference;
|
|
|
|
typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
|
2015-12-31 05:52:00 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-07-24 04:36:55 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) {
|
|
|
|
_LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
__hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __node_(__x.__node_),
|
|
|
|
__bucket_(__x.__bucket_),
|
|
|
|
__bucket_count_(__x.__bucket_count_)
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
_LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x));
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__hash_const_local_iterator(const __hash_const_local_iterator& __i)
|
|
|
|
: __node_(__i.__node_),
|
|
|
|
__bucket_(__i.__bucket_),
|
|
|
|
__bucket_count_(__i.__bucket_count_)
|
|
|
|
{
|
|
|
|
__get_db()->__iterator_copy(this, &__i);
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
~__hash_const_local_iterator()
|
|
|
|
{
|
|
|
|
__get_db()->__erase_i(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i)
|
|
|
|
{
|
|
|
|
if (this != &__i)
|
|
|
|
{
|
|
|
|
__get_db()->__iterator_copy(this, &__i);
|
|
|
|
__node_ = __i.__node_;
|
|
|
|
__bucket_ = __i.__bucket_;
|
|
|
|
__bucket_count_ = __i.__bucket_count_;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_DEBUG_LEVEL >= 2
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
reference operator*() const {
|
|
|
|
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
"Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
|
2016-07-24 04:36:55 +08:00
|
|
|
return __node_->__upcast()->__value_;
|
|
|
|
}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
pointer operator->() const {
|
|
|
|
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
"Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
|
2016-07-24 04:36:55 +08:00
|
|
|
return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
__hash_const_local_iterator& operator++() {
|
|
|
|
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
"Attempted to increment non-incrementable unordered container const_local_iterator");
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_ = __node_->__next_;
|
2016-07-24 04:36:55 +08:00
|
|
|
if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_)
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_ = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__hash_const_local_iterator operator++(int)
|
|
|
|
{
|
|
|
|
__hash_const_local_iterator __t(*this);
|
|
|
|
++(*this);
|
|
|
|
return __t;
|
|
|
|
}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
{
|
|
|
|
return __x.__node_ == __y.__node_;
|
|
|
|
}
|
2010-09-22 01:32:39 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
{return !(__x == __y);}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
private:
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
__hash_const_local_iterator(__next_pointer __node, size_t __bucket,
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
size_t __bucket_count, const void* __c) _NOEXCEPT
|
|
|
|
: __node_(__node),
|
|
|
|
__bucket_(__bucket),
|
|
|
|
__bucket_count_(__bucket_count)
|
|
|
|
{
|
|
|
|
__get_db()->__insert_ic(this, __c);
|
|
|
|
if (__node_ != nullptr)
|
|
|
|
__node_ = __node_->__next_;
|
|
|
|
}
|
|
|
|
#else
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-07-24 04:36:55 +08:00
|
|
|
__hash_const_local_iterator(__next_pointer __node, size_t __bucket,
|
2011-06-05 02:54:24 +08:00
|
|
|
size_t __bucket_count) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __node_(__node),
|
|
|
|
__bucket_(__bucket),
|
|
|
|
__bucket_count_(__bucket_count)
|
|
|
|
{
|
|
|
|
if (__node_ != nullptr)
|
|
|
|
__node_ = __node_->__next_;
|
|
|
|
}
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class, class, class, class> friend class __hash_table;
|
2017-01-05 07:56:00 +08:00
|
|
|
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
class __bucket_list_deallocator
|
|
|
|
{
|
|
|
|
typedef _Alloc allocator_type;
|
|
|
|
typedef allocator_traits<allocator_type> __alloc_traits;
|
|
|
|
typedef typename __alloc_traits::size_type size_type;
|
|
|
|
|
|
|
|
__compressed_pair<size_type, allocator_type> __data_;
|
|
|
|
public:
|
|
|
|
typedef typename __alloc_traits::pointer pointer;
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__bucket_list_deallocator()
|
2011-06-05 02:54:24 +08:00
|
|
|
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
: __data_(0) {}
|
2010-09-22 01:32:39 +08:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__bucket_list_deallocator(const allocator_type& __a, size_type __size)
|
2011-06-05 02:54:24 +08:00
|
|
|
_NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
: __data_(__size, __a) {}
|
|
|
|
|
2017-04-19 09:23:04 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__bucket_list_deallocator(__bucket_list_deallocator&& __x)
|
2011-06-05 02:54:24 +08:00
|
|
|
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
|
2011-07-01 05:18:19 +08:00
|
|
|
: __data_(_VSTD::move(__x.__data_))
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__x.size() = 0;
|
|
|
|
}
|
2017-04-19 09:23:04 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-05 02:54:24 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
size_type& size() _NOEXCEPT {return __data_.first();}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
size_type size() const _NOEXCEPT {return __data_.first();}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-05 02:54:24 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
allocator_type& __alloc() _NOEXCEPT {return __data_.second();}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
void operator()(pointer __p) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__alloc_traits::deallocate(__alloc(), __p, size());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-06-15 03:58:17 +08:00
|
|
|
template <class _Alloc> class __hash_map_node_destructor;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
class __hash_node_destructor
|
|
|
|
{
|
|
|
|
typedef _Alloc allocator_type;
|
|
|
|
typedef allocator_traits<allocator_type> __alloc_traits;
|
2016-02-11 04:46:23 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
|
|
|
typedef typename __alloc_traits::pointer pointer;
|
|
|
|
private:
|
2016-02-11 19:59:44 +08:00
|
|
|
typedef __hash_node_types<pointer> _NodeTypes;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
allocator_type& __na_;
|
|
|
|
|
|
|
|
__hash_node_destructor& operator=(const __hash_node_destructor&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool __value_constructed;
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-08-01 01:04:30 +08:00
|
|
|
explicit __hash_node_destructor(allocator_type& __na,
|
|
|
|
bool __constructed = false) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __na_(__na),
|
2011-08-01 01:04:30 +08:00
|
|
|
__value_constructed(__constructed)
|
2010-05-12 03:42:16 +08:00
|
|
|
{}
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
void operator()(pointer __p) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
if (__value_constructed)
|
2016-02-11 19:59:44 +08:00
|
|
|
__alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_));
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__p)
|
|
|
|
__alloc_traits::deallocate(__na_, __p, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class> friend class __hash_map_node_destructor;
|
|
|
|
};
|
|
|
|
|
2018-08-01 09:33:38 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
|
|
|
template <class _NodeType, class _Alloc>
|
|
|
|
struct __generic_container_node_destructor;
|
|
|
|
|
|
|
|
template <class _Tp, class _VoidPtr, class _Alloc>
|
|
|
|
struct __generic_container_node_destructor<__hash_node<_Tp, _VoidPtr>, _Alloc>
|
|
|
|
: __hash_node_destructor<_Alloc>
|
|
|
|
{
|
|
|
|
using __hash_node_destructor<_Alloc>::__hash_node_destructor;
|
|
|
|
};
|
|
|
|
#endif
|
2017-01-14 06:42:53 +08:00
|
|
|
|
2018-12-07 05:46:17 +08:00
|
|
|
template <class _Key, class _Hash, class _Equal>
|
|
|
|
struct __enforce_unordered_container_requirements {
|
2017-01-14 06:42:53 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2017-03-04 06:35:58 +08:00
|
|
|
static_assert(__check_hash_requirements<_Key, _Hash>::value,
|
2018-12-07 05:46:17 +08:00
|
|
|
"the specified hash does not meet the Hash requirements");
|
2017-03-01 10:02:28 +08:00
|
|
|
static_assert(is_copy_constructible<_Equal>::value,
|
2018-12-07 05:46:17 +08:00
|
|
|
"the specified comparator is required to be copy constructible");
|
|
|
|
#endif
|
|
|
|
typedef int type;
|
2017-01-14 06:42:53 +08:00
|
|
|
};
|
|
|
|
|
2018-12-07 05:46:17 +08:00
|
|
|
template <class _Key, class _Hash, class _Equal>
|
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
|
|
|
_LIBCPP_DIAGNOSE_WARNING(!__invokable<_Equal const&, _Key const&, _Key const&>::value,
|
|
|
|
"the specified comparator type does not provide a const call operator")
|
|
|
|
_LIBCPP_DIAGNOSE_WARNING(!__invokable<_Hash const&, _Key const&>::value,
|
|
|
|
"the specified hash functor does not provide a const call operator")
|
|
|
|
#endif
|
|
|
|
typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type
|
|
|
|
__diagnose_unordered_container_requirements(int);
|
|
|
|
|
|
|
|
// This dummy overload is used so that the compiler won't emit a spurious
|
|
|
|
// "no matching function for call to __diagnose_unordered_xxx" diagnostic
|
|
|
|
// when the overload above causes a hard error.
|
|
|
|
template <class _Key, class _Hash, class _Equal>
|
|
|
|
int __diagnose_unordered_container_requirements(void*);
|
2017-01-14 06:42:53 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
class __hash_table
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef _Tp value_type;
|
|
|
|
typedef _Hash hasher;
|
|
|
|
typedef _Equal key_equal;
|
|
|
|
typedef _Alloc allocator_type;
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef allocator_traits<allocator_type> __alloc_traits;
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef typename
|
|
|
|
__make_hash_node_types<value_type, typename __alloc_traits::void_pointer>::type
|
|
|
|
_NodeTypes;
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
2016-02-11 19:59:44 +08:00
|
|
|
|
|
|
|
typedef typename _NodeTypes::__node_value_type __node_value_type;
|
|
|
|
typedef typename _NodeTypes::__container_value_type __container_value_type;
|
2016-03-18 04:45:20 +08:00
|
|
|
typedef typename _NodeTypes::key_type key_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef value_type& reference;
|
|
|
|
typedef const value_type& const_reference;
|
|
|
|
typedef typename __alloc_traits::pointer pointer;
|
|
|
|
typedef typename __alloc_traits::const_pointer const_pointer;
|
2016-02-11 04:46:23 +08:00
|
|
|
#ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef typename __alloc_traits::size_type size_type;
|
2016-02-11 04:46:23 +08:00
|
|
|
#else
|
|
|
|
typedef typename _NodeTypes::size_type size_type;
|
|
|
|
#endif
|
|
|
|
typedef typename _NodeTypes::difference_type difference_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
|
|
|
// Create __node
|
2016-02-11 04:46:23 +08:00
|
|
|
|
|
|
|
typedef typename _NodeTypes::__node_type __node;
|
2015-04-07 13:21:38 +08:00
|
|
|
typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef allocator_traits<__node_allocator> __node_traits;
|
2016-02-11 23:22:37 +08:00
|
|
|
typedef typename _NodeTypes::__void_pointer __void_pointer;
|
2016-02-11 04:46:23 +08:00
|
|
|
typedef typename _NodeTypes::__node_pointer __node_pointer;
|
|
|
|
typedef typename _NodeTypes::__node_pointer __node_const_pointer;
|
|
|
|
typedef typename _NodeTypes::__node_base_type __first_node;
|
|
|
|
typedef typename _NodeTypes::__node_base_pointer __node_base_pointer;
|
2016-07-24 04:36:55 +08:00
|
|
|
typedef typename _NodeTypes::__next_pointer __next_pointer;
|
2016-02-11 04:46:23 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
// check for sane allocator pointer rebinding semantics. Rebinding the
|
|
|
|
// allocator for a new pointer type should be exactly the same as rebinding
|
|
|
|
// the pointer using 'pointer_traits'.
|
|
|
|
static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value),
|
|
|
|
"Allocator does not rebind pointers in a sane manner.");
|
|
|
|
typedef typename __rebind_alloc_helper<__node_traits, __first_node>::type
|
|
|
|
__node_base_allocator;
|
|
|
|
typedef allocator_traits<__node_base_allocator> __node_base_traits;
|
|
|
|
static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value),
|
|
|
|
"Allocator does not rebind pointers in a sane manner.");
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-07-24 04:36:55 +08:00
|
|
|
typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter;
|
2016-07-24 04:36:55 +08:00
|
|
|
typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits;
|
2016-07-24 04:36:55 +08:00
|
|
|
typedef typename __bucket_list_deleter::pointer __node_pointer_pointer;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
// --- Member data begin ---
|
2016-02-11 04:46:23 +08:00
|
|
|
__bucket_list __bucket_list_;
|
|
|
|
__compressed_pair<__first_node, __node_allocator> __p1_;
|
|
|
|
__compressed_pair<size_type, hasher> __p2_;
|
|
|
|
__compressed_pair<float, key_equal> __p3_;
|
2010-05-12 03:42:16 +08:00
|
|
|
// --- Member data end ---
|
|
|
|
|
2011-06-05 02:54:24 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
size_type& size() _NOEXCEPT {return __p2_.first();}
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
2011-06-05 02:54:24 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
size_type size() const _NOEXCEPT {return __p2_.first();}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-05 02:54:24 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
hasher& hash_function() _NOEXCEPT {return __p2_.second();}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const hasher& hash_function() const _NOEXCEPT {return __p2_.second();}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-05 02:54:24 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
float& max_load_factor() _NOEXCEPT {return __p3_.first();}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
float max_load_factor() const _NOEXCEPT {return __p3_.first();}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-05 02:54:24 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
key_equal& key_eq() _NOEXCEPT {return __p3_.second();}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-05 02:54:24 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const __node_allocator& __node_alloc() const _NOEXCEPT
|
|
|
|
{return __p1_.second();}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef __hash_iterator<__node_pointer> iterator;
|
2013-06-22 23:21:29 +08:00
|
|
|
typedef __hash_const_iterator<__node_pointer> const_iterator;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef __hash_local_iterator<__node_pointer> local_iterator;
|
2013-06-22 23:21:29 +08:00
|
|
|
typedef __hash_const_local_iterator<__node_pointer> const_local_iterator;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
__hash_table()
|
|
|
|
_NOEXCEPT_(
|
|
|
|
is_nothrow_default_constructible<__bucket_list>::value &&
|
|
|
|
is_nothrow_default_constructible<__first_node>::value &&
|
|
|
|
is_nothrow_default_constructible<__node_allocator>::value &&
|
|
|
|
is_nothrow_default_constructible<hasher>::value &&
|
|
|
|
is_nothrow_default_constructible<key_equal>::value);
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__hash_table(const hasher& __hf, const key_equal& __eql);
|
|
|
|
__hash_table(const hasher& __hf, const key_equal& __eql,
|
|
|
|
const allocator_type& __a);
|
|
|
|
explicit __hash_table(const allocator_type& __a);
|
|
|
|
__hash_table(const __hash_table& __u);
|
|
|
|
__hash_table(const __hash_table& __u, const allocator_type& __a);
|
2016-02-11 19:59:44 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2011-06-05 02:54:24 +08:00
|
|
|
__hash_table(__hash_table&& __u)
|
|
|
|
_NOEXCEPT_(
|
|
|
|
is_nothrow_move_constructible<__bucket_list>::value &&
|
|
|
|
is_nothrow_move_constructible<__first_node>::value &&
|
|
|
|
is_nothrow_move_constructible<__node_allocator>::value &&
|
|
|
|
is_nothrow_move_constructible<hasher>::value &&
|
|
|
|
is_nothrow_move_constructible<key_equal>::value);
|
2010-05-12 03:42:16 +08:00
|
|
|
__hash_table(__hash_table&& __u, const allocator_type& __a);
|
2016-02-11 19:59:44 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
~__hash_table();
|
|
|
|
|
|
|
|
__hash_table& operator=(const __hash_table& __u);
|
2016-02-11 19:59:44 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
__hash_table& operator=(__hash_table&& __u)
|
|
|
|
_NOEXCEPT_(
|
|
|
|
__node_traits::propagate_on_container_move_assignment::value &&
|
|
|
|
is_nothrow_move_assignable<__node_allocator>::value &&
|
|
|
|
is_nothrow_move_assignable<hasher>::value &&
|
|
|
|
is_nothrow_move_assignable<key_equal>::value);
|
2010-05-12 03:42:16 +08:00
|
|
|
#endif
|
|
|
|
template <class _InputIterator>
|
|
|
|
void __assign_unique(_InputIterator __first, _InputIterator __last);
|
|
|
|
template <class _InputIterator>
|
|
|
|
void __assign_multi(_InputIterator __first, _InputIterator __last);
|
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
size_type max_size() const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-11-23 09:18:56 +08:00
|
|
|
return std::min<size_type>(
|
2016-11-23 17:16:12 +08:00
|
|
|
__node_traits::max_size(__node_alloc()),
|
2016-11-23 09:18:56 +08:00
|
|
|
numeric_limits<difference_type >::max()
|
|
|
|
);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2018-11-01 01:31:35 +08:00
|
|
|
private:
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__next_pointer __node_insert_multi_prepare(size_t __cp_hash,
|
|
|
|
value_type& __cp_val);
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __node_insert_multi_perform(__node_pointer __cp,
|
|
|
|
__next_pointer __pn) _NOEXCEPT;
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__next_pointer __node_insert_unique_prepare(size_t __nd_hash,
|
|
|
|
value_type& __nd_val);
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __node_insert_unique_perform(__node_pointer __ptr) _NOEXCEPT;
|
|
|
|
|
|
|
|
public:
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
pair<iterator, bool> __node_insert_unique(__node_pointer __nd);
|
2018-11-01 01:31:35 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
iterator __node_insert_multi(__node_pointer __nd);
|
2018-11-01 01:31:35 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
iterator __node_insert_multi(const_iterator __p,
|
|
|
|
__node_pointer __nd);
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
|
|
|
template <class _Key, class ..._Args>
|
2016-03-18 04:45:20 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-02-11 19:59:44 +08:00
|
|
|
pair<iterator, bool> __emplace_unique_key_args(_Key const& __k, _Args&&... __args);
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class... _Args>
|
2016-03-18 04:45:20 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pair<iterator, bool> __emplace_unique_impl(_Args&&... __args);
|
|
|
|
|
|
|
|
template <class _Pp>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pair<iterator, bool> __emplace_unique(_Pp&& __x) {
|
|
|
|
return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x),
|
|
|
|
__can_extract_key<_Pp, key_type>());
|
|
|
|
}
|
2016-04-16 08:23:12 +08:00
|
|
|
|
|
|
|
template <class _First, class _Second>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename enable_if<
|
|
|
|
__can_extract_map_key<_First, key_type, __container_value_type>::value,
|
|
|
|
pair<iterator, bool>
|
|
|
|
>::type __emplace_unique(_First&& __f, _Second&& __s) {
|
|
|
|
return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f),
|
|
|
|
_VSTD::forward<_Second>(__s));
|
|
|
|
}
|
|
|
|
|
2016-03-18 04:45:20 +08:00
|
|
|
template <class... _Args>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pair<iterator, bool> __emplace_unique(_Args&&... __args) {
|
|
|
|
return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Pp>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pair<iterator, bool>
|
|
|
|
__emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) {
|
|
|
|
return __emplace_unique_impl(_VSTD::forward<_Pp>(__x));
|
|
|
|
}
|
|
|
|
template <class _Pp>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pair<iterator, bool>
|
|
|
|
__emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) {
|
|
|
|
return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x));
|
|
|
|
}
|
|
|
|
template <class _Pp>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pair<iterator, bool>
|
|
|
|
__emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) {
|
|
|
|
return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x));
|
|
|
|
}
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class... _Args>
|
2016-03-18 04:45:20 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-02-11 19:59:44 +08:00
|
|
|
iterator __emplace_multi(_Args&&... __args);
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class... _Args>
|
2016-03-18 04:45:20 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-02-11 19:59:44 +08:00
|
|
|
iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2015-06-13 15:18:32 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-02-11 19:59:44 +08:00
|
|
|
pair<iterator, bool>
|
|
|
|
__insert_unique(__container_value_type&& __x) {
|
|
|
|
return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _VSTD::move(__x));
|
|
|
|
}
|
2015-06-13 15:18:32 +08:00
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
template <class _Pp, class = typename enable_if<
|
|
|
|
!__is_same_uncvref<_Pp, __container_value_type>::value
|
|
|
|
>::type>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pair<iterator, bool> __insert_unique(_Pp&& __x) {
|
|
|
|
return __emplace_unique(_VSTD::forward<_Pp>(__x));
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-11-30 02:15:50 +08:00
|
|
|
template <class _Pp>
|
2016-02-11 19:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
iterator __insert_multi(_Pp&& __x) {
|
|
|
|
return __emplace_multi(_VSTD::forward<_Pp>(__x));
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-11-30 02:15:50 +08:00
|
|
|
template <class _Pp>
|
2016-02-11 19:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
iterator __insert_multi(const_iterator __p, _Pp&& __x) {
|
|
|
|
return __emplace_hint_multi(__p, _VSTD::forward<_Pp>(__x));
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // !defined(_LIBCPP_CXX03_LANG)
|
|
|
|
template <class _Key, class _Args>
|
2016-09-25 12:05:46 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-02-11 19:59:44 +08:00
|
|
|
pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args);
|
|
|
|
|
|
|
|
iterator __insert_multi(const __container_value_type& __x);
|
|
|
|
iterator __insert_multi(const_iterator __p, const __container_value_type& __x);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
pair<iterator, bool> __insert_unique(const __container_value_type& __x) {
|
|
|
|
return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2018-08-01 09:33:38 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
|
|
|
template <class _NodeHandle, class _InsertReturnType>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
_InsertReturnType __node_handle_insert_unique(_NodeHandle&& __nh);
|
|
|
|
template <class _NodeHandle>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
iterator __node_handle_insert_unique(const_iterator __hint,
|
|
|
|
_NodeHandle&& __nh);
|
2018-11-01 01:31:35 +08:00
|
|
|
template <class _Table>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __node_handle_merge_unique(_Table& __source);
|
2018-08-01 09:33:38 +08:00
|
|
|
|
|
|
|
template <class _NodeHandle>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
iterator __node_handle_insert_multi(_NodeHandle&& __nh);
|
|
|
|
template <class _NodeHandle>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
iterator __node_handle_insert_multi(const_iterator __hint, _NodeHandle&& __nh);
|
2018-11-01 01:31:35 +08:00
|
|
|
template <class _Table>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __node_handle_merge_multi(_Table& __source);
|
2018-08-01 09:33:38 +08:00
|
|
|
|
|
|
|
template <class _NodeHandle>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
_NodeHandle __node_handle_extract(key_type const& __key);
|
|
|
|
template <class _NodeHandle>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
_NodeHandle __node_handle_extract(const_iterator __it);
|
|
|
|
#endif
|
|
|
|
|
2011-06-05 02:54:24 +08:00
|
|
|
void clear() _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
void rehash(size_type __n);
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void reserve(size_type __n)
|
2010-05-12 03:42:16 +08:00
|
|
|
{rehash(static_cast<size_type>(ceil(__n / max_load_factor())));}
|
2010-09-22 01:32:39 +08:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
size_type bucket_count() const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
return __bucket_list_.get_deleter().size();
|
|
|
|
}
|
|
|
|
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
iterator begin() _NOEXCEPT;
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
iterator end() _NOEXCEPT;
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
const_iterator begin() const _NOEXCEPT;
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
const_iterator end() const _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Key>
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
size_type bucket(const _Key& __k) const
|
2013-07-30 03:05:47 +08:00
|
|
|
{
|
|
|
|
_LIBCPP_ASSERT(bucket_count() > 0,
|
|
|
|
"unordered container::bucket(key) called when bucket_count() == 0");
|
|
|
|
return __constrain_hash(hash_function()(__k), bucket_count());
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Key>
|
|
|
|
iterator find(const _Key& __x);
|
|
|
|
template <class _Key>
|
|
|
|
const_iterator find(const _Key& __x) const;
|
|
|
|
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef __hash_node_destructor<__node_allocator> _Dp;
|
|
|
|
typedef unique_ptr<__node, _Dp> __node_holder;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
iterator erase(const_iterator __p);
|
|
|
|
iterator erase(const_iterator __first, const_iterator __last);
|
|
|
|
template <class _Key>
|
|
|
|
size_type __erase_unique(const _Key& __k);
|
|
|
|
template <class _Key>
|
|
|
|
size_type __erase_multi(const _Key& __k);
|
2011-06-05 02:54:24 +08:00
|
|
|
__node_holder remove(const_iterator __p) _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Key>
|
2015-11-07 09:22:13 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
size_type __count_unique(const _Key& __k) const;
|
|
|
|
template <class _Key>
|
|
|
|
size_type __count_multi(const _Key& __k) const;
|
|
|
|
|
|
|
|
template <class _Key>
|
|
|
|
pair<iterator, iterator>
|
|
|
|
__equal_range_unique(const _Key& __k);
|
|
|
|
template <class _Key>
|
|
|
|
pair<const_iterator, const_iterator>
|
|
|
|
__equal_range_unique(const _Key& __k) const;
|
|
|
|
|
|
|
|
template <class _Key>
|
|
|
|
pair<iterator, iterator>
|
|
|
|
__equal_range_multi(const _Key& __k);
|
|
|
|
template <class _Key>
|
|
|
|
pair<const_iterator, const_iterator>
|
|
|
|
__equal_range_multi(const _Key& __k) const;
|
|
|
|
|
2011-06-05 02:54:24 +08:00
|
|
|
void swap(__hash_table& __u)
|
2015-07-19 04:40:46 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 11
|
2016-12-28 13:53:01 +08:00
|
|
|
_NOEXCEPT_DEBUG_(
|
2015-07-14 04:04:56 +08:00
|
|
|
__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
|
|
|
|
&& (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
|
|
|
|
|| __is_nothrow_swappable<__pointer_allocator>::value)
|
|
|
|
&& (!__node_traits::propagate_on_container_swap::value
|
|
|
|
|| __is_nothrow_swappable<__node_allocator>::value)
|
|
|
|
);
|
2015-07-19 04:40:46 +08:00
|
|
|
#else
|
2016-12-28 13:53:01 +08:00
|
|
|
_NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value);
|
2015-07-19 04:40:46 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
size_type max_bucket_count() const _NOEXCEPT
|
2016-11-23 09:18:56 +08:00
|
|
|
{return max_size(); }
|
2010-05-12 03:42:16 +08:00
|
|
|
size_type bucket_size(size_type __n) const;
|
2011-06-05 02:54:24 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
size_type __bc = bucket_count();
|
|
|
|
return __bc != 0 ? (float)size() / __bc : 0.f;
|
|
|
|
}
|
2011-06-05 02:54:24 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT
|
2013-07-30 03:05:47 +08:00
|
|
|
{
|
|
|
|
_LIBCPP_ASSERT(__mlf > 0,
|
|
|
|
"unordered container::max_load_factor(lf) called with lf <= 0");
|
|
|
|
max_load_factor() = _VSTD::max(__mlf, load_factor());
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
local_iterator
|
|
|
|
begin(size_type __n)
|
|
|
|
{
|
2013-07-30 03:05:47 +08:00
|
|
|
_LIBCPP_ASSERT(__n < bucket_count(),
|
|
|
|
"unordered container::begin(n) called with n >= bucket_count()");
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
return local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
|
|
|
|
#else
|
|
|
|
return local_iterator(__bucket_list_[__n], __n, bucket_count());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
local_iterator
|
|
|
|
end(size_type __n)
|
|
|
|
{
|
2013-07-30 03:05:47 +08:00
|
|
|
_LIBCPP_ASSERT(__n < bucket_count(),
|
|
|
|
"unordered container::end(n) called with n >= bucket_count()");
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
return local_iterator(nullptr, __n, bucket_count(), this);
|
|
|
|
#else
|
|
|
|
return local_iterator(nullptr, __n, bucket_count());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_local_iterator
|
|
|
|
cbegin(size_type __n) const
|
|
|
|
{
|
2013-07-30 03:05:47 +08:00
|
|
|
_LIBCPP_ASSERT(__n < bucket_count(),
|
|
|
|
"unordered container::cbegin(n) called with n >= bucket_count()");
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
|
|
|
|
#else
|
|
|
|
return const_local_iterator(__bucket_list_[__n], __n, bucket_count());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
const_local_iterator
|
|
|
|
cend(size_type __n) const
|
|
|
|
{
|
2013-07-30 03:05:47 +08:00
|
|
|
_LIBCPP_ASSERT(__n < bucket_count(),
|
|
|
|
"unordered container::cend(n) called with n >= bucket_count()");
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
return const_local_iterator(nullptr, __n, bucket_count(), this);
|
|
|
|
#else
|
|
|
|
return const_local_iterator(nullptr, __n, bucket_count());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
|
|
|
|
bool __dereferenceable(const const_iterator* __i) const;
|
|
|
|
bool __decrementable(const const_iterator* __i) const;
|
|
|
|
bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
|
|
|
|
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
|
|
|
|
|
|
|
|
#endif // _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
private:
|
|
|
|
void __rehash(size_type __n);
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class ..._Args>
|
2016-02-11 19:59:44 +08:00
|
|
|
__node_holder __construct_node(_Args&& ...__args);
|
|
|
|
|
|
|
|
template <class _First, class ..._Rest>
|
|
|
|
__node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest);
|
|
|
|
#else // _LIBCPP_CXX03_LANG
|
|
|
|
__node_holder __construct_node(const __container_value_type& __v);
|
|
|
|
__node_holder __construct_node_hash(size_t __hash, const __container_value_type& __v);
|
2010-05-12 03:42:16 +08:00
|
|
|
#endif
|
2016-02-11 19:59:44 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void __copy_assign_alloc(const __hash_table& __u)
|
|
|
|
{__copy_assign_alloc(__u, integral_constant<bool,
|
|
|
|
__node_traits::propagate_on_container_copy_assignment::value>());}
|
|
|
|
void __copy_assign_alloc(const __hash_table& __u, true_type);
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-12-02 04:21:04 +08:00
|
|
|
void __copy_assign_alloc(const __hash_table&, false_type) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
void __move_assign(__hash_table& __u, false_type);
|
2011-06-05 02:54:24 +08:00
|
|
|
void __move_assign(__hash_table& __u, true_type)
|
|
|
|
_NOEXCEPT_(
|
|
|
|
is_nothrow_move_assignable<__node_allocator>::value &&
|
|
|
|
is_nothrow_move_assignable<hasher>::value &&
|
|
|
|
is_nothrow_move_assignable<key_equal>::value);
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void __move_assign_alloc(__hash_table& __u)
|
|
|
|
_NOEXCEPT_(
|
|
|
|
!__node_traits::propagate_on_container_move_assignment::value ||
|
|
|
|
(is_nothrow_move_assignable<__pointer_allocator>::value &&
|
|
|
|
is_nothrow_move_assignable<__node_allocator>::value))
|
2010-05-12 03:42:16 +08:00
|
|
|
{__move_assign_alloc(__u, integral_constant<bool,
|
|
|
|
__node_traits::propagate_on_container_move_assignment::value>());}
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void __move_assign_alloc(__hash_table& __u, true_type)
|
2011-06-05 02:54:24 +08:00
|
|
|
_NOEXCEPT_(
|
|
|
|
is_nothrow_move_assignable<__pointer_allocator>::value &&
|
|
|
|
is_nothrow_move_assignable<__node_allocator>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__bucket_list_.get_deleter().__alloc() =
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::move(__u.__bucket_list_.get_deleter().__alloc());
|
|
|
|
__node_alloc() = _VSTD::move(__u.__node_alloc());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
2010-09-22 01:32:39 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-05 02:54:24 +08:00
|
|
|
void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {}
|
2016-02-11 19:59:44 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-01-07 11:01:24 +08:00
|
|
|
void __deallocate_node(__next_pointer __np) _NOEXCEPT;
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __detach() _NOEXCEPT;
|
2013-06-22 23:21:29 +08:00
|
|
|
|
2017-01-05 07:56:00 +08:00
|
|
|
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
|
|
|
|
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table()
|
2011-06-05 02:54:24 +08:00
|
|
|
_NOEXCEPT_(
|
|
|
|
is_nothrow_default_constructible<__bucket_list>::value &&
|
|
|
|
is_nothrow_default_constructible<__first_node>::value &&
|
2015-12-16 08:53:04 +08:00
|
|
|
is_nothrow_default_constructible<__node_allocator>::value &&
|
2011-06-05 02:54:24 +08:00
|
|
|
is_nothrow_default_constructible<hasher>::value &&
|
|
|
|
is_nothrow_default_constructible<key_equal>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
: __p2_(0),
|
|
|
|
__p3_(1.0f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
|
|
|
|
const key_equal& __eql)
|
|
|
|
: __bucket_list_(nullptr, __bucket_list_deleter()),
|
|
|
|
__p1_(),
|
|
|
|
__p2_(0, __hf),
|
|
|
|
__p3_(1.0f, __eql)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
|
|
|
|
const key_equal& __eql,
|
|
|
|
const allocator_type& __a)
|
|
|
|
: __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
|
2017-04-13 07:45:53 +08:00
|
|
|
__p1_(__second_tag(), __node_allocator(__a)),
|
2010-05-12 03:42:16 +08:00
|
|
|
__p2_(0, __hf),
|
|
|
|
__p3_(1.0f, __eql)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a)
|
|
|
|
: __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
|
2017-04-13 07:45:53 +08:00
|
|
|
__p1_(__second_tag(), __node_allocator(__a)),
|
2010-05-12 03:42:16 +08:00
|
|
|
__p2_(0),
|
|
|
|
__p3_(1.0f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u)
|
|
|
|
: __bucket_list_(nullptr,
|
|
|
|
__bucket_list_deleter(allocator_traits<__pointer_allocator>::
|
|
|
|
select_on_container_copy_construction(
|
|
|
|
__u.__bucket_list_.get_deleter().__alloc()), 0)),
|
2017-04-13 07:45:53 +08:00
|
|
|
__p1_(__second_tag(), allocator_traits<__node_allocator>::
|
2010-05-12 03:42:16 +08:00
|
|
|
select_on_container_copy_construction(__u.__node_alloc())),
|
|
|
|
__p2_(0, __u.hash_function()),
|
|
|
|
__p3_(__u.__p3_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u,
|
|
|
|
const allocator_type& __a)
|
|
|
|
: __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
|
2017-04-13 07:45:53 +08:00
|
|
|
__p1_(__second_tag(), __node_allocator(__a)),
|
2010-05-12 03:42:16 +08:00
|
|
|
__p2_(0, __u.hash_function()),
|
|
|
|
__p3_(__u.__p3_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u)
|
2011-06-05 02:54:24 +08:00
|
|
|
_NOEXCEPT_(
|
|
|
|
is_nothrow_move_constructible<__bucket_list>::value &&
|
|
|
|
is_nothrow_move_constructible<__first_node>::value &&
|
2015-12-16 08:53:04 +08:00
|
|
|
is_nothrow_move_constructible<__node_allocator>::value &&
|
2011-06-05 02:54:24 +08:00
|
|
|
is_nothrow_move_constructible<hasher>::value &&
|
|
|
|
is_nothrow_move_constructible<key_equal>::value)
|
2011-07-01 05:18:19 +08:00
|
|
|
: __bucket_list_(_VSTD::move(__u.__bucket_list_)),
|
|
|
|
__p1_(_VSTD::move(__u.__p1_)),
|
|
|
|
__p2_(_VSTD::move(__u.__p2_)),
|
|
|
|
__p3_(_VSTD::move(__u.__p3_))
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
if (size() > 0)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
|
|
|
|
__p1_.first().__ptr();
|
2010-05-12 03:42:16 +08:00
|
|
|
__u.__p1_.first().__next_ = nullptr;
|
|
|
|
__u.size() = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u,
|
|
|
|
const allocator_type& __a)
|
|
|
|
: __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
|
2017-04-13 07:45:53 +08:00
|
|
|
__p1_(__second_tag(), __node_allocator(__a)),
|
2011-07-01 05:18:19 +08:00
|
|
|
__p2_(0, _VSTD::move(__u.hash_function())),
|
|
|
|
__p3_(_VSTD::move(__u.__p3_))
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
if (__a == allocator_type(__u.__node_alloc()))
|
|
|
|
{
|
|
|
|
__bucket_list_.reset(__u.__bucket_list_.release());
|
|
|
|
__bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
|
|
|
|
__u.__bucket_list_.get_deleter().size() = 0;
|
|
|
|
if (__u.size() > 0)
|
|
|
|
{
|
|
|
|
__p1_.first().__next_ = __u.__p1_.first().__next_;
|
|
|
|
__u.__p1_.first().__next_ = nullptr;
|
2016-07-24 04:36:55 +08:00
|
|
|
__bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
|
|
|
|
__p1_.first().__ptr();
|
2010-05-12 03:42:16 +08:00
|
|
|
size() = __u.size();
|
|
|
|
__u.size() = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
|
|
|
|
{
|
2017-03-01 10:02:28 +08:00
|
|
|
#if defined(_LIBCPP_CXX03_LANG)
|
2016-07-01 06:05:45 +08:00
|
|
|
static_assert((is_copy_constructible<key_equal>::value),
|
|
|
|
"Predicate must be copy-constructible.");
|
|
|
|
static_assert((is_copy_constructible<hasher>::value),
|
|
|
|
"Hasher must be copy-constructible.");
|
2017-01-14 06:42:53 +08:00
|
|
|
#endif
|
2017-03-01 10:02:28 +08:00
|
|
|
|
2017-01-07 11:01:24 +08:00
|
|
|
__deallocate_node(__p1_.first().__next_);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
__get_db()->__erase_c(this);
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
void
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc(
|
|
|
|
const __hash_table& __u, true_type)
|
|
|
|
{
|
|
|
|
if (__node_alloc() != __u.__node_alloc())
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
__bucket_list_.reset();
|
|
|
|
__bucket_list_.get_deleter().size() = 0;
|
|
|
|
}
|
|
|
|
__bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc();
|
|
|
|
__node_alloc() = __u.__node_alloc();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>&
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u)
|
|
|
|
{
|
|
|
|
if (this != &__u)
|
|
|
|
{
|
|
|
|
__copy_assign_alloc(__u);
|
|
|
|
hash_function() = __u.hash_function();
|
|
|
|
key_eq() = __u.key_eq();
|
|
|
|
max_load_factor() = __u.max_load_factor();
|
|
|
|
__assign_multi(__u.begin(), __u.end());
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
void
|
2017-01-07 11:01:24 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np)
|
2011-06-05 02:54:24 +08:00
|
|
|
_NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__node_allocator& __na = __node_alloc();
|
|
|
|
while (__np != nullptr)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __next = __np->__next_;
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
__c_node* __c = __get_db()->__find_c_and_lock(this);
|
|
|
|
for (__i_node** __p = __c->end_; __p != __c->beg_; )
|
|
|
|
{
|
|
|
|
--__p;
|
|
|
|
iterator* __i = static_cast<iterator*>((*__p)->__i_);
|
|
|
|
if (__i->__node_ == __np)
|
|
|
|
{
|
|
|
|
(*__p)->__c_ = nullptr;
|
|
|
|
if (--__c->end_ != __p)
|
|
|
|
memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__get_db()->unlock();
|
|
|
|
#endif
|
2016-07-24 04:36:55 +08:00
|
|
|
__node_pointer __real_np = __np->__upcast();
|
|
|
|
__node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__value_));
|
|
|
|
__node_traits::deallocate(__na, __real_np, 1);
|
2010-05-12 03:42:16 +08:00
|
|
|
__np = __next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2016-07-24 04:36:55 +08:00
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer
|
2011-06-05 02:54:24 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
size_type __bc = bucket_count();
|
|
|
|
for (size_type __i = 0; __i < __bc; ++__i)
|
|
|
|
__bucket_list_[__i] = nullptr;
|
|
|
|
size() = 0;
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __cache = __p1_.first().__next_;
|
2010-05-12 03:42:16 +08:00
|
|
|
__p1_.first().__next_ = nullptr;
|
|
|
|
return __cache;
|
|
|
|
}
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
void
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
|
|
|
|
__hash_table& __u, true_type)
|
2011-06-05 02:54:24 +08:00
|
|
|
_NOEXCEPT_(
|
|
|
|
is_nothrow_move_assignable<__node_allocator>::value &&
|
|
|
|
is_nothrow_move_assignable<hasher>::value &&
|
|
|
|
is_nothrow_move_assignable<key_equal>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
__bucket_list_.reset(__u.__bucket_list_.release());
|
|
|
|
__bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
|
|
|
|
__u.__bucket_list_.get_deleter().size() = 0;
|
|
|
|
__move_assign_alloc(__u);
|
|
|
|
size() = __u.size();
|
2011-07-01 05:18:19 +08:00
|
|
|
hash_function() = _VSTD::move(__u.hash_function());
|
2010-05-12 03:42:16 +08:00
|
|
|
max_load_factor() = __u.max_load_factor();
|
2011-07-01 05:18:19 +08:00
|
|
|
key_eq() = _VSTD::move(__u.key_eq());
|
2010-05-12 03:42:16 +08:00
|
|
|
__p1_.first().__next_ = __u.__p1_.first().__next_;
|
|
|
|
if (size() > 0)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
|
|
|
|
__p1_.first().__ptr();
|
2010-05-12 03:42:16 +08:00
|
|
|
__u.__p1_.first().__next_ = nullptr;
|
|
|
|
__u.size() = 0;
|
|
|
|
}
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
__get_db()->swap(this, &__u);
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
void
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
|
|
|
|
__hash_table& __u, false_type)
|
|
|
|
{
|
|
|
|
if (__node_alloc() == __u.__node_alloc())
|
|
|
|
__move_assign(__u, true_type());
|
|
|
|
else
|
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
hash_function() = _VSTD::move(__u.hash_function());
|
|
|
|
key_eq() = _VSTD::move(__u.key_eq());
|
2010-05-12 03:42:16 +08:00
|
|
|
max_load_factor() = __u.max_load_factor();
|
|
|
|
if (bucket_count() != 0)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __cache = __detach();
|
2010-05-12 03:42:16 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
const_iterator __i = __u.begin();
|
|
|
|
while (__cache != nullptr && __u.size() != 0)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__cache->__upcast()->__value_ =
|
|
|
|
_VSTD::move(__u.remove(__i++)->__value_);
|
|
|
|
__next_pointer __next = __cache->__next_;
|
|
|
|
__node_insert_multi(__cache->__upcast());
|
2010-05-12 03:42:16 +08:00
|
|
|
__cache = __next;
|
|
|
|
}
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2017-01-07 11:01:24 +08:00
|
|
|
__deallocate_node(__cache);
|
2010-05-12 03:42:16 +08:00
|
|
|
throw;
|
|
|
|
}
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2017-01-07 11:01:24 +08:00
|
|
|
__deallocate_node(__cache);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
const_iterator __i = __u.begin();
|
|
|
|
while (__u.size() != 0)
|
|
|
|
{
|
2016-02-11 19:59:44 +08:00
|
|
|
__node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_));
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_insert_multi(__h.get());
|
|
|
|
__h.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>&
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u)
|
2011-06-05 02:54:24 +08:00
|
|
|
_NOEXCEPT_(
|
|
|
|
__node_traits::propagate_on_container_move_assignment::value &&
|
|
|
|
is_nothrow_move_assignable<__node_allocator>::value &&
|
|
|
|
is_nothrow_move_assignable<hasher>::value &&
|
|
|
|
is_nothrow_move_assignable<key_equal>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__move_assign(__u, integral_constant<bool,
|
|
|
|
__node_traits::propagate_on_container_move_assignment::value>());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _InputIterator>
|
|
|
|
void
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first,
|
|
|
|
_InputIterator __last)
|
|
|
|
{
|
2016-02-11 19:59:44 +08:00
|
|
|
typedef iterator_traits<_InputIterator> _ITraits;
|
|
|
|
typedef typename _ITraits::value_type _ItValueType;
|
|
|
|
static_assert((is_same<_ItValueType, __container_value_type>::value),
|
|
|
|
"__assign_unique may only be called with the containers value type");
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
if (bucket_count() != 0)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __cache = __detach();
|
2010-05-12 03:42:16 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
for (; __cache != nullptr && __first != __last; ++__first)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__cache->__upcast()->__value_ = *__first;
|
|
|
|
__next_pointer __next = __cache->__next_;
|
|
|
|
__node_insert_unique(__cache->__upcast());
|
2010-05-12 03:42:16 +08:00
|
|
|
__cache = __next;
|
|
|
|
}
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2017-01-07 11:01:24 +08:00
|
|
|
__deallocate_node(__cache);
|
2010-05-12 03:42:16 +08:00
|
|
|
throw;
|
|
|
|
}
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2017-01-07 11:01:24 +08:00
|
|
|
__deallocate_node(__cache);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
for (; __first != __last; ++__first)
|
|
|
|
__insert_unique(*__first);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _InputIterator>
|
|
|
|
void
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first,
|
|
|
|
_InputIterator __last)
|
|
|
|
{
|
2016-02-11 19:59:44 +08:00
|
|
|
typedef iterator_traits<_InputIterator> _ITraits;
|
|
|
|
typedef typename _ITraits::value_type _ItValueType;
|
|
|
|
static_assert((is_same<_ItValueType, __container_value_type>::value ||
|
|
|
|
is_same<_ItValueType, __node_value_type>::value),
|
|
|
|
"__assign_multi may only be called with the containers value type"
|
|
|
|
" or the nodes value type");
|
2010-05-12 03:42:16 +08:00
|
|
|
if (bucket_count() != 0)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __cache = __detach();
|
2010-05-12 03:42:16 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
for (; __cache != nullptr && __first != __last; ++__first)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__cache->__upcast()->__value_ = *__first;
|
|
|
|
__next_pointer __next = __cache->__next_;
|
|
|
|
__node_insert_multi(__cache->__upcast());
|
2010-05-12 03:42:16 +08:00
|
|
|
__cache = __next;
|
|
|
|
}
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2017-01-07 11:01:24 +08:00
|
|
|
__deallocate_node(__cache);
|
2010-05-12 03:42:16 +08:00
|
|
|
throw;
|
|
|
|
}
|
2010-08-22 08:02:43 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2017-01-07 11:01:24 +08:00
|
|
|
__deallocate_node(__cache);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
for (; __first != __last; ++__first)
|
2016-02-11 19:59:44 +08:00
|
|
|
__insert_multi(_NodeTypes::__get_value(*__first));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
2011-06-05 02:54:24 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
return iterator(__p1_.first().__next_, this);
|
|
|
|
#else
|
2010-05-12 03:42:16 +08:00
|
|
|
return iterator(__p1_.first().__next_);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
2011-06-05 02:54:24 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
return iterator(nullptr, this);
|
|
|
|
#else
|
2010-05-12 03:42:16 +08:00
|
|
|
return iterator(nullptr);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
|
2011-06-05 02:54:24 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
return const_iterator(__p1_.first().__next_, this);
|
|
|
|
#else
|
2010-05-12 03:42:16 +08:00
|
|
|
return const_iterator(__p1_.first().__next_);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
|
2011-06-05 02:54:24 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
return const_iterator(nullptr, this);
|
|
|
|
#else
|
2010-05-12 03:42:16 +08:00
|
|
|
return const_iterator(nullptr);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
void
|
2011-06-05 02:54:24 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
if (size() > 0)
|
|
|
|
{
|
2017-01-07 11:01:24 +08:00
|
|
|
__deallocate_node(__p1_.first().__next_);
|
2010-05-12 03:42:16 +08:00
|
|
|
__p1_.first().__next_ = nullptr;
|
|
|
|
size_type __bc = bucket_count();
|
2011-07-05 22:14:17 +08:00
|
|
|
for (size_type __i = 0; __i < __bc; ++__i)
|
2010-05-12 03:42:16 +08:00
|
|
|
__bucket_list_[__i] = nullptr;
|
|
|
|
size() = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-01 01:31:35 +08:00
|
|
|
|
|
|
|
// Prepare the container for an insertion of the value __value with the hash
|
|
|
|
// __hash. This does a lookup into the container to see if __value is already
|
|
|
|
// present, and performs a rehash if necessary. Returns a pointer to the
|
|
|
|
// existing element if it exists, otherwise nullptr.
|
|
|
|
//
|
|
|
|
// Note that this function does forward exceptions if key_eq() throws, and never
|
|
|
|
// mutates __value or actually inserts into the map.
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2018-11-01 01:31:35 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare(
|
|
|
|
size_t __hash, value_type& __value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
size_type __bc = bucket_count();
|
2018-11-01 01:31:35 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__bc != 0)
|
|
|
|
{
|
2018-11-01 01:31:35 +08:00
|
|
|
size_t __chash = __constrain_hash(__hash, __bc);
|
|
|
|
__next_pointer __ndptr = __bucket_list_[__chash];
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__ndptr != nullptr)
|
|
|
|
{
|
|
|
|
for (__ndptr = __ndptr->__next_; __ndptr != nullptr &&
|
2016-07-24 04:36:55 +08:00
|
|
|
__constrain_hash(__ndptr->__hash(), __bc) == __chash;
|
2010-05-12 03:42:16 +08:00
|
|
|
__ndptr = __ndptr->__next_)
|
|
|
|
{
|
2018-11-01 01:31:35 +08:00
|
|
|
if (key_eq()(__ndptr->__upcast()->__value_, __value))
|
|
|
|
return __ndptr;
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-01 01:31:35 +08:00
|
|
|
if (size()+1 > __bc * max_load_factor() || __bc == 0)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2018-11-01 01:31:35 +08:00
|
|
|
rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
|
|
|
|
size_type(ceil(float(size() + 1) / max_load_factor()))));
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert the node __nd into the container by pushing it into the right bucket,
|
|
|
|
// and updating size(). Assumes that __nd->__hash is up-to-date, and that
|
|
|
|
// rehashing has already occurred and that no element with the same key exists
|
|
|
|
// in the map.
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform(
|
|
|
|
__node_pointer __nd) _NOEXCEPT
|
|
|
|
{
|
|
|
|
size_type __bc = bucket_count();
|
|
|
|
size_t __chash = __constrain_hash(__nd->__hash(), __bc);
|
|
|
|
// insert_after __bucket_list_[__chash], or __first_node if bucket is null
|
|
|
|
__next_pointer __pn = __bucket_list_[__chash];
|
|
|
|
if (__pn == nullptr)
|
|
|
|
{
|
|
|
|
__pn =__p1_.first().__ptr();
|
|
|
|
__nd->__next_ = __pn->__next_;
|
|
|
|
__pn->__next_ = __nd->__ptr();
|
|
|
|
// fix up __bucket_list_
|
|
|
|
__bucket_list_[__chash] = __pn;
|
|
|
|
if (__nd->__next_ != nullptr)
|
|
|
|
__bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__nd->__next_ = __pn->__next_;
|
|
|
|
__pn->__next_ = __nd->__ptr();
|
|
|
|
}
|
|
|
|
++size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd)
|
|
|
|
{
|
|
|
|
__nd->__hash_ = hash_function()(__nd->__value_);
|
|
|
|
__next_pointer __existing_node =
|
|
|
|
__node_insert_unique_prepare(__nd->__hash(), __nd->__value_);
|
|
|
|
|
|
|
|
// Insert the node, unless it already exists in the container.
|
|
|
|
bool __inserted = false;
|
|
|
|
if (__existing_node == nullptr)
|
|
|
|
{
|
|
|
|
__node_insert_unique_perform(__nd);
|
|
|
|
__existing_node = __nd->__ptr();
|
2010-05-12 03:42:16 +08:00
|
|
|
__inserted = true;
|
|
|
|
}
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
2018-11-01 01:31:35 +08:00
|
|
|
return pair<iterator, bool>(iterator(__existing_node, this), __inserted);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#else
|
2018-11-01 01:31:35 +08:00
|
|
|
return pair<iterator, bool>(iterator(__existing_node), __inserted);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2018-11-01 01:31:35 +08:00
|
|
|
// Prepare the container for an insertion of the value __cp_val with the hash
|
|
|
|
// __cp_hash. This does a lookup into the container to see if __cp_value is
|
|
|
|
// already present, and performs a rehash if necessary. Returns a pointer to the
|
|
|
|
// last occurance of __cp_val in the map.
|
|
|
|
//
|
|
|
|
// Note that this function does forward exceptions if key_eq() throws, and never
|
|
|
|
// mutates __value or actually inserts into the map.
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2018-11-01 01:31:35 +08:00
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_prepare(
|
|
|
|
size_t __cp_hash, value_type& __cp_val)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
size_type __bc = bucket_count();
|
|
|
|
if (size()+1 > __bc * max_load_factor() || __bc == 0)
|
|
|
|
{
|
2015-02-03 05:31:48 +08:00
|
|
|
rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
|
2010-05-12 03:42:16 +08:00
|
|
|
size_type(ceil(float(size() + 1) / max_load_factor()))));
|
|
|
|
__bc = bucket_count();
|
|
|
|
}
|
2018-11-01 01:31:35 +08:00
|
|
|
size_t __chash = __constrain_hash(__cp_hash, __bc);
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __pn = __bucket_list_[__chash];
|
2018-11-01 01:31:35 +08:00
|
|
|
if (__pn != nullptr)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
for (bool __found = false; __pn->__next_ != nullptr &&
|
2016-07-24 04:36:55 +08:00
|
|
|
__constrain_hash(__pn->__next_->__hash(), __bc) == __chash;
|
2010-05-12 03:42:16 +08:00
|
|
|
__pn = __pn->__next_)
|
2010-08-22 08:02:43 +08:00
|
|
|
{
|
2010-05-12 03:42:16 +08:00
|
|
|
// __found key_eq() action
|
|
|
|
// false false loop
|
|
|
|
// true true loop
|
|
|
|
// false true set __found to true
|
|
|
|
// true false break
|
2018-11-01 01:31:35 +08:00
|
|
|
if (__found != (__pn->__next_->__hash() == __cp_hash &&
|
|
|
|
key_eq()(__pn->__next_->__upcast()->__value_, __cp_val)))
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
if (!__found)
|
|
|
|
__found = true;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-11-01 01:31:35 +08:00
|
|
|
}
|
|
|
|
return __pn;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert the node __cp into the container after __pn (which is the last node in
|
|
|
|
// the bucket that compares equal to __cp). Rehashing, and checking for
|
|
|
|
// uniqueness has already been performed (in __node_insert_multi_prepare), so
|
|
|
|
// all we need to do is update the bucket and size(). Assumes that __cp->__hash
|
|
|
|
// is up-to-date.
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
void
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform(
|
|
|
|
__node_pointer __cp, __next_pointer __pn) _NOEXCEPT
|
|
|
|
{
|
|
|
|
size_type __bc = bucket_count();
|
|
|
|
size_t __chash = __constrain_hash(__cp->__hash_, __bc);
|
|
|
|
if (__pn == nullptr)
|
|
|
|
{
|
|
|
|
__pn =__p1_.first().__ptr();
|
|
|
|
__cp->__next_ = __pn->__next_;
|
|
|
|
__pn->__next_ = __cp->__ptr();
|
|
|
|
// fix up __bucket_list_
|
|
|
|
__bucket_list_[__chash] = __pn;
|
|
|
|
if (__cp->__next_ != nullptr)
|
|
|
|
__bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)]
|
|
|
|
= __cp->__ptr();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-12 03:42:16 +08:00
|
|
|
__cp->__next_ = __pn->__next_;
|
2016-07-24 04:36:55 +08:00
|
|
|
__pn->__next_ = __cp->__ptr();
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__cp->__next_ != nullptr)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc);
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__nhash != __chash)
|
2016-07-24 04:36:55 +08:00
|
|
|
__bucket_list_[__nhash] = __cp->__ptr();
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++size();
|
2018-11-01 01:31:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp)
|
|
|
|
{
|
|
|
|
__cp->__hash_ = hash_function()(__cp->__value_);
|
|
|
|
__next_pointer __pn = __node_insert_multi_prepare(__cp->__hash(), __cp->__value_);
|
|
|
|
__node_insert_multi_perform(__cp, __pn);
|
|
|
|
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
2016-07-24 04:36:55 +08:00
|
|
|
return iterator(__cp->__ptr(), this);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#else
|
2016-07-24 04:36:55 +08:00
|
|
|
return iterator(__cp->__ptr());
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
|
|
|
|
const_iterator __p, __node_pointer __cp)
|
|
|
|
{
|
2013-08-03 01:50:49 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
|
|
|
|
"unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
|
|
|
|
" referring to this unordered container");
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__p != end() && key_eq()(*__p, __cp->__value_))
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __np = __p.__node_;
|
|
|
|
__cp->__hash_ = __np->__hash();
|
2010-05-12 03:42:16 +08:00
|
|
|
size_type __bc = bucket_count();
|
|
|
|
if (size()+1 > __bc * max_load_factor() || __bc == 0)
|
|
|
|
{
|
2015-02-03 05:31:48 +08:00
|
|
|
rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
|
2010-05-12 03:42:16 +08:00
|
|
|
size_type(ceil(float(size() + 1) / max_load_factor()))));
|
|
|
|
__bc = bucket_count();
|
|
|
|
}
|
2012-07-07 01:31:14 +08:00
|
|
|
size_t __chash = __constrain_hash(__cp->__hash_, __bc);
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __pp = __bucket_list_[__chash];
|
2010-05-12 03:42:16 +08:00
|
|
|
while (__pp->__next_ != __np)
|
|
|
|
__pp = __pp->__next_;
|
|
|
|
__cp->__next_ = __np;
|
2016-07-24 04:36:55 +08:00
|
|
|
__pp->__next_ = static_cast<__next_pointer>(__cp);
|
2010-05-12 03:42:16 +08:00
|
|
|
++size();
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
2016-07-24 04:36:55 +08:00
|
|
|
return iterator(static_cast<__next_pointer>(__cp), this);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#else
|
2016-07-24 04:36:55 +08:00
|
|
|
return iterator(static_cast<__next_pointer>(__cp));
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
return __node_insert_multi(__cp);
|
|
|
|
}
|
|
|
|
|
2015-06-13 15:18:32 +08:00
|
|
|
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2015-06-13 15:18:32 +08:00
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2016-02-11 19:59:44 +08:00
|
|
|
template <class _Key, class ..._Args>
|
2015-06-13 15:18:32 +08:00
|
|
|
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
|
2016-02-11 19:59:44 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args)
|
2015-06-13 15:18:32 +08:00
|
|
|
#else
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2016-02-11 19:59:44 +08:00
|
|
|
template <class _Key, class _Args>
|
2015-06-13 15:18:32 +08:00
|
|
|
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
|
2016-02-11 19:59:44 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args)
|
2015-06-13 15:18:32 +08:00
|
|
|
#endif
|
|
|
|
{
|
2016-02-11 19:59:44 +08:00
|
|
|
|
|
|
|
size_t __hash = hash_function()(__k);
|
2010-05-12 03:42:16 +08:00
|
|
|
size_type __bc = bucket_count();
|
|
|
|
bool __inserted = false;
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __nd;
|
2010-05-12 03:42:16 +08:00
|
|
|
size_t __chash;
|
|
|
|
if (__bc != 0)
|
|
|
|
{
|
2012-07-07 01:31:14 +08:00
|
|
|
__chash = __constrain_hash(__hash, __bc);
|
2010-05-12 03:42:16 +08:00
|
|
|
__nd = __bucket_list_[__chash];
|
|
|
|
if (__nd != nullptr)
|
|
|
|
{
|
|
|
|
for (__nd = __nd->__next_; __nd != nullptr &&
|
2016-07-24 14:22:25 +08:00
|
|
|
(__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash);
|
2010-05-12 03:42:16 +08:00
|
|
|
__nd = __nd->__next_)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
if (key_eq()(__nd->__upcast()->__value_, __k))
|
2010-05-12 03:42:16 +08:00
|
|
|
goto __done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
2016-02-11 19:59:44 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
|
|
|
__node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...);
|
|
|
|
#else
|
|
|
|
__node_holder __h = __construct_node_hash(__hash, __args);
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
if (size()+1 > __bc * max_load_factor() || __bc == 0)
|
|
|
|
{
|
2015-02-03 05:31:48 +08:00
|
|
|
rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
|
2010-05-12 03:42:16 +08:00
|
|
|
size_type(ceil(float(size() + 1) / max_load_factor()))));
|
|
|
|
__bc = bucket_count();
|
2012-07-07 01:31:14 +08:00
|
|
|
__chash = __constrain_hash(__hash, __bc);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
// insert_after __bucket_list_[__chash], or __first_node if bucket is null
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __pn = __bucket_list_[__chash];
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__pn == nullptr)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__pn = __p1_.first().__ptr();
|
2010-05-12 03:42:16 +08:00
|
|
|
__h->__next_ = __pn->__next_;
|
2016-07-24 04:36:55 +08:00
|
|
|
__pn->__next_ = __h.get()->__ptr();
|
2010-05-12 03:42:16 +08:00
|
|
|
// fix up __bucket_list_
|
|
|
|
__bucket_list_[__chash] = __pn;
|
|
|
|
if (__h->__next_ != nullptr)
|
2016-07-24 04:36:55 +08:00
|
|
|
__bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)]
|
|
|
|
= __h.get()->__ptr();
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__h->__next_ = __pn->__next_;
|
2016-07-24 04:36:55 +08:00
|
|
|
__pn->__next_ = static_cast<__next_pointer>(__h.get());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
2016-07-24 04:36:55 +08:00
|
|
|
__nd = static_cast<__next_pointer>(__h.release());
|
2010-05-12 03:42:16 +08:00
|
|
|
// increment size
|
|
|
|
++size();
|
|
|
|
__inserted = true;
|
|
|
|
}
|
|
|
|
__done:
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
return pair<iterator, bool>(iterator(__nd, this), __inserted);
|
|
|
|
#else
|
2010-05-12 03:42:16 +08:00
|
|
|
return pair<iterator, bool>(iterator(__nd), __inserted);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class... _Args>
|
|
|
|
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
|
2016-03-18 04:45:20 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
pair<iterator, bool> __r = __node_insert_unique(__h.get());
|
|
|
|
if (__r.second)
|
|
|
|
__h.release();
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class... _Args>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args)
|
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
iterator __r = __node_insert_multi(__h.get());
|
|
|
|
__h.release();
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class... _Args>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(
|
|
|
|
const_iterator __p, _Args&&... __args)
|
|
|
|
{
|
2013-07-30 03:05:47 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
|
|
|
|
"unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
|
|
|
|
" referring to this unordered container");
|
|
|
|
#endif
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
iterator __r = __node_insert_multi(__p, __h.get());
|
|
|
|
__h.release();
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#else // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
2016-02-11 19:59:44 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const __container_value_type& __x)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__node_holder __h = __construct_node(__x);
|
|
|
|
iterator __r = __node_insert_multi(__h.get());
|
|
|
|
__h.release();
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
|
2016-02-11 19:59:44 +08:00
|
|
|
const __container_value_type& __x)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2013-07-30 03:05:47 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
|
|
|
|
"unordered container::insert(const_iterator, lvalue) called with an iterator not"
|
|
|
|
" referring to this unordered container");
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_holder __h = __construct_node(__x);
|
|
|
|
iterator __r = __node_insert_multi(__p, __h.get());
|
|
|
|
__h.release();
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2018-08-01 09:33:38 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _NodeHandle, class _InsertReturnType>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
_InsertReturnType
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique(
|
|
|
|
_NodeHandle&& __nh)
|
|
|
|
{
|
|
|
|
if (__nh.empty())
|
|
|
|
return _InsertReturnType{end(), false, _NodeHandle()};
|
|
|
|
pair<iterator, bool> __result = __node_insert_unique(__nh.__ptr_);
|
|
|
|
if (__result.second)
|
|
|
|
__nh.__release();
|
|
|
|
return _InsertReturnType{__result.first, __result.second, _VSTD::move(__nh)};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _NodeHandle>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique(
|
|
|
|
const_iterator, _NodeHandle&& __nh)
|
|
|
|
{
|
|
|
|
if (__nh.empty())
|
|
|
|
return end();
|
|
|
|
pair<iterator, bool> __result = __node_insert_unique(__nh.__ptr_);
|
|
|
|
if (__result.second)
|
|
|
|
__nh.__release();
|
|
|
|
return __result.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _NodeHandle>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
_NodeHandle
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract(
|
|
|
|
key_type const& __key)
|
|
|
|
{
|
|
|
|
iterator __i = find(__key);
|
|
|
|
if (__i == end())
|
|
|
|
return _NodeHandle();
|
|
|
|
return __node_handle_extract<_NodeHandle>(__i);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _NodeHandle>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
_NodeHandle
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract(
|
|
|
|
const_iterator __p)
|
|
|
|
{
|
|
|
|
allocator_type __alloc(__node_alloc());
|
|
|
|
return _NodeHandle(remove(__p).release(), __alloc);
|
|
|
|
}
|
|
|
|
|
2018-11-01 01:31:35 +08:00
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _Table>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_unique(
|
|
|
|
_Table& __source)
|
|
|
|
{
|
|
|
|
static_assert(is_same<__node, typename _Table::__node>::value, "");
|
|
|
|
|
|
|
|
for (typename _Table::iterator __it = __source.begin();
|
|
|
|
__it != __source.end();)
|
|
|
|
{
|
|
|
|
__node_pointer __src_ptr = __it.__node_->__upcast();
|
|
|
|
size_t __hash = hash_function()(__src_ptr->__value_);
|
|
|
|
__next_pointer __existing_node =
|
|
|
|
__node_insert_unique_prepare(__hash, __src_ptr->__value_);
|
|
|
|
auto __prev_iter = __it++;
|
|
|
|
if (__existing_node == nullptr)
|
|
|
|
{
|
|
|
|
(void)__source.remove(__prev_iter).release();
|
|
|
|
__src_ptr->__hash_ = __hash;
|
|
|
|
__node_insert_unique_perform(__src_ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-01 09:33:38 +08:00
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _NodeHandle>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi(
|
|
|
|
_NodeHandle&& __nh)
|
|
|
|
{
|
|
|
|
if (__nh.empty())
|
|
|
|
return end();
|
|
|
|
iterator __result = __node_insert_multi(__nh.__ptr_);
|
|
|
|
__nh.__release();
|
|
|
|
return __result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _NodeHandle>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi(
|
|
|
|
const_iterator __hint, _NodeHandle&& __nh)
|
|
|
|
{
|
|
|
|
if (__nh.empty())
|
|
|
|
return end();
|
|
|
|
iterator __result = __node_insert_multi(__hint, __nh.__ptr_);
|
|
|
|
__nh.__release();
|
|
|
|
return __result;
|
|
|
|
}
|
|
|
|
|
2018-11-01 01:31:35 +08:00
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _Table>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_multi(
|
|
|
|
_Table& __source)
|
|
|
|
{
|
|
|
|
static_assert(is_same<typename _Table::__node, __node>::value, "");
|
|
|
|
|
|
|
|
for (typename _Table::iterator __it = __source.begin();
|
|
|
|
__it != __source.end();)
|
|
|
|
{
|
|
|
|
__node_pointer __src_ptr = __it.__node_->__upcast();
|
|
|
|
size_t __src_hash = hash_function()(__src_ptr->__value_);
|
|
|
|
__next_pointer __pn =
|
|
|
|
__node_insert_multi_prepare(__src_hash, __src_ptr->__value_);
|
|
|
|
(void)__source.remove(__it++).release();
|
|
|
|
__src_ptr->__hash_ = __src_hash;
|
|
|
|
__node_insert_multi_perform(__src_ptr, __pn);
|
|
|
|
}
|
|
|
|
}
|
2018-08-01 09:33:38 +08:00
|
|
|
#endif // _LIBCPP_STD_VER > 14
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
void
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
|
|
|
|
{
|
2018-01-09 06:57:12 +08:00
|
|
|
if (__n == 1)
|
2012-07-07 01:31:14 +08:00
|
|
|
__n = 2;
|
|
|
|
else if (__n & (__n - 1))
|
|
|
|
__n = __next_prime(__n);
|
2010-05-12 03:42:16 +08:00
|
|
|
size_type __bc = bucket_count();
|
|
|
|
if (__n > __bc)
|
|
|
|
__rehash(__n);
|
2012-07-07 01:31:14 +08:00
|
|
|
else if (__n < __bc)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
__n = _VSTD::max<size_type>
|
2010-05-12 03:42:16 +08:00
|
|
|
(
|
|
|
|
__n,
|
2015-02-03 05:31:48 +08:00
|
|
|
__is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) :
|
|
|
|
__next_prime(size_t(ceil(float(size()) / max_load_factor())))
|
2010-05-12 03:42:16 +08:00
|
|
|
);
|
|
|
|
if (__n < __bc)
|
|
|
|
__rehash(__n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
void
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
|
|
|
|
{
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
__get_db()->__invalidate_all(this);
|
|
|
|
#endif // _LIBCPP_DEBUG_LEVEL >= 2
|
2010-05-12 03:42:16 +08:00
|
|
|
__pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc();
|
|
|
|
__bucket_list_.reset(__nbc > 0 ?
|
|
|
|
__pointer_alloc_traits::allocate(__npa, __nbc) : nullptr);
|
|
|
|
__bucket_list_.get_deleter().size() = __nbc;
|
|
|
|
if (__nbc > 0)
|
|
|
|
{
|
|
|
|
for (size_type __i = 0; __i < __nbc; ++__i)
|
|
|
|
__bucket_list_[__i] = nullptr;
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __pp = __p1_.first().__ptr();
|
|
|
|
__next_pointer __cp = __pp->__next_;
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__cp != nullptr)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
size_type __chash = __constrain_hash(__cp->__hash(), __nbc);
|
2010-05-12 03:42:16 +08:00
|
|
|
__bucket_list_[__chash] = __pp;
|
|
|
|
size_type __phash = __chash;
|
|
|
|
for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
|
|
|
|
__cp = __pp->__next_)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__chash = __constrain_hash(__cp->__hash(), __nbc);
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__chash == __phash)
|
|
|
|
__pp = __cp;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (__bucket_list_[__chash] == nullptr)
|
|
|
|
{
|
|
|
|
__bucket_list_[__chash] = __pp;
|
|
|
|
__pp = __cp;
|
|
|
|
__phash = __chash;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __np = __cp;
|
2010-05-12 03:42:16 +08:00
|
|
|
for (; __np->__next_ != nullptr &&
|
2016-07-24 04:36:55 +08:00
|
|
|
key_eq()(__cp->__upcast()->__value_,
|
|
|
|
__np->__next_->__upcast()->__value_);
|
2010-05-12 03:42:16 +08:00
|
|
|
__np = __np->__next_)
|
|
|
|
;
|
|
|
|
__pp->__next_ = __np->__next_;
|
|
|
|
__np->__next_ = __bucket_list_[__chash]->__next_;
|
|
|
|
__bucket_list_[__chash]->__next_ = __cp;
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _Key>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k)
|
|
|
|
{
|
|
|
|
size_t __hash = hash_function()(__k);
|
|
|
|
size_type __bc = bucket_count();
|
|
|
|
if (__bc != 0)
|
|
|
|
{
|
2012-07-07 01:31:14 +08:00
|
|
|
size_t __chash = __constrain_hash(__hash, __bc);
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __nd = __bucket_list_[__chash];
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__nd != nullptr)
|
|
|
|
{
|
|
|
|
for (__nd = __nd->__next_; __nd != nullptr &&
|
2016-07-24 04:36:55 +08:00
|
|
|
(__nd->__hash() == __hash
|
|
|
|
|| __constrain_hash(__nd->__hash(), __bc) == __chash);
|
2010-05-12 03:42:16 +08:00
|
|
|
__nd = __nd->__next_)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
if ((__nd->__hash() == __hash)
|
|
|
|
&& key_eq()(__nd->__upcast()->__value_, __k))
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
return iterator(__nd, this);
|
|
|
|
#else
|
2010-05-12 03:42:16 +08:00
|
|
|
return iterator(__nd);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return end();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _Key>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const
|
|
|
|
{
|
|
|
|
size_t __hash = hash_function()(__k);
|
|
|
|
size_type __bc = bucket_count();
|
|
|
|
if (__bc != 0)
|
|
|
|
{
|
2012-07-07 01:31:14 +08:00
|
|
|
size_t __chash = __constrain_hash(__hash, __bc);
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __nd = __bucket_list_[__chash];
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__nd != nullptr)
|
|
|
|
{
|
|
|
|
for (__nd = __nd->__next_; __nd != nullptr &&
|
2016-07-24 04:36:55 +08:00
|
|
|
(__hash == __nd->__hash()
|
|
|
|
|| __constrain_hash(__nd->__hash(), __bc) == __chash);
|
2010-05-12 03:42:16 +08:00
|
|
|
__nd = __nd->__next_)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
if ((__nd->__hash() == __hash)
|
|
|
|
&& key_eq()(__nd->__upcast()->__value_, __k))
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
return const_iterator(__nd, this);
|
|
|
|
#else
|
2010-05-12 03:42:16 +08:00
|
|
|
return const_iterator(__nd);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
return end();
|
|
|
|
}
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class ..._Args>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args)
|
|
|
|
{
|
2016-02-11 19:59:44 +08:00
|
|
|
static_assert(!__is_hash_value_type<_Args...>::value,
|
|
|
|
"Construct cannot be called with a hash value type");
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_allocator& __na = __node_alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
__node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
|
2016-02-11 19:59:44 +08:00
|
|
|
__node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
__h.get_deleter().__value_constructed = true;
|
|
|
|
__h->__hash_ = hash_function()(__h->__value_);
|
|
|
|
__h->__next_ = nullptr;
|
|
|
|
return __h;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
2016-02-11 19:59:44 +08:00
|
|
|
template <class _First, class ..._Rest>
|
2010-05-12 03:42:16 +08:00
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
|
2016-02-11 19:59:44 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(
|
|
|
|
size_t __hash, _First&& __f, _Rest&& ...__rest)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-02-11 19:59:44 +08:00
|
|
|
static_assert(!__is_hash_value_type<_First, _Rest...>::value,
|
|
|
|
"Construct cannot be called with a hash value type");
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_allocator& __na = __node_alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
__node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
|
2016-02-11 19:59:44 +08:00
|
|
|
__node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_),
|
|
|
|
_VSTD::forward<_First>(__f),
|
|
|
|
_VSTD::forward<_Rest>(__rest)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
__h.get_deleter().__value_constructed = true;
|
|
|
|
__h->__hash_ = __hash;
|
|
|
|
__h->__next_ = nullptr;
|
2013-08-23 02:29:50 +08:00
|
|
|
return __h;
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#else // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
|
2016-02-11 19:59:44 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const __container_value_type& __v)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__node_allocator& __na = __node_alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
__node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
|
2016-02-11 19:59:44 +08:00
|
|
|
__node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
|
2010-05-12 03:42:16 +08:00
|
|
|
__h.get_deleter().__value_constructed = true;
|
|
|
|
__h->__hash_ = hash_function()(__h->__value_);
|
|
|
|
__h->__next_ = nullptr;
|
Fix warnings about pessimizing return moves for C++11 and higher
Summary:
Throughout the libc++ headers, there are a few instances where
_VSTD::move() is used to return a local variable. Howard commented in
r189039 that these were there "for non-obvious reasons such as to help
things limp along in C++03 language mode".
However, when compiling these headers with warnings on, and in C++11 or
higher mode (like we do in FreeBSD), they cause the following complaints
about pessimizing moves:
In file included from tests.cpp:26:
In file included from tests.hpp:29:
/usr/include/c++/v1/map:1368:12: error: moving a local object in a return statement prevents copy elision [-Werror,-Wpessimizing-move]
return _VSTD::move(__h); // explicitly moved for C++03
^
/usr/include/c++/v1/__config:368:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
^
Attempt to fix this by adding a _LIBCPP_EXPLICIT_MOVE() macro to
__config, which gets defined to _VSTD::move for pre-C++11, and to
nothing for C++11 and later.
I am not completely satisfied with the macro name (I also considered
_LIBCPP_COMPAT_MOVE and some other variants), so suggestions are
welcome. :)
Reviewers: mclow.lists, howard.hinnant, EricWF
Subscribers: arthur.j.odwyer, cfe-commits
Differential Revision: http://reviews.llvm.org/D11394
llvm-svn: 245421
2015-08-19 14:43:33 +08:00
|
|
|
return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
|
2016-02-11 19:59:44 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash,
|
|
|
|
const __container_value_type& __v)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__node_allocator& __na = __node_alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
__node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
|
2016-02-11 19:59:44 +08:00
|
|
|
__node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
|
2010-05-12 03:42:16 +08:00
|
|
|
__h.get_deleter().__value_constructed = true;
|
|
|
|
__h->__hash_ = __hash;
|
|
|
|
__h->__next_ = nullptr;
|
Fix warnings about pessimizing return moves for C++11 and higher
Summary:
Throughout the libc++ headers, there are a few instances where
_VSTD::move() is used to return a local variable. Howard commented in
r189039 that these were there "for non-obvious reasons such as to help
things limp along in C++03 language mode".
However, when compiling these headers with warnings on, and in C++11 or
higher mode (like we do in FreeBSD), they cause the following complaints
about pessimizing moves:
In file included from tests.cpp:26:
In file included from tests.hpp:29:
/usr/include/c++/v1/map:1368:12: error: moving a local object in a return statement prevents copy elision [-Werror,-Wpessimizing-move]
return _VSTD::move(__h); // explicitly moved for C++03
^
/usr/include/c++/v1/__config:368:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
^
Attempt to fix this by adding a _LIBCPP_EXPLICIT_MOVE() macro to
__config, which gets defined to _VSTD::move for pre-C++11, and to
nothing for C++11 and later.
I am not completely satisfied with the macro name (I also considered
_LIBCPP_COMPAT_MOVE and some other variants), so suggestions are
welcome. :)
Reviewers: mclow.lists, howard.hinnant, EricWF
Subscribers: arthur.j.odwyer, cfe-commits
Differential Revision: http://reviews.llvm.org/D11394
llvm-svn: 245421
2015-08-19 14:43:33 +08:00
|
|
|
return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
2016-02-11 19:59:44 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __np = __p.__node_;
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
|
|
|
|
"unordered container erase(iterator) called with an iterator not"
|
|
|
|
" referring to this container");
|
|
|
|
_LIBCPP_ASSERT(__p != end(),
|
|
|
|
"unordered container erase(iterator) called with a non-dereferenceable iterator");
|
|
|
|
iterator __r(__np, this);
|
|
|
|
#else
|
2010-05-12 03:42:16 +08:00
|
|
|
iterator __r(__np);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
++__r;
|
|
|
|
remove(__p);
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
|
|
|
|
const_iterator __last)
|
|
|
|
{
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
|
|
|
|
"unodered container::erase(iterator, iterator) called with an iterator not"
|
|
|
|
" referring to this unodered container");
|
|
|
|
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
|
|
|
|
"unodered container::erase(iterator, iterator) called with an iterator not"
|
|
|
|
" referring to this unodered container");
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
for (const_iterator __p = __first; __first != __last; __p = __first)
|
|
|
|
{
|
|
|
|
++__first;
|
|
|
|
erase(__p);
|
|
|
|
}
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __np = __last.__node_;
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
return iterator (__np, this);
|
|
|
|
#else
|
2010-05-12 03:42:16 +08:00
|
|
|
return iterator (__np);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _Key>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k)
|
|
|
|
{
|
|
|
|
iterator __i = find(__k);
|
|
|
|
if (__i == end())
|
|
|
|
return 0;
|
|
|
|
erase(__i);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _Key>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k)
|
|
|
|
{
|
|
|
|
size_type __r = 0;
|
|
|
|
iterator __i = find(__k);
|
|
|
|
if (__i != end())
|
|
|
|
{
|
|
|
|
iterator __e = end();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
erase(__i++);
|
|
|
|
++__r;
|
|
|
|
} while (__i != __e && key_eq()(*__i, __k));
|
|
|
|
}
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
|
2011-06-05 02:54:24 +08:00
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
// current node
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __cn = __p.__node_;
|
2010-05-12 03:42:16 +08:00
|
|
|
size_type __bc = bucket_count();
|
2016-07-24 04:36:55 +08:00
|
|
|
size_t __chash = __constrain_hash(__cn->__hash(), __bc);
|
2010-05-12 03:42:16 +08:00
|
|
|
// find previous node
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __pn = __bucket_list_[__chash];
|
2010-05-12 03:42:16 +08:00
|
|
|
for (; __pn->__next_ != __cn; __pn = __pn->__next_)
|
|
|
|
;
|
|
|
|
// Fix up __bucket_list_
|
|
|
|
// if __pn is not in same bucket (before begin is not in same bucket) &&
|
|
|
|
// if __cn->__next_ is not in same bucket (nullptr is not in same bucket)
|
2016-07-24 04:36:55 +08:00
|
|
|
if (__pn == __p1_.first().__ptr()
|
|
|
|
|| __constrain_hash(__pn->__hash(), __bc) != __chash)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
if (__cn->__next_ == nullptr
|
|
|
|
|| __constrain_hash(__cn->__next_->__hash(), __bc) != __chash)
|
2010-05-12 03:42:16 +08:00
|
|
|
__bucket_list_[__chash] = nullptr;
|
|
|
|
}
|
|
|
|
// if __cn->__next_ is not in same bucket (nullptr is in same bucket)
|
|
|
|
if (__cn->__next_ != nullptr)
|
|
|
|
{
|
2016-07-24 04:36:55 +08:00
|
|
|
size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc);
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__nhash != __chash)
|
|
|
|
__bucket_list_[__nhash] = __pn;
|
|
|
|
}
|
|
|
|
// remove __cn
|
|
|
|
__pn->__next_ = __cn->__next_;
|
|
|
|
__cn->__next_ = nullptr;
|
|
|
|
--size();
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
__c_node* __c = __get_db()->__find_c_and_lock(this);
|
2016-12-28 13:53:01 +08:00
|
|
|
for (__i_node** __dp = __c->end_; __dp != __c->beg_; )
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
{
|
2016-12-28 13:53:01 +08:00
|
|
|
--__dp;
|
|
|
|
iterator* __i = static_cast<iterator*>((*__dp)->__i_);
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
if (__i->__node_ == __cn)
|
|
|
|
{
|
2016-12-28 13:53:01 +08:00
|
|
|
(*__dp)->__c_ = nullptr;
|
|
|
|
if (--__c->end_ != __dp)
|
|
|
|
memmove(__dp, __dp+1, (__c->end_ - __dp)*sizeof(__i_node*));
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
__get_db()->unlock();
|
|
|
|
#endif
|
2016-07-24 04:36:55 +08:00
|
|
|
return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _Key>
|
2015-11-07 09:22:13 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const
|
|
|
|
{
|
|
|
|
return static_cast<size_type>(find(__k) != end());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _Key>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const
|
|
|
|
{
|
|
|
|
size_type __r = 0;
|
|
|
|
const_iterator __i = find(__k);
|
|
|
|
if (__i != end())
|
|
|
|
{
|
|
|
|
const_iterator __e = end();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
++__i;
|
|
|
|
++__r;
|
|
|
|
} while (__i != __e && key_eq()(*__i, __k));
|
|
|
|
}
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _Key>
|
|
|
|
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
|
|
|
|
const _Key& __k)
|
|
|
|
{
|
|
|
|
iterator __i = find(__k);
|
|
|
|
iterator __j = __i;
|
|
|
|
if (__i != end())
|
|
|
|
++__j;
|
|
|
|
return pair<iterator, iterator>(__i, __j);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _Key>
|
|
|
|
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
|
|
|
|
const _Key& __k) const
|
|
|
|
{
|
|
|
|
const_iterator __i = find(__k);
|
|
|
|
const_iterator __j = __i;
|
|
|
|
if (__i != end())
|
|
|
|
++__j;
|
|
|
|
return pair<const_iterator, const_iterator>(__i, __j);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _Key>
|
|
|
|
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
|
|
|
|
const _Key& __k)
|
|
|
|
{
|
|
|
|
iterator __i = find(__k);
|
|
|
|
iterator __j = __i;
|
|
|
|
if (__i != end())
|
|
|
|
{
|
|
|
|
iterator __e = end();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
++__j;
|
|
|
|
} while (__j != __e && key_eq()(*__j, __k));
|
|
|
|
}
|
|
|
|
return pair<iterator, iterator>(__i, __j);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
template <class _Key>
|
|
|
|
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
|
|
|
|
const _Key& __k) const
|
|
|
|
{
|
|
|
|
const_iterator __i = find(__k);
|
|
|
|
const_iterator __j = __i;
|
|
|
|
if (__i != end())
|
|
|
|
{
|
|
|
|
const_iterator __e = end();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
++__j;
|
|
|
|
} while (__j != __e && key_eq()(*__j, __k));
|
|
|
|
}
|
|
|
|
return pair<const_iterator, const_iterator>(__i, __j);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
void
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
|
2015-07-19 04:40:46 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 11
|
2016-12-28 13:53:01 +08:00
|
|
|
_NOEXCEPT_DEBUG_(
|
2015-07-14 04:04:56 +08:00
|
|
|
__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
|
|
|
|
&& (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
|
|
|
|
|| __is_nothrow_swappable<__pointer_allocator>::value)
|
|
|
|
&& (!__node_traits::propagate_on_container_swap::value
|
|
|
|
|| __is_nothrow_swappable<__node_allocator>::value)
|
|
|
|
)
|
2015-07-19 04:40:46 +08:00
|
|
|
#else
|
2016-12-28 13:53:01 +08:00
|
|
|
_NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value)
|
2015-07-19 04:40:46 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-12-28 13:53:01 +08:00
|
|
|
_LIBCPP_ASSERT(__node_traits::propagate_on_container_swap::value ||
|
|
|
|
this->__node_alloc() == __u.__node_alloc(),
|
|
|
|
"list::swap: Either propagate_on_container_swap must be true"
|
|
|
|
" or the allocators must compare equal");
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__node_pointer_pointer __npp = __bucket_list_.release();
|
|
|
|
__bucket_list_.reset(__u.__bucket_list_.release());
|
|
|
|
__u.__bucket_list_.reset(__npp);
|
|
|
|
}
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size());
|
2015-07-14 04:04:56 +08:00
|
|
|
__swap_allocator(__bucket_list_.get_deleter().__alloc(),
|
2010-05-12 03:42:16 +08:00
|
|
|
__u.__bucket_list_.get_deleter().__alloc());
|
2015-07-14 04:04:56 +08:00
|
|
|
__swap_allocator(__node_alloc(), __u.__node_alloc());
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_);
|
2010-05-12 03:42:16 +08:00
|
|
|
__p2_.swap(__u.__p2_);
|
|
|
|
__p3_.swap(__u.__p3_);
|
|
|
|
if (size() > 0)
|
2016-07-24 04:36:55 +08:00
|
|
|
__bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
|
|
|
|
__p1_.first().__ptr();
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__u.size() > 0)
|
2016-07-24 04:36:55 +08:00
|
|
|
__u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] =
|
|
|
|
__u.__p1_.first().__ptr();
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
__get_db()->swap(this, &__u);
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const
|
|
|
|
{
|
2013-07-30 03:05:47 +08:00
|
|
|
_LIBCPP_ASSERT(__n < bucket_count(),
|
|
|
|
"unordered container::bucket_size(n) called with n >= bucket_count()");
|
2016-07-24 04:36:55 +08:00
|
|
|
__next_pointer __np = __bucket_list_[__n];
|
2010-05-12 03:42:16 +08:00
|
|
|
size_type __bc = bucket_count();
|
|
|
|
size_type __r = 0;
|
|
|
|
if (__np != nullptr)
|
|
|
|
{
|
|
|
|
for (__np = __np->__next_; __np != nullptr &&
|
2016-07-24 04:36:55 +08:00
|
|
|
__constrain_hash(__np->__hash(), __bc) == __n;
|
2010-05-12 03:42:16 +08:00
|
|
|
__np = __np->__next_, ++__r)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
2011-06-05 02:54:24 +08:00
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x,
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>& __y)
|
|
|
|
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
|
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
Debug mode for unordered_set. I believe this to be fairly complete for
unordered_set, however it is not complete yet for unordered_multiset,
unordered_map or unordered_multimap. There has been a lot of work done
for these other three containers, however that work was done just to
keep all of the tests passing.
You can try this out with -D_LIBCPP_DEBUG2. You will have to link to a
libc++.dylib that has been compiled with src/debug.cpp. So far, vector
(but not vector<bool>), list, and unordered_set are treated. I hope to
get the other three unordered containers up fairly quickly now that
unordered_set is done.
The flag _LIBCPP_DEBUG2 will eventually be changed to _LIBCPP_DEBUG, but
not today. This is my second effort at getting debug mode going for
libc++, and I'm not quite yet ready to throw all of the work under the
first attempt away.
The basic design is that all of the debug information is kept in a
central database, instead of in the containers. This has been done as
an attempt to have debug mode and non-debug mode be ABI compatible with
each other. There are some circumstances where if you construct a
container in an environment without debug mode and pass it into debug
mode, the checking will get confused and let you know with a readable
error message. Passing containers the other way: from debug mode out to
a non-debugging mode container should be 100% safe (at least that is the
goal).
llvm-svn: 186991
2013-07-24 06:01:58 +08:00
|
|
|
#if _LIBCPP_DEBUG_LEVEL >= 2
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
bool
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const
|
|
|
|
{
|
|
|
|
return __i->__node_ != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
bool
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
bool
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Hash, class _Equal, class _Alloc>
|
|
|
|
bool
|
|
|
|
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _LIBCPP_DEBUG_LEVEL >= 2
|
2017-06-01 06:07:49 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2017-06-01 06:07:49 +08:00
|
|
|
_LIBCPP_POP_MACROS
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
#endif // _LIBCPP__HASH_TABLE
|