Summary
Assuming ordering is not important:
std::unordered_map
std::map
. This is because reads on it are O(log n)
.std::map
is good option. std::unordered_map
.Historical Context
In most languages, unordered map (aka hash based dictionaries) are the default map however in C++ you get ordered map as default map. How did that happen? Some people erroneously assume that C++ committee made this decision in their unique wisdom but the truth is unfortunately uglier than that.
It is widely believed that C++ ended up with ordered map as default because there are not too many parameters on how they can be implemented. On the other hand, hash based implementations has tons of things to talk about. So to avoid gridlocks in standardization they just got along with ordered map. Around 2005, many languages already had good implementations of hash based implementation and so it was more easier for the committee to accept new std::unordered_map
. In a perfect world, std::map
would have been unordered and we would have std::ordered_map
as separate type.
Performance
Below two graphs should speak for themselves (source):