Open ThibaultDECO opened 1 year ago
As discussed in issue #648.
I didn't know about that algorithm--it's pretty cool! Could you explain how it improves performance though? It seems like the operations are about the same (bit shift ~= multiplication, addition ~= boolean OR).
If the pairing function is a perfect hash function, maybe we could remove the call to std::hash<size_t>
entirely and simply return the 1-d value as the result of the custom hash. I could see that being much faster.
The Szudzik function has 100% value packing efficiency, i.e. no overflow. With Szudzik, pairing two 32-bits numbers results in a 64-bits number, which is not the case for Cantor or the current implementation. For example:
cantor(9, 9) = 200
szudzik(9, 9) = 99
You will find more details and a benchmark on performance here.
We could indeed remove the call to std::hash
Using Szudzik's pairing function (more efficient than the previous approach or Cantor's)