$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r80561 - in trunk: boost/unordered boost/unordered/detail libs/unordered/test/unordered
From: dnljms_at_[hidden]
Date: 2012-09-17 14:59:04
Author: danieljames
Date: 2012-09-17 14:59:03 EDT (Mon, 17 Sep 2012)
New Revision: 80561
URL: http://svn.boost.org/trac/boost/changeset/80561
Log:
Unordered: Get rid of get_start.
Text files modified: 
   trunk/boost/unordered/detail/equivalent.hpp          |     7 ++-----                                 
   trunk/boost/unordered/detail/table.hpp               |    33 ++++++++++++---------------------       
   trunk/boost/unordered/detail/unique.hpp              |     7 ++-----                                 
   trunk/boost/unordered/unordered_map.hpp              |    30 ++++++++++++------------------          
   trunk/boost/unordered/unordered_set.hpp              |    30 ++++++++++++------------------          
   trunk/libs/unordered/test/unordered/insert_tests.cpp |    15 +++++++++++++++                         
   6 files changed, 55 insertions(+), 67 deletions(-)
Modified: trunk/boost/unordered/detail/equivalent.hpp
==============================================================================
--- trunk/boost/unordered/detail/equivalent.hpp	(original)
+++ trunk/boost/unordered/detail/equivalent.hpp	2012-09-17 14:59:03 EDT (Mon, 17 Sep 2012)
@@ -234,11 +234,9 @@
                 Key const& k,
                 Pred const& eq) const
         {
-            if (!this->size_) return iterator();
-
             std::size_t bucket_index =
                 policy::to_bucket(this->bucket_count_, key_hash);
-            iterator n = this->get_start(bucket_index);
+            iterator n = this->begin(bucket_index);
 
             for (;;)
             {
@@ -293,9 +291,8 @@
         bool equals(grouped_table_impl const& other) const
         {
             if(this->size_ != other.size_) return false;
-            if(!this->size_) return true;
     
-            for(iterator n1 = this->get_start(); n1.node_;)
+            for(iterator n1 = this->begin(); n1.node_;)
             {
                 iterator n2 = other.find_matching_node(n1);
                 if (!n2.node_) return false;
Modified: trunk/boost/unordered/detail/table.hpp
==============================================================================
--- trunk/boost/unordered/detail/table.hpp	(original)
+++ trunk/boost/unordered/detail/table.hpp	2012-09-17 14:59:03 EDT (Mon, 17 Sep 2012)
@@ -222,6 +222,7 @@
 
         bucket_pointer get_bucket(std::size_t bucket_index) const
         {
+            BOOST_ASSERT(buckets_);
             return buckets_ + static_cast<std::ptrdiff_t>(bucket_index);
         }
 
@@ -235,14 +236,15 @@
             return get_bucket(bucket_index)->next_;
         }
 
-        iterator get_start() const
+        iterator begin() const
         {
-            return iterator(static_cast<node_pointer>(
-                        get_previous_start()->next_));
+            return size_ ? iterator(static_cast<node_pointer>(
+                        get_previous_start()->next_)) : iterator();
         }
 
-        iterator get_start(std::size_t bucket_index) const
+        iterator begin(std::size_t bucket_index) const
         {
+            if (!size_) return iterator();
             previous_pointer prev = get_previous_start(bucket_index);
             return prev ? iterator(static_cast<node_pointer>(prev->next_)) :
                 iterator();
@@ -257,8 +259,7 @@
 
         std::size_t bucket_size(std::size_t index) const
         {
-            if (!size_) return 0;
-            iterator it = get_start(index);
+            iterator it = begin(index);
             if (!it.node_) return 0;
 
             std::size_t count = 0;
@@ -384,7 +385,7 @@
             if (x.size_) {
                 create_buckets(bucket_count_);
                 copy_nodes<node_allocator> copy(node_alloc());
-                table_impl::fill_buckets(x.get_start(), *this, copy);
+                table_impl::fill_buckets(x.begin(), *this, copy);
             }
         }
 
@@ -526,7 +527,7 @@
         void delete_buckets()
         {
             if(buckets_) {
-                delete_nodes(get_start(), iterator());
+                delete_nodes(begin(), iterator());
 
                 if (bucket::extra_node) {
                     node_pointer n = static_cast<node_pointer>(
@@ -548,7 +549,7 @@
         {
             if(!size_) return;
 
-            delete_nodes(get_start(), iterator());
+            delete_nodes(begin(), iterator());
             get_previous_start()->next_ = link_pointer();
             clear_buckets();
 
@@ -652,13 +653,6 @@
         }
 
         ////////////////////////////////////////////////////////////////////////
-        // Iterators
-
-        iterator begin() const {
-            return !buckets_ ? iterator() : get_start();
-        }
-
-        ////////////////////////////////////////////////////////////////////////
         // Assignment
 
         void assign(table const& x)
@@ -694,10 +688,7 @@
             // assigning to them if possible, and deleting any that are
             // left over.
             assign_nodes<table> assign(*this);
-
-            if (x.size_) {
-                table_impl::fill_buckets(x.get_start(), *this, assign);
-            }
+            table_impl::fill_buckets(x.begin(), *this, assign);
         }
 
         void assign(table const& x, true_type)
@@ -725,7 +716,7 @@
                 if (x.size_) {
                     create_buckets(bucket_count_);
                     copy_nodes<node_allocator> copy(node_alloc());
-                    table_impl::fill_buckets(x.get_start(), *this, copy);
+                    table_impl::fill_buckets(x.begin(), *this, copy);
                 }
             }
         }
Modified: trunk/boost/unordered/detail/unique.hpp
==============================================================================
--- trunk/boost/unordered/detail/unique.hpp	(original)
+++ trunk/boost/unordered/detail/unique.hpp	2012-09-17 14:59:03 EDT (Mon, 17 Sep 2012)
@@ -231,11 +231,9 @@
                 Key const& k,
                 Pred const& eq) const
         {
-            if (!this->size_) return iterator();
-
             std::size_t bucket_index =
                 policy::to_bucket(this->bucket_count_, key_hash);
-            iterator n = this->get_start(bucket_index);
+            iterator n = this->begin(bucket_index);
 
             for (;;)
             {
@@ -288,9 +286,8 @@
         bool equals(table_impl const& other) const
         {
             if(this->size_ != other.size_) return false;
-            if(!this->size_) return true;
     
-            for(iterator n1 = this->get_start(); n1.node_; ++n1)
+            for(iterator n1 = this->begin(); n1.node_; ++n1)
             {
                 iterator n2 = other.find_matching_node(n1);
 
Modified: trunk/boost/unordered/unordered_map.hpp
==============================================================================
--- trunk/boost/unordered/unordered_map.hpp	(original)
+++ trunk/boost/unordered/unordered_map.hpp	2012-09-17 14:59:03 EDT (Mon, 17 Sep 2012)
@@ -469,16 +469,14 @@
 
         local_iterator begin(size_type n)
         {
-            return table_.size_ ? local_iterator(
-                table_.get_start(n), n, table_.bucket_count_) :
-                local_iterator();
+            return local_iterator(
+                table_.begin(n), n, table_.bucket_count_);
         }
 
         const_local_iterator begin(size_type n) const
         {
-            return table_.size_ ? const_local_iterator(
-                table_.get_start(n), n, table_.bucket_count_) :
-                const_local_iterator();
+            return const_local_iterator(
+                table_.begin(n), n, table_.bucket_count_);
         }
 
         local_iterator end(size_type)
@@ -493,9 +491,8 @@
 
         const_local_iterator cbegin(size_type n) const
         {
-            return table_.size_ ? const_local_iterator(
-                table_.get_start(n), n, table_.bucket_count_) :
-                const_local_iterator();
+            return const_local_iterator(
+                table_.begin(n), n, table_.bucket_count_);
         }
 
         const_local_iterator cend(size_type) const
@@ -951,16 +948,14 @@
 
         local_iterator begin(size_type n)
         {
-            return table_.size_ ? local_iterator(
-                table_.get_start(n), n, table_.bucket_count_) :
-                local_iterator();
+            return local_iterator(
+                table_.begin(n), n, table_.bucket_count_);
         }
 
         const_local_iterator begin(size_type n) const
         {
-            return table_.size_ ? const_local_iterator(
-                table_.get_start(n), n, table_.bucket_count_) :
-                const_local_iterator();
+            return const_local_iterator(
+                table_.begin(n), n, table_.bucket_count_);
         }
 
         local_iterator end(size_type)
@@ -975,9 +970,8 @@
 
         const_local_iterator cbegin(size_type n) const
         {
-            return table_.size_ ? const_local_iterator(
-                table_.get_start(n), n, table_.bucket_count_) :
-                const_local_iterator();
+            return const_local_iterator(
+                table_.begin(n), n, table_.bucket_count_);
         }
 
         const_local_iterator cend(size_type) const
Modified: trunk/boost/unordered/unordered_set.hpp
==============================================================================
--- trunk/boost/unordered/unordered_set.hpp	(original)
+++ trunk/boost/unordered/unordered_set.hpp	2012-09-17 14:59:03 EDT (Mon, 17 Sep 2012)
@@ -454,16 +454,14 @@
 
         local_iterator begin(size_type n)
         {
-            return table_.size_ ? local_iterator(
-                table_.get_start(n), n, table_.bucket_count_) :
-                local_iterator();
+            return local_iterator(
+                table_.begin(n), n, table_.bucket_count_);
         }
 
         const_local_iterator begin(size_type n) const
         {
-            return table_.size_ ? const_local_iterator(
-                table_.get_start(n), n, table_.bucket_count_) :
-                const_local_iterator();
+            return const_local_iterator(
+                table_.begin(n), n, table_.bucket_count_);
         }
 
         local_iterator end(size_type)
@@ -478,9 +476,8 @@
 
         const_local_iterator cbegin(size_type n) const
         {
-            return table_.size_ ? const_local_iterator(
-                table_.get_start(n), n, table_.bucket_count_) :
-                const_local_iterator();
+            return const_local_iterator(
+                table_.begin(n), n, table_.bucket_count_);
         }
 
         const_local_iterator cend(size_type) const
@@ -926,16 +923,14 @@
 
         local_iterator begin(size_type n)
         {
-            return table_.size_ ? local_iterator(
-                table_.get_start(n), n, table_.bucket_count_) :
-                local_iterator();
+            return local_iterator(
+                table_.begin(n), n, table_.bucket_count_);
         }
 
         const_local_iterator begin(size_type n) const
         {
-            return table_.size_ ? const_local_iterator(
-                table_.get_start(n), n, table_.bucket_count_) :
-                const_local_iterator();
+            return const_local_iterator(
+                table_.begin(n), n, table_.bucket_count_);
         }
 
         local_iterator end(size_type)
@@ -950,9 +945,8 @@
 
         const_local_iterator cbegin(size_type n) const
         {
-            return table_.size_ ? const_local_iterator(
-                table_.get_start(n), n, table_.bucket_count_) :
-                const_local_iterator();
+            return const_local_iterator(
+                table_.begin(n), n, table_.bucket_count_);
         }
 
         const_local_iterator cend(size_type) const
Modified: trunk/libs/unordered/test/unordered/insert_tests.cpp
==============================================================================
--- trunk/libs/unordered/test/unordered/insert_tests.cpp	(original)
+++ trunk/libs/unordered/test/unordered/insert_tests.cpp	2012-09-17 14:59:03 EDT (Mon, 17 Sep 2012)
@@ -276,6 +276,21 @@
 
         test::check_equivalent_keys(x);
     }
+
+    std::cerr<<"insert copy iterator range test 2.\n";
+
+    {
+        test::check_instances check_;
+
+        X x;
+
+        test::random_values<X> v1(500, generator);
+        test::random_values<X> v2(500, generator);
+        x.insert(test::copy_iterator(v1.begin()), test::copy_iterator(v1.end()));
+        x.insert(test::copy_iterator(v2.begin()), test::copy_iterator(v2.end()));
+
+        test::check_equivalent_keys(x);
+    }
 }
 
 #if !defined(BOOST_NO_RVALUE_REFERENCES) && !defined(BOOST_NO_VARIADIC_TEMPLATES)