2

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

Thomson
  • 20,586
  • 28
  • 90
  • 134
  • possible duplicate of [map vs. hash_map in C++](http://stackoverflow.com/questions/2189189/map-vs-hash-map-in-c) – jpalecek Jul 27 '10 at 09:42

2 Answers2

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:

map vs. hash_map in C++

Community
  • 1
  • 1
Salgar
  • 7,687
  • 1
  • 25
  • 39