Skip to content

Commit

Permalink
Better hash mixing for 64 bit integer keys and doubles (issue #64)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed May 17, 2018
1 parent 7ac6088 commit 27c61e7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sparsepp/spp_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,19 @@ inline size_t spp_mix_32(uint32_t a)
return static_cast<size_t>(a);
}

// Maybe we should do a more thorough scrambling as described in
// More thorough scrambling as described in
// https://gist.github.com/badboy/6267743
// -------------------------------------------------------------
// ----------------------------------------
inline size_t spp_mix_64(uint64_t a)
{
a = a ^ (a >> 4);
a = (a ^ 0xdeadbeef) + (a << 5);
a = a ^ (a >> 11);
return (size_t)a;
a = (~a) + (a << 21); // a = (a << 21) - a - 1;
a = a ^ (a >> 24);
a = (a + (a << 3)) + (a << 8); // a * 265
a = a ^ (a >> 14);
a = (a + (a << 2)) + (a << 4); // a * 21
a = a ^ (a >> 28);
a = a + (a << 31);
return a;
}

template<class ArgumentType, class ResultType>
Expand Down

0 comments on commit 27c61e7

Please sign in to comment.