skeeto / hash-prospector

Automated integer hash function discovery
The Unlicense
672 stars 27 forks source link

Option to evaluate 64-bit functions as 32-bit hashes #3

Open ajohnson1 opened 4 years ago

ajohnson1 commented 4 years ago

This is an enhancement request, rather than a defect, so feel free to accept or close if you aren't doing further development.

In some situations a 32-bit hash is specified, but fast 64-bit arithmetic is available (e.g. Java on 64-bit machines). Generating 64-bit hash functions of the form mul xorr mul rot:32 but calling them as 32-bit functions (zero extend input to 64 bits, take lower 32 bits of the output) can work much better than the 2-round 32-bit functions and nearly as well as the 3-round 32-bit functions. It would be nice if hash-prospector could search for these. I think this could be done quite simply with an extra flag and a different test for whether to call the 32-bit or 64-bit functions. The 64-bit generated functions appear to be callable as 32-bit functions without change.

skeeto commented 4 years ago

The problem with 64-bit intermediates in a 32-bit hash is that the resulting function will not be a 32-bit permutation. In other words, some inputs would map to the same output. The hash prospector's goal is to discover high quality permutations, and it does this by composing functions only from reversible primitives.