next up previous index
Next: The String hash function Up: Hash Tables Previous: Removal   Index

Choice of hash function

The ideal hash function maps data items uniformly into table locations. There should be an equal probability of h(n) taking any of the values 0..table.length-1. This depends not only on the hash function, but also on the prior probability of different data items being entered into the table. The hash code should also be computable as rapidly as possible.

In Java a hash code is already defined for any Object by the hashCode method. Specifically, if o is any object then o.hashCode() will return a hash value. This method is frequently overwritten in extensions of the Object class, e.g. by the String, Integer and Boolean classes.



Subsections

Peter Williams 2005-06-07