Better 64-bit hash_combine
This commit is contained in:
parent
bcc908d064
commit
f9894647e3
1 changed files with 6 additions and 2 deletions
|
|
@ -6,10 +6,14 @@
|
||||||
namespace psemek::util
|
namespace psemek::util
|
||||||
{
|
{
|
||||||
|
|
||||||
// based on boost::hash_combine
|
|
||||||
inline void hash_combine(std::size_t & seed, std::size_t value)
|
inline void hash_combine(std::size_t & seed, std::size_t value)
|
||||||
{
|
{
|
||||||
seed ^= value + 0x9e3779b9 + (seed<<6) + (seed>>2);
|
static const std::size_t k = 0x9ddfea08eb382d69ULL;
|
||||||
|
std::size_t a = (value ^ seed) * k;
|
||||||
|
a ^= (a >> 47);
|
||||||
|
std::size_t b = (seed ^ a) * k;
|
||||||
|
b ^= (b >> 47);
|
||||||
|
seed = b * k;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue