Compare commits

...

7 Commits

Author SHA1 Message Date
joaquintides 1e57c08686 fourth attempt 2022-11-28 17:58:15 +01:00
joaquintides 3a34b8dae9 micro-optimized previous 2022-11-28 12:13:04 +01:00
joaquintides 0a91421fb8 third attempt 2022-11-27 20:54:26 +01:00
joaquintides 602488abc1 reverted c463cf13fd (wrong branch) 2022-11-24 20:12:48 +01:00
joaquintides c463cf13fd added "Open Addressing Implementation" section 2022-11-24 20:00:04 +01:00
joaquintides 09171776f7 second attempt 2022-11-24 13:01:09 +01:00
joaquintides cf2a0ef303 added first draft of new pow2_size_policy 2022-11-22 20:06:29 +01:00
+42
View File
@@ -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 */