From 3dc14b78a64f60c5524390d7d07ca9225fc93ef1 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Fri, 4 Nov 2016 15:46:53 +0100
Subject: [PATCH] split Glushkov traversal (rtes) and use visitors

---
 .../ToPostfixPushdownAutomatonGlushkov.cpp    |   7 +-
 alib2algo/src/rte/glushkov/GlushkovFirst.cpp  |  68 ++++
 alib2algo/src/rte/glushkov/GlushkovFirst.h    |  41 +++
 alib2algo/src/rte/glushkov/GlushkovFollow.cpp | 173 +++++++++
 alib2algo/src/rte/glushkov/GlushkovFollow.h   |  45 +++
 alib2algo/src/rte/glushkov/GlushkovPos.cpp    |  47 +++
 alib2algo/src/rte/glushkov/GlushkovPos.h      |  38 ++
 .../src/rte/glushkov/GlushkovTraversal.cpp    | 346 ------------------
 .../src/rte/glushkov/GlushkovTraversal.h      |  73 ----
 9 files changed, 416 insertions(+), 422 deletions(-)
 create mode 100644 alib2algo/src/rte/glushkov/GlushkovFirst.cpp
 create mode 100644 alib2algo/src/rte/glushkov/GlushkovFirst.h
 create mode 100644 alib2algo/src/rte/glushkov/GlushkovFollow.cpp
 create mode 100644 alib2algo/src/rte/glushkov/GlushkovFollow.h
 create mode 100644 alib2algo/src/rte/glushkov/GlushkovPos.cpp
 create mode 100644 alib2algo/src/rte/glushkov/GlushkovPos.h
 delete mode 100644 alib2algo/src/rte/glushkov/GlushkovTraversal.cpp
 delete mode 100644 alib2algo/src/rte/glushkov/GlushkovTraversal.h

diff --git a/alib2algo/src/rte/convert/ToPostfixPushdownAutomatonGlushkov.cpp b/alib2algo/src/rte/convert/ToPostfixPushdownAutomatonGlushkov.cpp
index 9fb502a18a..dfc06d9bd1 100644
--- a/alib2algo/src/rte/convert/ToPostfixPushdownAutomatonGlushkov.cpp
+++ b/alib2algo/src/rte/convert/ToPostfixPushdownAutomatonGlushkov.cpp
@@ -16,8 +16,9 @@
 
 #include "global/GlobalData.h"
 
-#include "../glushkov/GlushkovTraversal.h"
+#include "../glushkov/GlushkovFollow.h"
 #include "../glushkov/GlushkovIndexate.h"
+#include "../glushkov/GlushkovFirst.h"
 
 #include <iterator>
 
