Hash table definition: a hash table is a data-mapping structure that searches for values based on key codes, and the structure searches for places where the values are stored by mapping the location of the key code. Keys can correspond to multiple values (that is, hash conflicts), and the values are stored in the corresponding key according to the corresponding hash formula.
The construction of a hash function requires:
- The operation process should be as simple and efficient as possible to improve the efficiency of inserting and retrieving the hash table;
- The hash function should have a good hash to reduce the probability of a hash collision, that is, to make the corresponding records of the keyword evenly distributed in the hash table
- The hash function should have greater compressibility to save memory
- A very small change in the keyword can cause a great change in the hash value.
Hash conflict resolution: 1. Chain Address Method
The principle of the chain address method if a conflict occurs, he creates a new space at the original address and inserts it into the space as a linked table node .
The following from Baidu intercepted a picture, you can clearly understand the structure of the reaction below. For example, I have a bunch of data {1,12,26,337,353 ...}, and my hashing algorithm is H (key) =key MoD 16, the hash value of the first Data 1 f (1) = 1, inserted after the 1 node, the second data 12 hash value f (12) = 12, inserted into the 12 node, The hash value of the third data 26, F (26) = 10, inserted after the 10 node, 4th Data 337, calculated that the hash value is 1, encountered a conflict, but still only need to find the last link node of the 1 node insertion, the same 353.
2. Open Address Law
Reference article:
Https://www.cnblogs.com/s-b-b/p/6208565.html
Https://www.cnblogs.com/jijiji/p/4856805.html
A hash table of C + + data structures