The fact that the following member functions are offered by std::unordered_map suggests that it is based on a hash table, possibly a separate chain with linked lists .
bucket_count, hash_function, load_factor, max_load_count, rehash
Whether the elements are adjacent or not depends on the distributor. The defaults for unordered_map and list do not allocate items in contiguous memory. The memory for each item is allocated during its insertion.
However, you can provide a custom allocator (such as a pool manager ) that can allocate items from a pre-allocated memory pool. Still, logically adjacent elements in the data structure may not be physically close to the memory.
Thus, if going through all the elements is the most common operation, then unordered_map might not be the best solution. Performing dominant use cases through the profiler for all competing solutions will show the best solution.
In addition to this, unordered_map not the best choice for a loop for another reason. Pay attention to the word " unordered " in the name, it conveys this value - unlike list , vector or map - the order of the elements . For example, a member of the rehash function can change the relative order of elements. In fact, rehashes is automatically performed by the container when its load factor exceeds max_load_factor during any operation.
source share