Provide an initial bucket to the intrusive container for hash-based containers

This commit is contained in:
Ion Gaztañaga
2022-03-10 11:36:02 +01:00
parent b113017930
commit 43a22fee95
2 changed files with 33 additions and 15 deletions

View File

@@ -285,7 +285,8 @@ struct hash_table_types
template <class T, class KeyOfValue, class KeyHash, class KeyEqual, class Allocator, class Options> template <class T, class KeyOfValue, class KeyHash, class KeyEqual, class Allocator, class Options>
class hash_table class hash_table
: public hash_table_types<KeyOfValue, KeyHash, KeyEqual, Allocator, Options>::bucket_holder_t : public hash_table_types<KeyOfValue, KeyHash, KeyEqual, Allocator, Options>::bucket_type
, public hash_table_types<KeyOfValue, KeyHash, KeyEqual, Allocator, Options>::bucket_holder_t
, public hash_table_types<KeyOfValue, KeyHash, KeyEqual, Allocator, Options>::AllocHolder , public hash_table_types<KeyOfValue, KeyHash, KeyEqual, Allocator, Options>::AllocHolder
{ {
typedef hash_table_types<KeyOfValue, KeyHash, KeyEqual, Allocator, Options> hash_table_types_t; typedef hash_table_types<KeyOfValue, KeyHash, KeyEqual, Allocator, Options> hash_table_types_t;
@@ -365,7 +366,7 @@ class hash_table
public: public:
BOOST_CONTAINER_FORCEINLINE hash_table() BOOST_CONTAINER_FORCEINLINE hash_table()
: AllocHolder() : AllocHolder(bucket_traits(this, 1))
{ this->reserve(0); } { this->reserve(0); }
BOOST_CONTAINER_FORCEINLINE explicit hash_table(const allocator_type& a) BOOST_CONTAINER_FORCEINLINE explicit hash_table(const allocator_type& a)

View File

@@ -191,6 +191,8 @@ BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(key_compare)
BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(key_equal) BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(key_equal)
BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(hasher) BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(hasher)
BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(predicate_type) BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(predicate_type)
BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(bucket_traits)
BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(bucket_type)
template<class Allocator, class ICont> template<class Allocator, class ICont>
struct node_alloc_holder struct node_alloc_holder
@@ -216,7 +218,13 @@ struct node_alloc_holder
, ICont, key_equal, dtl::nat2) intrusive_val_equal; , ICont, key_equal, dtl::nat2) intrusive_val_equal;
typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
(boost::container::dtl:: (boost::container::dtl::
, ICont, hasher, dtl::nat3) intrusive_val_hasher; , ICont, hasher, dtl::nat3) intrusive_val_hasher;
typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
(boost::container::dtl::
, ICont, bucket_traits, dtl::nat) intrusive_bucket_traits;
typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
(boost::container::dtl::
, ICont, bucket_type, dtl::nat2) intrusive_bucket_type;
//In that case obtain the value predicate from the node predicate via predicate_type //In that case obtain the value predicate from the node predicate via predicate_type
//if intrusive_val_compare is node_compare<>, nat otherwise //if intrusive_val_compare is node_compare<>, nat otherwise
typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
@@ -259,31 +267,40 @@ struct node_alloc_holder
BOOST_CONTAINER_FORCEINLINE node_alloc_holder() BOOST_CONTAINER_FORCEINLINE node_alloc_holder()
{} {}
explicit node_alloc_holder(const intrusive_bucket_traits& bt)
: m_icont(bt)
{}
explicit node_alloc_holder(const ValAlloc &a) explicit node_alloc_holder(const ValAlloc &a)
: NodeAlloc(a) : NodeAlloc(a)
{} {}
node_alloc_holder(const intrusive_bucket_traits& bt, const ValAlloc& a)
: NodeAlloc(a)
, m_icont(bt)
{}
//Constructors for associative containers //Constructors for associative containers
node_alloc_holder(const val_compare &c, const ValAlloc &a) node_alloc_holder(const val_compare &c, const ValAlloc &a)
: NodeAlloc(a), m_icont(typename ICont::key_compare(c)) : NodeAlloc(a), m_icont(typename ICont::key_compare(c))
{} {}
node_alloc_holder(const val_hasher &hf, const val_equal &eql, const ValAlloc &a) node_alloc_holder(const intrusive_bucket_traits & bt, const val_hasher &hf, const val_equal &eql, const ValAlloc &a)
: NodeAlloc(a) : NodeAlloc(a)
, m_icont(typename ICont::bucket_traits() , m_icont(bt
, typename ICont::hasher(hf) , typename ICont::hasher(hf)
, typename ICont::key_equal(eql)) , typename ICont::key_equal(eql))
{} {}
node_alloc_holder(const val_hasher &hf, const ValAlloc &a) node_alloc_holder(const intrusive_bucket_traits& bt, const val_hasher &hf, const ValAlloc &a)
: NodeAlloc(a) : NodeAlloc(a)
, m_icont(typename ICont::bucket_traits() , m_icont(bt
, typename ICont::hasher(hf) , typename ICont::hasher(hf)
, typename ICont::key_equal()) , typename ICont::key_equal())
{} {}
node_alloc_holder(const val_hasher &hf) node_alloc_holder(const intrusive_bucket_traits& bt, const val_hasher &hf)
: m_icont(typename ICont::bucket_traits() : m_icont(bt
, typename ICont::hasher(hf) , typename ICont::hasher(hf)
, typename ICont::key_equal()) , typename ICont::key_equal())
{} {}
@@ -297,15 +314,15 @@ struct node_alloc_holder
, m_icont(typename ICont::key_compare(c)) , m_icont(typename ICont::key_compare(c))
{} {}
node_alloc_holder(const node_alloc_holder &x, const val_hasher &hf, const val_equal &eql) node_alloc_holder(const node_alloc_holder &x, const intrusive_bucket_traits& bt, const val_hasher &hf, const val_equal &eql)
: NodeAlloc(NodeAllocTraits::select_on_container_copy_construction(x.node_alloc())) : NodeAlloc(NodeAllocTraits::select_on_container_copy_construction(x.node_alloc()))
, m_icont( typename ICont::bucket_traits() , m_icont( bt
, typename ICont::hasher(hf) , typename ICont::hasher(hf)
, typename ICont::key_equal(eql)) , typename ICont::key_equal(eql))
{} {}
node_alloc_holder(const val_hasher &hf, const val_equal &eql) node_alloc_holder(const val_hasher &hf, const intrusive_bucket_traits& bt, const val_equal &eql)
: m_icont(typename ICont::bucket_traits() : m_icont(bt
, typename ICont::hasher(hf) , typename ICont::hasher(hf)
, typename ICont::key_equal(eql)) , typename ICont::key_equal(eql))
{} {}
@@ -323,9 +340,9 @@ struct node_alloc_holder
: NodeAlloc(boost::move(BOOST_MOVE_TO_LV(x).node_alloc())), m_icont(typename ICont::key_compare(c)) : NodeAlloc(boost::move(BOOST_MOVE_TO_LV(x).node_alloc())), m_icont(typename ICont::key_compare(c))
{ this->icont().swap(x.icont()); } { this->icont().swap(x.icont()); }
explicit node_alloc_holder(BOOST_RV_REF(node_alloc_holder) x, const val_hasher &hf, const val_equal &eql) explicit node_alloc_holder(BOOST_RV_REF(node_alloc_holder) x, const intrusive_bucket_traits& bt, const val_hasher &hf, const val_equal &eql)
: NodeAlloc(boost::move(BOOST_MOVE_TO_LV(x).node_alloc())) : NodeAlloc(boost::move(BOOST_MOVE_TO_LV(x).node_alloc()))
, m_icont( typename ICont::bucket_traits() , m_icont( bt
, typename ICont::hasher(hf) , typename ICont::hasher(hf)
, typename ICont::key_equal(eql)) , typename ICont::key_equal(eql))
{ this->icont().swap(BOOST_MOVE_TO_LV(x).icont()); } { this->icont().swap(BOOST_MOVE_TO_LV(x).icont()); }