Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56570 - in trunk: boost/unordered/detail libs/unordered/test/unordered
From: daniel_james_at_[hidden]
Date: 2009-10-04 06:37:38


Author: danieljames
Date: 2009-10-04 06:37:36 EDT (Sun, 04 Oct 2009)
New Revision: 56570
URL: http://svn.boost.org/trac/boost/changeset/56570

Log:
Clean up some unordered TODOs.
Text files modified:
   trunk/boost/unordered/detail/buckets.hpp | 3 -
   trunk/boost/unordered/detail/equivalent.hpp | 1
   trunk/boost/unordered/detail/table.hpp | 17 +++++----------
   trunk/libs/unordered/test/unordered/rehash_tests.cpp | 43 ++++++++++++++++++++++++++++++++++++++++
   4 files changed, 50 insertions(+), 14 deletions(-)

Modified: trunk/boost/unordered/detail/buckets.hpp
==============================================================================
--- trunk/boost/unordered/detail/buckets.hpp (original)
+++ trunk/boost/unordered/detail/buckets.hpp 2009-10-04 06:37:36 EDT (Sun, 04 Oct 2009)
@@ -15,7 +15,6 @@
     
     ////////////////////////////////////////////////////////////////////////////
     // Buckets
- // TODO: Are these needed?
     
     template <class A, class G>
     inline BOOST_DEDUCED_TYPENAME hash_buckets<A, G>::bucket_ptr
@@ -32,7 +31,7 @@
     }
     
     template <class A, class G>
- inline std::size_t hash_buckets<A, G>::bucket_size(std::size_t index) const
+ std::size_t hash_buckets<A, G>::bucket_size(std::size_t index) const
     {
         if(!buckets_) return 0;
         bucket_ptr ptr = get_bucket(index)->next_;

Modified: trunk/boost/unordered/detail/equivalent.hpp
==============================================================================
--- trunk/boost/unordered/detail/equivalent.hpp (original)
+++ trunk/boost/unordered/detail/equivalent.hpp 2009-10-04 06:37:36 EDT (Sun, 04 Oct 2009)
@@ -257,7 +257,6 @@
 
     // if hash function throws, or inserting > 1 element, basic exception safety
     // strong otherwise
- // TODO: Should I special case an empty container?
     template <class H, class P, class A, class K>
     template <class I>
     void hash_equivalent_table<H, P, A, K>::insert_range(I i, I j)

Modified: trunk/boost/unordered/detail/table.hpp
==============================================================================
--- trunk/boost/unordered/detail/table.hpp (original)
+++ trunk/boost/unordered/detail/table.hpp 2009-10-04 06:37:36 EDT (Sun, 04 Oct 2009)
@@ -431,23 +431,20 @@
 
     // if hash function throws, basic exception safety
     // strong otherwise.
- // TODO: Should this always create buckets?
+
     template <class H, class P, class A, class G, class K>
     inline void hash_table<H, P, A, G, K>::rehash(std::size_t min_buckets)
     {
         using namespace std;
 
- if(!this->buckets_) {
+ if(!this->size_) {
+ if(this->buckets_) this->delete_buckets();
             this->bucket_count_ = next_prime(min_buckets);
- this->create_buckets();
- this->init_buckets();
         }
         else {
             // no throw:
- // TODO: Needlessly calling next_prime twice.
- min_buckets = (std::max)(
- next_prime(min_buckets),
- this->min_buckets_for_size(this->size_));
+ min_buckets = next_prime((std::max)(min_buckets,
+ double_to_size_t(floor(this->size_ / (double) mlf_)) + 1));
             if(min_buckets != this->bucket_count_) rehash_impl(min_buckets);
         }
     }
@@ -619,7 +616,6 @@
     template <class H, class P, class A, class G, class K>
     void hash_table<H, P, A, G, K>::clear()
     {
- // TODO: Is this check needed when called internally?
         if(!this->size_) return;
 
         bucket_ptr end = this->get_bucket(this->bucket_count_);
@@ -645,8 +641,7 @@
     }
     
     template <class H, class P, class A, class G, class K>
- std::size_t hash_table<H, P, A, G, K>
- ::erase_key(key_type const& k)
+ std::size_t hash_table<H, P, A, G, K>::erase_key(key_type const& k)
     {
         if(!this->size_) return 0;
     

Modified: trunk/libs/unordered/test/unordered/rehash_tests.cpp
==============================================================================
--- trunk/libs/unordered/test/unordered/rehash_tests.cpp (original)
+++ trunk/libs/unordered/test/unordered/rehash_tests.cpp 2009-10-04 06:37:36 EDT (Sun, 04 Oct 2009)
@@ -33,6 +33,43 @@
 }
 
 template <class X>
+void rehash_empty_test2(X* = 0, test::random_generator generator = test::default_generator)
+{
+ test::random_values<X> v(1000, generator);
+ test::ordered<X> tracker;
+
+ X x;
+
+ x.rehash(10000);
+ BOOST_TEST(postcondition(x, 10000));
+
+ tracker.insert_range(v.begin(), v.end());
+ x.insert(v.begin(), v.end());
+ tracker.compare(x);
+
+ BOOST_TEST(postcondition(x, 10000));
+}
+
+template <class X>
+void rehash_empty_test3(X* = 0, test::random_generator generator = test::default_generator)
+{
+ test::random_values<X> v(1000, generator);
+ test::ordered<X> tracker;
+
+ X x;
+
+ x.rehash(0);
+ BOOST_TEST(postcondition(x, 0));
+
+ tracker.insert_range(v.begin(), v.end());
+ x.insert(v.begin(), v.end());
+ tracker.compare(x);
+
+ BOOST_TEST(postcondition(x, 0));
+}
+
+
+template <class X>
 void rehash_test1(X* = 0, test::random_generator generator = test::default_generator)
 {
     test::random_values<X> v(1000, generator);
@@ -63,6 +100,12 @@
 UNORDERED_TEST(rehash_empty_test1,
     ((int_set_ptr)(int_multiset_ptr)(int_map_ptr)(int_multimap_ptr))
 )
+UNORDERED_TEST(rehash_empty_test2,
+ ((int_set_ptr)(int_multiset_ptr)(int_map_ptr)(int_multimap_ptr))
+)
+UNORDERED_TEST(rehash_empty_test3,
+ ((int_set_ptr)(int_multiset_ptr)(int_map_ptr)(int_multimap_ptr))
+)
 UNORDERED_TEST(rehash_test1,
     ((int_set_ptr)(int_multiset_ptr)(int_map_ptr)(int_multimap_ptr))
 )


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