The PolymurHash universal hash function
github.com
github.com
So hopefully people have tested this empirically that the collision rates for the top and bottom n bits are all reasonable looking for varrious values of n (and might be useful to know which bits are the strongest, assuming you get a choice). Assuming there are no hidden gotchas like that, this looks pretty great.
PolymurHash has no such guarantee, the claims are only over the full hash. That said, I don't expect problems in practice due to the Murmur style bit mixing at the end.
Though it's hard to imagine anything with 4kib of state being very fast! is it just a precomputed power table or something where the whole thing isn't even accessed for short inputs?
> The finalizer for that hash is a universal hash which I believe is 2^(2-k) almost-delta universal mod 2^k for any k <= 64. So the bottom bits are always high quality.
That's interesting!
> PolymurHash has no such guarantee, the claims are only over the full hash. That said, I don't expect problems in practice due to the Murmur style bit mixing at the end.
That mix at the end is just an addition with a secret constant, right? I'd expect then the least significant bits to not be improved much by it.
Correct, it's a pregenerated table of random bits that, in essence, gets multiplied with the input. If the input is small, only a small portion gets accessed.
> That mix at the end is just an addition with a secret constant, right? I'd expect then the least significant bits to not be improved much by it.
No, the mix at the end is as follows:
x ^= x >> 32;
x *= 0xe9846af9b1a615dULL;
x ^= x >> 32;
x *= 0xe9846af9b1a615dULL;
x ^= x >> 28;
x += secret;
The addition of secret at the end ensures that the permutation is not trivially invertible by an adversary. The rest is a Murmur-style permutation, which PolymurHash gets part of its name from.From a dev perspective though, it seems very nice. Short and clean code with decent comments. Although I'm struggling to understand what `polymur_hash_poly611` is doing.