A hash table of C + + data structures

Source: Internet
Author: User
Tags table definition

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:

    1. The operation process should be as simple and efficient as possible to improve the efficiency of inserting and retrieving the hash table;
    2. 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
    3. The hash function should have greater compressibility to save memory
    4. 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

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.