Purifying flames Purifying flames - 1 month ago 13
C++ Question

Comparing unordered_map vs unordered_set

First of all, what is the main difference between them?

The only thing i've found is that

unordered_set
has no operator
[]
.
How should i access an element in
unordered_set
, since there is no
[]
?

Which container is using random access to memory(or both)?

And which one of them faster in any sense or using less memory?

Answer

They are nearly identical. unordered_set only contains keys, and no values. There is no mapping from a key to a value, so no need for an operator[]. unordered_map maps a key to a value.

You can use the various find methods within unordered_set to locate things.

Comments