![]() |
Elementa v8.0.0
Minimalistic library for any C++ application (C++11 and up)
|
Mathematical trees that use underlying graphs.

Classes | |
| class | elementa::adts::Tree< Vertex, Edge > |
| This class is the base for any tree implementation. More... | |
| class | elementa::adts::Szer_TreeText< Vertex, Edge > |
| Serializer of any tree as a text with a tree-like structure. More... | |
Functions | |
| void | elementa::adts::Szer_TreeText< Vertex, Edge >::ser (elementa::base::OutSerCh &chout, const TreeType &tree) |
| Serialize. More... | |
Consulting methods | |
| BGraph::viterator | elementa::adts::Tree< Vertex, Edge >::root (void) const |
| Return an iterator to the root of the tree or to end() if empty. More... | |
| graphs::size_edge | elementa::adts::Tree< Vertex, Edge >::depth (const typename BGraph::viterator &n) const |
| Return the depth of the given node in the tree (0 for root). More... | |
Modification methods | |
| BGraph::viterator | elementa::adts::Tree< Vertex, Edge >::setRoot (const Vertex &v) |
| If the tree has a root, changes its value by V; otherwise, add V as root. More... | |
| BGraph::viterator | elementa::adts::Tree< Vertex, Edge >::addChild (const typename BGraph::viterator &parent, const Vertex &v, const Edge &e) |
| Add a new child to a given node, as the last child of the node. More... | |
| void | elementa::adts::Tree< Vertex, Edge >::eraseNode (const typename BGraph::viterator &node) |
| Erase a node and all its descendants. More... | |
| void | elementa::adts::Tree< Vertex, Edge >::splice (Tree &oth, const Edge &edgeval) |
| Move OTH to this tree, connecting its root to this root, and clearing it. More... | |
| class elementa::adts::Tree |
This class is the base for any tree implementation.
The particular graph implementation that is used for supporting the tree is provided in the constructors, not becoming part of the tree type.
\code
using MyTree = Tree< char, double>;
MyTree tree{SparseGraph<MyTree::BGraph::VertexType,
MyTree::BGraph::EdgeType>{}};
\endcode
Public Types | |
Types, consts, etc. | |
| using | BGraph = graphs::Graph< Vertex, Edge > |
| Base Graph class of any particular graph implementation used in the tree. More... | |
| using | Ptr = std::shared_ptr< Tree > |
| Pointer to a tree. More... | |
| using | Forest = std::vector< Ptr > |
| A forest is a set of pointers to trees. More... | |
Public Member Functions | |
Constructors | |
| Tree (const BGraph &exemplar) | |
| Constructor. More... | |
| Tree (const Tree &oth) | |
| Copy constructor. More... | |
| Tree (Tree &&oth) | |
| Move constructor. More... | |
| Tree & | operator= (const Tree &oth) |
| Copy assignment. More... | |
| Tree & | operator= (Tree &&oth) |
| Move assignment. More... | |
| virtual | ~Tree (void) |
| Virtual destructor. More... | |
Consulting methods | |
| bool | empty (void) const |
| Return TRUE if the tree is empty. More... | |
| BGraph & | graph (void) const |
| return a reference to the internal graph. More... | |
| BGraph::viterator | root (void) const |
| Return an iterator to the root of the tree or to end() if empty. More... | |
| graphs::size_edge | depth (const typename BGraph::viterator &n) const |
| Return the depth of the given node in the tree (0 for root). More... | |
Modification methods | |
| void | clear (void) |
| Clear the tree. More... | |
| BGraph::viterator | setRoot (const Vertex &v) |
| If the tree has a root, changes its value by V; otherwise, add V as root. More... | |
| BGraph::viterator | addChild (const typename BGraph::viterator &parent, const Vertex &v, const Edge &e) |
| Add a new child to a given node, as the last child of the node. More... | |
| void | eraseNode (const typename BGraph::viterator &node) |
| Erase a node and all its descendants. More... | |
| void | splice (Tree &oth, const Edge &edgeval) |
| Move OTH to this tree, connecting its root to this root, and clearing it. More... | |
| using elementa::adts::Tree< Vertex, Edge >::BGraph = graphs::Graph<Vertex,Edge> |
| using elementa::adts::Tree< Vertex, Edge >::Ptr = std::shared_ptr<Tree> |
| using elementa::adts::Tree< Vertex, Edge >::Forest = std::vector<Ptr> |
|
inline |
Constructor.
| exemplar | is just used to get an empty clone of a particular supporting graph type. |
|
inline |
|
inline |
|
inlinevirtual |
|
inline |
|
inline |
|
inline |
Return TRUE if the tree is empty.
Definition at line 126 of file trees.h.
References ELE_CODE_TRACE_OFF, and elementa::base::to_number().
Referenced by elementa::adts::Szer_TreeText< Vertex, Edge >::ser(), and elementa::adts::Tree< Vertex, Edge >::splice().
|
inline |
return a reference to the internal graph.
Definition at line 132 of file trees.h.
Referenced by elementa::adts::Szer_TreeText< Vertex, Edge >::ser().
|
inline |
Clear the tree.
Definition at line 148 of file trees.h.
Referenced by elementa::adts::Tree< Vertex, Edge >::splice().
| class elementa::adts::Szer_TreeText |
Serializer of any tree as a text with a tree-like structure.
Mainly useful for visualization.


