![]() |
TerraLib 4.1
|
Template class for Red-Black trees. More...
#include <TeRedBlackTree.h>
Classes | |
| class | internal_iterator |
| Iterators class for the tree. It is used to abstract walking on the tree. More... | |
Public Types | |
| typedef NODE * | REDBLACKNODEPOINTER |
| Export node type. | |
| typedef NODE::TeRedBlackNodeData | TeRedBlackNodeData |
| Export node data type. | |
| typedef internal_iterator< NODE > | iterator |
| Exports iterator type. | |
Public Member Functions | |
| TeRBTree () | |
| Constructor. | |
| virtual | ~TeRBTree () |
| Destructor. | |
| bool | IsEmpty (void) const |
| Returns true if the tree is empty otherwise returns false. | |
| unsigned int | Size (void) const |
| Returns the number of nodes in the tree, excluding the nil_ one. | |
| virtual void | Delete (NODE *z) |
| Removes the node from the tree and do rebalancing. | |
| virtual NODE * | Successor (NODE *x) const |
| Returns the sucessor of a given node or zero if not. | |
| virtual NODE * | Predecessor (NODE *x) const |
| Returns the predecessor of a given node or zero if not. | |
| NODE * | First (void) const |
| Returns the leftmost node in the tree, or zero if not. | |
| NODE * | Last (void) const |
| Returns the rightmost node in the tree, or zero if not. | |
| virtual bool | GetFirst (TeRedBlackNodeData &d) |
| Return the first element in the tree and removes it. | |
| void | Clear (void) |
| Removes all nodes from the tree (excepty the nil node). Clear memory. | |
| virtual void | WriteToFile (const string &fileName) const |
| Write the node's data to a file. The data must implement a methos called: void ToString(void). | |
| iterator | begin (void) |
| Returns an iterator to the leftmost node of the tree. | |
| iterator | end (void) |
| Returns a reference iterator indicating the end of a tree. | |
| void | erase (iterator &it) |
| Erases a node pointed by an interator. | |
Protected Member Functions | |
| virtual void | LeftRotate (NODE *x, NODE *&root) |
| Left rotation. | |
| virtual void | RightRotate (NODE *y, NODE *&root) |
| Right rotation. | |
| void | InsertFixUp (NODE *&n, NODE *&root) |
| Must be called after an insert, to fix-up the tree. | |
| void | DeleteFixUp (NODE *x, NODE *x_parent, NODE *&root) |
| Must be called after a deletion, to fix-up the tree. | |
| virtual void | WriteToFile (NODE *n, string &strRepres) const |
| Only to be used by the public method, walking on the tree. | |
| void | Erase (NODE *n) |
| Removes the node and all node below it and doesn't do rebalancing. Used to free the memory. | |
Protected Attributes | |
| NODE * | nil_ |
| Reference node. | |
| NODE * | root_ |
| Tree's root. | |
| unsigned int | nodeCount_ |
| Count the number of nodes in the tree (excluding nil_ node). | |
Template class for Red-Black trees.
This class contains the common operations in a Red-Black Tree. It can be used like a framework. Extend the methods like "Insert" and "Search" to walk and to do some usefull things. You will use the methods for Rotation, Insert Propagation, Delete Propagation, Sucessor, Predecessor, IsEmpty, Clear. This tree is based on the algorithm of Cormen's book. The only difference is when a node being deleted has two children its successor node is relinked into its place, rather than copied, so that the only iterators invalidated are those referring to the deleted node. Every data used in nodes must implements a ToString() method.
| typedef internal_iterator<NODE> TeREDBLACK::TeRBTree< NODE >::iterator |
Exports iterator type.
| typedef NODE* TeREDBLACK::TeRBTree< NODE >::REDBLACKNODEPOINTER |
Export node type.
| typedef NODE::TeRedBlackNodeData TeREDBLACK::TeRBTree< NODE >::TeRedBlackNodeData |
Export node data type.
| TeREDBLACK::TeRBTree< NODE >::TeRBTree | ( | ) | [inline] |
Constructor.
| virtual TeREDBLACK::TeRBTree< NODE >::~TeRBTree | ( | ) | [inline, virtual] |
Destructor.
| iterator TeREDBLACK::TeRBTree< NODE >::begin | ( | void | ) | [inline] |
Returns an iterator to the leftmost node of the tree.
| void TeREDBLACK::TeRBTree< NODE >::Clear | ( | void | ) | [inline] |
Removes all nodes from the tree (excepty the nil node). Clear memory.
| virtual void TeREDBLACK::TeRBTree< NODE >::Delete | ( | NODE * | z | ) | [inline, virtual] |
Removes the node from the tree and do rebalancing.
| void TeREDBLACK::TeRBTree< NODE >::DeleteFixUp | ( | NODE * | x, |
| NODE * | x_parent, | ||
| NODE *& | root | ||
| ) | [inline, protected] |
Must be called after a deletion, to fix-up the tree.
| iterator TeREDBLACK::TeRBTree< NODE >::end | ( | void | ) | [inline] |
Returns a reference iterator indicating the end of a tree.
| void TeREDBLACK::TeRBTree< NODE >::Erase | ( | NODE * | n | ) | [inline, protected] |
Removes the node and all node below it and doesn't do rebalancing. Used to free the memory.
| void TeREDBLACK::TeRBTree< NODE >::erase | ( | iterator & | it | ) | [inline] |
Erases a node pointed by an interator.
| NODE* TeREDBLACK::TeRBTree< NODE >::First | ( | void | ) | const [inline] |
Returns the leftmost node in the tree, or zero if not.
| virtual bool TeREDBLACK::TeRBTree< NODE >::GetFirst | ( | TeRedBlackNodeData & | d | ) | [inline, virtual] |
Return the first element in the tree and removes it.
| void TeREDBLACK::TeRBTree< NODE >::InsertFixUp | ( | NODE *& | n, |
| NODE *& | root | ||
| ) | [inline, protected] |
Must be called after an insert, to fix-up the tree.
| bool TeREDBLACK::TeRBTree< NODE >::IsEmpty | ( | void | ) | const [inline] |
Returns true if the tree is empty otherwise returns false.
| NODE* TeREDBLACK::TeRBTree< NODE >::Last | ( | void | ) | const [inline] |
Returns the rightmost node in the tree, or zero if not.
| virtual void TeREDBLACK::TeRBTree< NODE >::LeftRotate | ( | NODE * | x, |
| NODE *& | root | ||
| ) | [inline, protected, virtual] |
Left rotation.
| virtual NODE* TeREDBLACK::TeRBTree< NODE >::Predecessor | ( | NODE * | x | ) | const [inline, virtual] |
Returns the predecessor of a given node or zero if not.
| virtual void TeREDBLACK::TeRBTree< NODE >::RightRotate | ( | NODE * | y, |
| NODE *& | root | ||
| ) | [inline, protected, virtual] |
Right rotation.
| unsigned int TeREDBLACK::TeRBTree< NODE >::Size | ( | void | ) | const [inline] |
Returns the number of nodes in the tree, excluding the nil_ one.
| virtual NODE* TeREDBLACK::TeRBTree< NODE >::Successor | ( | NODE * | x | ) | const [inline, virtual] |
Returns the sucessor of a given node or zero if not.
| virtual void TeREDBLACK::TeRBTree< NODE >::WriteToFile | ( | const string & | fileName | ) | const [inline, virtual] |
Write the node's data to a file. The data must implement a methos called: void ToString(void).
| virtual void TeREDBLACK::TeRBTree< NODE >::WriteToFile | ( | NODE * | n, |
| string & | strRepres | ||
| ) | const [inline, protected, virtual] |
Only to be used by the public method, walking on the tree.
NODE* TeREDBLACK::TeRBTree< NODE >::nil_ [protected] |
Reference node.
unsigned int TeREDBLACK::TeRBTree< NODE >::nodeCount_ [protected] |
Count the number of nodes in the tree (excluding nil_ node).
NODE* TeREDBLACK::TeRBTree< NODE >::root_ [protected] |
Tree's root.