There is nothing that can beat an array access in terms of speed, all the higher level containers like unordered_map<>
add additional work. When you can use a plain array or vector<>
, that is always the fastest you can get.
You need unordered_map<>
only if you have a sparsely populated keyspace which prohibits use of a plain array/vector due to space considerations. In that case, the unordered_map<>
can translate the keys in the sparse keyspace to a hash index into the tightly populated hash table, which in turn is nothing more or less than an array.