Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
NormalizeTreeLabels.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <alib/map>
9#include <alib/vector>
10#include <alib/tree>
11
13
14namespace tree {
15
16namespace simplify {
17
22 template < class SymbolType >
24
25public:
30 template < class SymbolType >
32
33};
34
35template < class SymbolType >
37
39
40 for ( const ext::tree < common::ranked_symbol < SymbolType > > & child : tree )
41 children.push_back ( normalize < SymbolType > ( child, mapping, counter ) );
42
43 auto newLabelIt = mapping.find ( tree.getData ( ) );
44 unsigned newLabel;
45
46 if ( newLabelIt == mapping.end ( ) ) {
47 mapping.insert ( std::make_pair ( tree.getData ( ), counter ) );
48 newLabel = counter;
49 counter += 1;
50 } else {
51 newLabel = newLabelIt->second;
52 }
53
54 return ext::tree < common::ranked_symbol < unsigned > > ( common::ranked_symbol < unsigned > ( newLabel, tree.getData ( ).getRank ( ) ), std::move ( children ) );
55
56}
57
58template < class SymbolType >
59tree::RankedTree < unsigned > NormalizeTreeLabels::normalize ( const tree::RankedTree < SymbolType > & tree ) {
60
62 unsigned counter = 1;
63
64 return tree::RankedTree < unsigned > ( normalize ( tree.getContent ( ), mapping, counter ) );
65}
66
67} /* namespace simplify */
68
69} /* namespace tree */
70
Definition: ranked_symbol.hpp:20
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
Class introducing a tree with interface trying to be close to the interface of standard library conta...
Definition: tree.hpp:52
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
reverse_iterator insert(const_reverse_iterator pos, const T &value)
Inserts the value on position given by iterator pos.
Definition: vector.hpp:229
Tree structure represented in its natural representation. The representation is so called ranked,...
Definition: RankedTree.h:72
Definition: NormalizeTreeLabels.h:21
unsigned counter
Definition: Rename.h:247
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: BackwardOccurrenceTest.h:17