Update implementation to support a default-constructible table and grouped_bucket_array

This commit is contained in:
Christian Mazakas
2022-08-23 11:16:46 -07:00
parent 6f342bf119
commit db9d9d1f77
4 changed files with 39 additions and 15 deletions

View File

@ -494,11 +494,25 @@ namespace boost {
group_pointer groups;
public:
grouped_bucket_array()
: empty_value<node_allocator_type>(
empty_init_t(), node_allocator_type()),
size_index_(0), size_(0), buckets(), groups()
{
}
grouped_bucket_array(size_type n, const Allocator& al)
: empty_value<node_allocator_type>(empty_init_t(), al),
size_index_(size_policy::size_index(n)),
size_(size_policy::size(size_index_)), buckets(), groups()
size_index_(0),
size_(0), buckets(), groups()
{
if (n == 0) {
return;
}
size_index_ = size_policy::size_index(n);
size_ = size_policy::size(size_index_);
bucket_allocator_type bucket_alloc = this->get_bucket_allocator();
group_allocator_type group_alloc = this->get_group_allocator();

View File

@ -2075,9 +2075,16 @@ namespace boost {
// From 6.3.1/13:
// Only resize when size >= mlf_ * count
max_load_ = boost::unordered::detail::double_to_size(
floor(static_cast<double>(mlf_) *
static_cast<double>(buckets_.bucket_count())));
std::size_t const bc = buckets_.bucket_count();
// it's important we do the `bc == 0` check here because the `mlf_`
// can be specified to be infinity. The operation `n * INF` is `INF`
// for all `n > 0` but NaN for `n == 0`.
//
max_load_ =
bc == 0 ? 0
: boost::unordered::detail::double_to_size(floor(
static_cast<double>(mlf_) * static_cast<double>(bc)));
}
void max_load_factor(float z)
@ -2090,6 +2097,12 @@ namespace boost {
////////////////////////////////////////////////////////////////////////
// Constructors
table()
: functions(hasher(), key_equal()), size_(0), mlf_(1.0f),
max_load_(0)
{
}
table(std::size_t num_buckets, hasher const& hf, key_equal const& eq,
node_allocator_type const& a)
: functions(hf, eq), size_(0), mlf_(1.0f), max_load_(0),
@ -2361,7 +2374,10 @@ namespace boost {
template <typename UniqueType>
void move_assign(table& x, UniqueType is_unique, false_type)
{
reserve(x.size_);
if (x.size_ > 0) {
reserve(x.size_);
}
if (node_alloc() == x.node_alloc()) {
move_assign_equal_alloc(x);
} else {
@ -2390,7 +2406,9 @@ namespace boost {
{
mlf_ = x.mlf_;
recalculate_max_load();
this->reserve_for_insert(x.size_);
if (x.size_ > 0) {
this->reserve_for_insert(x.size_);
}
this->clear_impl();
}
BOOST_CATCH(...)

View File

@ -1664,8 +1664,6 @@ namespace boost {
template <class K, class T, class H, class P, class A>
unordered_map<K, T, H, P, A>::unordered_map()
: table_(boost::unordered::detail::default_bucket_count, hasher(),
key_equal(), allocator_type())
{
}
@ -2147,8 +2145,6 @@ namespace boost {
template <class K, class T, class H, class P, class A>
unordered_multimap<K, T, H, P, A>::unordered_multimap()
: table_(boost::unordered::detail::default_bucket_count, hasher(),
key_equal(), allocator_type())
{
}

View File

@ -1266,8 +1266,6 @@ namespace boost {
////////////////////////////////////////////////////////////////////////////
template <class T, class H, class P, class A>
unordered_set<T, H, P, A>::unordered_set()
: table_(boost::unordered::detail::default_bucket_count, hasher(),
key_equal(), allocator_type())
{
}
@ -1664,8 +1662,6 @@ namespace boost {
template <class T, class H, class P, class A>
unordered_multiset<T, H, P, A>::unordered_multiset()
: table_(boost::unordered::detail::default_bucket_count, hasher(),
key_equal(), allocator_type())
{
}