Hashing in Java (1)
Instance method in class Object:
public int hashCode ();// Translate this object to an integer, such that x.equals(y) // implies x.hashcode() == y.hashcode().
Note that hashCode is consistent. We can use it to implement a hash function for a hash table with m buckets:
int hash (Object k) { return Math.abs(k.hashCode()) % m;}
Math.abs returns a nonnegative integer.
Modulo-m arithmetic then gives an integer in the range 0…m–1.