#include <RedBlackTree.h>
Inheritance diagram for RedBlackTree< Data, ConfigData >:
Public Member Functions | |
RedBlackTree (ACompareNodesAlgorithm< Data, ConfigData > *Compare, DeleteTreeDataEnum DeleteTreeData=NO_DELETE_TREE_ITEM, ConfigData *pConfigData=NULL) | |
Constructor. | |
~RedBlackTree () | |
Destructor. | |
virtual Data * | Search (Data *NodeData, bool *NodeInserted) |
Find a data item. If not found, insert it. | |
virtual Data * | Find (Data *NodeData) |
Find a data item. If not found, return NULL. | |
Data * | Lookup (RedBlackTreeLookup Mode, Data *NodeData) |
Search for a value according to a mode. | |
Data * | Delete (Data *NodeData) |
Delete a node from the tree. | |
Protected Member Functions | |
RedBlackNode< Data > * | Traverse (bool Insert, Data *NodeData, bool *NodeInserted) |
Find a data item, conditionally insert it if not found. | |
void | DeleteNode (RedBlackNode< Data > **Root, RedBlackNode< Data > *Node) |
Delete a node from the tree. | |
void | DeleteNodeFix (RedBlackNode< Data > **Root, RedBlackNode< Data > *Node) |
Rebalance the tree after a deletion. | |
void | LeftRotate (RedBlackNode< Data > **Root, RedBlackNode< Data > *x) |
Rotate node one node to the left. | |
void | RightRotate (RedBlackNode< Data > **Root, RedBlackNode< Data > *y) |
Rotate node one node to the right. | |
RedBlackNode< Data > * | GetSuccessor (const RedBlackNode< Data > *Node) |
Get the smallest value greater than x. | |
RedBlackNode< Data > * | GetPredecessor (const RedBlackNode< Data > *Node) |
Get the largest value smaller than x. | |
Protected Attributes | |
RedBlackNode< Data > * | m_Root |
Root node of the tree. |
Basically a red/black balanced tree has the following properties:-*
1) Every node is either red or black (color is RED or BLACK)
2) A leaf (RBNULL pointer) is considered black
3) If a node is red then its children are black
4) Every path from a node to a leaf contains the same no of black nodes
3) & 4) above guarantee that the longest path (alternating red and black nodes) is only twice as long as the shortest path (all black nodes). Thus the tree remains fairly balanced.
Definition at line 38 of file RedBlackTree.h.
|
Definition at line 386 of file RedBlackTree.h. References RedBlackTree< Data, ConfigData >::DeleteNode(), RedBlackNode< Data >::m_Data, RedBlackTree< Data, ConfigData >::m_Root, and RedBlackTree< Data, ConfigData >::Traverse(). Referenced by TestRedBlackTree(). |
|
Definition at line 405 of file RedBlackTree.h. References RedBlackTree< Data, ConfigData >::DeleteNodeFix(), RedBlackTree< Data, ConfigData >::GetSuccessor(), RedBlackNode< Data >::m_Color, RedBlackNode< Data >::m_Data, RedBlackNode< Data >::m_Left, RedBlackNode< Data >::m_Right, and RedBlackNode< Data >::m_Up. Referenced by RedBlackTree< Data, ConfigData >::Delete(). |
|
Definition at line 445 of file RedBlackTree.h. References RedBlackTree< Data, ConfigData >::LeftRotate(), RedBlackNode< Data >::m_Color, RedBlackNode< Data >::m_Left, RedBlackNode< Data >::m_Right, RedBlackNode< Data >::m_Up, and RedBlackTree< Data, ConfigData >::RightRotate(). Referenced by RedBlackTree< Data, ConfigData >::DeleteNode(). |
|
Implements AGenericTree< Data, ConfigData >. Definition at line 145 of file RedBlackTree.h. References RedBlackNode< Data >::m_Data, RedBlackTree< Data, ConfigData >::m_Root, and RedBlackTree< Data, ConfigData >::Traverse(). Referenced by TestRedBlackTree(). |
|
Definition at line 653 of file RedBlackTree.h. References RedBlackNode< Data >::m_Left, RedBlackNode< Data >::m_Right, and RedBlackNode< Data >::m_Up. Referenced by RedBlackTree< Data, ConfigData >::Lookup(). |
|
Definition at line 627 of file RedBlackTree.h. References RedBlackNode< Data >::m_Left, RedBlackNode< Data >::m_Right, and RedBlackNode< Data >::m_Up. Referenced by RedBlackTree< Data, ConfigData >::DeleteNode(), and RedBlackTree< Data, ConfigData >::Lookup(). |
|
Definition at line 540 of file RedBlackTree.h. References RedBlackNode< Data >::m_Left, RedBlackNode< Data >::m_Right, and RedBlackNode< Data >::m_Up. Referenced by RedBlackTree< Data, ConfigData >::DeleteNodeFix(), and RedBlackTree< Data, ConfigData >::Traverse(). |
|
Definition at line 160 of file RedBlackTree.h. References RedBlackTree< Data, ConfigData >::GetPredecessor(), RedBlackTree< Data, ConfigData >::GetSuccessor(), AGenericTree< Data, ConfigData >::m_CompareNodes, AGenericTree< Data, ConfigData >::m_ConfigData, RedBlackNode< Data >::m_Data, RedBlackNode< Data >::m_Left, RedBlackNode< Data >::m_Right, and RedBlackTree< Data, ConfigData >::m_Root. Referenced by TestRedBlackTree(). |
|
Definition at line 582 of file RedBlackTree.h. References RedBlackNode< Data >::m_Left, RedBlackNode< Data >::m_Right, and RedBlackNode< Data >::m_Up. Referenced by RedBlackTree< Data, ConfigData >::DeleteNodeFix(), and RedBlackTree< Data, ConfigData >::Traverse(). |
|
Implements AGenericTree< Data, ConfigData >. Definition at line 137 of file RedBlackTree.h. References RedBlackNode< Data >::m_Data, and RedBlackTree< Data, ConfigData >::Traverse(). Referenced by TestRedBlackTree(). |
|
Definition at line 251 of file RedBlackTree.h. References RedBlackTree< Data, ConfigData >::LeftRotate(), RedBlackNode< Data >::m_Color, AGenericTree< Data, ConfigData >::m_CompareNodes, AGenericTree< Data, ConfigData >::m_ConfigData, RedBlackNode< Data >::m_Data, RedBlackNode< Data >::m_Left, RedBlackNode< Data >::m_Right, RedBlackTree< Data, ConfigData >::m_Root, RedBlackNode< Data >::m_Up, and RedBlackTree< Data, ConfigData >::RightRotate(). Referenced by RedBlackTree< Data, ConfigData >::Delete(), RedBlackTree< Data, ConfigData >::Find(), and RedBlackTree< Data, ConfigData >::Search(). |