summaryrefslogtreecommitdiff
path: root/boost/intrusive/hashtable.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/intrusive/hashtable.hpp')
-rw-r--r--boost/intrusive/hashtable.hpp127
1 files changed, 71 insertions, 56 deletions
diff --git a/boost/intrusive/hashtable.hpp b/boost/intrusive/hashtable.hpp
index 313da829d3..bae9d52485 100644
--- a/boost/intrusive/hashtable.hpp
+++ b/boost/intrusive/hashtable.hpp
@@ -117,6 +117,24 @@ struct prime_list_holder
{
static const std::size_t prime_list[];
static const std::size_t prime_list_size;
+
+ static std::size_t suggested_upper_bucket_count(std::size_t n)
+ {
+ const std::size_t *primes = &prime_list_holder<0>::prime_list[0];
+ const std::size_t *primes_end = primes + prime_list_holder<0>::prime_list_size;
+ std::size_t const* bound = std::lower_bound(primes, primes_end, n);
+ bound -= (bound == primes_end);
+ return *bound;
+ }
+
+ static std::size_t suggested_lower_bucket_count(std::size_t n)
+ {
+ const std::size_t *primes = &prime_list_holder<0>::prime_list[0];
+ const std::size_t *primes_end = primes + prime_list_holder<0>::prime_list_size;
+ std::size_t const* bound = std::upper_bound(primes, primes_end, n);
+ bound -= (bound != primes);
+ return *bound;
+ }
};
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
@@ -588,7 +606,6 @@ struct bucket_plus_vtraits
typedef typename value_traits::node_traits node_traits;
typedef unordered_group_adapter<node_traits> group_traits;
typedef typename slist_impl::iterator siterator;
- typedef typename slist_impl::size_type size_type;
typedef detail::bucket_impl<slist_impl> bucket_type;
typedef detail::group_functions<node_traits> group_functions_t;
typedef typename slist_impl::node_algorithms node_algorithms;
@@ -655,7 +672,7 @@ struct bucket_plus_vtraits
BOOST_INTRUSIVE_FORCEINLINE bucket_ptr priv_bucket_pointer() const
{ return this->priv_bucket_traits().bucket_begin(); }
- typename slist_impl::size_type priv_bucket_count() const
+ std::size_t priv_bucket_count() const
{ return this->priv_bucket_traits().bucket_count(); }
BOOST_INTRUSIVE_FORCEINLINE bucket_ptr priv_invalid_bucket() const
@@ -668,9 +685,9 @@ struct bucket_plus_vtraits
{ return this->priv_bucket_traits().bucket_begin()->before_begin(); }
template<class NodeDisposer>
- static size_type priv_erase_from_single_bucket(bucket_type &b, siterator sbefore_first, siterator slast, NodeDisposer node_disposer, detail::true_) //optimize multikey
+ static std::size_t priv_erase_from_single_bucket(bucket_type &b, siterator sbefore_first, siterator slast, NodeDisposer node_disposer, detail::true_) //optimize multikey
{
- size_type n = 0;
+ std::size_t n = 0;
siterator const sfirst(++siterator(sbefore_first));
if(sfirst != slast){
node_ptr const nf = detail::dcast_bucket_ptr<node>(sfirst.pointed_node());
@@ -708,9 +725,9 @@ struct bucket_plus_vtraits
}
template<class NodeDisposer>
- static size_type priv_erase_from_single_bucket(bucket_type &b, siterator sbefore_first, siterator slast, NodeDisposer node_disposer, detail::false_) //optimize multikey
+ static std::size_t priv_erase_from_single_bucket(bucket_type &b, siterator sbefore_first, siterator slast, NodeDisposer node_disposer, detail::false_) //optimize multikey
{
- size_type n = 0;
+ std::size_t n = 0;
siterator it(++siterator(sbefore_first));
while(it != slast){
node_disposer((it++).pointed_node());
@@ -757,17 +774,17 @@ struct bucket_plus_vtraits
{ b.erase_after_and_dispose(b.previous(i), node_disposer); }
template<class NodeDisposer, bool OptimizeMultikey>
- size_type priv_erase_node_range( siterator const &before_first_it, size_type const first_bucket
- , siterator const &last_it, size_type const last_bucket
+ std::size_t priv_erase_node_range( siterator const &before_first_it, std::size_t const first_bucket
+ , siterator const &last_it, std::size_t const last_bucket
, NodeDisposer node_disposer, detail::bool_<OptimizeMultikey> optimize_multikey_tag)
{
- size_type num_erased(0);
+ std::size_t num_erased(0);
siterator last_step_before_it;
if(first_bucket != last_bucket){
bucket_type *b = (&this->priv_bucket_pointer()[0]);
num_erased += this->priv_erase_from_single_bucket
(b[first_bucket], before_first_it, b[first_bucket].end(), node_disposer, optimize_multikey_tag);
- for(size_type i = 0, n = (last_bucket - first_bucket - 1); i != n; ++i){
+ for(std::size_t i = 0, n = (last_bucket - first_bucket - 1); i != n; ++i){
num_erased += this->priv_erase_whole_bucket(b[first_bucket+i+1], node_disposer);
}
last_step_before_it = b[last_bucket].before_begin();
@@ -797,9 +814,9 @@ struct bucket_plus_vtraits
}
template<class NodeDisposer>
- size_type priv_erase_whole_bucket(bucket_type &b, NodeDisposer node_disposer)
+ std::size_t priv_erase_whole_bucket(bucket_type &b, NodeDisposer node_disposer)
{
- size_type num_erased = 0;
+ std::size_t num_erased = 0;
siterator b_begin(b.before_begin());
siterator nxt(b_begin);
++nxt;
@@ -841,7 +858,7 @@ struct bucket_plus_vtraits
const bucket_type &b = static_cast<const bucket_type&>
(bucket_type::slist_type::container_from_end_iterator(bucket_type::s_iterator_to(*bb)));
//Now just calculate the index b has in the bucket array
- return static_cast<size_type>(&b - &*f);
+ return static_cast<std::size_t>(&b - &*f);
}
std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::false_) //NO optimize multikey
@@ -881,10 +898,10 @@ struct bucket_plus_vtraits
BOOST_INTRUSIVE_FORCEINLINE const_reference priv_value_from_slist_node(slist_node_ptr n) const
{ return *this->priv_value_traits().to_value_ptr(detail::dcast_bucket_ptr<node>(n)); }
- void priv_clear_buckets(const bucket_ptr buckets_ptr, const size_type bucket_cnt)
+ void priv_clear_buckets(const bucket_ptr buckets_ptr, const std::size_t bucket_cnt)
{
bucket_ptr buckets_it = buckets_ptr;
- for(size_type bucket_i = 0; bucket_i != bucket_cnt; ++buckets_it, ++bucket_i){
+ for(std::size_t bucket_i = 0; bucket_i != bucket_cnt; ++buckets_it, ++bucket_i){
if(safemode_or_autounlink){
buckets_it->clear_and_dispose(detail::init_disposer<node_algorithms>());
}
@@ -909,24 +926,6 @@ struct bucket_plus_vtraits
BOOST_INTRUSIVE_FORCEINLINE const_iterator cend() const
{ return const_iterator(this->priv_invalid_local_it(), 0); }
- static size_type suggested_upper_bucket_count(size_type n)
- {
- const std::size_t *primes = &prime_list_holder<0>::prime_list[0];
- const std::size_t *primes_end = primes + prime_list_holder<0>::prime_list_size;
- std::size_t const* bound = std::lower_bound(primes, primes_end, n);
- bound -= (bound == primes_end);
- return size_type(*bound);
- }
-
- static size_type suggested_lower_bucket_count(size_type n)
- {
- const std::size_t *primes = &prime_list_holder<0>::prime_list[0];
- const std::size_t *primes_end = primes + prime_list_holder<0>::prime_list_size;
- size_type const* bound = std::upper_bound(primes, primes_end, n);
- bound -= (bound != primes);
- return size_type(*bound);
- }
-
//Public functions:
struct data_type : public ValueTraits
{
@@ -1072,7 +1071,6 @@ struct bucket_hash_equal_t
typedef typename bucket_hash_type::hasher hasher;
typedef BucketTraits bucket_traits;
typedef typename bucket_plus_vtraits_t::slist_impl slist_impl;
- typedef typename slist_impl::size_type size_type;
typedef typename slist_impl::iterator siterator;
typedef detail::bucket_impl<slist_impl> bucket_type;
typedef typename detail::unordered_bucket_ptr_impl<value_traits>::type bucket_ptr;
@@ -1089,7 +1087,7 @@ struct bucket_hash_equal_t
BOOST_INTRUSIVE_FORCEINLINE void priv_set_cache(const bucket_ptr &)
{}
- BOOST_INTRUSIVE_FORCEINLINE size_type priv_get_cache_bucket_num()
+ BOOST_INTRUSIVE_FORCEINLINE std::size_t priv_get_cache_bucket_num()
{ return 0u; }
BOOST_INTRUSIVE_FORCEINLINE void priv_initialize_cache()
@@ -1100,8 +1098,8 @@ struct bucket_hash_equal_t
siterator priv_begin() const
{
- size_type n = 0;
- size_type bucket_cnt = this->bucket_hash_type::priv_bucket_count();
+ std::size_t n = 0;
+ std::size_t bucket_cnt = this->bucket_hash_type::priv_bucket_count();
for (n = 0; n < bucket_cnt; ++n){
bucket_type &b = this->bucket_hash_type::priv_bucket_pointer()[n];
if(!b.empty()){
@@ -1111,10 +1109,10 @@ struct bucket_hash_equal_t
return this->bucket_hash_type::priv_invalid_local_it();
}
- BOOST_INTRUSIVE_FORCEINLINE void priv_insertion_update_cache(size_type)
+ BOOST_INTRUSIVE_FORCEINLINE void priv_insertion_update_cache(std::size_t)
{}
- BOOST_INTRUSIVE_FORCEINLINE void priv_erasure_update_cache_range(size_type, size_type)
+ BOOST_INTRUSIVE_FORCEINLINE void priv_erasure_update_cache_range(std::size_t, std::size_t)
{}
BOOST_INTRUSIVE_FORCEINLINE void priv_erasure_update_cache()
@@ -1145,7 +1143,6 @@ struct bucket_hash_equal_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrK
typedef bucket_hash_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, BucketTraits> bucket_hash_type;
typedef typename bucket_hash_type::hasher hasher;
typedef BucketTraits bucket_traits;
- typedef typename bucket_plus_vtraits_t::slist_impl::size_type size_type;
typedef typename bucket_plus_vtraits_t::slist_impl::iterator siterator;
template<class BucketTraitsType>
@@ -1187,7 +1184,7 @@ struct bucket_hash_equal_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrK
}
}
- void priv_insertion_update_cache(size_type insertion_bucket)
+ void priv_insertion_update_cache(std::size_t insertion_bucket)
{
bucket_ptr p = this->bucket_hash_type::priv_bucket_pointer() + insertion_bucket;
if(p < this->cached_begin_){
@@ -1201,7 +1198,7 @@ struct bucket_hash_equal_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrK
BOOST_INTRUSIVE_FORCEINLINE key_equal &priv_equal()
{ return this->equal_holder_t::get(); }
- void priv_erasure_update_cache_range(size_type first_bucket_num, size_type last_bucket_num)
+ void priv_erasure_update_cache_range(std::size_t first_bucket_num, std::size_t last_bucket_num)
{
//If the last bucket is the end, the cache must be updated
//to the last position if all
@@ -1215,8 +1212,8 @@ struct bucket_hash_equal_t<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrK
void priv_erasure_update_cache()
{
if(this->cached_begin_ != this->bucket_hash_type::priv_invalid_bucket()){
- size_type current_n = this->priv_get_cache() - this->bucket_hash_type::priv_bucket_pointer();
- for( const size_type num_buckets = this->bucket_hash_type::priv_bucket_count()
+ std::size_t current_n = this->priv_get_cache() - this->bucket_hash_type::priv_bucket_pointer();
+ for( const std::size_t num_buckets = this->bucket_hash_type::priv_bucket_count()
; current_n < num_buckets
; ++current_n, ++this->priv_get_cache()){
if(!this->priv_get_cache()->empty()){
@@ -1307,7 +1304,7 @@ struct hashdata_internal
typedef typename internal_type::key_equal key_equal;
typedef typename internal_type::hasher hasher;
typedef bucket_plus_vtraits<ValueTraits,BucketTraits> bucket_plus_vtraits_t;
- typedef typename bucket_plus_vtraits_t::size_type size_type;
+ typedef SizeType size_type;
typedef typename internal_type::size_traits split_traits;
typedef typename bucket_plus_vtraits_t::bucket_ptr bucket_ptr;
typedef typename bucket_plus_vtraits_t::const_value_traits_ptr const_value_traits_ptr;
@@ -1459,7 +1456,11 @@ struct hashdata_internal
}
BOOST_INTRUSIVE_FORCEINLINE size_type bucket_count() const
- { return this->priv_bucket_count(); }
+ {
+ const std::size_t bc = this->priv_bucket_count();
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(sizeof(size_type) >= sizeof(std::size_t) || bc <= size_type(-1));
+ return static_cast<size_type>(bc);
+ }
BOOST_INTRUSIVE_FORCEINLINE size_type bucket_size(size_type n) const
{ return this->priv_bucket_pointer()[n].size(); }
@@ -1473,6 +1474,20 @@ struct hashdata_internal
BOOST_INTRUSIVE_FORCEINLINE const_local_iterator begin(size_type n) const
{ return this->cbegin(n); }
+ static BOOST_INTRUSIVE_FORCEINLINE size_type suggested_upper_bucket_count(size_type n)
+ {
+ std::size_t c = prime_list_holder<0>::suggested_upper_bucket_count
+ (sizeof(size_type) > sizeof(std::size_t) && n > std::size_t(-1) ? std::size_t(-1) : static_cast<std::size_t>(n));
+ return sizeof(size_type) < sizeof(std::size_t) && c > size_type(-1) ? size_type(-1) : static_cast<size_type>(c);
+ }
+
+ static BOOST_INTRUSIVE_FORCEINLINE size_type suggested_lower_bucket_count(size_type n)
+ {
+ std::size_t c = prime_list_holder<0>::suggested_lower_bucket_count
+ (sizeof(size_type) > sizeof(std::size_t) && n > std::size_t(-1) ? std::size_t(-1) : static_cast<std::size_t>(n));
+ return sizeof(size_type) < sizeof(std::size_t) && c > size_type(-1) ? size_type(-1) : static_cast<size_type>(c);
+ }
+
const_local_iterator cbegin(size_type n) const
{
return const_local_iterator
@@ -1737,7 +1752,7 @@ class hashtable_impl
{
this->priv_initialize_buckets_and_cache();
this->priv_size_traits().set_size(size_type(0));
- size_type bucket_sz = this->priv_bucket_count();
+ size_type bucket_sz = this->bucket_count();
BOOST_INTRUSIVE_INVARIANT_ASSERT(bucket_sz != 0);
//Check power of two bucket array if the option is activated
BOOST_INTRUSIVE_INVARIANT_ASSERT
@@ -1770,7 +1785,7 @@ class hashtable_impl
{
this->priv_initialize_buckets_and_cache();
this->priv_size_traits().set_size(size_type(0));
- size_type bucket_sz = this->priv_bucket_count();
+ size_type bucket_sz = this->bucket_count();
BOOST_INTRUSIVE_INVARIANT_ASSERT(bucket_sz != 0);
//Check power of two bucket array if the option is activated
BOOST_INTRUSIVE_INVARIANT_ASSERT
@@ -1894,8 +1909,8 @@ class hashtable_impl
return this->begin() == this->end();
}
else{
- size_type bucket_cnt = this->priv_bucket_count();
- const bucket_type *b = boost::intrusive::detail::to_raw_pointer(this->priv_bucket_pointer());
+ size_type bucket_cnt = this->bucket_count();
+ const bucket_type *b = boost::movelib::to_raw_pointer(this->priv_bucket_pointer());
for (size_type n = 0; n < bucket_cnt; ++n, ++b){
if(!b->empty()){
return false;
@@ -1917,8 +1932,8 @@ class hashtable_impl
return this->priv_size_traits().get_size();
else{
size_type len = 0;
- size_type bucket_cnt = this->priv_bucket_count();
- const bucket_type *b = boost::intrusive::detail::to_raw_pointer(this->priv_bucket_pointer());
+ size_type bucket_cnt = this->bucket_count();
+ const bucket_type *b = boost::movelib::to_raw_pointer(this->priv_bucket_pointer());
for (size_type n = 0; n < bucket_cnt; ++n, ++b){
len += b->size();
}
@@ -2898,7 +2913,7 @@ class hashtable_impl
//This function is only available for containers with incremental hashing
BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
const size_type split_idx = this->priv_split_traits().get_size();
- const size_type bucket_cnt = this->priv_bucket_count();
+ const size_type bucket_cnt = this->bucket_count();
const bucket_ptr buck_ptr = this->priv_bucket_pointer();
bool ret = false;
@@ -2961,7 +2976,7 @@ class hashtable_impl
//This function is only available for containers with incremental hashing
BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
size_type const new_bucket_traits_size = new_bucket_traits.bucket_count();
- size_type const cur_bucket_traits = this->priv_bucket_count();
+ size_type const cur_bucket_traits = this->bucket_count();
const size_type split_idx = this->split_count();
//Test new bucket size is consistent with internal bucket size and split count
@@ -3071,7 +3086,7 @@ class hashtable_impl
const bucket_ptr new_buckets = new_bucket_traits.bucket_begin();
size_type new_bucket_count = new_bucket_traits.bucket_count();
const bucket_ptr old_buckets = this->priv_bucket_pointer();
- size_type old_bucket_count = this->priv_bucket_count();
+ size_type old_bucket_count = this->bucket_count();
//Check power of two bucket array if the option is activated
BOOST_INTRUSIVE_INVARIANT_ASSERT
@@ -3400,7 +3415,7 @@ class hashtable_impl
to_return.second == bp[n_bucket].end()){
to_return.second = this->priv_invalid_local_it();
++n_bucket;
- for( const size_type max_bucket = this->priv_bucket_count()
+ for( const size_type max_bucket = this->bucket_count()
; n_bucket != max_bucket
; ++n_bucket){
bucket_type &b = bp[n_bucket];