re PR libstdc++/51386 (23_containers/unordered_set/hash_policy/load_factor.cc execution timeout)

2011-12-07  François Dumont <fdumont@gcc.gnu.org>

	PR libstdc++/51386
	* include/bits/hashtable_policy.h (_Prime_rehash_policy::_M_next_bkt):
	Fix computation of _M_prev_resize so that hashtable do not keep on
	being rehashed when _M_max_load_factor is lower than 1.

From-SVN: r182085
This commit is contained in:
François Dumont 2011-12-07 19:47:03 +00:00
parent 3c411f3f2c
commit 95c0a8a714
2 changed files with 27 additions and 13 deletions

View File

@ -1,3 +1,10 @@
2011-12-07 François Dumont <fdumont@gcc.gnu.org>
PR libstdc++/51386
* include/bits/hashtable_policy.h (_Prime_rehash_policy::_M_next_bkt):
Fix computation of _M_prev_resize so that hashtable do not keep on
being rehashed when _M_max_load_factor is lower than 1.
2011-12-06 Paolo Carlini <paolo.carlini@oracle.com> 2011-12-06 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/51438 PR libstdc++/51438

View File

@ -300,23 +300,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ {
// Optimize lookups involving the first elements of __prime_list. // Optimize lookups involving the first elements of __prime_list.
// (useful to speed-up, eg, constructors) // (useful to speed-up, eg, constructors)
static const unsigned long __fast_bkt[12] static const unsigned char __fast_bkt[12]
= { 2, 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11 }; = { 2, 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11 };
const unsigned long* __p if (__n <= 11)
= __n <= 11 ? __fast_bkt + __n {
: std::lower_bound(__prime_list + 5, _M_prev_resize = 0;
__prime_list + _S_n_primes, __n); _M_next_resize
= __builtin_ceil(__fast_bkt[__n] * (long double)_M_max_load_factor);
return __fast_bkt[__n];
}
_M_prev_resize = __builtin_floor(*__p * (long double)_M_max_load_factor); const unsigned long* __p
if (__p != __fast_bkt) = std::lower_bound(__prime_list + 5, __prime_list + _S_n_primes, __n);
_M_prev_resize = std::min(_M_prev_resize,
static_cast<std::size_t>(*(__p - 1))); // Shrink will take place only if the number of elements is small enough
// Lets guaranty a minimal grow step of 11: // so that the prime number 2 steps before __p is large enough to still
// conform to the max load factor:
_M_prev_resize
= __builtin_floor(*(__p - 2) * (long double)_M_max_load_factor);
// Let's guaranty that a minimal grow step of 11 is used
if (*__p - __n < 11) if (*__p - __n < 11)
__p = std::lower_bound(__prime_list + 5, __p = std::lower_bound(__p, __prime_list + _S_n_primes, __n + 11);
__prime_list + _S_n_primes, __n + 11); _M_next_resize = __builtin_ceil(*__p * (long double)_M_max_load_factor);
_M_next_resize = __builtin_floor(*__p * (long double)_M_max_load_factor);
return *__p; return *__p;
} }