The underlying principles of SET and MAP

The underlying principles of SET and MAP
1. SET
gather underlying implementation Is it in order? Is it repeatable? Whether it can be modified Query efficiency Addition and deletion efficiency
std::set red black tree orderly no no O(logn) O(logn)
std::multiset red black tree orderly Can no O(logn) O(logn)
std::unorded_set Hash table disorder no no O(1) O(1)
2. MAP
mapping underlying implementation Is it in order (key) Whether to duplicate (key) Whether to modify (key) Query efficiency Addition and deletion efficiency
std::map red black tree have no no O(logn) O(logn)
std::multimap red black tree have Can no O(logn) O(logn)
std::unordered_map Hash table none no no O(1) O(1)
3. Summary:

In STL, although the data structures of different underlying implementations are the same, distinguishing different underlying implementations, understanding their similarities and differences, and selecting different underlying implementations according to different application scenarios are of great use in improving program performance and reducing unnecessary calculations. .

Guess you like

Origin blog.csdn.net/qq_44733706/article/details/128522839