Rereading STL source code analysis: map and set

map and set the bottom are called RBTree

First look RBTree

RBTree

Red-black tree features:

1. The root is black

2. The new node must be the red

3. The node has only two colors, black or red

4. The two nodes can not be the same red color

The same number of black nodes on any path 5

Red-black tree node design:

1. The color variable nodes representing color

2. Link pointer left left subtree

3. Link the right subtree of the right pointer

4. The parent pointer of the parent node links

5 represents the variable node values ​​value_field; pair in the map for the pair in the set only key

RBTree iterator:

1. belong to the bidirectional iterator

2.RBTree is ordered, the iterator ++ and - process is actually to find the next node in the binary tree

RBTree data structure:

1. A pointer to the head node header:

The first node:

RBTree maintained in a first node, the parent node of the head node is the root node of the tree in fact, while the parent node is the root node of the tree the first node.

Left and the left pointer points to the first node of the leftmost node of the entire tree, i.e. the minimum

Right and the right pointer points to the first node of the rightmost node to the entire tree, i.e. the maximum

2.node_count record size tree

3. a comparison element for the size of the functor

insert_equal()与insert_unique:

When insert_equal RBTree allows the same node exists, the insert, is less than the current node is down to the left; equal or equal to the right away; if the same element is inserted on the right side of the same element, such as the right child node 9 there is a 10, the insert 10 is inserted in the right child in 10

inert_unique allowed to exist in the same node RBTree, after finding the insertion position, if the value of the parent node of the insertion node position to be inserted (insert inserted in a certain position of an empty tree) the same, there are no intervening.

 

Set

set of nodes with only a key value, and therefore can not be amended, otherwise it will destroy the structure of RBTree.

Set list properties consistent with when inserting or deleting an iterator, iterator addition to this, other iterators will not fail.

Set as a red-black tree to the bottom, there is a red-black tree data structure variable t.

Map

The map is a node pair that owning the key-value characteristic, sorted according to the sorting key

And set the same, it does not affect other iterators to iterators insertion or deletion

MultiSet与MultiMap

set and multiset; map and usage mutimap are the same, but multiset and multimap using insert_equal.

 

Guess you like

Origin www.cnblogs.com/lxy-xf/p/11525381.html