Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
Data Structures | Public Types | Public Member Functions | Friends
ext::forward_tree< T > Class Template Reference

Class introducing a forward_tree with interface trying to be close to the interface of standard library containers. More...

#include <forward_tree.hpp>

Data Structures

class  const_postfix_iterator
 The iterator type over structure of the tree following postorder traversal. More...
 
class  const_prefix_iterator
 The iterator type over structure of the tree following preorder traversal. More...
 
class  const_structure_iterator
 The iterator type over structure of the tree representing nodes and node_ends. More...
 

Public Types

typedef ext::vector< forward_tree >::const_iterator const_children_iterator
 The iterator type over children of the node. More...
 
typedef ext::vector< forward_tree >::iterator children_iterator
 The iterator type over children of the node. More...
 

Public Member Functions

T & getData ()
 Getter of the value in the root node. More...
 
const T & getData () const
 Getter of the value in the root node. More...
 
ext::vector< forward_tree > & getChildren ()
 Getter of children of the root node. More...
 
const ext::vector< forward_tree > & getChildren () const
 Getter of children of the root node. More...
 
const_children_iterator insert (const_children_iterator position, forward_tree< T > &&value)
 Inserts a subtree into a forward_tree. More...
 
const_children_iterator insert (const_children_iterator position, const forward_tree< T > &value)
 Inserts a subtree into a forward_tree. More...
 
const_children_iterator insert (const_children_iterator position, const_children_iterator begin, const_children_iterator end)
 Insert helper for insertion specified by position in children and inserted subtrees given by range of iterators. More...
 
template<class Iterator >
const_children_iterator insert (const_children_iterator position, Iterator begin, Iterator end)
 Inserts a subtrees into a forward_tree. The subtrees are nullary nodes having value given by values in the range begin to end. More...
 
 forward_tree (T &&data, ext::vector< forward_tree > &&children)
 Constructor of the forward_tree from value to be stored in the root node and children trees. More...
 
 forward_tree (const T &data, const ext::vector< forward_tree > &subtrees)
 Constructor of the forward_tree from value to be stored in the root node and children trees. More...
 
template<typename ... Types>
 forward_tree (const T &data, Types ... subtrees)
 Constructor of the forward_tree from value to be stored in the root node and pack of children trees. More...
 
template<typename ... Types>
 forward_tree (T &&data, Types ... subtrees)
 Constructor of the forward_tree from value to be stored in the root node and pack of children trees. More...
 
template<typename Iterator >
 forward_tree (const T &data, Iterator begin, Iterator end)
 Constructor of the forward_tree from value to be stored in the root node and range of values to construct nullary nodes from range of values. More...
 
 forward_tree (const T &data, const_children_iterator begin, const_children_iterator end)
 Constructor of the forward_tree from value to be stored in the root node and range of subtrees. More...
 
const_children_iterator begin () const
 Getter of a children iterator to the begining of children. More...
 
children_iterator begin ()
 Getter of a children iterator to the begining of children. More...
 
const_children_iterator end () const
 Getter of a children iterator one after the last child. More...
 
children_iterator end ()
 Getter of a children iterator one after the last child. More...
 
const_prefix_iterator prefix_begin () const
 Getter of the prefix iterator to the root node. More...
 
const_prefix_iterator prefix_end () const
 Getter of the prefix iterator one after the last node in the prefix traversal. More...
 
const_postfix_iterator postfix_begin () const
 Getter of the postfix iterator to the first node in the postfix traversal. More...
 
const_postfix_iterator postfix_end () const
 Getter of the postfix iterator one after the last node in the postfix traversal. More...
 
const_structure_iterator structure_begin () const
 Getter of the structure iterator to the first node in the traversal. More...
 
const_structure_iterator structure_end () const
 Getter of the structure iterator to one after the last node in the traversal. More...
 
void push_back (ext::forward_tree< T > &&value)
 Pushbacks a subtree after last child of a tree. More...
 
void push_back (const ext::forward_tree< T > &value)
 Pushbacks a subtree after last child of a tree. More...
 
void push_back (T &&value)
 Pushbacks a nullary node after last child of a tree. More...
 
void push_back (const T &value)
 Pushbacks a nullary node after last child of a tree. More...
 
