Search code examples
hashuuidhashcodehash-function

Hash UUIDs without requiring ordering


I have two UUIDs. I want to hash them perfectly to produce a single unique value, but with a constraint that f(m,n) and f(n,m) must generate the same hash.

  • UUIDs are 128-bit values
  • the hash function should have no collisions - all possible input pairings must generate unique hash values
  • f(m,n) and f(n,m) must generate the same hash - that is, ordering is not important
  • I'm working in Go, so the resulting value must fit in a 256-bit int
  • the hash does not need to be reversible

Can anyone help?


Solution

  • Concatenate them with the smaller one first.