Hacker News new | ask | show | jobs
by sicp-enjoyer 1207 days ago
Can many hashes be combined quickly in a uniform way? This is another benefit of `<`, it composes.
1 comments

> Can many hashes be combined quickly in a uniform way?

The XOR operator?

All pairs of {x,y} with x==y or hash(x)==hash(y) would hash to the same value (0). That's seems suboptimal.
If you do that 10 times for all members of your struct, do you get good uniformly distributed keys?

This post doesn't think so: https://stackoverflow.com/questions/5889238/why-is-xor-the-d...

XOR is a bad way to do it, but there are ones that work much better that are described in answers to that post, and it's what other languages use in similar situations (e.g. tuples in Python and C#):

https://github.com/python/cpython/blob/71db5dbcd714b2e1297c4...

Yes, and eventually you start computing another hash of the buffer of the concatenated members. I'm not saying it can't be done, I'm just comparing it with recursive memberwise comparison.