children_iterator erase (const_children_iterator position)
 Erases a subtree from a tree on given by position. More...
 
template<class ... Indexes>
const T & operator() (Indexes ... indexes) const
 Access value given indexes of chindren allong the selection path. More...
 
const T & operator() (std::initializer_list< size_t > indexes) const
 Access value given indexes of chindren allong the selection path. More...
 
template<class ... Indexes>
T & operator() (Indexes ... indexes)
 Access value given indexes of chindren allong the selection path. More...
 
T & operator() (std::initializer_list< size_t > indexes)
 Access value given indexes of chindren allong the selection path. More...
 
bool operator== (const forward_tree &other) const
 Equality comparison operator. More...
 
auto operator<=> (const forward_tree &other) const
 Less comparison operator. More...
 
std::ostream & nicePrint (std::ostream &os) const
 Internal method of printing a tree into a stream. More...
 

Friends

void swap (forward_tree &first, forward_tree &second)
 Swap method of two forward trees. More...
 

Detailed Description

template<class T>
class ext::forward_tree< T >

Class introducing a forward_tree with interface trying to be close to the interface of standard library containers.

The tree is a hierarchical structure of nodes with parent child relationship, where the children are ordered and indexed by integers.

Nodes of the forward tree do not store pointers to their parent node.

Template Parameters
Tthe type of values inside nodes of the forward_tree

Member Typedef Documentation

◆ children_iterator

template<class T >
typedef ext::vector<forward_tree>::iterator ext::forward_tree< T >::children_iterator

The iterator type over children of the node.

◆ const_children_iterator

template<class T >
typedef ext::vector<forward_tree>::const_iterator ext::forward_tree< T >::const_children_iterator

The iterator type over children of the node.

Constructor & Destructor Documentation

◆ forward_tree() [1/6]

template<class T >
ext::forward_tree< T >::forward_tree ( T &&  data,
ext::vector< forward_tree< T > > &&  children 
)
inline

Constructor of the forward_tree from value to be stored in the root node and children trees.

Parameters
datathe value to be stored in the root
childrenlist of subtrees

◆ forward_tree() [2/6]

template<class T >
ext::forward_tree< T >::forward_tree ( const T &  data,
const ext::vector< forward_tree< T > > &  subtrees 
)
inline

Constructor of the forward_tree from value to be stored in the root node and children trees.

Parameters
datathe value to be stored in the root
childrenlist of subtrees

◆ forward_tree() [3/6]

template<class T >
template<typename ... Types>
ext::forward_tree< T >::forward_tree ( const T &  data,
Types ...  subtrees 
)
inline

Constructor of the forward_tree from value to be stored in the root node and pack of children trees.

Template Parameters
Types... pack of types convertible to forward_trees
Parameters
datathe value to be stored in the root
subtrees... pack of subtrees

◆ forward_tree() [4/6]

template<class T >
template<typename ... Types>
ext::forward_tree< T >::forward_tree ( T &&  data,
Types ...  subtrees 
)
inline

Constructor of the forward_tree from value to be stored in the root node and pack of children trees.

Template Parameters
Types... pack of types convertible to forward_trees
Parameters
datathe value to be stored in the root
subtrees... pack of subtrees

◆ forward_tree() [5/6]

template<class T >
template<typename Iterator >
ext::forward_tree< T >::forward_tree ( const T &  data,
Iterator  begin,
Iterator  end 
)
inline

Constructor of the forward_tree from value to be stored in the root node and range of values to construct nullary nodes from range of values.

Parameters
datathe value to be stored in the root
beginthe iterator to the begining of values range
endthe iterator to the end of values range

◆ forward_tree() [6/6]

template<class T >
ext::forward_tree< T >::forward_tree ( const T &  data,
const_children_iterator  begin,
const_children_iterator  end 
)
inline

Constructor of the forward_tree from value to be stored in the root node and range of subtrees.

Parameters
datathe value to be stored in the root
beginthe iterator to the begining of subtree range
endthe iterator to the end of subtree range

Member Function Documentation

◆ begin() [1/2]

template<class T >
children_iterator ext::forward_tree< T >::begin ( )
inline

Getter of a children iterator to the begining of children.

Returns
iterator to the first child
Here is the call graph for this function:

◆ begin() [2/2]

