In my application I have the following requirements -
The data structure will be populated just once with some values (not key/value pairs). The values may be repeated but I want the data structure to store them once only.
I will be iterating 100s of times through all the elements of the data structure created above. The order in which the elements appear in the iteration is immaterial.
Constraint 1 suggests that I will either have to use set or unordered_set as data is not in the form of key value pairs.
Now set insertion is costlier than unordered_set insertion but the data structure is populated only once in the beginning of my program.
I believe the deciding factor will be how fast I can iterate through all the elements of the data structure. I am not sure whether set or unordered_set will be faster for this purpose. I believe the standard makes no mention of this fact as this operation will be O(n) for either data structure. But I wonder for which data structure iterator.next() will be faster.
set
, then once finished copy/move everything into avector
for fast iteration. Thus the question is: do you need anything else than iteration once it is frozen ? (like fast look-up) – Edeestd::lower_bound
:-S – Gutenbergstd::less<T*>
... – Gutenbergunordered_set
in finding though (depending on the number of elements) because it requires log(N) cache lines to be loaded whereas a hash table loads a fixed number of cache lines (for a given load factor). – Edee