Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78369 - in trunk: boost/unordered/detail libs/unordered/test/unordered
From: dnljms_at_[hidden]
Date: 2012-05-07 14:10:06


Author: danieljames
Date: 2012-05-07 14:10:04 EDT (Mon, 07 May 2012)
New Revision: 78369
URL: http://svn.boost.org/trac/boost/changeset/78369

Log:
Unordered: Check that reserve works for both range and single element insert.
Text files modified:
   trunk/boost/unordered/detail/unique.hpp | 2
   trunk/libs/unordered/test/unordered/rehash_tests.cpp | 54 ++++++++++++++++++++++++++++++++++++---
   2 files changed, 50 insertions(+), 6 deletions(-)

Modified: trunk/boost/unordered/detail/unique.hpp
==============================================================================
--- trunk/boost/unordered/detail/unique.hpp (original)
+++ trunk/boost/unordered/detail/unique.hpp 2012-05-07 14:10:04 EDT (Mon, 07 May 2012)
@@ -535,7 +535,7 @@
                 a.construct_node();
                 a.construct_value2(*i);
     
- if(this->size_ + 1 >= this->max_load_)
+ if(this->size_ + 1 > this->max_load_)
                     this->reserve_for_insert(this->size_ +
                         boost::unordered::detail::insert_size(i, j));
     

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 2012-05-07 14:10:04 EDT (Mon, 07 May 2012)
@@ -101,12 +101,12 @@
 }
 
 template <class X>
-void reserve_test(X* = 0,
+void reserve_test1(X* = 0,
     test::random_generator generator = test::default_generator)
 {
     for (int random_mlf = 0; random_mlf < 2; ++random_mlf)
     {
- for (int i = 0; i < 2000; i += i < 50 ? 1 : 13)
+ for (int i = 1; i < 2000; i += i < 50 ? 1 : 13)
         {
             test::random_values<X> v(i, generator);
 
@@ -115,13 +115,54 @@
 
             X x;
             x.max_load_factor(random_mlf ?
- static_cast<float>(std::rand() % 1000) / 500.0 + 0.5f : 1.0f);
+ static_cast<float>(std::rand() % 1000) / 500.0f + 0.5f : 1.0f);
+
             // For the current standard this should reserve i+1, I've
             // submitted a defect report and will assume it's a defect
             // for now.
             x.reserve(i);
+
+ // Insert an element before the range insert, otherwise there are
+ // no iterators to invalidate in the range insert, and it can
+ // rehash.
+ typename test::random_values<X>::iterator it = v.begin();
+ x.insert(*it);
+ ++it;
+
             std::size_t bucket_count = x.bucket_count();
- x.insert(v.begin(), v.end());
+ x.insert(it, v.end());
+ BOOST_TEST(bucket_count == x.bucket_count());
+ tracker.compare(x);
+ }
+ }
+}
+
+template <class X>
+void reserve_test2(X* = 0,
+ test::random_generator generator = test::default_generator)
+{
+ for (int random_mlf = 0; random_mlf < 2; ++random_mlf)
+ {
+ for (int i = 0; i < 2000; i += i < 50 ? 1 : 13)
+ {
+ test::random_values<X> v(i, generator);
+
+ test::ordered<X> tracker;
+ tracker.insert_range(v.begin(), v.end());
+
+ X x;
+ x.max_load_factor(random_mlf ?
+ static_cast<float>(std::rand() % 1000) / 500.0f + 0.5f : 1.0f);
+
+ x.reserve(i);
+ std::size_t bucket_count = x.bucket_count();
+
+ for (typename test::random_values<X>::iterator it = v.begin();
+ it != v.end(); ++it)
+ {
+ x.insert(*it);
+ }
+
             BOOST_TEST(bucket_count == x.bucket_count());
             tracker.compare(x);
         }
@@ -145,7 +186,10 @@
 UNORDERED_TEST(rehash_test1,
     ((int_set_ptr)(int_multiset_ptr)(int_map_ptr)(int_multimap_ptr))
 )
-UNORDERED_TEST(reserve_test,
+UNORDERED_TEST(reserve_test1,
+ ((int_set_ptr)(int_multiset_ptr)(int_map_ptr)(int_multimap_ptr))
+)
+UNORDERED_TEST(reserve_test2,
     ((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