Double hashing

Double hashing

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:

h(k,j)=(h_1(k) + j \cdot h_2(k))\mod m

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.


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.

On top of that, it is possible for the secondary hash function to evaluate to zero. For example, if we choose k=5 with the following function:


 h_2(k) = 5 - (k\mod 7)


The resulting sequence will always remain at the initial hash value. One possible solution is to change the secondary hash function to:


 h_2(k) = (k\mod 7) + 1


This ensures that the secondary hash function will always be non zero.

See also

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Cuckoo hashing — example. The arrows show the alternative location of each key. A new item would be inserted in the location of A by moving A to its alternative location, currently occupied by B, and moving B to its alternative location which is currently vacant …   Wikipedia

  • Doppel-Hashing — Beim Doppelstreuwertverfahren oder Doppel Hashing (englisch double hashing) handelt es sich um eine Methode zur Realisierung eines geschlossenen Hash Verfahrens. In geschlossenen Hash Verfahren wird versucht, Überläufer in der Hash Tabelle… …   Deutsch Wikipedia

  • Hash table — Not to be confused with Hash list or Hash tree. Unordered map redirects here. For the proposed C++ class, see unordered map (C++). Hash Table Type unsorted dictionary Invented 1953 Time complexity in big O notation Average Worst case Space …   Wikipedia

  • List of terms relating to algorithms and data structures — The [http://www.nist.gov/dads/ NIST Dictionary of Algorithms and Data Structures] is a reference work maintained by the U.S. National Institute of Standards and Technology. It defines a large number of terms relating to algorithms and data… …   Wikipedia

  • Список терминов, относящихся к алгоритмам и структурам данных —   Это служебный список статей, созданный для координации работ по развитию темы.   Данное предупреждение не устанавливается на информационные списки и глоссарии …   Википедия

  • Список терминов — Список терминов, относящихся к алгоритмам и структурам данных   Это сл …   Википедия

  • Bloom filter — The Bloom filter, conceived by Burton H. Bloom in 1970, is a space efficient probabilistic data structure that is used to test whether an element is a member of a set. False positives are possible, but false negatives are not. Elements can be… …   Wikipedia

  • Open addressing — Hash collision resolved by linear probing (interval=1). Open addressing, or closed hashing, is a method of collision resolution in hash tables. With this method a hash collision is resolved by probing, or searching through alternate locations in… …   Wikipedia

  • Table de hachage — Une table de hachage est en informatique, une structure de données qui permet une association clé élément, c est à dire une implémentation du type abstrait table de symboles. On accède à chaque élément de la table via sa clé. Il s agit d un… …   Wikipédia en Français

  • Hashmap — Table de hachage En informatique, une table de hachage est une structure de données qui permet une association clé élément, c est à dire une implémentation du type abstrait table de symboles. On accède à chaque élément de la table via sa clé. Il… …   Wikipédia en Français

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”