fixed space reservation in concurrent_table::operator=(std::initializer_list)

This commit is contained in:
joaquintides
2023-05-04 18:09:28 +02:00
parent 23e720a968
commit 26924c73b9
2 changed files with 19 additions and 21 deletions

View File

@ -414,9 +414,7 @@ public:
concurrent_table& operator=(std::initializer_list<value_type> il) {
auto lck=exclusive_access();
super::clear();
if (super::capacity()<il.size()) {
super::reserve(il.size());
}
super::noshrink_reserve(il.size());
for (auto const& v : il) {
this->unprotected_emplace(v);
}

View File

@ -1642,6 +1642,24 @@ public:
return it;
}
void noshrink_reserve(std::size_t n)
{
/* used only on assignment after element clearance */
BOOST_ASSERT(empty());
if(n){
n=std::size_t(std::ceil(float(n)/mlf)); /* elements -> slots */
n=capacity_for(n); /* exact resulting capacity */
if(n>capacity()){
auto new_arrays_=new_arrays(n);
delete_arrays(arrays);
arrays=new_arrays_;
ml=initial_max_load();
}
}
}
template<typename F>
void for_all_elements(F f)const
{
@ -1947,24 +1965,6 @@ private:
ml=initial_max_load();
}
void noshrink_reserve(std::size_t n)
{
/* used only on assignment after element clearance */
BOOST_ASSERT(empty());
if(n){
n=std::size_t(std::ceil(float(n)/mlf)); /* elements -> slots */
n=capacity_for(n); /* exact resulting capacity */
if(n>capacity()){
auto new_arrays_=new_arrays(n);
delete_arrays(arrays);
arrays=new_arrays_;
ml=initial_max_load();
}
}
}
template<typename Value>
void unchecked_insert(Value&& x)
{