New features in c++11: unordered_map

Source: Internet
Author: User

Unordered_map, like map, are stored key-value values that can be quickly indexed to value by key.

The difference is that the unordered_map will not be sorted according to the size of the key, the storage is based on the hash value of key to determine whether the element is the same, that is, unordered_map internal elements are unordered, and map elements are stored according to the binary search tree, The sequential traversal is carried out sequentially.

So when using the key of map, we need to define operator<. Instead, Unordered_map needs to define the Hash_value function and overload the operator==. But many of the system's built-in data types come with these, so if it's a custom type, you'll need to reload operator< or Hash_value () yourself.

Conclusion: If you need to sort internal elements automatically, use map and do not need to sort using unordered_map

c++0x why not define unordered_map as Hash_map? That's because many library manufacturers have taken up the term hash_map before the new standard comes into being. Therefore, the new unordered_map must be defined for forward compatibility.

Function prototypes

Template < class Key,                                    //Unordered_map::key_type           class T,                                      //Unordered_map::mapped_type           class Hash = Hash<key>,                       //Unordered_map::hasher           class Pred = Equal_to<key>,                   //Unordered_map::key_ Equal           class Alloc = allocator< pair<const key,t> >  //Unordered_map::allocator_type           
Class Unordered_map;

Key indicates the type of build
T denotes the type of hash value to which the key is mapped
A hash is a function object that takes a parameter and the type is compatible with the key. The return value is type T. Note that the parameter is a const reference and the function is a const
Pred is a function object that accepts two parameters and has a type that is compatible with key. The return value is type bool. Note that the parameter is a const reference and the function is a const




member functions:
Member functions
(constructor)
Construct unordered_map (public member function)
(destructor)
Destroy unordered Map (public member function)
Operator=
Assign Content (public member function)
Capacity
Empty
Test Whether container is empty (public member function)
Size
Return Container size (public member function)
Max_size
Return Maximum size (public member function)
Iterators
Begin
Return iterator to beginning (public member function)
End
Return iterator to end (public member function)
Cbegin
Return const_iterator to beginning (public member function)
Cend
Return const_iterator to end (public member function)
Element Access
Operator[]
Access Element (public member function)
At
Access Element (public member function)
Element Lookup
Find
Get iterator to Element (public member function)
Count
Count elements with a specific key (public member function)
Equal_range
Get range of elements with specific key (public member function)
Modifiers
Emplace
Construct and insert element (public member function)
Emplace_hint
Construct and insert element with hint (public member function)
Insert
Insert Elements (public member function)
Erase
Erase Elements (public member function)
Clear
Clear Content (public member function)
Swap
Swap Content (public member function)
Buckets
Bucket_count
Return number of
buckets (public member function)
Max_bucket_count
Return Maximum number of buckets (public member function)
Bucket_size
Return Bucket Size (public member type)
Buckets
Locate element ' s bucket (public member function)
Hash Policy
Load_factor
Return load factor (public member function)
Max_load_factor
Get or set maximum load factor (public member function)
Rehash
Set number of
buckets (public member function)
Reserve
Request A capacity change (public member function)
Observers
Hash_function
Get hash Function (public member type)
Key_eq
Get key equivalence predicate (public member type)
Get_allocator
Get Allocator (public member function)














New features in c++11: unordered_map

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.