1

let say i have a two integer hash keys and I want to combine them into a product hash key that is unique to the two hashes and sensitive to the order.

For example:

hashKey(3,2) != hashKey(2,3)

There must be a good mathematical way to achieve this. My math is pretty rusty. any help in reading material or suggestions is appreciated.

Edward Ashak
  • 2,411
  • 2
  • 23
  • 38
  • This should give you the answer - [Hash Value for 3D Vector](http://stackoverflow.com/questions/31951502/hash-value-for-3d-vector/31953012#31953012) – Bernhard Barker Aug 12 '15 at 21:02
  • this is more or less equivalent to a normal hash code implementation of string. – Jason Hu Aug 12 '15 at 21:08
  • It does sound like the [Hash Value for 3D Vector](http://stackoverflow.com/questions/31951502/hash-value-for-3d-vector/31953012#31953012) – Edward Ashak Aug 12 '15 at 21:23

1 Answers1

1

A common trick is to use the fact that the prime factorization of integers is unique: there's a 1-to-1 mapping between integer pairs (x,y) and numbers of the form 2x3y.

Since this is homework, I'll leave figuring out what to do with negative integers as an exercise for the reader :)

Joni
  • 108,737
  • 14
  • 143
  • 193