forked from boostorg/unordered
added SizeImpl and fixed some size arithmetic bugs
This commit is contained in:
committed by
Christian Mazakas
parent
840ea1ce5c
commit
8010f506a6
@@ -1115,8 +1115,8 @@ union uninitialized_storage
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<
|
template<
|
||||||
typename TypePolicy,typename Group,typename Hash,typename Pred,
|
typename TypePolicy,typename Group,typename SizeImpl,
|
||||||
typename Allocator
|
typename Hash,typename Pred,typename Allocator
|
||||||
>
|
>
|
||||||
class
|
class
|
||||||
|
|
||||||
@@ -1160,7 +1160,7 @@ public:
|
|||||||
const Pred& pred_=Pred(),const Allocator& al_=Allocator()):
|
const Pred& pred_=Pred(),const Allocator& al_=Allocator()):
|
||||||
hash_base{empty_init,h_},pred_base{empty_init,pred_},
|
hash_base{empty_init,h_},pred_base{empty_init,pred_},
|
||||||
allocator_base{empty_init,al_},arrays(new_arrays(n)),
|
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):
|
table_core(const table_core& x):
|
||||||
@@ -1174,11 +1174,11 @@ public:
|
|||||||
hash_base{empty_init,std::move(x.h())},
|
hash_base{empty_init,std::move(x.h())},
|
||||||
pred_base{empty_init,std::move(x.pred())},
|
pred_base{empty_init,std::move(x.pred())},
|
||||||
allocator_base{empty_init,std::move(x.al())},
|
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.arrays=x.new_arrays(0);
|
||||||
x.ml=x.initial_max_load();
|
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_):
|
table_core(const table_core& x,const Allocator& al_):
|
||||||
@@ -1379,7 +1379,7 @@ public:
|
|||||||
}
|
}
|
||||||
arrays.groups[arrays.groups_size_mask].set_sentinel();
|
arrays.groups[arrays.groups_size_mask].set_sentinel();
|
||||||
ml=initial_max_load();
|
ml=initial_max_load();
|
||||||
available=ml;
|
available=std::size_t(ml);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1625,11 +1625,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
arrays_type arrays;
|
arrays_type arrays;
|
||||||
std::size_t ml;
|
SizeImpl ml;
|
||||||
std::size_t available;
|
SizeImpl available;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename,typename,typename,typename,typename>
|
template<typename,typename,typename,typename,typename,typename>
|
||||||
friend class table_core;
|
friend class table_core;
|
||||||
|
|
||||||
using hash_base=empty_value<Hash,0>;
|
using hash_base=empty_value<Hash,0>;
|
||||||
@@ -1689,7 +1689,7 @@ private:
|
|||||||
std::memcpy(
|
std::memcpy(
|
||||||
arrays.groups,x.arrays.groups,
|
arrays.groups,x.arrays.groups,
|
||||||
(arrays.groups_size_mask+1)*sizeof(group_type));
|
(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
|
* that average probe length won't increase unboundedly in repeated
|
||||||
* insert/erase cycles (drift).
|
* 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);
|
group_type::reset(pc);
|
||||||
++available;
|
available+=!ov;
|
||||||
}
|
}
|
||||||
|
|
||||||
void recover_slot(group_type* pg,std::size_t pos)
|
void recover_slot(group_type* pg,std::size_t pos)
|
||||||
@@ -1820,7 +1821,9 @@ private:
|
|||||||
}
|
}
|
||||||
delete_arrays(arrays);
|
delete_arrays(arrays);
|
||||||
arrays=new_arrays_;
|
arrays=new_arrays_;
|
||||||
|
auto s=size();
|
||||||
ml=initial_max_load();
|
ml=initial_max_load();
|
||||||
|
available=ml-s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void noshrink_reserve(std::size_t n)
|
void noshrink_reserve(std::size_t n)
|
||||||
@@ -1836,7 +1839,9 @@ private:
|
|||||||
auto new_arrays_=new_arrays(n);
|
auto new_arrays_=new_arrays(n);
|
||||||
delete_arrays(arrays);
|
delete_arrays(arrays);
|
||||||
arrays=new_arrays_;
|
arrays=new_arrays_;
|
||||||
|
auto s=size();
|
||||||
ml=initial_max_load();
|
ml=initial_max_load();
|
||||||
|
available=ml-s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -216,13 +216,16 @@ private:
|
|||||||
* boost::unordered_[flat|node]_[map|set].
|
* boost::unordered_[flat|node]_[map|set].
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
template <typename TypePolicy,typename Hash,typename Pred,typename Allocator>
|
||||||
|
using table_core_impl=
|
||||||
|
table_core<TypePolicy,group15<plain_integral>,std::size_t,Hash,Pred,Allocator>;
|
||||||
|
|
||||||
#include <boost/unordered/detail/foa/ignore_wshadow.hpp>
|
#include <boost/unordered/detail/foa/ignore_wshadow.hpp>
|
||||||
|
|
||||||
template<typename TypePolicy,typename Hash,typename Pred,typename Allocator>
|
template<typename TypePolicy,typename Hash,typename Pred,typename Allocator>
|
||||||
class table:table_core<TypePolicy,group15<plain_integral>,Hash,Pred,Allocator>
|
class table:table_core_impl<TypePolicy,Hash,Pred,Allocator>
|
||||||
{
|
{
|
||||||
using super=
|
using super=table_core_impl<TypePolicy,Hash,Pred,Allocator>;
|
||||||
table_core<TypePolicy,group15<plain_integral>,Hash,Pred,Allocator>;
|
|
||||||
using type_policy=typename super::type_policy;
|
using type_policy=typename super::type_policy;
|
||||||
using group_type=typename super::group_type;
|
using group_type=typename super::group_type;
|
||||||
using super::N;
|
using super::N;
|
||||||
@@ -500,7 +503,7 @@ private:
|
|||||||
if(it!=end()){
|
if(it!=end()){
|
||||||
return {it,false};
|
return {it,false};
|
||||||
}
|
}
|
||||||
if(BOOST_LIKELY(this->available)){
|
if(BOOST_LIKELY(this->available!=0)){
|
||||||
return {
|
return {
|
||||||
make_iterator(
|
make_iterator(
|
||||||
this->unchecked_emplace_at(pos0,hash,std::forward<Args>(args)...)),
|
this->unchecked_emplace_at(pos0,hash,std::forward<Args>(args)...)),
|
||||||
|
Reference in New Issue
Block a user