I have a question about lookup speed. I want to know which STL container can produce the fastest lookup time in C++. unordered_map
comes to my mind since it is implemented by hash map, but I am afraid its performance is penalized because it contains key-value pair, whereas set
contains only key. I guess the answer will depends on 1) the data type of key; and 2) the STL implementation of set
.
In other words, which container is faster to search for the existence of an key, is it set, unordered_map, or something else?
Edit:
Would appreciate the answer with more explanation on the implementation or mechanism of the container. For instance, unordered_map is fast because it's implemented with hashmap. That will be more helpful than saying "it depends on the need". Thanks!