![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
Nodes of a binary trees. More...
#include <agrum/tools/core/binTreeNode.h>
Public Member Functions | |
Class constructors and destructors | |
BinTreeNode (const Val &v) | |
Basic constructor: a node without parent nor children. More... | |
BinTreeNode (const BinTreeNode< Val > &from) | |
copy constructor: creates a new disconnected node with the same value as "from". More... | |
~BinTreeNode () | |
Class destructor. More... | |
Class operators | |
BinTreeNode< Val > & | operator= (const BinTreeNode< Val > &from) |
Copy operator: copy the value of from into this. More... | |
Val & | operator* () |
Alias for method value. More... | |
Class accessors and modifiers | |
Val & | value () |
Returns the value stored in a node of the binary search tree. More... | |
BinTreeNode< Val > * | child (BinTreeDir dir) const |
Returns the given child of a node. More... | |
BinTreeNode< Val > * | leftChild () const |
Returns the given child of a node. More... | |
BinTreeNode< Val > * | rightChild () const |
Returns the given child of a node. More... | |
BinTreeNode< Val > * | parent () const |
Returns the parent of a node. More... | |
BinTreeDir | parentDir () const |
Returns the direction of the edge parent->current node, if any. More... | |
BinTreeNode< Val > * | insertLeftChild (const Val &val) |
Adds a new left child to the current node. More... | |
void | insertLeftChild (BinTreeNode< Val > &new_child) |
Adds a new left child to the current node. More... | |
BinTreeNode< Val > * | insertRightChild (const Val &val) |
Adds a new left child to the current node. More... | |
void | insertRightChild (BinTreeNode< Val > &new_child) |
Adds a new right child to the current node. More... | |
BinTreeNode< Val > * | insertChild (const Val &val, BinTreeDir child_dir) |
Adds a new child to the current node. More... | |
void | insertChild (BinTreeNode< Val > &new_child, BinTreeDir child_dir) |
Adds a new child to the current node. More... | |
void | eraseLeftLink () |
Remove the link between the current node and its left child. More... | |
void | eraseRightLink () |
Remove the link between the current node and its right child. More... | |
void | eraseLink (BinTreeDir tree_dir) |
Remove the link between the current node and one of its children. More... | |
BinTreeNode< Val > * | leftmostNode () const |
Returns the leftmost node of the current tree. More... | |
BinTreeNode< Val > * | rightmostNode () const |
Returns the rightmost node of the current tree. More... | |
BinTreeNode< Val > * | root () const |
Returns the top ancestor of the current tree. More... | |
Protected Attributes | |
Val | val_ |
The value stored in a node of the tree. More... | |
BinTreeNode< Val > * | parent_ |
The parent of the node. More... | |
BinTreeDir | parent_dir_ |
the direction to follow from the parent to reach the current node. More... | |
BinTreeNode< Val > * | children_ [2] |
The children of the current node. More... | |
Nodes of a binary trees.
BinTreeNode is the base class for nodes of binary trees. It is equipped with the material to add nodes to or remove them from the tree. The class ensures that trees are always a coherent structure, that is, it is not possible to have a node X having, say, a left child, and this child having no parent or a parent different from X.
Val | The value's type storde in the gum::BinTreeNode. |
Definition at line 104 of file binTreeNode.h.
gum::BinTreeNode< Val >::BinTreeNode | ( | const Val & | v | ) |
Basic constructor: a node without parent nor children.
v | The value stored in the node. |
gum::BinTreeNode< Val >::BinTreeNode | ( | const BinTreeNode< Val > & | from | ) |
copy constructor: creates a new disconnected node with the same value as "from".
from | The node to copy. |
gum::BinTreeNode< Val >::~BinTreeNode | ( | ) |
Class destructor.
In addition to removing the node, this method updates appropriately its parent and children
BinTreeNode< Val >* gum::BinTreeNode< Val >::child | ( | BinTreeDir | dir | ) | const |
Returns the given child of a node.
dir | The direction where we loog for a child. |
void gum::BinTreeNode< Val >::eraseLeftLink | ( | ) |
Remove the link between the current node and its left child.
Note that only the link is removed, i.e., the left child is not removed itself nor, a fortiori, the left subtree of the current node. If there is no left child, the method does nothing. In particular, it does not raise any exception.
void gum::BinTreeNode< Val >::eraseLink | ( | BinTreeDir | tree_dir | ) |
Remove the link between the current node and one of its children.
Note that only the link is removed, i.e., the child is not removed itself nor, a fortiori, its subtree. If the child does not exist, the method does nothing. In particular, it does not raise any exception.
tree_dir | The direction where to remove the link. |
void gum::BinTreeNode< Val >::eraseRightLink | ( | ) |
Remove the link between the current node and its right child.
Note that only the link is removed, i.e., the right child is not removed itself nor, a fortiori, the right subtree of the current node. If there is no right child, the method does nothing. In particular, it does not raise any exception.
BinTreeNode< Val >* gum::BinTreeNode< Val >::insertChild | ( | const Val & | val, |
BinTreeDir | child_dir | ||
) |
Adds a new child to the current node.
val | The value to add. |
child_dir | The direction where to add the child. |
DuplicateElement | Raised if the current node had already a child in the child_dir subtree. |
void gum::BinTreeNode< Val >::insertChild | ( | BinTreeNode< Val > & | new_child, |
BinTreeDir | child_dir | ||
) |
Adds a new child to the current node.
new_child | The child to add. |
child_dir | The direction where to add the child. |
DuplicateElement | Raised if the current node had already a child in the child_dir direction or if new_child already has a parent . |
BinTreeNode< Val >* gum::BinTreeNode< Val >::insertLeftChild | ( | const Val & | val | ) |
Adds a new left child to the current node.
val | The value to store in the new child. |
DuplicateElement | if the current node had already a left child |
void gum::BinTreeNode< Val >::insertLeftChild | ( | BinTreeNode< Val > & | new_child | ) |
Adds a new left child to the current node.
new_child | The child to add. |
DuplicateElement | Raised if the current node had already a left child or if new_child already has a parent. |
BinTreeNode< Val >* gum::BinTreeNode< Val >::insertRightChild | ( | const Val & | val | ) |
Adds a new left child to the current node.
val | The value to store in the new child. |
DuplicateElement | if the current node had already a left child |
void gum::BinTreeNode< Val >::insertRightChild | ( | BinTreeNode< Val > & | new_child | ) |
Adds a new right child to the current node.
new_child | The child to add. |
DuplicateElement | Raised if the current node had already a right child or if new_child already has a parent. |
BinTreeNode< Val >* gum::BinTreeNode< Val >::leftChild | ( | ) | const |
Returns the given child of a node.
BinTreeNode< Val >* gum::BinTreeNode< Val >::leftmostNode | ( | ) | const |
Returns the leftmost node of the current tree.
If there is no left child, the method returns this.
Val& gum::BinTreeNode< Val >::operator* | ( | ) |
Alias for method value.
BinTreeNode< Val >& gum::BinTreeNode< Val >::operator= | ( | const BinTreeNode< Val > & | from | ) |
Copy operator: copy the value of from into this.
However, this does not change the current connections (parents and children) of this.
from | The node to copy. |
BinTreeNode< Val >* gum::BinTreeNode< Val >::parent | ( | ) | const |
Returns the parent of a node.
BinTreeDir gum::BinTreeNode< Val >::parentDir | ( | ) | const |
Returns the direction of the edge parent->current node, if any.
BinTreeNode< Val >* gum::BinTreeNode< Val >::rightChild | ( | ) | const |
Returns the given child of a node.
BinTreeNode< Val >* gum::BinTreeNode< Val >::rightmostNode | ( | ) | const |
Returns the rightmost node of the current tree.
If there is no right child, the method returns this.
BinTreeNode< Val >* gum::BinTreeNode< Val >::root | ( | ) | const |
Returns the top ancestor of the current tree.
If the current node has no parent, the the method returns this.
Val& gum::BinTreeNode< Val >::value | ( | ) |
Returns the value stored in a node of the binary search tree.
|
protected |
The children of the current node.
Definition at line 332 of file binTreeNode.h.
|
protected |
The parent of the node.
Definition at line 326 of file binTreeNode.h.
|
protected |
the direction to follow from the parent to reach the current node.
Definition at line 329 of file binTreeNode.h.
|
protected |
The value stored in a node of the tree.
Definition at line 323 of file binTreeNode.h.