Double hashing
When double spread value method or double hashing ( English double hashing ) is a method for realizing a closed hash method . In closed hash procedures, attempts are made to accommodate defectors in the hash table instead of storing them within the cell (e.g. as a list). (Open hash procedures can assign entries twice and therefore do not require any exploration.) Attention: As it is in the article hash table under "Variants of the hash procedure", the terms "open" or "closed hashing" are used in exactly the opposite way.
To do this, double hashing uses a probing function that includes a secondary hash function, e.g. B. , and which is used if the index calculated by the primary hash function is already occupied.
The full hash function then reads:, where j is the number of already "tried" indices, i. This means that j is increased by 1 every time an index is already used.
The probing function is supposed to form a permutation of the indices of the hash table.
The sequence of hash functions that are now formed using and looks like this:
The cost of this method is close to the cost of ideal hashing.
Independence of the hash functions
Double hashing uses two independent hash functions and . These are called independent if the probability of a so-called double collision, i.e. H. , is less than or equal to and therefore minimal, where is the size of the array.
Examples
Example functions
Size of the array: m
Indices: {0; m-1}
Primary hash function: ( division remainder method )
Secondary hash function:
Exploratory function:
Full double hash function:
Calculation example
Size of the array: m = 7
- Hash functions
- Exploratory function
Hash table:
k | 10 | 19th | 31 | 22nd | 14th | 16 |
---|---|---|---|---|---|---|
H | 3 | 5 | 3 | 1 | 0 | 2 |
H' | 1 | 5 | 2 | 3 | 5 | 2 |
The array filled with the help of hash table and probe function:
0 | 1 | 2 | 3 | 4th | 5 | 6th |
---|---|---|---|---|---|---|
31 | 22nd | 16 | 10 | - | 19th | 14th |
Explanation using the example :
and do not generate a collision and therefore do not need the double hash function . The index of the hash function can be read off here. creates a collision in the array at the point , which is why you now use the double hash function with :
The point creates a collision again, which is why the following is called with:
The position is vacant and thus receives the content .