For index search or continuous table search, you must compare keywords and search values. Do you need to compare them? You can use keywords to obtain the address corresponding to the keywords, this is the hash query.
Storage location = F (keyword );
The hash technique establishes a definite correspondence relationship F between the storage location of the record and Its keywords, so that each key corresponds to a storage location F (key );
The corresponding relationship F is called a hash function. Hash technology is used to store records in a continuous space. This continuous space is called a hash table or a hash table. The record location corresponding to the keyword is called the hash address.
Conflict: If two keywords key1! = Key2, but Fkey1) = f (key2). This phenomenon is called conflict and key1 and key2 are called synonyms of this hash function.
8.7.1 construction of Hash Functions
How to evaluate a good hash function
1) Simple computing
2) scattered addresses are evenly distributed, rather than distributed on a few addresses.
1. Direct addressing.
2. Digital analysis.
3. China and France.
4. Folding Method.
5. Remove the remaining parts.
F (key) = key mod pp <= m)
Mod indicates the modulo operation.
Generally, p is the minimum prime number that is less than or equal to the table length.
6. Random Number method, specifically the pseudo-random number method.
8.7.2 how to handle hash conflicts
If two keywords key1 are found after the hash function is used! = Key2, but f (key1) = f (key2) exists. What should I do when there is a conflict.
1. Open address Method
If a conflict occurs, search for the next empty hash address. As long as the hash address is large enough, the empty hash address can always be found and the record is saved.
F1 (key) = (f (key) + d1) mod m (d1 = 1, 2, 3, 4 ...... m-1)
Low search efficiency leads to accumulation.
2. link address Method
If there is a conflict or not, add a header pointer to the hash list and connect it to the end of the conflict with it. If there is a conflict between keyword 3 and keyword 6, it must exist in address 9, it can be designed in this way.
Address 9: 3 Data Pointer -----> 6 data NULL
This article is from "Li Haichuan" blog, please be sure to keep this source http://lihaichuan.blog.51cto.com/498079/1282378