mirror of
https://github.com/boostorg/unordered.git
synced 2026-08-06 13:44:12 +02:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e57c08686 | |||
| 3a34b8dae9 | |||
| 0a91421fb8 | |||
| 602488abc1 | |||
| c463cf13fd | |||
| 09171776f7 | |||
| cf2a0ef303 |
@@ -656,6 +656,7 @@ private:
|
||||
* these values and positioning to be as uncorrelated as possible.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
struct pow2_size_policy
|
||||
{
|
||||
static inline std::size_t size_index(std::size_t n)
|
||||
@@ -679,6 +680,47 @@ struct pow2_size_policy
|
||||
return hash>>size_index_;
|
||||
}
|
||||
};
|
||||
#else
|
||||
struct pow2_size_policy
|
||||
{
|
||||
static inline std::size_t size_index(std::size_t n)
|
||||
{
|
||||
// TODO: min size is 2, see if we can bring it down to 1 without loss
|
||||
// of performance
|
||||
|
||||
std::size_t used_bits_=n<=2?1:((std::size_t)(boost::core::bit_width(n-1)));
|
||||
std::size_t shift_right_=total_bits-used_bits_;
|
||||
std::size_t shift_left_=shift_right_%2?0:shift_right_-8;
|
||||
|
||||
return (shift_left_<<16)|shift_right_;
|
||||
}
|
||||
|
||||
static inline std::size_t size(std::size_t size_index_)
|
||||
{
|
||||
return std::size_t(1)<<(total_bits-shift_right(size_index_));
|
||||
}
|
||||
|
||||
static constexpr std::size_t min_size(){return 2;}
|
||||
|
||||
static inline std::size_t position(std::size_t hash,std::size_t size_index_)
|
||||
{
|
||||
return (hash<<shift_left(size_index_))>>shift_right(size_index_);
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr std::size_t total_bits=sizeof(std::size_t)*CHAR_BIT;
|
||||
|
||||
static inline std::size_t shift_left(std::size_t size_index_)
|
||||
{
|
||||
return size_index_>>16;
|
||||
}
|
||||
|
||||
static inline std::size_t shift_right(std::size_t size_index_)
|
||||
{
|
||||
return size_index_&0xffffu;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
/* size index of a group array for a given *element* capacity */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user