Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81209 - in trunk/boost/unordered: . detail
From: dnljms_at_[hidden]
Date: 2012-11-05 13:33:31


Author: danieljames
Date: 2012-11-05 13:33:29 EST (Mon, 05 Nov 2012)
New Revision: 81209
URL: http://svn.boost.org/trac/boost/changeset/81209

Log:
Unorderd: Stop deriving from hash policy.
Text files modified:
   trunk/boost/unordered/detail/buckets.hpp | 2 --
   trunk/boost/unordered/detail/equivalent.hpp | 28 ++++++++++------------------
   trunk/boost/unordered/detail/table.hpp | 11 +++++++----
   trunk/boost/unordered/detail/unique.hpp | 23 ++++++++---------------
   trunk/boost/unordered/unordered_map.hpp | 6 ++----
   trunk/boost/unordered/unordered_set.hpp | 6 ++----
   6 files changed, 29 insertions(+), 47 deletions(-)

Modified: trunk/boost/unordered/detail/buckets.hpp
==============================================================================
--- trunk/boost/unordered/detail/buckets.hpp (original)
+++ trunk/boost/unordered/detail/buckets.hpp 2012-11-05 13:33:29 EST (Mon, 05 Nov 2012)
@@ -578,8 +578,6 @@
     ///////////////////////////////////////////////////////////////////
     //
     // Hash Policy
- //
- // Don't really want table to derive from this, but will for now.
 
     template <typename SizeT>
     struct prime_policy

Modified: trunk/boost/unordered/detail/equivalent.hpp
==============================================================================
--- trunk/boost/unordered/detail/equivalent.hpp (original)
+++ trunk/boost/unordered/detail/equivalent.hpp 2012-11-05 13:33:29 EST (Mon, 05 Nov 2012)
@@ -237,8 +237,7 @@
                 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 @@
                 }
                 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 @@
             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<node_pointer>(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<node_pointer>(start_node->next_)->hash_
                         ))->next_ = n;
                     }
@@ -541,8 +537,7 @@
             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 @@
                 if (!prev->next_) return 0;
                 std::size_t node_hash =
                     static_cast<node_pointer>(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 @@
 
         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 @@
         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;

Modified: trunk/boost/unordered/detail/table.hpp
==============================================================================
--- trunk/boost/unordered/detail/table.hpp (original)
+++ trunk/boost/unordered/detail/table.hpp 2012-11-05 13:33:29 EST (Mon, 05 Nov 2012)
@@ -125,7 +125,6 @@
 
     template <typename Types>
     struct table :
- Types::policy,
         boost::unordered::detail::functions<
             typename Types::hasher,
             typename Types::key_equal>
@@ -244,6 +243,11 @@
             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 @@
             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 @@
 
             if (end)
             {
- bucket_index2 = policy::to_bucket(bucket_count_,
+ bucket_index2 = hash_to_bucket(
                     static_cast<node_pointer>(end)->hash_);
 
                 // If begin and end are in the same bucket, then

Modified: trunk/boost/unordered/detail/unique.hpp
==============================================================================
--- trunk/boost/unordered/detail/unique.hpp (original)
+++ trunk/boost/unordered/detail/unique.hpp 2012-11-05 13:33:29 EST (Mon, 05 Nov 2012)
@@ -232,8 +232,7 @@
                 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 @@
                 }
                 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 @@
             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<node_pointer>(start_node->next_)->hash_)
                     )->next_ = n;
                 }
@@ -519,8 +516,7 @@
             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 @@
                 if (!prev->next_) return 0;
                 std::size_t node_hash =
                     static_cast<node_pointer>(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 @@
 
         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 @@
         static link_pointer place_in_bucket(table& dst, link_pointer prev)
         {
             node_pointer n = static_cast<node_pointer>(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;

Modified: trunk/boost/unordered/unordered_map.hpp
==============================================================================
--- trunk/boost/unordered/unordered_map.hpp (original)
+++ trunk/boost/unordered/unordered_map.hpp 2012-11-05 13:33:29 EST (Mon, 05 Nov 2012)
@@ -463,8 +463,7 @@
 
         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 @@
 
         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)

Modified: trunk/boost/unordered/unordered_set.hpp
==============================================================================
--- trunk/boost/unordered/unordered_set.hpp (original)
+++ trunk/boost/unordered/unordered_set.hpp 2012-11-05 13:33:29 EST (Mon, 05 Nov 2012)
@@ -448,8 +448,7 @@
 
         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 @@
 
         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)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk