tags:

views:

113

answers:

2

Is there any principle to choose one over another between hash_map and map in STL?

+3  A: 

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.

vtorhonen
+1  A: 

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:

http://stackoverflow.com/questions/2189189/map-vs-hash-map-in-c

Salgar