Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56347 - in trunk: boost/unordered/detail libs/unordered/test/unordered
From: daniel_james_at_[hidden]
Date: 2009-09-21 17:17:41


Author: danieljames
Date: 2009-09-21 17:17:40 EDT (Mon, 21 Sep 2009)
New Revision: 56347
URL: http://svn.boost.org/trac/boost/changeset/56347

Log:
Fix bug where container was reducing the number of buckets.
Text files modified:
   trunk/boost/unordered/detail/table.hpp | 5 ++---
   trunk/libs/unordered/test/unordered/constructor_tests.cpp | 13 +++++++++++++
   2 files changed, 15 insertions(+), 3 deletions(-)

Modified: trunk/boost/unordered/detail/table.hpp
==============================================================================
--- trunk/boost/unordered/detail/table.hpp (original)
+++ trunk/boost/unordered/detail/table.hpp 2009-09-21 17:17:40 EDT (Mon, 21 Sep 2009)
@@ -406,9 +406,8 @@
     template <class H, class P, class A, class G, class K>
     inline void hash_table<H, P, A, G, K>::create_for_insert(std::size_t size)
     {
- // TODO: Write a test to detect this bug:
- if(size > this->bucket_count_)
- this->bucket_count_ = this->min_buckets_for_size(size);
+ std::size_t min_buckets = this->min_buckets_for_size(size);
+ if(min_buckets > this->bucket_count_) this->bucket_count_ = min_buckets;
         this->create_buckets();
         this->init_buckets();
     }

Modified: trunk/libs/unordered/test/unordered/constructor_tests.cpp
==============================================================================
--- trunk/libs/unordered/test/unordered/constructor_tests.cpp (original)
+++ trunk/libs/unordered/test/unordered/constructor_tests.cpp 2009-09-21 17:17:40 EDT (Mon, 21 Sep 2009)
@@ -250,6 +250,19 @@
         test::check_equivalent_keys(x);
         test::check_equivalent_keys(y);
     }
+
+ std::cerr<<"Construct 9\n";
+ {
+ test::random_values<T> v(100, generator);
+ T x(50);
+ BOOST_TEST(x.bucket_count() >= 50);
+ x.max_load_factor(10);
+ BOOST_TEST(x.bucket_count() >= 50);
+ x.insert(v.begin(), v.end());
+ BOOST_TEST(x.bucket_count() >= 50);
+ test::check_container(x, v);
+ test::check_equivalent_keys(x);
+ }
 }
 
 template <class T>


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