next up previous index
Next: Success Up: Collision resolution Previous: Clustering   Index


Double hashing

Double hashing is another alternative to linear probing. In this case we explore a sequence of probes

h, h+k, h+2k, h+3k, h+4k, ...
where k lies between 1 and table.length-1. The point of this approach is that not only h, but also k, should depend on the item that we have to insert. The idea is that even if two items hash to the same value of h, they will have different values of k, so that different probe sequences will be followed. Given the restriction on the range of k, the simplest choice for k is
1 + (h(n) % (table.length-1))
This means we shall only have to calculate the hash code value of n once; take the remainder modulo table.length to obtain h, and add one to the remainder modulo table.length-1 to obtain k. Since h(n) is typically much larger than table.length, we are likely to obtain different values for k even if we have the same value for h.



Subsections

Peter Williams 2005-06-07