Java intermittent interruption-hash table also known as hash table

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.