Unordered associative containers (C++)
| C++ Standard Library |
|---|
| Containers |
| C standard library |
In C++, unordered associative containers or unordered associative collections are a group of class templates in the C++ Standard Library that implement hash table variants. Being templates, they can be used to store arbitrary elements, such as integers or custom classes. Like all other standard library components, they reside in namespace std.
The following containers are defined in the current revision of the C++ standard:
std::unordered_set<T>std::unordered_map<K, V>std::unordered_multiset<T>std::unordered_multimap<K, V>.
Each of these containers differ only on constraints placed on their elements.
std::unordered_set and std::unordered_multiset are declared in header <unordered_set>, while std::unordered_map and std::unordered_multimap are declared in header <unordered_map>.
There are also versions of these collections in namespace std::pmr (for polymorphic memory resources). These versions specify the optional template parameter Allocator as std::pmr::polymorphic_allocator.
The unordered associative containers are similar to the associative containers in the C++ Standard Library but have different constraints. As their name implies, the elements in the unordered associative containers are not ordered. This is due to the use of hashing to store objects. The containers can still be iterated through like a regular associative container.
std::unordered_map and std::unordered_set are essentially (respectively) equivalent to java.util.HashMap and java.util.HashSet from Java, System.Collections.Generic.Dictionary and System.Collections.Generic.HashSet from .NET, or std::collections::HashMap and std::collections::HashSet from Rust.