template<class T >
const_children_iterator ext::forward_tree< T >::begin ( ) const
inline

Getter of a children iterator to the begining of children.

Returns
iterator to the first child
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end() [1/2]

template<class T >
children_iterator ext::forward_tree< T >::end ( )
inline

Getter of a children iterator one after the last child.

Returns
iterator one after the last child
Here is the call graph for this function:

◆ end() [2/2]

template<class T >
const_children_iterator ext::forward_tree< T >::end ( ) const
inline

Getter of a children iterator one after the last child.

Returns
iterator one after the last child
Here is the call graph for this function:
Here is the caller graph for this function:

◆ erase()

template<class T >
children_iterator ext::forward_tree< T >::erase ( const_children_iterator  position)
inline

Erases a subtree from a tree on given by position.

Parameters
positionthe specification of position in children where to erase the subtree
Here is the call graph for this function:

◆ getChildren() [1/2]

template<class T >
ext::vector< forward_tree > & ext::forward_tree< T >::getChildren ( )
inline

Getter of children of the root node.

Returns
children of the root node
Here is the caller graph for this function:

◆ getChildren() [2/2]

template<class T >
const ext::vector< forward_tree > & ext::forward_tree< T >::getChildren ( ) const
inline

Getter of children of the root node.

Returns
children of the root node

◆ getData() [1/2]

template<class T >
T & ext::forward_tree< T >::getData ( )
inline

Getter of the value in the root node.

Returns
the value in the root node

◆ getData() [2/2]

template<class T >
const T & ext::forward_tree< T >::getData ( ) const
inline

Getter of the value in the root node.

Returns
the value in the root node

◆ insert() [1/4]

template<class T >
const_children_iterator ext::forward_tree< T >::insert ( const_children_iterator  position,
const forward_tree< T > &  value 
)
inline

Inserts a subtree into a forward_tree.

Parameters
positionthe specification of position in children of the node where to add subtrees
valuea subtree to insert
Returns
updated position iterator pointing to the first node inserted
Here is the call graph for this function:

◆ insert() [2/4]

template<class T >
const_children_iterator ext::forward_tree< T >::insert ( const_children_iterator  position,
const_children_iterator  begin,
const_children_iterator  end 
)
inline

Insert helper for insertion specified by position in children and inserted subtrees given by range of iterators.

Parameters
positionthe specification of position in children of the node where to add subtrees
beginthe start of the range of subtrees
endthe end of the range of subtrees
Returns
updated position iterator pointing to the first node inserted
Here is the call graph for this function:

◆ insert() [3/4]

template<class T >
const_children_iterator ext::forward_tree< T >::insert ( const_children_iterator  position,
forward_tree< T > &&  value 
)
inline

Inserts a subtree into a forward_tree.

Parameters
positionthe specification of position in children of the node where to add subtrees
valuea subtree to insert
Returns
updated position iterator pointing to the first node inserted
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert() [4/4]

template<class T >
template<class Iterator >
const_children_iterator ext::forward_tree< T >::insert ( const_children_iterator  position,
Iterator  begin,
Iterator  end 
)
inline

Inserts a subtrees into a forward_tree. The subtrees are nullary nodes having value given by values in the range begin to end.

Template Parameters
Iteratorthe type of iterators forming the range
Parameters
positionthe specification of position in children of the node where to add subtrees
beginthe start of the range of values
endthe end of the range of values
Returns
updated position iterator pointing to the first node inserted
Here is the call graph for this function:

◆ nicePrint()

template<class T >
std::ostream & ext::forward_tree< T >::nicePrint ( std::ostream &  os) const
inline

Internal method of printing a tree into a stream.

The tree is printed hierarchically.

Example tree a ( b ( c ), b ( c ) ) would be printed like

-a | |-b | | | -c | -b | -c

Parameters
osthe stream to print to
Returns
the changed output stream
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator()() [1/4]

template<class T >
template<class ... Indexes>
T & ext::forward_tree< T >::operator() ( Indexes ...  indexes)
inline

Access value given indexes of chindren allong the selection path.

Template Parameters
Indexes... types of child indexes
Parameters
indexesactual values of child indexes
Returns
the value in the selected node
Here is the call graph for this function:

◆ operator()() [2/4]

