C + + unordered_map map

Source: Internet
Author: User

Hash map is an associative container that allows you to quickly retrieve individual elements based on key values.

Elements inside the unordered_map are not sorted in any particular order by key or mapped elements, and their storage location depends on the hash value allowing for quick access to a single element (with a constant average time complexity) directly through its key value.

Hash map allows you to use the operator operator (operator []) to directly access an element with its key value as a parameter.

Map determines whether elements are the same according to operator<, compares the size of elements, and then chooses the appropriate location to insert into the tree. So, if the map is traversed (in the middle order traversal), the result of the output is ordered. The order is sorted by the size defined by the operator<.

In any case, if you want to choose between these two containers, we should not hesitate to choose Unordered_map. Because of his performance in the above 4 operations are superior to hash_map, and even can be said to be far superior to hash_map.

When we need an orderly associative container, we have to choose Std::map.

C + + unordered_map map

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.