Hashing uints in Go

by go:ngine

So I needed to hash three unsigned integers into one integer value uniquely identifying that particular combination of uints, to be used as a "hash key" in a map[int]sometype.

Simple arithmetics (add or mult) are out to uniquely hash different combinations: the set 1,2,4 should produce a different hash key than 1,4,2 and 2,1,4 and 2,4,1 and 4,1,2 and 4,2,1.

Found Robert Jenkins' 96 bit Mix Function with a neat source snippet right there (Java). Implemented in Go and seems to work even though I'm not sure if Golangs >> right-shift operator (spec'd as integer >> unsigned integer) really works like Java's >>> "unsigned right shift"...

Update: actually by now it dawned on me I can just use a [3]uint as a hash key in Golang here, which is fine in this use-case. Simplicity FTW!

But if you're curious about this topic, here's an incredible testing & comparison of hashing algos.

go:ngine on GitHub