diff --git a/include/boost/unordered/detail/foa/core.hpp b/include/boost/unordered/detail/foa/core.hpp index 175f7493..e6e3fd1c 100644 --- a/include/boost/unordered/detail/foa/core.hpp +++ b/include/boost/unordered/detail/foa/core.hpp @@ -1115,8 +1115,8 @@ union uninitialized_storage #endif template< - typename TypePolicy,typename Group,typename Hash,typename Pred, - typename Allocator + typename TypePolicy,typename Group,typename SizeImpl, + typename Hash,typename Pred,typename Allocator > class @@ -1160,7 +1160,7 @@ public: const Pred& pred_=Pred(),const Allocator& al_=Allocator()): hash_base{empty_init,h_},pred_base{empty_init,pred_}, allocator_base{empty_init,al_},arrays(new_arrays(n)), - ml{initial_max_load()},available{ml} + ml{initial_max_load()},available{std::size_t(ml)} {} table_core(const table_core& x): @@ -1174,11 +1174,11 @@ public: hash_base{empty_init,std::move(x.h())}, pred_base{empty_init,std::move(x.pred())}, allocator_base{empty_init,std::move(x.al())}, - arrays(x.arrays),ml{x.ml},available{x.available} + arrays(x.arrays),ml{std::size_t(x.ml)},available{std::size_t(x.available)} { x.arrays=x.new_arrays(0); x.ml=x.initial_max_load(); - x.available=x.ml; + x.available=std::size_t(x.ml); } table_core(const table_core& x,const Allocator& al_): @@ -1379,7 +1379,7 @@ public: } arrays.groups[arrays.groups_size_mask].set_sentinel(); ml=initial_max_load(); - available=ml; + available=std::size_t(ml); } } @@ -1625,11 +1625,11 @@ public: } arrays_type arrays; - std::size_t ml; - std::size_t available; + SizeImpl ml; + SizeImpl available; private: - template + template friend class table_core; using hash_base=empty_value; @@ -1689,7 +1689,7 @@ private: std::memcpy( arrays.groups,x.arrays.groups, (arrays.groups_size_mask+1)*sizeof(group_type)); - available=x.available; + available=std::size_t(x.available); } } @@ -1752,9 +1752,10 @@ private: * that average probe length won't increase unboundedly in repeated * insert/erase cycles (drift). */ - ml-=group_type::maybe_caused_overflow(pc); + auto ov=group_type::maybe_caused_overflow(pc); + ml-=ov; group_type::reset(pc); - ++available; + available+=!ov; } void recover_slot(group_type* pg,std::size_t pos) @@ -1820,7 +1821,9 @@ private: } delete_arrays(arrays); arrays=new_arrays_; + auto s=size(); ml=initial_max_load(); + available=ml-s; } void noshrink_reserve(std::size_t n) @@ -1836,7 +1839,9 @@ private: auto new_arrays_=new_arrays(n); delete_arrays(arrays); arrays=new_arrays_; + auto s=size(); ml=initial_max_load(); + available=ml-s; } } } diff --git a/include/boost/unordered/detail/foa/table.hpp b/include/boost/unordered/detail/foa/table.hpp index 6b9268c1..96006dcc 100644 --- a/include/boost/unordered/detail/foa/table.hpp +++ b/include/boost/unordered/detail/foa/table.hpp @@ -216,13 +216,16 @@ private: * boost::unordered_[flat|node]_[map|set]. */ +template +using table_core_impl= + table_core,std::size_t,Hash,Pred,Allocator>; + #include template -class table:table_core,Hash,Pred,Allocator> +class table:table_core_impl { - using super= - table_core,Hash,Pred,Allocator>; + using super=table_core_impl; using type_policy=typename super::type_policy; using group_type=typename super::group_type; using super::N; @@ -500,7 +503,7 @@ private: if(it!=end()){ return {it,false}; } - if(BOOST_LIKELY(this->available)){ + if(BOOST_LIKELY(this->available!=0)){ return { make_iterator( this->unchecked_emplace_at(pos0,hash,std::forward(args)...)),