Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80559 - trunk/boost/unordered/detail
From: dnljms_at_[hidden]
Date: 2012-09-17 14:58:00


Author: danieljames
Date: 2012-09-17 14:57:58 EDT (Mon, 17 Sep 2012)
New Revision: 80559
URL: http://svn.boost.org/trac/boost/changeset/80559

Log:
Unordered: Set `max_load_` to 0 when there are no buckets.
Text files modified:
   trunk/boost/unordered/detail/table.hpp | 17 ++++++++++-------
   trunk/boost/unordered/detail/unique.hpp | 22 +++-------------------
   2 files changed, 13 insertions(+), 26 deletions(-)

Modified: trunk/boost/unordered/detail/table.hpp
==============================================================================
--- trunk/boost/unordered/detail/table.hpp (original)
+++ trunk/boost/unordered/detail/table.hpp 2012-09-17 14:57:58 EDT (Mon, 17 Sep 2012)
@@ -187,7 +187,7 @@
         std::size_t bucket_count_;
         std::size_t size_;
         float mlf_;
- std::size_t max_load_; // Only use if buckets_.
+ std::size_t max_load_;
         bucket_pointer buckets_;
 
         ////////////////////////////////////////////////////////////////////////
@@ -292,10 +292,10 @@
     
             // From 6.3.1/13:
             // Only resize when size >= mlf_ * count
- max_load_ = boost::unordered::detail::double_to_size(ceil(
+ max_load_ = buckets_ ? boost::unordered::detail::double_to_size(ceil(
                     static_cast<double>(mlf_) *
                     static_cast<double>(bucket_count_)
- ));
+ )) : 0;
 
         }
 
@@ -303,7 +303,7 @@
         {
             BOOST_ASSERT(z > 0);
             mlf_ = (std::max)(z, minimum_max_load_factor);
- if (buckets_) recalculate_max_load();
+ recalculate_max_load();
         }
 
         std::size_t min_buckets_for_size(std::size_t size) const
@@ -362,6 +362,7 @@
         {
             x.buckets_ = bucket_pointer();
             x.size_ = 0;
+ x.max_load_ = 0;
         }
 
         table(table& x, node_allocator const& a,
@@ -487,6 +488,7 @@
             size_ = other.size_;
             other.buckets_ = bucket_pointer();
             other.size_ = 0;
+ other.max_load_ = 0;
         }
 
         ////////////////////////////////////////////////////////////////////////
@@ -536,6 +538,7 @@
 
                 destroy_buckets();
                 buckets_ = bucket_pointer();
+ max_load_ = 0;
             }
 
             BOOST_ASSERT(!size_);
@@ -680,7 +683,7 @@
 
             if (!size_ && !x.size_) return;
 
- if (!buckets_ || x.size_ >= max_load_) {
+ if (x.size_ >= max_load_) {
                 create_buckets(min_buckets_for_size(x.size_));
             }
             else {
@@ -760,7 +763,7 @@
 
                 if (!size_ && !x.size_) return;
 
- if (!buckets_ || x.size_ >= max_load_) {
+ if (x.size_ >= max_load_) {
                     create_buckets(min_buckets_for_size(x.size_));
                 }
                 else {
@@ -784,9 +787,9 @@
             boost::unordered::detail::set_hash_functions<hasher, key_equal>
                 new_func_this(*this, x);
             // No throw from here.
- move_buckets_from(x);
             mlf_ = x.mlf_;
             max_load_ = x.max_load_;
+ move_buckets_from(x);
             new_func_this.commit();
         }
 

Modified: trunk/boost/unordered/detail/unique.hpp
==============================================================================
--- trunk/boost/unordered/detail/unique.hpp (original)
+++ trunk/boost/unordered/detail/unique.hpp 2012-09-17 14:57:58 EDT (Mon, 17 Sep 2012)
@@ -466,14 +466,9 @@
         {
             node_constructor a(this->node_alloc());
 
- // Special case for empty buckets so that we can use
- // max_load_ (which isn't valid when buckets_ is null).
- if (!this->buckets_) {
- insert_range_empty(a, k, i, j);
- if (++i == j) return;
- }
+ insert_range_impl2(a, k, i, j);
 
- do {
+ while(++i != j) {
                 // Note: can't use get_key as '*i' might not be value_type - it
                 // could be a pair with first_types as key_type without const or
                 // a different second_type.
@@ -483,18 +478,7 @@
                 // be less efficient if copying the full value_type is
                 // expensive.
                 insert_range_impl2(a, extractor::extract(*i), i, j);
- } while(++i != j);
- }
-
- template <class InputIt>
- void insert_range_empty(node_constructor& a, key_type const& k,
- InputIt i, InputIt j)
- {
- std::size_t key_hash = this->hash(k);
- a.construct_with_value2(*i);
- this->reserve_for_insert(this->size_ +
- boost::unordered::detail::insert_size(i, j));
- this->add_node(a, key_hash);
+ }
         }
 
         template <class InputIt>


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