@@ -46,13 +47,13 @@ automaton::NPDA < > ToPostfixPushdownAutomatonGlushkov::convert ( const rte::For
 
 	 // step 2; compute:
 	 // - first set
-	const std::set < std::ranked_symbol < > > firstSet = rte::GlushkovTraversal::first ( indexedRTE );
+	const std::set < std::ranked_symbol < > > firstSet = rte::GlushkovFirst::first ( indexedRTE );
 
 	 // - follow set for every element of (non-indexed) RTE alphabet element
 	std::map < std::ranked_symbol < >, std::set < std::vector < std::ranked_symbol < > > > > followSet;
 
 	for ( const std::ranked_symbol < > & symbol : indexedRTE.getAlphabet ( ) )
-		followSet.insert ( std::make_pair ( symbol, rte::GlushkovTraversal::follow ( indexedRTE, symbol ) ) );
+		followSet.insert ( std::make_pair ( symbol, rte::GlushkovFollow::follow ( indexedRTE, symbol ) ) );
 
 	 /* check for exceptions -> there must be NO substitution symbol in first or follow sets */
 	if ( isSubstSymbolPresent ( firstSet, rte.getSubstitutionAlphabet ( ) ) )
diff --git a/alib2algo/src/rte/glushkov/GlushkovFirst.cpp b/alib2algo/src/rte/glushkov/GlushkovFirst.cpp
new file mode 100644
index 0000000000..31e5bc4521
--- /dev/null
+++ b/alib2algo/src/rte/glushkov/GlushkovFirst.cpp
@@ -0,0 +1,68 @@
+/*
+ * GlushkovFirst.cpp
+ *
+ *  Created on: 14. 4. 2016
+ *	  Author: Tomas Pecka
+ */
+
+#include "GlushkovFirst.h"
+
+namespace rte {
+
+std::set < std::ranked_symbol < > > GlushkovFirst::first ( const rte::FormalRTE < > & rte ) {
+	return rte.getRTE ( ).getStructure ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal > ( );
+}
+
+std::set < std::ranked_symbol < > > GlushkovFirst::Formal::visit ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node ) {
+	std::set < std::ranked_symbol < > > ret, tmp;
+
+	tmp = node.getLeftElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal::Formal > ( );
+	ret.insert ( tmp.begin ( ), tmp.end ( ) );
+
+	tmp = node.getRightElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal::Formal > ( );
+	ret.insert ( tmp.begin ( ), tmp.end ( ) );
+
+	return ret;
+}
+
+std::set < std::ranked_symbol < > > GlushkovFirst::Formal::visit ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node ) {
+	std::set < std::ranked_symbol < > > ret, tmp;
+
+	tmp = node.getLeftElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal::Formal > ( );
+	ret.insert ( tmp.begin ( ), tmp.end ( ) );
+
+	 // First::Formal() returns a set. hence only one occurrence.
+	auto it = std::find_if ( ret.begin ( ), ret.end ( ), [node] ( const std::ranked_symbol < > & a ) {
+			return a == node.getSubstitutionSymbol ( ).getSymbol ( );
+		} );
+
+	if ( it != ret.end ( ) ) {
+		ret.erase ( it );
+		tmp = node.getRightElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal::Formal > ( );
+		ret.insert ( tmp.begin ( ), tmp.end ( ) );
+	}
+
+	return ret;
+}
+
+std::set < std::ranked_symbol < > > GlushkovFirst::Formal::visit ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node ) {
+	std::set < std::ranked_symbol < > > ret;
+
+	ret = node.getElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal::Formal > ( );
+	ret.insert ( node.getSubstitutionSymbol ( ).getSymbol ( ) );
+	return ret;
+}
+
+std::set < std::ranked_symbol < > > GlushkovFirst::Formal::visit ( const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > & node ) {
+	return std::set < std::ranked_symbol < > > { node.getSymbol ( ) };
+}
+
+std::set < std::ranked_symbol < > > GlushkovFirst::Formal::visit ( const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > & node ) {
+	return std::set < std::ranked_symbol < > > { node.getSymbol ( ) };
+}
+
+std::set < std::ranked_symbol < > > GlushkovFirst::Formal::visit ( const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > & /* node */ ) {
+	return std::set < std::ranked_symbol < > > ( );
+}
+
+} /* namespace rte */
diff --git a/alib2algo/src/rte/glushkov/GlushkovFirst.h b/alib2algo/src/rte/glushkov/GlushkovFirst.h
new file mode 100644
index 0000000000..b9c31490d5
--- /dev/null
+++ b/alib2algo/src/rte/glushkov/GlushkovFirst.h
@@ -0,0 +1,41 @@
+/*
+ * GlushkovFirst.h
+ *
+ *  Created on: 14. 4. 2016
+ *	  Author: Tomas Pecka
+ */
+
+#ifndef RTE_GLUSHKOV_FIRST_H_
+#define RTE_GLUSHKOV_FIRST_H_
+
+#include <set>
+
+#include <rte/formal/FormalRTE.h>
+#include <rte/RTEFeatures.h>
+
+#include <alphabet/RankedSymbol.h>
+
+namespace rte {
+
+class GlushkovFirst {
+public:
+	/**
+	 * @param re rte to probe
+	 * @return all rteSymbols which can be root of the tree.
+	 */
+	static std::set < std::ranked_symbol < > > first ( const rte::FormalRTE < > & re );
+
+	class Formal {
+	public:
+		static std::set < std::ranked_symbol < > > visit ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node );
+		static std::set < std::ranked_symbol < > > visit ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node );
+		static std::set < std::ranked_symbol < > > visit ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node );
+		static std::set < std::ranked_symbol < > > visit ( const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > & node );
+		static std::set < std::ranked_symbol < > > visit ( const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > & node );
+		static std::set < std::ranked_symbol < > > visit ( const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > & node );
+	};
+};
+
+} /* namespace rte */
+
+#endif /* RTE_GLUSHKOV_FIRST_H_ */
diff --git a/alib2algo/src/rte/glushkov/GlushkovFollow.cpp b/alib2algo/src/rte/glushkov/GlushkovFollow.cpp
new file mode 100644
index 0000000000..68b16df6e2
--- /dev/null
+++ b/alib2algo/src/rte/glushkov/GlushkovFollow.cpp
@@ -0,0 +1,173 @@
+/*
+ * GlushkovFollow.cpp
+ *
+ *  Created on: 14. 4. 2016
+ *	  Author: Tomas Pecka
+ */
+
+#include "GlushkovFollow.h"
+#include "GlushkovFirst.h"
+#include "GlushkovPos.h"
+#include <iterator>
+#include <vector>
+
+namespace rte {
+
+std::set < std::vector < std::ranked_symbol < > > > GlushkovFollow::follow ( const rte::FormalRTE < > & rte, const std::ranked_symbol < > & symbol ) {
+	std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > subMap;
+
+	 /* Init substitution map, ie \forall a \in K: sub[a] = \emptyset */
+	for ( const std::ranked_symbol < > & ssymb : rte.getSubstitutionAlphabet ( ) )
+		subMap.insert ( std::make_pair ( ssymb, std::set < std::ranked_symbol < > > { } ) );
+
+	 /* recursively compute follow */
+	return rte.getRTE ( ).getStructure ( ).accept < std::set < std::vector < std::ranked_symbol < > > >, GlushkovFollow::Formal > ( symbol, rte.getSubstitutionAlphabet ( ), subMap );
+}
+
+// -----------------------------------------------------------------------------
+
+template < class T >
+void cartesian_rec ( const std::vector < std::vector < T > > & input, std::vector < std::vector < T > > & ret, std::vector < T > & current, size_t depth ) {
+	if ( depth == input.size ( ) )
+		ret.push_back ( current );
+	else
+		for ( size_t i = 0; i < input[depth].size ( ); i++ ) {
+			current[depth] = input[depth][i];
+			cartesian_rec ( input, ret, current, depth + 1 );
+		}
+
+}
+
+template < class T >
+std::vector < std::vector < T > > cartesian ( const std::vector < std::vector < T > > & input ) {
+	std::vector < std::vector < T > > ret;
+	std::vector < T > current ( input.size ( ), std::ranked_symbol < > ( 0, 0 ) );
+
+	cartesian_rec ( input, ret, current, 0 );
+
+	return ret;
+}
+
+void preprocessSubMap ( const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap ) {
+	bool change = true;
+
+	while ( change ) {
+		change = false;
+
+		for ( std::pair < const std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & kv : subMap ) {
+			std::set < std::ranked_symbol < > > & substSet = kv.second;
+
+			for ( const auto & e : substSet ) {
+				if ( alphabetK.count ( e ) == 0 ) continue;
+
+				auto it = subMap.find ( e );
+				size_t oldSize = substSet.size ( );
+				substSet.insert ( it->second.begin ( ), it->second.end ( ) );
+				change = ( oldSize != substSet.size ( ) ); // something was added
+				substSet.erase ( e );
+			}
+		}
+	}
+}
+
+std::set < std::vector < std::ranked_symbol < > > > replaceConstants ( const std::set < std::ranked_symbol < > > & alphabetK, const std::vector < std::ranked_symbol < > > & follow, const std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap2 ) {
+	std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > subMap ( subMap2 );
+	preprocessSubMap ( alphabetK, subMap );
+
+	std::vector < std::vector < std::ranked_symbol < > > > input;
+
+	for ( const std::ranked_symbol < > & e : follow ) {
+		if ( alphabetK.count ( e ) > 0 )
+			input.push_back ( std::vector < std::ranked_symbol < > > ( subMap.at ( e ).begin ( ), subMap.at ( e ).end ( ) ) );
+		else
+			input.push_back ( std::vector < std::ranked_symbol < > > { e } );
+	}
+
+	 /* now do the cartesian product on "input" */
+	std::vector < std::vector < std::ranked_symbol < > > > followSet = cartesian ( input );
+	return std::set < std::vector < std::ranked_symbol < > > > ( followSet.begin ( ), followSet.end ( ) );
+}
+
+// -----------------------------------------------------------------------------
+
+std::set < std::vector < std::ranked_symbol < > > > GlushkovFollow::Formal::visit ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap ) {
+	std::set < std::vector < std::ranked_symbol < > > > ret, tmp;
+
+	tmp = node.getLeftElement ( ).accept < std::set < std::vector < std::ranked_symbol < > > >, GlushkovFollow::Formal > ( symbolF, alphabetK, subMap );
+	ret.insert ( tmp.begin ( ), tmp.end ( ) );
+
+	tmp = node.getRightElement ( ).accept < std::set < std::vector < std::ranked_symbol < > > >, GlushkovFollow::Formal > ( symbolF, alphabetK, subMap );
+	ret.insert ( tmp.begin ( ), tmp.end ( ) );
+
+	return ret;
+}
+
+std::set < std::vector < std::ranked_symbol < > > > GlushkovFollow::Formal::visit ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap ) {
+
+	std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > subMap2 ( subMap );
+	auto itMap = subMap2.find ( node.getSubstitutionSymbol ( ).getSymbol ( ) );
+
+	itMap->second.clear ( );
+
+	for ( const auto & s : node.getRightElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal > ( ) )
+		itMap->second.insert ( s );
+
+	/*
+	 * E sub F
+	 *   1. if symbolF in F subtree, then Follow(F, symbolF);
+	 *   2. if symbolF in E subtree, then Follow(E, symbolF);
+	 */
+
+	std::set < std::vector < std::ranked_symbol < > > > ret;
+
+	if ( node.getLeftElement ( ).accept < bool, GlushkovPos::Formal > ( symbolF ) )
+		ret = node.getLeftElement ( ).accept < std::set < std::vector < std::ranked_symbol < > > >, GlushkovFollow::Formal > ( symbolF, alphabetK, subMap2 );
+	else
+		ret = node.getRightElement ( ).accept < std::set < std::vector < std::ranked_symbol < > > >, GlushkovFollow::Formal > ( symbolF, alphabetK, subMap );
+
+	return ret;
+}
+
+std::set < std::vector < std::ranked_symbol < > > > GlushkovFollow::Formal::visit ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap ) {
+
+	std::set < std::vector < std::ranked_symbol < > > > ret;
+
+	for ( const auto & s : node.getElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal > ( ) )
+		subMap[node.getSubstitutionSymbol ( ).getSymbol ( )].insert ( s );
+
+	ret = node.getElement ( ).accept < std::set < std::vector < std::ranked_symbol < > > >, GlushkovFollow::Formal > ( symbolF, alphabetK, subMap );
+
+	return ret;
+}
+
+std::set < std::vector < std::ranked_symbol < > > > GlushkovFollow::Formal::visit ( const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap ) {
+
+	std::set < std::vector < std::ranked_symbol < > > > ret, tmp;
+
+	if ( symbolF == node.getSymbol ( ) ) {
+		std::vector < std::ranked_symbol < > > children;
+
+		for ( const std::smart_ptr < const rte::FormalRTESymbol < alphabet::Symbol, primitive::Unsigned > > & c : node.getElements ( ) )
+			children.push_back ( c->getSymbol ( ) );
+
+		ret = replaceConstants ( alphabetK, children, subMap );
+		return ret;
+	}
+
+	for ( const auto & c : node.getElements ( ) ) {
+		tmp = c->accept < std::set < std::vector < std::ranked_symbol < > > >, GlushkovFollow::Formal > ( symbolF, alphabetK, subMap );
+		ret.insert ( tmp.begin ( ), tmp.end ( ) );
+	}
+
+	return ret;
+}
+
+std::set < std::vector < std::ranked_symbol < > > > GlushkovFollow::Formal::visit ( const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > & /* node */, const std::ranked_symbol < > & /* symbolF */, const std::set < std::ranked_symbol < > > & /* alphabetK */, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & /* subMap */ ) {
+	return std::set < std::vector < std::ranked_symbol < > > > ( );
+}
+
+std::set < std::vector < std::ranked_symbol < > > > GlushkovFollow::Formal::visit ( const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > & /* node */, const std::ranked_symbol < > & /* symbolF */, const std::set < std::ranked_symbol < > > & /* alphabetK */, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & /* subMap */ ) {
+	return std::set < std::vector < std::ranked_symbol < > > > ( );
+}
+
+} /* namespace rte */
diff --git a/alib2algo/src/rte/glushkov/GlushkovFollow.h b/alib2algo/src/rte/glushkov/GlushkovFollow.h
new file mode 100644
index 0000000000..0de211129a
--- /dev/null
+++ b/alib2algo/src/rte/glushkov/GlushkovFollow.h
@@ -0,0 +1,45 @@
+/*
+ * GlushkovFollow.h
+ *
+ *  Created on: 14. 4. 2016
+ *	  Author: Tomas Pecka
+ */
+
+#ifndef RTE_GLUSHKOV_FOLLOW_H_
+#define RTE_GLUSHKOV_FOLLOW_H_
+
+#include <vector>
+#include <map>
+#include <set>
+
+#include <rte/formal/FormalRTE.h>
+#include <rte/formal/FormalRTEElements.h>
+
+#include <alphabet/RankedSymbol.h>
+
+namespace rte {
+
+class GlushkovFollow {
+public:
+	/**
+	 * @param re rte to probe
+	 * @param symbol FormalRTESymbol for which we need the follow(), i.e., Follow(RTE, symbol)
+	 * @return all symbols that can follow specific symbol in word
+	 */
+	static std::set < std::vector < std::ranked_symbol < > > > follow ( const rte::FormalRTE < > & re, const std::ranked_symbol < > & symbol );
+
+	class Formal {
+	public:
+		static std::set < std::vector < std::ranked_symbol < > > > visit ( const rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
+		static std::set < std::vector < std::ranked_symbol < > > > visit ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
+		static std::set < std::vector < std::ranked_symbol < > > > visit ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
+		static std::set < std::vector < std::ranked_symbol < > > > visit ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
+		static std::set < std::vector < std::ranked_symbol < > > > visit ( const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
+		static std::set < std::vector < std::ranked_symbol < > > > visit ( const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
+		static std::set < std::vector < std::ranked_symbol < > > > visit ( const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
+	};
+};
+
+} /* namespace rte */
+
+#endif /* RTE_GLUSHKOV_FOLLOW_H_ */
diff --git a/alib2algo/src/rte/glushkov/GlushkovPos.cpp b/alib2algo/src/rte/glushkov/GlushkovPos.cpp
new file mode 100644
index 0000000000..c1ef63729b
--- /dev/null
+++ b/alib2algo/src/rte/glushkov/GlushkovPos.cpp
@@ -0,0 +1,47 @@
+/*
+ * GlushkovPos.cpp
+ *
+ *  Created on: 14. 4. 2016
+ *	  Author: Tomas Pecka
+ */
+
+#include "GlushkovPos.h"
+#include <rte/formal/FormalRTEElements.h>
+
+namespace rte {
+
+bool GlushkovPos::pos ( const std::ranked_symbol < > & symbol, const rte::FormalRTE < > & rte ) {
+	return rte.getRTE ( ).getStructure ( ).accept < bool, GlushkovPos::Formal > ( symbol );
+}
+
+bool GlushkovPos::Formal::visit ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF ) {
+	return node.getLeftElement ( ).accept < bool, GlushkovPos::Formal > ( symbolF ) || node.getRightElement ( ).accept < bool, GlushkovPos::Formal > ( symbolF );
+}
+
+bool GlushkovPos::Formal::visit ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF ) {
+	return node.getLeftElement ( ).accept < bool, GlushkovPos::Formal > ( symbolF ) || node.getRightElement ( ).accept < bool, GlushkovPos::Formal > ( symbolF );
+}
+
+bool GlushkovPos::Formal::visit ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF ) {
+	return node.getElement ( ).accept < bool, GlushkovPos::Formal > ( symbolF );
+}
+
+bool GlushkovPos::Formal::visit ( const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF ) {
+	if ( symbolF == node.getSymbol ( ) ) return true;
+
+	for ( const std::smart_ptr < const rte::FormalRTESymbol < alphabet::Symbol, primitive::Unsigned > > & element : node.getElements ( ) )
+		if ( element->accept < bool, GlushkovPos::Formal > ( symbolF ) )
+			return true;
+
+	return false;
+}
+
+bool GlushkovPos::Formal::visit ( const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF ) {
+	return symbolF == node.getSymbol ( );
+}
+
+bool GlushkovPos::Formal::visit ( const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > & /* node */, const std::ranked_symbol < > & /* symbolF */ ) {
+	return false;
+}
+
+} /* namespace rte */
diff --git a/alib2algo/src/rte/glushkov/GlushkovPos.h b/alib2algo/src/rte/glushkov/GlushkovPos.h
new file mode 100644
index 0000000000..5ca719fac7
--- /dev/null
+++ b/alib2algo/src/rte/glushkov/GlushkovPos.h
@@ -0,0 +1,38 @@
+/*
+ * GlushkovPos.h
+ *
+ *  Created on: 14. 4. 2016
+ *	  Author: Tomas Pecka
+ */
+
+#ifndef RTE_GLUSHKOV_POS_H_
+#define RTE_GLUSHKOV_POS_H_
+
+#include <rte/formal/FormalRTE.h>
+#include <rte/RTEFeatures.h>
+
+#include <alphabet/RankedSymbol.h>
+
+namespace rte {
+
+class GlushkovPos {
+public:
+	/**
+	 * @return bool true if symbol pointer is in this subtree
+	 */
+	static bool pos ( const std::ranked_symbol < > & symbol, const rte::FormalRTE < > & node );
+
+	class Formal {
+	public:
+		static bool visit ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
+		static bool visit ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
+		static bool visit ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
+		static bool visit ( const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
+		static bool visit ( const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
+		static bool visit ( const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
+	};
+};
+
+} /* namespace rte */
+
+#endif /* RTE_GLUSHKOV_POS_H_ */
diff --git a/alib2algo/src/rte/glushkov/GlushkovTraversal.cpp b/alib2algo/src/rte/glushkov/GlushkovTraversal.cpp
deleted file mode 100644
index 9c00b73141..0000000000
--- a/alib2algo/src/rte/glushkov/GlushkovTraversal.cpp
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- * GlushkovTraversal.cpp
- *
- *  Created on: 14. 4. 2016
- *	  Author: Tomas Pecka
- */
-
-#include "GlushkovTraversal.h"
-#include <alphabet/SymbolPairSymbol.h>
-#include <iterator>
-#include <vector>
-
-namespace rte {
-
-bool GlushkovTraversal::pos ( const std::ranked_symbol < > & symbol, const rte::FormalRTE < > & rte ) {
-	return pos ( rte.getRTE ( ).getStructure ( ), symbol );
-}
-
-std::set < std::ranked_symbol < > > GlushkovTraversal::first ( const rte::FormalRTE < > & rte ) {
-	return first ( rte.getRTE ( ).getStructure ( ) );
-}
-
-std::set < std::vector < std::ranked_symbol < > > > GlushkovTraversal::follow ( const rte::FormalRTE < > & rte, const std::ranked_symbol < > & symbol ) {
-	std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > subMap;
-
-	 /* Init substitution map, ie \forall a \in K: sub[a] = \emptyset */
-	for ( const std::ranked_symbol < > & ssymb : rte.getSubstitutionAlphabet ( ) )
-		subMap.insert ( std::make_pair ( ssymb, std::set < std::ranked_symbol < > > { } ) );
-
-	 /* recursively compute follow */
-	return follow ( rte.getRTE ( ).getStructure ( ), symbol, rte.getSubstitutionAlphabet ( ), subMap );
-}
-
-// -----------------------------------------------------------------------------
-
-std::set < std::ranked_symbol < > > GlushkovTraversal::first ( const rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > & node ) {
-	const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > * alternation = dynamic_cast < const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > * concatenation = dynamic_cast < const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > * iteration = dynamic_cast < const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > * symbol = dynamic_cast < const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > * substSymbol = dynamic_cast < const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > * empty = dynamic_cast < const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-
-	if ( alternation )
-		return first ( * alternation );
-	else if ( concatenation )
-		return first ( * concatenation );
-	else if ( iteration )
-		return first ( * iteration );
-	else if ( empty )
-		return first ( * empty );
-	else if ( symbol )
-		return first ( * symbol );
-	else if ( substSymbol )
-		return first ( * substSymbol );
-
-	throw exception::CommonException ( "GlushkovTraversal::first - invalid FormalRTEElement node" );
-}
-
-std::set < std::ranked_symbol < > > GlushkovTraversal::first ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node ) {
-	std::set < std::ranked_symbol < > > ret, tmp;
-
-	tmp = first ( node.getLeftElement ( ) );
-	ret.insert ( tmp.begin ( ), tmp.end ( ) );
-
-	tmp = first ( node.getRightElement ( ) );
-	ret.insert ( tmp.begin ( ), tmp.end ( ) );
-
-	return ret;
-}
-
-std::set < std::ranked_symbol < > > GlushkovTraversal::first ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node ) {
-	std::set < std::ranked_symbol < > > ret, tmp;
-
-	tmp = first ( node.getLeftElement ( ) );
-	ret.insert ( tmp.begin ( ), tmp.end ( ) );
-
-	 // First() returns a set. hence only one occurrence.
-	auto it = std::find_if ( ret.begin ( ), ret.end ( ), [node] ( const std::ranked_symbol < > & a ) {
-			return a == node.getSubstitutionSymbol ( ).getSymbol ( );
-		} );
-
-	if ( it != ret.end ( ) ) {
-		ret.erase ( it );
-		tmp = first ( node.getRightElement ( ) );
-		ret.insert ( tmp.begin ( ), tmp.end ( ) );
-	}
-
-	return ret;
-}
-
-std::set < std::ranked_symbol < > > GlushkovTraversal::first ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node ) {
-	std::set < std::ranked_symbol < > > ret;
-
-	ret = first ( node.getElement ( ) );
-	ret.insert ( node.getSubstitutionSymbol ( ).getSymbol ( ) );
-	return ret;
-}
-
-std::set < std::ranked_symbol < > > GlushkovTraversal::first ( const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > & node ) {
-	return std::set < std::ranked_symbol < > > { node.getSymbol ( ) };
-}
-
-std::set < std::ranked_symbol < > > GlushkovTraversal::first ( const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > & node ) {
-	return std::set < std::ranked_symbol < > > { node.getSymbol ( ) };
-}
-
-std::set < std::ranked_symbol < > > GlushkovTraversal::first ( const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > & /* node */ ) {
-	return std::set < std::ranked_symbol < > > ( );
-}
-
-// ----------------------------------------------------------------------------
-
-std::set < std::vector < std::ranked_symbol < > > > GlushkovTraversal::follow ( const rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap ) {
-	const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > * alternation = dynamic_cast < const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > * concatenation = dynamic_cast < const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > * iteration = dynamic_cast < const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > * symbol = dynamic_cast < const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > * substSymbol = dynamic_cast < const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > * empty = dynamic_cast < const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-
-	if ( alternation )
-		return follow ( * alternation, symbolF, alphabetK, subMap );
-
-	else if ( concatenation )
-		return follow ( * concatenation, symbolF, alphabetK, subMap );
-
-	else if ( iteration )
-		return follow ( * iteration, symbolF, alphabetK, subMap );
-
-	else if ( symbol )
-		return follow ( * symbol, symbolF, alphabetK, subMap );
-
-	else if ( substSymbol )
-		return follow ( * substSymbol, symbolF, alphabetK, subMap );
-
-	else if ( empty )
-		return follow ( * empty, symbolF, alphabetK, subMap );
-
-	throw exception::CommonException ( "GlushkovTraversal::follow() - unknown FormalRTEElement node" );
-}
-
-std::set < std::vector < std::ranked_symbol < > > > GlushkovTraversal::follow ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap ) {
-	std::set < std::vector < std::ranked_symbol < > > > ret, tmp;
-
-	tmp = follow ( node.getLeftElement ( ), symbolF, alphabetK, subMap );
-	ret.insert ( tmp.begin ( ), tmp.end ( ) );
-
-	tmp = follow ( node.getRightElement ( ), symbolF, alphabetK, subMap );
-	ret.insert ( tmp.begin ( ), tmp.end ( ) );
-
-	return ret;
-}
-
-std::set < std::vector < std::ranked_symbol < > > > GlushkovTraversal::follow ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap ) {
-
-	std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > subMap2 ( subMap );
-	auto itMap = subMap2.find ( node.getSubstitutionSymbol ( ).getSymbol ( ) );
-
-	itMap->second.clear ( );
-
-	for ( const auto & s : first ( node.getRightElement ( ) ) )
-		itMap->second.insert ( s );
-
-	/*
-	 * E sub F
-	 *   1. if symbolF in F subtree, then Follow(F, symbolF);
-	 *   2. if symbolF in E subtree, then Follow(E, symbolF);
-	 */
-
-	std::set < std::vector < std::ranked_symbol < > > > ret;
-
-	if ( pos ( node.getLeftElement ( ), symbolF ) )
-		ret = follow ( node.getLeftElement ( ), symbolF, alphabetK, subMap2 );
-	else
-		ret = follow ( node.getRightElement ( ), symbolF, alphabetK, subMap );
-
-	return ret;
-}
-
-std::set < std::vector < std::ranked_symbol < > > > GlushkovTraversal::follow ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap ) {
-
-	std::set < std::vector < std::ranked_symbol < > > > ret;
-
-	for ( const auto & s : first ( node.getElement ( ) ) )
-		subMap[node.getSubstitutionSymbol ( ).getSymbol ( )].insert ( s );
-
-	ret = follow ( node.getElement ( ), symbolF, alphabetK, subMap );
-
-	return ret;
-}
-
-void preprocessSubMap ( const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap ) {
-	bool change = true;
-
-	while ( change ) {
-		change = false;
-
-		for ( std::pair < const std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & kv : subMap ) {
-			std::set < std::ranked_symbol < > > & substSet = kv.second;
-
-			for ( const auto & e : substSet ) {
-				if ( alphabetK.count ( e ) == 0 ) continue;
-
-				auto it = subMap.find ( e );
-				size_t oldSize = substSet.size ( );
-				substSet.insert ( it->second.begin ( ), it->second.end ( ) );
-				change = ( oldSize != substSet.size ( ) ); // something was added
-				substSet.erase ( e );
-			}
-		}
-	}
-}
-
-template < class T >
-void cartesian_rec ( const std::vector < std::vector < T > > & input, std::vector < std::vector < T > > & ret, std::vector < T > & current, size_t depth ) {
-	if ( depth == input.size ( ) )
-		ret.push_back ( current );
-	else
-		for ( size_t i = 0; i < input[depth].size ( ); i++ ) {
-			current[depth] = input[depth][i];
-			cartesian_rec ( input, ret, current, depth + 1 );
-		}
-
-}
-
-template < class T >
-std::vector < std::vector < T > > cartesian ( const std::vector < std::vector < T > > & input ) {
-	std::vector < std::vector < T > > ret;
-	std::vector < T > current ( input.size ( ), std::ranked_symbol < > ( 0, 0 ) );
-
-	cartesian_rec ( input, ret, current, 0 );
-
-	return ret;
-}
-
-std::set < std::vector < std::ranked_symbol < > > > replaceConstants ( const std::set < std::ranked_symbol < > > & alphabetK, const std::vector < std::ranked_symbol < > > & follow, const std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap2 ) {
-	std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > subMap ( subMap2 );
-	preprocessSubMap ( alphabetK, subMap );
-
-	std::vector < std::vector < std::ranked_symbol < > > > input;
-
-	for ( const std::ranked_symbol < > & e : follow ) {
-		if ( alphabetK.count ( e ) > 0 )
-			input.push_back ( std::vector < std::ranked_symbol < > > ( subMap.at ( e ).begin ( ), subMap.at ( e ).end ( ) ) );
-		else
-			input.push_back ( std::vector < std::ranked_symbol < > > { e } );
-	}
-
-	 /* now do the cartesian product on "input" */
-	std::vector < std::vector < std::ranked_symbol < > > > followSet = cartesian ( input );
-	return std::set < std::vector < std::ranked_symbol < > > > ( followSet.begin ( ), followSet.end ( ) );
-}
-
-std::set < std::vector < std::ranked_symbol < > > > GlushkovTraversal::follow ( const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subMap ) {
-
-	std::set < std::vector < std::ranked_symbol < > > > ret, tmp;
-
-	if ( symbolF == node.getSymbol ( ) ) {
-		std::vector < std::ranked_symbol < > > children;
-
-		for ( const std::smart_ptr < const rte::FormalRTESymbol < alphabet::Symbol, primitive::Unsigned > > & c : node.getElements ( ) )
-			children.push_back ( c->getSymbol ( ) );
-
-		ret = replaceConstants ( alphabetK, children, subMap );
-		return ret;
-	}
-
-	for ( const auto & c : node.getElements ( ) ) {
-		tmp = follow ( * c, symbolF, alphabetK, subMap );
-		ret.insert ( tmp.begin ( ), tmp.end ( ) );
-	}
-
-	return ret;
-}
-
-std::set < std::vector < std::ranked_symbol < > > > GlushkovTraversal::follow ( const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > & /* node */, const std::ranked_symbol < > & /* symbolF */, const std::set < std::ranked_symbol < > > & /* alphabetK */, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & /* subMap */ ) {
-	return std::set < std::vector < std::ranked_symbol < > > > ( );
-}
-
-std::set < std::vector < std::ranked_symbol < > > > GlushkovTraversal::follow ( const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > & /* node */, const std::ranked_symbol < > & /* symbolF */, const std::set < std::ranked_symbol < > > & /* alphabetK */, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & /* subMap */ ) {
-	return std::set < std::vector < std::ranked_symbol < > > > ( );
-}
-
-// ----------------------------------------------------------------------------
-
-bool GlushkovTraversal::pos ( const rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF ) {
-	const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > * alternation = dynamic_cast < const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > * iteration = dynamic_cast < const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > * concatenation = dynamic_cast < const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > * symbol = dynamic_cast < const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > * substSymbol = dynamic_cast < const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-	const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > * empty = dynamic_cast < const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > * > ( & node );
-
-	if ( alternation )
-		return pos ( * alternation, symbolF );
-
-	else if ( concatenation )
-		return pos ( * concatenation, symbolF );
-
-	else if ( iteration )
-		return pos ( * iteration, symbolF );
-
-	else if ( symbol )
-		return pos ( * symbol, symbolF );
-
-	else if ( substSymbol )
-		return pos ( * substSymbol, symbolF );
-
-	else if ( empty )
-		return pos ( * empty, symbolF );
-
-	throw exception::CommonException ( "GlushkovTraversal::pos() - unknown FormalRTEElement node" );
-}
-
-bool GlushkovTraversal::pos ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF ) {
-	return pos ( node.getLeftElement ( ), symbolF ) || pos ( node.getRightElement ( ), symbolF );
-}
-
-bool GlushkovTraversal::pos ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF ) {
-	return pos ( node.getLeftElement ( ), symbolF ) || pos ( node.getRightElement ( ), symbolF );
-}
-
-bool GlushkovTraversal::pos ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF ) {
-	return pos ( node.getElement ( ), symbolF );
-}
-
-bool GlushkovTraversal::pos ( const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF ) {
-	if ( symbolF == node.getSymbol ( ) ) return true;
-
-	for ( const std::smart_ptr < const rte::FormalRTESymbol < alphabet::Symbol, primitive::Unsigned > > & element : node.getElements ( ) )
-		if ( pos ( * element.get ( ), symbolF ) )
-			return true;
-
-	return false;
-}
-
-bool GlushkovTraversal::pos ( const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbolF ) {
-	return symbolF == node.getSymbol ( );
-}
-
-bool GlushkovTraversal::pos ( const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > & /* node */, const std::ranked_symbol < > & /* symbolF */ ) {
-	return false;
-}
-
-} /* namespace rte */
diff --git a/alib2algo/src/rte/glushkov/GlushkovTraversal.h b/alib2algo/src/rte/glushkov/GlushkovTraversal.h
deleted file mode 100644
index 05c642714b..0000000000
--- a/alib2algo/src/rte/glushkov/GlushkovTraversal.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * GlushkovTraversal.h
- *
- *  Created on: 14. 4. 2016
- *	  Author: Tomas Pecka
- */
-
-#ifndef RTE_GLUSHKOVTRAVERSAL_H_
-#define RTE_GLUSHKOVTRAVERSAL_H_
-
-#include <algorithm>
-#include <map>
-#include <set>
-#include <vector>
-
-#include <rte/formal/FormalRTE.h>
-#include <rte/formal/FormalRTEElements.h>
-
-#include <exception/CommonException.h>
-
-#include <alphabet/RankedSymbol.h>
-
-namespace rte {
-
-class GlushkovTraversal {
-public:
-	/**
-	 * @param re rte to probe
-	 * @return all rteSymbols which can be root of the tree.
-	 */
-	static std::set < std::ranked_symbol < > > first ( const rte::FormalRTE < > & re );
-
-	/**
-	 * @param re rte to probe
-	 * @param symbol FormalRTESymbol for which we need the follow(), i.e., Follow(RTE, symbol)
-	 * @return all symbols that can follow specific symbol in word
-	 */
-	static std::set < std::vector < std::ranked_symbol < > > > follow ( const rte::FormalRTE < > & re, const std::ranked_symbol < > & symbol );
-
-private:
-	/**
-	 * @return bool true if symbol pointer is in this subtree
-	 */
-	static bool pos ( const std::ranked_symbol < > & symbol, const rte::FormalRTE < > & node );
-
-	static std::set < std::ranked_symbol < > > first ( const rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > & node );
-	static std::set < std::ranked_symbol < > > first ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node );
-	static std::set < std::ranked_symbol < > > first ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node );
-	static std::set < std::ranked_symbol < > > first ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node );
-	static std::set < std::ranked_symbol < > > first ( const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > & node );
-	static std::set < std::ranked_symbol < > > first ( const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > & node );
-	static std::set < std::ranked_symbol < > > first ( const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > & node );
-
-	static bool pos ( const rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
-	static bool pos ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
-	static bool pos ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
-	static bool pos ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
-	static bool pos ( const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
-	static bool pos ( const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
-	static bool pos ( const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbSearch );
-
-	static std::set < std::vector < std::ranked_symbol < > > > follow ( const rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
-	static std::set < std::vector < std::ranked_symbol < > > > follow ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
-	static std::set < std::vector < std::ranked_symbol < > > > follow ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
-	static std::set < std::vector < std::ranked_symbol < > > > follow ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
-	static std::set < std::vector < std::ranked_symbol < > > > follow ( const rte::FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
-	static std::set < std::vector < std::ranked_symbol < > > > follow ( const rte::FormalRTESymbolSubst < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
-	static std::set < std::vector < std::ranked_symbol < > > > follow ( const rte::FormalRTEEmpty < alphabet::Symbol, primitive::Unsigned > & node, const std::ranked_symbol < > & symbol, const std::set < std::ranked_symbol < > > & alphabetK, std::map < std::ranked_symbol < >, std::set < std::ranked_symbol < > > > & subM );
-};
-
-} /* namespace rte */
-
-#endif /* RTE_GLUSHKOVTRAVERSAL_H_ */
-- 
GitLab