template<class T >
template<class ... Indexes>
const T & ext::forward_tree< T >::operator() ( Indexes ...  indexes) const
inline

Access value given indexes of chindren allong the selection path.

Template Parameters
Indexes... types of child indexes
Parameters
indexesactual values of child indexes
Returns
the value in the selected node
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator()() [3/4]

template<class T >
T & ext::forward_tree< T >::operator() ( std::initializer_list< size_t >  indexes)
inline

Access value given indexes of chindren allong the selection path.

Parameters
indexesactual values of child indexes
Returns
the value in the selected node

◆ operator()() [4/4]

template<class T >
const T & ext::forward_tree< T >::operator() ( std::initializer_list< size_t >  indexes) const
inline

Access value given indexes of chindren allong the selection path.

Parameters
indexesactual values of child indexes
Returns
the value in the selected node

◆ operator<=>()

template<class T >
auto ext::forward_tree< T >::operator<=> ( const forward_tree< T > &  other) const
inline

Less comparison operator.

Parameters
otherthe other instance to compare with
Returns
true if this instance is smaller than other instance, false othervise
Here is the call graph for this function:

◆ operator==()

template<class T >
bool ext::forward_tree< T >::operator== ( const forward_tree< T > &  other) const
inline

Equality comparison operator.

Parameters
otherthe other instance to compare with
Returns
true if this instance is equal to other instance, false othervise
Here is the call graph for this function:

◆ postfix_begin()

template<class T >
const_postfix_iterator ext::forward_tree< T >::postfix_begin ( ) const
inline

Getter of the postfix iterator to the first node in the postfix traversal.

Returns
prefix iterator to the first node in the postfix traversal

◆ postfix_end()

template<class T >
const_postfix_iterator ext::forward_tree< T >::postfix_end ( ) const
inline

Getter of the postfix iterator one after the last node in the postfix traversal.

Returns
prefix iterator one after the last node in the postfix traversal

◆ prefix_begin()

template<class T >
const_prefix_iterator ext::forward_tree< T >::prefix_begin ( ) const
inline

Getter of the prefix iterator to the root node.

Returns
prefix iterator to the root
Here is the caller graph for this function:

◆ prefix_end()

template<class T >
const_prefix_iterator ext::forward_tree< T >::prefix_end ( ) const
inline

Getter of the prefix iterator one after the last node in the prefix traversal.

Returns
prefix iterator one after the last node in the prefix traversal
Here is the caller graph for this function:

◆ push_back() [1/4]

template<class T >
void ext::forward_tree< T >::push_back ( const ext::forward_tree< T > &  value)
inline

Pushbacks a subtree after last child of a tree.

Parameters
valuea subtree to pushback to child list
Here is the call graph for this function:

◆ push_back() [2/4]

template<class T >
void ext::forward_tree< T >::push_back ( const T &  value)
inline

Pushbacks a nullary node after last child of a tree.

Parameters
valuea value to store in nullary node push-backed to the child list
Here is the call graph for this function:

◆ push_back() [3/4]

template<class T >
void ext::forward_tree< T >::push_back ( ext::forward_tree< T > &&  value)
inline

Pushbacks a subtree after last child of a tree.

Parameters
valuea subtree to pushback to child list
Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_back() [4/4]

template<class T >
void ext::forward_tree< T >::push_back ( T &&  value)
inline

Pushbacks a nullary node after last child of a tree.

Parameters
valuea value to store in nullary node push-backed to the child list
Here is the call graph for this function:

◆ structure_begin()

template<class T >
const_structure_iterator ext::forward_tree< T >::structure_begin ( ) const
inline

Getter of the structure iterator to the first node in the traversal.

Returns
prefix iterator to the first node in the traversal

◆ structure_end()

template<class T >
const_structure_iterator ext::forward_tree< T >::structure_end ( ) const
inline

Getter of the structure iterator to one after the last node in the traversal.

Returns
prefix iterator to one after the last node in the traversal

Friends And Related Function Documentation

◆ swap

template<class T >
void swap ( forward_tree< T > &  first,
forward_tree< T > &  second 
)
friend

Swap method of two forward trees.

Parameters
firstthe first forward tree to swap
secondthe second forward tree to swap

The documentation for this class was generated from the following file: