A hash table, also known as a hash table, is used to quickly locate data.
Consider the following scenario.
A column of key-value pairs is stored in a table. How can I quickly find the corresponding value through the data keyword? Don't tell me to compare keys one by one.
As we all know, in all linear data structures, the array positioning speed is the fastest, because it can directly locate the corresponding array space through the array subscript, there is no need to look up one by one. The hash table uses the array structure that can quickly locate data to solve the above problems.
What should I do? Have you noticed the previous saying: "The array can be directly located to the corresponding space through the subscript", that is, the hash table is actually very simple, that is, the key is passed through a fixedAlgorithmThe function converts a hash function into an integer number, and then returns the remainder of the array length. The remainder result is treated as the subscript of the array, the value is stored in the array space where the number is the underlying object. When a hash table is used for query, the key is converted to the corresponding array subscript by using the hash function again, and locate the space to get the value, so that you can make full use of the array positioning performance for data positioning.
I don't know whether or not some friends who don't know about the principle of the hash table actually exchange space for time. Some may ask, does the hash function convert keys, and the remainder value must be unique? This is of course not guaranteed, mainly because hashcode will take the remainder of the array length, so the results will inevitably be duplicated due to the restriction of the array length, so there will be a "Conflict" problem, there are actually many ways to resolve conflicts, such as repeated hash, probably, if the space to be located already has values and the keys are different, re-hash and add them to calculate the number of elements in the modulus group, that is, (H (k) + I) mod S, I =, 3 ...... Until the space is found.