From b8c754d230192b19dc1da744605aaa4343b9e5f2 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 1 May 2017 21:03:11 +0100 Subject: [PATCH] Set the high bit in bucket_info_ to false for first node in group And true for the reset, so that in containers with unique keys bucket_info_ is always just the bucket index. --- .../boost/unordered/detail/implementation.hpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/include/boost/unordered/detail/implementation.hpp b/include/boost/unordered/detail/implementation.hpp index 879e0a15..49bc321e 100644 --- a/include/boost/unordered/detail/implementation.hpp +++ b/include/boost/unordered/detail/implementation.hpp @@ -3313,7 +3313,7 @@ struct table : boost::unordered::detail::functionsbucket_info_ = bucket_index; - n->set_first_in_group(); + // n->set_first_in_group(); if (!b->next_) { link_pointer start_node = this->get_previous_start(); @@ -3830,6 +3830,7 @@ struct table : boost::unordered::detail::functionsbucket_info_ = bucket_index; if (pos) { + n->reset_first_in_group(); n->next_ = pos->next_; pos->next_ = n; if (n->next_) { @@ -3839,7 +3840,7 @@ struct table : boost::unordered::detail::functionsset_first_in_group(); + // n->set_first_in_group(); bucket_pointer b = this->get_bucket(bucket_index); if (!b->next_) { @@ -4210,7 +4211,7 @@ inline void table::rehash_impl(std::size_t num_buckets) } n = next; n->bucket_info_ = bucket_index; - // n->reset_first_in_group(); + n->reset_first_in_group(); } // n is now the last node in the group @@ -4424,17 +4425,17 @@ struct node : boost::unordered::detail::value_base std::size_t is_first_in_group() const { - return bucket_info_ & ~((std::size_t)-1 >> 1); + return !(bucket_info_ & ~((std::size_t)-1 >> 1)); } void set_first_in_group() { - bucket_info_ = bucket_info_ | ~((std::size_t)-1 >> 1); + bucket_info_ = bucket_info_ & ((std::size_t)-1 >> 1); } void reset_first_in_group() { - bucket_info_ = bucket_info_ & ((std::size_t)-1 >> 1); + bucket_info_ = bucket_info_ | ~((std::size_t)-1 >> 1); } private: @@ -4465,17 +4466,17 @@ template struct ptr_node : boost::unordered::detail::ptr_bucket std::size_t is_first_in_group() const { - return bucket_info_ & ~((std::size_t)-1 >> 1); + return !(bucket_info_ & ~((std::size_t)-1 >> 1)); } void set_first_in_group() { - bucket_info_ = bucket_info_ | ~((std::size_t)-1 >> 1); + bucket_info_ = bucket_info_ & ((std::size_t)-1 >> 1); } void reset_first_in_group() { - bucket_info_ = bucket_info_ & ((std::size_t)-1 >> 1); + bucket_info_ = bucket_info_ | ~((std::size_t)-1 >> 1); } private: