Does clear () affect the number of buckets std :: unordered_set?

There are many answers using std::vector , but what about std::unordered_set ?

My real question (closely related) is this; Is it efficient to reuse the same unordered set, cleaning it before each use, if I reserve what I know for a reasonable size in advance?

+6
source share
1 answer

Formal answer: it depends on the implementation.

Unofficial answer: unordered_set inside is an array of (some) bucket, and most likely the implementation is consistent with vector , so this array will not be deleted when clear() called. Therefore, calling clear() is likely to bring some benefit.

+6
source

Source: https://habr.com/ru/post/974858/


All Articles