[PATCH] [libcxx] Fix __is_power2 and __next_power2. Change hashmap to handle new behavior.

Howard Hinnant howard.hinnant at gmail.com
Sun Aug 17 19:15:33 PDT 2014


On Aug 17, 2014, at 9:22 PM, Eric Fiselier <eric at efcs.ca> wrote:

> Hi Howard,
> 
> Thanks for the advice. I'll make sure to performance test these changes without moving forward.
> I also appreciate the insight. 
> 
> > 0 is a valid bucket count.  An upward bump of 0 buckets goes to 2.
> 1 is considered not a power of 2, but it rounded up to 2.
> 2 is considered prime, not a power of 2.  Thus a upward bump off bucket size 2 goes to 5, not 4.
> 
> Are you referring to the input/output from the __next_power2 function?
> Passing 1 to __next_power2 causes undefined behavior because it passes 0 to __clz. 
> 
> I'll consider just backing out these changes and renaming the functions so they don't imply mathematical accuracy.  

I’m not saying you should back them out.  I honestly don’t know.  I’m just saying one should tread with caution here, and use measurement to guide the way.

The bottom line is really really how rehash behaves, since the __functions are all implementation details.  And these __functions were purposefully implemented just to serve __hash_table, and are not general purpose facilities.

Howard





More information about the cfe-commits mailing list