Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FirstChildNextSibling.h
Go to the documentation of this file.
1
6#pragma once
7
9
10#include <alphabet/EndSymbol.h>
12
15
16namespace tree {
17
18namespace transform {
19
21public:
26 template < class SymbolType >
28
29private:
30 template < class SymbolType >
31 static ext::tree < common::ranked_symbol < SymbolType > > transformInternal ( const ext::vector < ext::tree < SymbolType > > & tree, const SymbolType & terminalSymbol );
32};
33
34template < class SymbolType >
35ext::tree < common::ranked_symbol < SymbolType > > FirstChildNextSibling::transformInternal ( const ext::vector < ext::tree < SymbolType > > & treeList, const SymbolType & terminalSymbol ) {
37 for ( const ext::tree < SymbolType > & node : ext::make_reverse ( treeList ) ) {
39 newRoot.push_back ( transformInternal ( node.getChildren ( ), terminalSymbol ) );
40 newRoot.push_back ( std::move ( root ) );
41 root = std::move ( newRoot );
42 }
43 return root;
44}
45
46template < class SymbolType >
48 SymbolType terminalSymbol = common::createUnique ( alphabet::EndSymbol::instance < SymbolType > ( ), subject.getAlphabet ( ) );
49 common::ranked_symbol < SymbolType > terminalNode ( terminalSymbol, 0 );
50
52 alphabet.insert ( terminalNode );
53 for ( const SymbolType & symbol : subject.getAlphabet ( ) )
54 alphabet.insert ( common::ranked_symbol < SymbolType > ( symbol, 2 ) );
55
57 root.push_back ( transformInternal ( subject.getContent ( ).getChildren ( ), terminalSymbol ) );
58 root.push_back ( ext::tree < common::ranked_symbol < SymbolType > > ( terminalNode ) );
59 return tree::RankedTree < SymbolType > ( std::move ( alphabet ), std::move ( root ) );
60}
61
62} /* namespace transform */
63
64} /* namespace tree */
65
Definition: ranked_symbol.hpp:20
Definition: set.hpp:44
Class introducing a tree with interface trying to be close to the interface of standard library conta...
Definition: tree.hpp:52
void push_back(ext::tree< T > &&value)
Pushbacks a subtree after last child of a tree.
Definition: tree.hpp:983
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Tree structure represented in its natural representation. The representation is so called ranked,...
Definition: RankedTree.h:72
Tree represented in its natural representation. The representation is so called unranked,...
Definition: UnrankedTree.h:69
const ext::set< SymbolType > & getAlphabet() const &
Definition: UnrankedTree.h:112
const ext::tree< SymbolType > & getContent() const &
Definition: UnrankedTree.h:217
Definition: FirstChildNextSibling.h:20
static tree::RankedTree< SymbolType > transform(const tree::UnrankedTree< SymbolType > &subject)
Definition: FirstChildNextSibling.h:47
Definition: BarSymbol.cpp:12
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
T createUnique(T object, const Alphabets &... alphabets)
Definition: createUnique.hpp:46
reverser< T > make_reverse(T &&container)
Reverese adaptor construction function.
Definition: iterator.hpp:544
ContainerType< ResType > transform(const ContainerType< InType, Ts ... > &in, Callback transform)
In container tranformation of all elements according to the tranform.
Definition: algorithm.hpp:150
Definition: Node.cpp:11
Definition: BackwardOccurrenceTest.h:17