Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81206 - trunk/boost/unordered/detail
From: dnljms_at_[hidden]
Date: 2012-11-05 13:32:46


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

Log:
Unordered: Simplify pointer use.
Text files modified:
   trunk/boost/unordered/detail/buckets.hpp | 14 ++++----
   trunk/boost/unordered/detail/equivalent.hpp | 65 +++++++++++++++++----------------------
   trunk/boost/unordered/detail/table.hpp | 16 ++++-----
   trunk/boost/unordered/detail/unique.hpp | 40 +++++++++++-------------
   4 files changed, 61 insertions(+), 74 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:32:45 EST (Mon, 05 Nov 2012)
@@ -445,7 +445,7 @@
             nodes_()
         {
             if (b.size_) {
- typename Table::previous_pointer prev = b.get_previous_start();
+ typename Table::link_pointer prev = b.get_previous_start();
                 nodes_ = static_cast<node_pointer>(prev->next_);
                 prev->next_ = link_pointer();
                 b.size_ = 0;
@@ -537,12 +537,12 @@
     template <typename NodePointer>
     struct bucket
     {
- typedef NodePointer previous_pointer;
- previous_pointer next_;
+ typedef NodePointer link_pointer;
+ link_pointer next_;
 
         bucket() : next_() {}
 
- previous_pointer first_from_start()
+ link_pointer first_from_start()
         {
             return next_;
         }
@@ -552,12 +552,12 @@
 
     struct ptr_bucket
     {
- typedef ptr_bucket* previous_pointer;
- previous_pointer next_;
+ typedef ptr_bucket* link_pointer;
+ link_pointer next_;
 
         ptr_bucket() : next_(0) {}
 
- previous_pointer first_from_start()
+ link_pointer first_from_start()
         {
             return this;
         }

Modified: trunk/boost/unordered/detail/equivalent.hpp
==============================================================================
--- trunk/boost/unordered/detail/equivalent.hpp (original)
+++ trunk/boost/unordered/detail/equivalent.hpp 2012-11-05 13:32:45 EST (Mon, 05 Nov 2012)
@@ -181,7 +181,6 @@
         typedef typename table::node_allocator_traits node_allocator_traits;
         typedef typename table::bucket_pointer bucket_pointer;
         typedef typename table::link_pointer link_pointer;
- typedef typename table::previous_pointer previous_pointer;
         typedef typename table::hasher hasher;
         typedef typename table::key_equal key_equal;
         typedef typename table::key_type key_type;
@@ -397,9 +396,8 @@
         {
             n->next_ = static_cast<node_pointer>(pos->group_prev_)->next_;
             n->group_prev_ = pos->group_prev_;
- static_cast<node_pointer>(pos->group_prev_)->next_ =
- static_cast<link_pointer>(n);
- pos->group_prev_ = static_cast<link_pointer>(n);
+ static_cast<node_pointer>(pos->group_prev_)->next_ = n;
+ pos->group_prev_ = n;
         }
 
         inline iterator add_node(
@@ -427,7 +425,7 @@
 
                 if (!b->next_)
                 {
- previous_pointer start_node = this->get_previous_start();
+ link_pointer start_node = this->get_previous_start();
                     
                     if (start_node->next_) {
                         this->get_bucket(policy::to_bucket(this->bucket_count_,
@@ -437,12 +435,12 @@
     
                     b->next_ = start_node;
                     n->next_ = start_node->next_;
- start_node->next_ = static_cast<link_pointer>(n);
+ start_node->next_ = n;
                 }
                 else
                 {
                     n->next_ = b->next_->next_;
- b->next_->next_ = static_cast<link_pointer>(n);
+ b->next_->next_ = n;
                 }
             }
             ++this->size_;
@@ -549,7 +547,7 @@
                 policy::to_bucket(this->bucket_count_, key_hash);
             bucket_pointer this_bucket = this->get_bucket(bucket_index);
 
- previous_pointer prev = this_bucket->next_;
+ link_pointer prev = this_bucket->next_;
             if (!prev) return 0;
 
             for (;;)
@@ -564,8 +562,7 @@
                     this->key_eq()(k, this->get_key(
                         static_cast<node_pointer>(prev->next_)->value())))
                     break;
- prev = static_cast<previous_pointer>(
- static_cast<node_pointer>(prev->next_)->group_prev_);
+ prev = static_cast<node_pointer>(prev->next_)->group_prev_;
             }
 
             node_pointer pos = static_cast<node_pointer>(prev->next_);
@@ -585,7 +582,7 @@
 
             bucket_pointer this_bucket = this->get_bucket(
                 policy::to_bucket(this->bucket_count_, r.node_->hash_));
- previous_pointer prev = unlink_node(*this_bucket, r.node_);
+ link_pointer prev = unlink_node(*this_bucket, r.node_);
 
             this->fix_buckets(this_bucket, prev, next.node_);
 
@@ -600,7 +597,7 @@
 
             std::size_t bucket_index =
                 policy::to_bucket(this->bucket_count_, r1.node_->hash_);
- previous_pointer prev = unlink_nodes(
+ link_pointer prev = unlink_nodes(
                 *this->get_bucket(bucket_index), r1.node_, r2.node_);
             this->fix_buckets_range(bucket_index, prev, r1.node_, r2.node_);
             this->delete_nodes(r1, r2);
@@ -608,11 +605,10 @@
             return iterator(r2.node_);
         }
 
- static previous_pointer unlink_node(bucket& b, node_pointer n)
+ static link_pointer unlink_node(bucket& b, node_pointer n)
         {
             node_pointer next = static_cast<node_pointer>(n->next_);
- previous_pointer prev =
- static_cast<previous_pointer>(n->group_prev_);
+ link_pointer prev = n->group_prev_;
 
             if(prev->next_ != n) {
                 // The node is at the beginning of a group.
@@ -620,17 +616,16 @@
                 // Find the previous node pointer:
                 prev = b.next_;
                 while(prev->next_ != n) {
- prev = static_cast<previous_pointer>(
- static_cast<node_pointer>(prev->next_)->group_prev_);
+ prev = static_cast<node_pointer>(prev->next_)->group_prev_;
                 }
 
                 // Remove from group
- if (next && next->group_prev_ == static_cast<link_pointer>(n))
+ if (next && next->group_prev_ == n)
                 {
                     next->group_prev_ = n->group_prev_;
                 }
             }
- else if (next && next->group_prev_ == static_cast<link_pointer>(n))
+ else if (next && next->group_prev_ == n)
             {
                 // The deleted node is not at the end of the group, so
                 // change the link from the next node.
@@ -641,30 +636,28 @@
                 // first node in the group is pointing to it.
                 // Find that to change its pointer.
                 node_pointer x = static_cast<node_pointer>(n->group_prev_);
- while(x->group_prev_ != static_cast<link_pointer>(n)) {
+ while (x->group_prev_ != n) {
                     x = static_cast<node_pointer>(x->group_prev_);
                 }
                 x->group_prev_ = n->group_prev_;
             }
 
- prev->next_ = static_cast<link_pointer>(next);
+ prev->next_ = next;
             return prev;
         }
 
- static previous_pointer unlink_nodes(bucket& b,
+ static link_pointer unlink_nodes(bucket& b,
                 node_pointer begin, node_pointer end)
         {
- previous_pointer prev = static_cast<previous_pointer>(
- begin->group_prev_);
+ link_pointer prev = begin->group_prev_;
 
- if(prev->next_ != static_cast<link_pointer>(begin)) {
+ if (prev->next_ != begin) {
                 // The node is at the beginning of a group.
 
                 // Find the previous node pointer:
                 prev = b.next_;
- while(prev->next_ != static_cast<link_pointer>(begin))
- prev = static_cast<previous_pointer>(
- static_cast<node_pointer>(prev->next_)->group_prev_);
+ while (prev->next_ != begin)
+ prev = static_cast<node_pointer>(prev->next_)->group_prev_;
 
                 if (end) split_group(end);
             }
@@ -683,7 +676,7 @@
                 }
             }
 
- prev->next_ = static_cast<link_pointer>(end);
+ prev->next_ = end;
 
             return prev;
         }
@@ -696,7 +689,7 @@
             // Find first node in group.
             node_pointer first = split;
             while (static_cast<node_pointer>(first->group_prev_)->next_ ==
- static_cast<link_pointer>(first))
+ first)
                 first = static_cast<node_pointer>(first->group_prev_);
 
             if(first == split) return split;
@@ -715,7 +708,7 @@
         static void fill_buckets(iterator n, table& dst,
             NodeCreator& creator)
         {
- previous_pointer prev = dst.get_previous_start();
+ link_pointer prev = dst.get_previous_start();
 
             while (n.node_) {
                 std::size_t key_hash = n.node_->hash_;
@@ -727,7 +720,7 @@
                 node_pointer first_node = creator.create(*n);
                 node_pointer end = first_node;
                 first_node->hash_ = key_hash;
- prev->next_ = static_cast<link_pointer>(first_node);
+ prev->next_ = first_node;
                 ++dst.size_;
 
                 for (++n; n != group_end; ++n)
@@ -748,7 +741,7 @@
             BOOST_ASSERT(this->buckets_);
 
             this->create_buckets(num_buckets);
- previous_pointer prev = this->get_previous_start();
+ link_pointer prev = this->get_previous_start();
             while (prev->next_)
                 prev = place_in_bucket(*this, prev,
                     static_cast<node_pointer>(
@@ -757,15 +750,15 @@
 
         // Iterate through the nodes placing them in the correct buckets.
         // pre: prev->next_ is not null.
- static previous_pointer place_in_bucket(table& dst,
- previous_pointer prev, node_pointer end)
+ 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_));
 
             if (!b->next_) {
                 b->next_ = static_cast<node_pointer>(prev);
- return static_cast<previous_pointer>(end);
+ return end;
             }
             else {
                 link_pointer next = end->next_;

Modified: trunk/boost/unordered/detail/table.hpp
==============================================================================
--- trunk/boost/unordered/detail/table.hpp (original)
+++ trunk/boost/unordered/detail/table.hpp 2012-11-05 13:32:45 EST (Mon, 05 Nov 2012)
@@ -164,8 +164,6 @@
             const_node_pointer;
         typedef typename bucket_allocator_traits::pointer
             bucket_pointer;
- typedef typename bucket::previous_pointer
- previous_pointer;
         typedef boost::unordered::detail::node_constructor<node_allocator>
             node_constructor;
 
@@ -226,12 +224,12 @@
             return buckets_ + static_cast<std::ptrdiff_t>(bucket_index);
         }
 
- previous_pointer get_previous_start() const
+ link_pointer get_previous_start() const
         {
             return get_bucket(bucket_count_)->first_from_start();
         }
 
- previous_pointer get_previous_start(std::size_t bucket_index) const
+ link_pointer get_previous_start(std::size_t bucket_index) const
         {
             return get_bucket(bucket_index)->next_;
         }
@@ -245,7 +243,7 @@
         iterator begin(std::size_t bucket_index) const
         {
             if (!size_) return iterator();
- previous_pointer prev = get_previous_start(bucket_index);
+ link_pointer prev = get_previous_start(bucket_index);
             return prev ? iterator(static_cast<node_pointer>(prev->next_)) :
                 iterator();
         }
@@ -584,7 +582,7 @@
         // This is called after erasing a node or group of nodes to fix up
         // the bucket pointers.
         void fix_buckets(bucket_pointer this_bucket,
- previous_pointer prev, node_pointer next)
+ link_pointer prev, node_pointer next)
         {
             if (!next)
             {
@@ -608,7 +606,7 @@
         // This is called after erasing a range of nodes to fix any bucket
         // pointers into that range.
         void fix_buckets_range(std::size_t bucket_index,
- previous_pointer prev, node_pointer begin, node_pointer end)
+ link_pointer prev, node_pointer begin, node_pointer end)
         {
             node_pointer n = begin;
 
@@ -640,7 +638,7 @@
 
             // Iterate through the remaining nodes, clearing out the bucket
             // pointers.
- get_bucket(bucket_index)->next_ = previous_pointer();
+ get_bucket(bucket_index)->next_ = link_pointer();
             for(;;) {
                 n = static_cast<node_pointer>(n->next_);
                 if (n == end) break;
@@ -649,7 +647,7 @@
                     policy::to_bucket(bucket_count_, n->hash_);
                 if (bucket_index != new_bucket_index) {
                     bucket_index = new_bucket_index;
- get_bucket(bucket_index)->next_ = previous_pointer();
+ get_bucket(bucket_index)->next_ = link_pointer();
                 }
             };
 

Modified: trunk/boost/unordered/detail/unique.hpp
==============================================================================
--- trunk/boost/unordered/detail/unique.hpp (original)
+++ trunk/boost/unordered/detail/unique.hpp 2012-11-05 13:32:45 EST (Mon, 05 Nov 2012)
@@ -176,7 +176,6 @@
         typedef typename table::node_allocator_traits node_allocator_traits;
         typedef typename table::bucket_pointer bucket_pointer;
         typedef typename table::link_pointer link_pointer;
- typedef typename table::previous_pointer previous_pointer;
         typedef typename table::hasher hasher;
         typedef typename table::key_equal key_equal;
         typedef typename table::key_type key_type;
@@ -317,7 +316,7 @@
 
             if (!b->next_)
             {
- previous_pointer start_node = this->get_previous_start();
+ link_pointer start_node = this->get_previous_start();
                 
                 if (start_node->next_) {
                     this->get_bucket(policy::to_bucket(this->bucket_count_,
@@ -327,12 +326,12 @@
 
                 b->next_ = start_node;
                 n->next_ = start_node->next_;
- start_node->next_ = static_cast<link_pointer>(n);
+ start_node->next_ = n;
             }
             else
             {
                 n->next_ = b->next_->next_;
- b->next_->next_ = static_cast<link_pointer>(n);
+ b->next_->next_ = n;
             }
 
             ++this->size_;
@@ -522,7 +521,7 @@
                 policy::to_bucket(this->bucket_count_, key_hash);
             bucket_pointer this_bucket = this->get_bucket(bucket_index);
 
- previous_pointer prev = this_bucket->next_;
+ link_pointer prev = this_bucket->next_;
             if (!prev) return 0;
 
             for (;;)
@@ -537,7 +536,7 @@
                         this->key_eq()(k, this->get_key(
                         static_cast<node_pointer>(prev->next_)->value())))
                     break;
- prev = static_cast<previous_pointer>(prev->next_);
+ prev = prev->next_;
             }
 
             node_pointer pos = static_cast<node_pointer>(prev->next_);
@@ -555,7 +554,7 @@
 
             bucket_pointer this_bucket = this->get_bucket(
                 policy::to_bucket(this->bucket_count_, r.node_->hash_));
- previous_pointer prev = unlink_node(*this_bucket, r.node_);
+ link_pointer prev = unlink_node(*this_bucket, r.node_);
 
             this->fix_buckets(this_bucket, prev, next.node_);
 
@@ -570,7 +569,7 @@
 
             std::size_t bucket_index =
                 policy::to_bucket(this->bucket_count_, r1.node_->hash_);
- previous_pointer prev = unlink_nodes(
+ link_pointer prev = unlink_nodes(
                 *this->get_bucket(bucket_index), r1.node_, r2.node_);
             this->fix_buckets_range(bucket_index, prev, r1.node_, r2.node_);
             this->delete_nodes(r1, r2);
@@ -578,19 +577,17 @@
             return iterator(r2.node_);
         }
 
- static previous_pointer unlink_node(bucket& b, node_pointer n)
+ static link_pointer unlink_node(bucket& b, node_pointer n)
         {
             return unlink_nodes(b, n, static_cast<node_pointer>(n->next_));
         }
 
- static previous_pointer unlink_nodes(bucket& b,
+ static link_pointer unlink_nodes(bucket& b,
                 node_pointer begin, node_pointer end)
         {
- previous_pointer prev = b.next_;
- link_pointer begin_void = static_cast<link_pointer>(begin);
- while(prev->next_ != begin_void)
- prev = static_cast<previous_pointer>(prev->next_);
- prev->next_ = static_cast<link_pointer>(end);
+ link_pointer prev = b.next_;
+ while (prev->next_ != begin) prev = prev->next_;
+ prev->next_ = end;
             return prev;
         }
 
@@ -601,12 +598,12 @@
         static void fill_buckets(iterator n, table& dst,
             NodeCreator& creator)
         {
- previous_pointer prev = dst.get_previous_start();
+ link_pointer prev = dst.get_previous_start();
 
             while (n.node_) {
                 node_pointer node = creator.create(*n);
                 node->hash_ = n.node_->hash_;
- prev->next_ = static_cast<link_pointer>(node);
+ prev->next_ = node;
                 ++dst.size_;
                 ++n;
 
@@ -620,15 +617,14 @@
             BOOST_ASSERT(this->buckets_);
 
             this->create_buckets(num_buckets);
- previous_pointer prev = this->get_previous_start();
+ link_pointer prev = this->get_previous_start();
             while (prev->next_)
                 prev = place_in_bucket(*this, prev);
         }
 
         // Iterate through the nodes placing them in the correct buckets.
         // pre: prev->next_ is not null.
- static previous_pointer place_in_bucket(table& dst,
- previous_pointer prev)
+ 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(
@@ -636,12 +632,12 @@
 
             if (!b->next_) {
                 b->next_ = prev;
- return static_cast<previous_pointer>(n);
+ return n;
             }
             else {
                 prev->next_ = n->next_;
                 n->next_ = b->next_->next_;
- b->next_->next_ = static_cast<link_pointer>(n);
+ b->next_->next_ = n;
                 return prev;
             }
         }


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