What is the data structure based on the

advertisements

In C++, map is based on a black-red tree, thus, insert/delete function will cost O(logn), and hash_map is based on a hash.

But I'm wandering that what data structure is set based?

Set is sorted as map does, so, is set also based on a black-red tree?

How its key and value stored in that tree?

And if so, what's data structure for unorder_set? Thanks!


There's no guarantee. The only thing that the standard mandates is the cost of the operations, so implementers are free to use whatever data structures they want. Typically std::set and std::map are balanced binary trees.

Also, std::unordered_set and std::unordered_map are hash tables. This I believe is actually guaranteed by the standard because you are allowed to specify the hashing function manually.