C++0x is introducing unordered_set
which is available in boost
and many other places. What I understand is that unordered_set
is hash table with O(1)
lookup complexity. On the other hand, set
is nothing but a tree with log(n)
lookup complexity. Why on earth would anyone use set
instead of unordered_set
? i.e is there a need for set
anymore?
Unordered sets have to pay for their O(1) average access time in a few ways:
set
uses less memory than unordered_set
to store the same number of elements.set
might be faster than lookups in an unordered_set
.unordered_set
, they are often guaranteed to have better worst case complexities for set
(for example insert
).set
sorts the elements is useful if you want to access them in order.set
s with <
, <=
, >
and >=
. unordered_set
s are not required to support these operations.