Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2008-01-09 07:16:38


Author: danieljames
Date: 2008-01-09 07:16:37 EST (Wed, 09 Jan 2008)
New Revision: 42635
URL: http://svn.boost.org/trac/boost/changeset/42635

Log:
Use doubles for max load factor calculations.
Text files modified:
   branches/unordered/trunk/boost/unordered/detail/hash_table.hpp | 4 ++--
   branches/unordered/trunk/boost/unordered/detail/hash_table_impl.hpp | 12 +++++++-----
   2 files changed, 9 insertions(+), 7 deletions(-)

Modified: branches/unordered/trunk/boost/unordered/detail/hash_table.hpp
==============================================================================
--- branches/unordered/trunk/boost/unordered/detail/hash_table.hpp (original)
+++ branches/unordered/trunk/boost/unordered/detail/hash_table.hpp 2008-01-09 07:16:37 EST (Wed, 09 Jan 2008)
@@ -63,9 +63,9 @@
 #endif
         }
 
- inline std::size_t float_to_size_t(float f)
+ inline std::size_t double_to_size_t(double f)
         {
- return f >= static_cast<float>((std::numeric_limits<std::size_t>::max)()) ?
+ return f >= static_cast<double>((std::numeric_limits<std::size_t>::max)()) ?
                 (std::numeric_limits<std::size_t>::max)() :
                 static_cast<std::size_t>(f);
         }

Modified: branches/unordered/trunk/boost/unordered/detail/hash_table_impl.hpp
==============================================================================
--- branches/unordered/trunk/boost/unordered/detail/hash_table_impl.hpp (original)
+++ branches/unordered/trunk/boost/unordered/detail/hash_table_impl.hpp 2008-01-09 07:16:37 EST (Wed, 09 Jan 2008)
@@ -1228,8 +1228,8 @@
                 using namespace std;
 
                 // size < mlf_ * count
- return float_to_size_t(ceil(
- max_bucket_count() * mlf_)) - 1;
+ return double_to_size_t(ceil(
+ (double) mlf_ * max_bucket_count())) - 1;
             }
 
             // strong safety
@@ -1274,7 +1274,7 @@
                 //
                 // Or from rehash post-condition:
                 // count > size / mlf_
- return static_cast<size_type>(floor(n / mlf_)) + 1;
+ return double_to_size_t(floor(n / (double) mlf_)) + 1;
             }
 
             // no throw
@@ -1284,7 +1284,8 @@
 
                 // From 6.3.1/13:
                 // Only resize when size >= mlf_ * count
- max_load_ = float_to_size_t(ceil(mlf_ * this->bucket_count_));
+ max_load_ = double_to_size_t(ceil(
+ (double) mlf_ * this->bucket_count_));
             }
 
             // basic exception safety
@@ -1310,7 +1311,8 @@
                 bool need_to_reserve = n >= max_load_;
                 // throws - basic:
                 if (need_to_reserve) {
- rehash_impl(static_cast<size_type>(floor(n / mlf_ * 1.25)) + 1);
+ rehash_impl(double_to_size_t(floor(
+ n / (double) mlf_ * 1.25)) + 1);
                 }
                 BOOST_ASSERT(n < max_load_ || n > max_size());
                 return need_to_reserve;


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