Is there any principle to choose one over another between hash_map and map in STL?
Asked
Active
Viewed 1,394 times
2 Answers
3
hash_map
is useful if you are only looking elements by their key. A possible use-case for a hash_map
would be a dictionary. If the elements need to be in order map
is the container for that.
And just for clarification (because of the usage of the word "STL"): hash_map
isn't yet part of the C++ Standard Library, but it has been implemented in several C++ compilers. unordered_map
was proposed in the C++ Technical Report 1, and it will be defined in the next edition of the standard, C++0x.

thevilledev
- 2,367
- 1
- 15
- 19
1
hash_map uses a traditional hash_table for its storage and a map uses a red-black tree for it's storage.
Here is a very similar question: