std::unordered_map
Think of this container as an unsorted version of std::map
. It associates keys with values but without imposing any order. Instead, it banks on hashing for swift operations.
Purpose and suitability
std::unordered_map
is a hash table-based key-value container in the STL. Its core strengths are as follows:
- Fast average-case key-based access, insertion, and removal
- Ability to maintain a key-value association
This container is the go-to in the following circumstances:
- When insertions, deletions, and lookups must be swift on average
- When the order of elements isn’t a concern
Ideal use cases
The following are some of the ideal use cases for std::unordered_map
:
- Fast associative lookups: When you need quick access to values based on unique keys,
std::unordered_map
provides average constant-time complexity forsearch
,insert
, anddelete
operations - Cache systems: When implementing cache mechanisms where the...