diff options
author | François Dumont <fdumont@gcc.gnu.org> | 2011-09-06 22:13:46 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2011-09-06 22:13:46 +0000 |
commit | e25fc78ff53a6e17c4c8ea4055a110f8b306c614 (patch) | |
tree | 5a88a4eaff2c769a213ee99af0749eb6125f1486 | |
parent | a30d652725c1854366e0f8a2326e21050d4e6807 (diff) | |
download | gcc-e25fc78ff53a6e17c4c8ea4055a110f8b306c614.tar.gz |
hashtable_policy.h (_Prime_rehash_policy:: _M_next_bkt): Cast _M_max_load_factor to long double.
2011-09-06 François Dumont <fdumont@gcc.gnu.org>
Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/hashtable_policy.h (_Prime_rehash_policy::
_M_next_bkt): Cast _M_max_load_factor to long double.
(_Prime_rehash_policy::_M_bkt_for_elements): Use _M_next_bkt.
(_Prime_rehash_policy::_M_need_rehash): Likewise; cast all
float quantities to long double.
Co-Authored-By: Paolo Carlini <paolo.carlini@oracle.com>
From-SVN: r178615
-rw-r--r-- | libstdc++-v3/ChangeLog | 9 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/hashtable_policy.h | 35 |
2 files changed, 21 insertions, 23 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d0c1b11c4eb..6c85ef70e82 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2011-09-06 François Dumont <fdumont@gcc.gnu.org> + Paolo Carlini <paolo.carlini@oracle.com> + + * include/bits/hashtable_policy.h (_Prime_rehash_policy:: + _M_next_bkt): Cast _M_max_load_factor to long double. + (_Prime_rehash_policy::_M_bkt_for_elements): Use _M_next_bkt. + (_Prime_rehash_policy::_M_need_rehash): Likewise; cast all + float quantities to long double. + 2011-09-06 Paolo Carlini <paolo.carlini@oracle.com> PR libstdc++/50257 diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h index 08a6dcd39a2..acb7e99a8df 100644 --- a/libstdc++-v3/include/bits/hashtable_policy.h +++ b/libstdc++-v3/include/bits/hashtable_policy.h @@ -429,15 +429,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { // Optimize lookups involving the first elements of __prime_list. // (useful to speed-up, eg, constructors) - static const unsigned char __fastbkt[12] + static const unsigned char __fast_bkt[12] = { 2, 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11 }; const unsigned long __p - = __n <= 11 ? __fastbkt[__n] + = __n <= 11 ? __fast_bkt[__n] : *std::lower_bound(__prime_list + 5, __prime_list + _S_n_primes, __n); - _M_next_resize = - static_cast<std::size_t>(__builtin_floor(__p * _M_max_load_factor)); + _M_next_resize = __builtin_floor(__p * (long double)_M_max_load_factor); return __p; } @@ -446,14 +445,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline std::size_t _Prime_rehash_policy:: _M_bkt_for_elements(std::size_t __n) const - { - const float __min_bkts = __n / _M_max_load_factor; - const unsigned long __p = *std::lower_bound(__prime_list, __prime_list - + _S_n_primes, __min_bkts); - _M_next_resize = - static_cast<std::size_t>(__builtin_floor(__p * _M_max_load_factor)); - return __p; - } + { return _M_next_bkt(__builtin_ceil(__n / (long double)_M_max_load_factor)); } // Finds the smallest prime p such that alpha p > __n_elt + __n_ins. // If p > __n_bkt, return make_pair(true, p); otherwise return @@ -471,22 +463,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { if (__n_elt + __n_ins > _M_next_resize) { - float __min_bkts = ((float(__n_ins) + float(__n_elt)) - / _M_max_load_factor); + long double __min_bkts = ((__n_elt + __n_ins) + / (long double)_M_max_load_factor); if (__min_bkts > __n_bkt) { - __min_bkts = std::max(__min_bkts, _M_growth_factor * __n_bkt); - const unsigned long __p = - *std::lower_bound(__prime_list, __prime_list + _S_n_primes, - __min_bkts); - _M_next_resize = static_cast<std::size_t> - (__builtin_floor(__p * _M_max_load_factor)); - return std::make_pair(true, __p); + __min_bkts = std::max(__min_bkts, (long double)_M_growth_factor + * __n_bkt); + return std::make_pair(true, + _M_next_bkt(__builtin_ceil(__min_bkts))); } else { - _M_next_resize = static_cast<std::size_t> - (__builtin_floor(__n_bkt * _M_max_load_factor)); + _M_next_resize + = __builtin_floor(__n_bkt * (long double)_M_max_load_factor); return std::make_pair(false, 0); } } |