[PATCH] [libcxx] Fix __is_power2 and __next_power2. Change hashmap to handle new behavior.
Marshall Clow
mclow.lists at gmail.com
Thu Oct 2 11:20:33 PDT 2014
If this isn't/wasn't going to help out the PMF stuff in std::experimental, then I don't think that this is worth doing.
that being said, other than the inline comments, I think this looks fine.
================
Comment at: include/__hash_table:86
@@ -79,2 +85,3 @@
{
- return size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1));
+ return __n < 2 ? __n + (__n == 0)
+ : size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1));
----------------
Looks to me that this produces:
0 --> 1
1 --> 1
2 --> 4
4 --> 8
Is that the intended behavior? (especially the second one)
================
Comment at: include/__hash_table:1959
@@ -1951,2 +1958,3 @@
+ : __next_prime(size_t(ceil(float(size()) / max_load_factor())))
);
if (__n < __bc)
----------------
This expression seems (to me) to be crying out for a small inline function, like: (untested code!)
size_t XXX ( size_t sz, float max_load )
{ return size_t( ciel (float(sz) / max_load )); }
and then the expression could be:
(__is_rehash_power2(__bc))
? __next_pow2 ( XXX ( size(), max_load_factor()))
: __next_prime ( XXX ( size(), max_load_factor()))
or even have XXX call `size()` and `max_load_factor()` itself.
http://reviews.llvm.org/D4948
More information about the cfe-commits
mailing list