Public Types | |
| using | TreeType = Tree< Vertex, Edge > |
| using | SType = Tree< Vertex, Edge > |
| To access the Sble type parameter of this type. More... | |
| using | RDeserType = Tree< Vertex, Edge > |
| To access the ReturnDeserType type parameter of this type. More... | |
| using | RSerType = Tree< Vertex, Edge > |
| To access the ReturnSerType type parameter of this type. More... | |
Public Member Functions | |
| Szer_TreeText (elementa::base::Serializer< Vertex > &szerv, elementa::base::Serializer< Edge > &szere) | |
| Constructor: configure the serializer. More... | |
| void | ser (elementa::base::OutSerCh &chout, const TreeType &tree) |
| Serialize. More... | |
| virtual void | ser (OutSerCh &chout, const Tree< Vertex, Edge > &obj) |
| Serializes an object, writing the resulting chars into CHOUT. More... | |
| virtual void | deser (InSerCh &chin, Tree< Vertex, Edge > &obj) |
| Deserializes an object from a sequence of chars in CHIN. More... | |
| using elementa::adts::Szer_TreeText< Vertex, Edge >::TreeType = Tree<Vertex,Edge> |
|
inherited |
To access the Sble type parameter of this type.
Definition at line 193 of file serializers.h.
|
inherited |
To access the ReturnDeserType type parameter of this type.
Definition at line 196 of file serializers.h.
|
inherited |
To access the ReturnSerType type parameter of this type.
Definition at line 199 of file serializers.h.
|
inline |
|
inlinevirtualinherited |
Serializes an object, writing the resulting chars into CHOUT.
Must throw if any error during serialization, including channel errors (in that case, the channel can be left in the state it was when the error occurred).
Definition at line 206 of file serializers.h.
|
inlinevirtualinherited |
Deserializes an object from a sequence of chars in CHIN.
Must change the content of OBJ with the result. Throw if any error during serialization, including channel errors (in that case, the channel and the object are left in the state they were at the moment of the error).
Definition at line 214 of file serializers.h.
| Tree< Vertex, Edge >::BGraph::viterator elementa::adts::Tree< Vertex, Edge >::root | ( | void | ) | const |
#include <elementa/adts/trees.h>
Return an iterator to the root of the tree or to end() if empty.
Definition at line 242 of file trees.h.
References elementa::adts::graphs::Graph< Vertex, Edge >::VRange_All::begin(), elementa::adts::graphs::Graph< Vertex, Edge >::VRange_All::end(), elementa::adts::graphs::Graph< Vertex, Edge >::size_vertices(), and elementa::adts::graphs::Graph< Vertex, Edge >::vrangeAll().
Referenced by elementa::adts::Szer_TreeText< Vertex, Edge >::ser(), and elementa::adts::Tree< Vertex, Edge >::splice().
| graphs::size_edge elementa::adts::Tree< Vertex, Edge >::depth | ( | const typename BGraph::viterator & | n | ) | const |
#include <elementa/adts/trees.h>
Return the depth of the given node in the tree (0 for root).
This method has to traverse all parents of N to calculate the depth.
Definition at line 249 of file trees.h.
References elementa::adts::graphs::Graph< Vertex, Edge >::ERange_Entering::begin(), elementa::adts::graphs::Graph< Vertex, Edge >::erangeEntering(), elementa::base::MultIterator< Data, BIDIR >::isEnd(), and elementa::adts::graphs::Graph< Vertex, Edge >::origin().
Referenced by elementa::adts::Szer_TreeText< Vertex, Edge >::ser().
| Tree< Vertex, Edge >::BGraph::viterator elementa::adts::Tree< Vertex, Edge >::setRoot | ( | const Vertex & | v | ) |
#include <elementa/adts/trees.h>
If the tree has a root, changes its value by V; otherwise, add V as root.
Return an iterator to the new node.
Definition at line 269 of file trees.h.
References elementa::adts::graphs::Graph< Vertex, Edge >::VRange_All::begin(), ELE_CODE_TRACE_OFF, elementa::adts::graphs::Graph< Vertex, Edge >::insert(), elementa::adts::graphs::Graph< Vertex, Edge >::size_vertices(), and elementa::adts::graphs::Graph< Vertex, Edge >::vrangeAll().
| Tree< Vertex, Edge >::BGraph::viterator elementa::adts::Tree< Vertex, Edge >::addChild | ( | const typename BGraph::viterator & | parent, |
| const Vertex & | v, | ||
| const Edge & | e | ||
| ) |
#include <elementa/adts/trees.h>
Add a new child to a given node, as the last child of the node.
Return an iterator to the new child node.
Definition at line 285 of file trees.h.
References elementa::adts::graphs::Graph< Vertex, Edge >::connect(), ELE_CODE_INVARG, ELE_CODE_TRACE_OFF, elementa::adts::graphs::Graph< Vertex, Edge >::insert(), elementa::base::MultIterator< Data, BIDIR >::isEnd(), elementa::base::MultIterator< Data, BIDIR >::to_string(), and elementa::base::MultIterator< Data, BIDIR >::valid().
| void elementa::adts::Tree< Vertex, Edge >::eraseNode | ( | const typename BGraph::viterator & | node | ) |
#include <elementa/adts/trees.h>
Erase a node and all its descendants.
Definition at line 305 of file trees.h.
References elementa::adts::graphs::Graph< Vertex, Edge >::ERange_DepthFirst::begin(), elementa::adts::graphs::Graph< Vertex, Edge >::connection(), ELE_CODE_TRACE_OFF, elementa::adts::graphs::Graph< Vertex, Edge >::erangeDepthFirst(), and elementa::adts::graphs::Graph< Vertex, Edge >::erase().
| void elementa::adts::Tree< Vertex, Edge >::splice | ( | Tree< Vertex, Edge > & | oth, |
| const Edge & | edgeval | ||
| ) |
#include <elementa/adts/trees.h>
Move OTH to this tree, connecting its root to this root, and clearing it.
EDGEVAL must have the value to annotate in the edge that connects this root with OTH root.
Definition at line 327 of file trees.h.
References elementa::adts::Tree< Vertex, Edge >::clear(), elementa::adts::graphs::Graph< Vertex, Edge >::connect(), ELE_CODE_TRACE_OFF, elementa::adts::Tree< Vertex, Edge >::empty(), elementa::adts::Tree< Vertex, Edge >::root(), and elementa::adts::graphs::Graph< Vertex, Edge >::splice().
| void elementa::adts::Szer_TreeText< Vertex, Edge >::ser | ( | elementa::base::OutSerCh & | chout, |
| const TreeType & | tree | ||
| ) |
#include <elementa/adts/trees.h>
Serialize.
Definition at line 356 of file trees.h.
References elementa::adts::Tree< Vertex, Edge >::depth(), ELE_CODE_PLACE, ELE_CODE_TRACE_OFF, elementa::adts::Tree< Vertex, Edge >::empty(), elementa::adts::Tree< Vertex, Edge >::graph(), elementa::adts::Tree< Vertex, Edge >::root(), elementa::base::serch_isgood(), and elementa::adts::graphs::Graph< Vertex, Edge >::size_edges().