I\'ve heard many people say that if the number of expected elements in the container is relatively small, it is better to use std::vector
instead of std::
Basically, maps are used for lookup.
But, sometimes std::vector
can be used instead of std::map
even for look up.
If there are going to be very less elements in your key-value pairs, then you can go for an iterative search using key even in std::vector<std::pair<x,y>>
.
This is because of the fact that hashing takes time, especially for hashing strings and for other operations in map like storing data in heap.
You would only see a better difference in std::map, if you have more elements in which you have to lookup and also when you want to do frequent lookup in the list of elements that you have.