Considering the positive effect of caching and data locality when searching in primary memory, I tend to use std::vector<>
with std::pair<>
-like key-value items and perform linear searches for both, if I know that the total amount of key-value items will never be "too large" to severely impact performance.
Lately I've been in lots of situations where I know beforehand that I will have huge amounts of key-value items and have therefore opted for std::map<>
from the beginning.
I'd like to know how you make your decisions for the proper container in situations like the ones described above.
Do you
- always use
std::vector<>
(or similar)? - always use
std::map<>
(or similar)? - have a gut feeling for where in the item-count range one is preferable over the other?
- something entirely different?
Thanks!