Double hashing
From Wikipedia, the free encyclopedia
Double hashing is a computer programming technique used in hash tables to resolve hash collisions, cases when two different values to be searched for produce the same hash key. It is a popular collision-resolution technique in open-addressed hash tables.
Like linear probing, it uses one hash value as a starting point and then repeatedly steps forward an interval until the desired value is located, an empty location is reached, or the entire table has been searched; but this interval is decided using a second, independent hash function (hence the name double hashing). Unlike linear probing and quadratic probing, the interval depends on the data, so that even values mapping to the same location have different bucket sequences; this minimizes repeated collisions and the effects of clustering. In other words, given independent hash functions h1 and h2, the jth location in the bucket sequence for value k in a hash table of size m is:
[edit] Disadvantages
Linear probing and, to a lesser extent, quadratic probing are able to take advantage of the data cache by accessing locations that are close together. Double hashing has larger intervals and is not able to achieve this advantage.
Deletions are also complex in a double-hashed hash table. After a collision has occurred for a certain slot, its contents cannot be deleted or all sequences crossing that slot may be severed. Instead, a delete marker known as a tombstone will be put in its place, filling up a slot and slightly degrading search performance. While tombstones can be reused on a later insertion, it is prudent to rebuild the table if the number of tombstones becomes too large.
Like all other forms of open addressing, double hashing becomes linear as the hash table approaches maximum capacity. The only solution to this is to rehash to a larger size.