What is the underlying data structure of a STL set in C++?

后端 未结 7 915
自闭症患者
自闭症患者 2020-11-29 01:11

I would like to know how a set is implemented in C++. If I were to implement my own set container without using the STL provided container, what would be the best way to go

相关标签:
7条回答
  • 2020-11-29 01:51

    cppreference says:

    Sets are usually implemented as red-black trees.

    I checked, and both libc++ and libstdc++ do use red-black trees for std::set.

    std::unordered_set was implemented with a hash table in libc++ and I presume the same for libstdc++ but didn't check.

    Edit: Apparently my word is not good enough.

    • libc++: 1 2
    • libstdc++: 1
    0 讨论(0)
提交回复
热议问题