diff --git a/include/boost/unordered/detail/buckets.hpp b/include/boost/unordered/detail/buckets.hpp index caeaaa32..ed7f5e01 100644 --- a/include/boost/unordered/detail/buckets.hpp +++ b/include/boost/unordered/detail/buckets.hpp @@ -578,8 +578,6 @@ namespace boost { namespace unordered { namespace detail { /////////////////////////////////////////////////////////////////// // // Hash Policy - // - // Don't really want table to derive from this, but will for now. template struct prime_policy diff --git a/include/boost/unordered/detail/equivalent.hpp b/include/boost/unordered/detail/equivalent.hpp index 292758b2..bd3d7588 100644 --- a/include/boost/unordered/detail/equivalent.hpp +++ b/include/boost/unordered/detail/equivalent.hpp @@ -237,8 +237,7 @@ namespace boost { namespace unordered { namespace detail { Key const& k, Pred const& eq) const { - std::size_t bucket_index = - policy::to_bucket(this->bucket_count_, key_hash); + std::size_t bucket_index = this->hash_to_bucket(key_hash); iterator n = this->begin(bucket_index); for (;;) @@ -253,8 +252,7 @@ namespace boost { namespace unordered { namespace detail { } else { - if (policy::to_bucket(this->bucket_count_, node_hash) - != bucket_index) + if (this->hash_to_bucket(node_hash) != bucket_index) return iterator(); } @@ -408,25 +406,23 @@ namespace boost { namespace unordered { namespace detail { if (pos.node_) { this->add_after_node(n, pos.node_); if (n->next_) { - std::size_t next_bucket = policy::to_bucket( - this->bucket_count_, + std::size_t next_bucket = this->hash_to_bucket( static_cast(n->next_)->hash_); - if (next_bucket != - policy::to_bucket(this->bucket_count_, key_hash)) { + if (next_bucket != this->hash_to_bucket(key_hash)) { this->get_bucket(next_bucket)->next_ = n; } } } else { bucket_pointer b = this->get_bucket( - policy::to_bucket(this->bucket_count_, key_hash)); + this->hash_to_bucket(key_hash)); if (!b->next_) { link_pointer start_node = this->get_previous_start(); if (start_node->next_) { - this->get_bucket(policy::to_bucket(this->bucket_count_, + this->get_bucket(this->hash_to_bucket( static_cast(start_node->next_)->hash_ ))->next_ = n; } @@ -541,8 +537,7 @@ namespace boost { namespace unordered { namespace detail { if(!this->size_) return 0; std::size_t key_hash = this->hash(k); - std::size_t bucket_index = - policy::to_bucket(this->bucket_count_, key_hash); + std::size_t bucket_index = this->hash_to_bucket(key_hash); link_pointer prev = this->get_previous_start(bucket_index); if (!prev) return 0; @@ -551,8 +546,7 @@ namespace boost { namespace unordered { namespace detail { if (!prev->next_) return 0; std::size_t node_hash = static_cast(prev->next_)->hash_; - if (policy::to_bucket(this->bucket_count_, node_hash) - != bucket_index) + if (this->hash_to_bucket(node_hash) != bucket_index) return 0; if (node_hash == key_hash && this->key_eq()(k, this->get_key( @@ -587,8 +581,7 @@ namespace boost { namespace unordered { namespace detail { link_pointer erase_nodes(node_pointer begin, node_pointer end) { - std::size_t bucket_index = - policy::to_bucket(this->bucket_count_, begin->hash_); + std::size_t bucket_index = this->hash_to_bucket(begin->hash_); // Split the groups containing 'begin' and 'end'. // And get the pointer to the node before begin while @@ -689,8 +682,7 @@ namespace boost { namespace unordered { namespace detail { static link_pointer place_in_bucket(table& dst, link_pointer prev, node_pointer end) { - bucket_pointer b = dst.get_bucket(policy::to_bucket( - dst.bucket_count_, end->hash_)); + bucket_pointer b = dst.get_bucket(dst.hash_to_bucket(end->hash_)); if (!b->next_) { b->next_ = prev; diff --git a/include/boost/unordered/detail/table.hpp b/include/boost/unordered/detail/table.hpp index cfaf313d..48319581 100644 --- a/include/boost/unordered/detail/table.hpp +++ b/include/boost/unordered/detail/table.hpp @@ -125,7 +125,6 @@ namespace boost { namespace unordered { namespace detail { template struct table : - Types::policy, boost::unordered::detail::functions< typename Types::hasher, typename Types::key_equal> @@ -244,6 +243,11 @@ namespace boost { namespace unordered { namespace detail { link_pointer prev = get_previous_start(bucket_index); return prev ? iterator(prev->next_) : iterator(); } + + std::size_t hash_to_bucket(std::size_t hash) const + { + return policy::to_bucket(bucket_count_, hash); + } float load_factor() const { @@ -258,8 +262,7 @@ namespace boost { namespace unordered { namespace detail { if (!it.node_) return 0; std::size_t count = 0; - while(it.node_ && policy::to_bucket( - bucket_count_, it.node_->hash_) == index) + while(it.node_ && hash_to_bucket(it.node_->hash_) == index) { ++count; ++it; @@ -586,7 +589,7 @@ namespace boost { namespace unordered { namespace detail { if (end) { - bucket_index2 = policy::to_bucket(bucket_count_, + bucket_index2 = hash_to_bucket( static_cast(end)->hash_); // If begin and end are in the same bucket, then diff --git a/include/boost/unordered/detail/unique.hpp b/include/boost/unordered/detail/unique.hpp index 583271da..9712eff3 100644 --- a/include/boost/unordered/detail/unique.hpp +++ b/include/boost/unordered/detail/unique.hpp @@ -232,8 +232,7 @@ namespace boost { namespace unordered { namespace detail { Key const& k, Pred const& eq) const { - std::size_t bucket_index = - policy::to_bucket(this->bucket_count_, key_hash); + std::size_t bucket_index = this->hash_to_bucket(key_hash); iterator n = this->begin(bucket_index); for (;;) @@ -248,8 +247,7 @@ namespace boost { namespace unordered { namespace detail { } else { - if (policy::to_bucket(this->bucket_count_, node_hash) - != bucket_index) + if (this->hash_to_bucket(node_hash) != bucket_index) return iterator(); } @@ -313,15 +311,14 @@ namespace boost { namespace unordered { namespace detail { node_pointer n = a.release(); n->hash_ = key_hash; - bucket_pointer b = this->get_bucket( - policy::to_bucket(this->bucket_count_, key_hash)); + bucket_pointer b = this->get_bucket(this->hash_to_bucket(key_hash)); if (!b->next_) { link_pointer start_node = this->get_previous_start(); if (start_node->next_) { - this->get_bucket(policy::to_bucket(this->bucket_count_, + this->get_bucket(this->hash_to_bucket( static_cast(start_node->next_)->hash_) )->next_ = n; } @@ -519,8 +516,7 @@ namespace boost { namespace unordered { namespace detail { if(!this->size_) return 0; std::size_t key_hash = this->hash(k); - std::size_t bucket_index = - policy::to_bucket(this->bucket_count_, key_hash); + std::size_t bucket_index = this->hash_to_bucket(key_hash); link_pointer prev = this->get_previous_start(bucket_index); if (!prev) return 0; @@ -529,8 +525,7 @@ namespace boost { namespace unordered { namespace detail { if (!prev->next_) return 0; std::size_t node_hash = static_cast(prev->next_)->hash_; - if (policy::to_bucket(this->bucket_count_, node_hash) - != bucket_index) + if (this->hash_to_bucket(node_hash) != bucket_index) return 0; if (node_hash == key_hash && this->key_eq()(k, this->get_key( @@ -564,8 +559,7 @@ namespace boost { namespace unordered { namespace detail { void erase_nodes(node_pointer begin, node_pointer end) { - std::size_t bucket_index = - policy::to_bucket(this->bucket_count_, begin->hash_); + std::size_t bucket_index = this->hash_to_bucket(begin->hash_); // Find the node before begin. link_pointer prev = this->get_previous_start(bucket_index); @@ -614,8 +608,7 @@ namespace boost { namespace unordered { namespace detail { static link_pointer place_in_bucket(table& dst, link_pointer prev) { node_pointer n = static_cast(prev->next_); - bucket_pointer b = dst.get_bucket( - table::to_bucket(dst.bucket_count_, n->hash_)); + bucket_pointer b = dst.get_bucket(dst.hash_to_bucket(n->hash_)); if (!b->next_) { b->next_ = prev; diff --git a/include/boost/unordered/unordered_map.hpp b/include/boost/unordered/unordered_map.hpp index d6067395..651fefaa 100644 --- a/include/boost/unordered/unordered_map.hpp +++ b/include/boost/unordered/unordered_map.hpp @@ -463,8 +463,7 @@ namespace unordered size_type bucket(const key_type& k) const { - return table::to_bucket(table_.bucket_count_, - table_.hash(k)); + return table_.hash_to_bucket(table_.hash(k)); } local_iterator begin(size_type n) @@ -942,8 +941,7 @@ namespace unordered size_type bucket(const key_type& k) const { - return table::to_bucket(table_.bucket_count_, - table_.hash(k)); + return table_.hash_to_bucket(table_.hash(k)); } local_iterator begin(size_type n) diff --git a/include/boost/unordered/unordered_set.hpp b/include/boost/unordered/unordered_set.hpp index 92cb2f65..b0a2a852 100644 --- a/include/boost/unordered/unordered_set.hpp +++ b/include/boost/unordered/unordered_set.hpp @@ -448,8 +448,7 @@ namespace unordered size_type bucket(const key_type& k) const { - return table::to_bucket(table_.bucket_count_, - table_.hash(k)); + return table_.hash_to_bucket(table_.hash(k)); } local_iterator begin(size_type n) @@ -917,8 +916,7 @@ namespace unordered size_type bucket(const key_type& k) const { - return table::to_bucket(table_.bucket_count_, - table_.hash(k)); + return table_.hash_to_bucket(table_.hash(k)); } local_iterator begin(size_type n)