Skip to content
Snippets Groups Projects
Commit 94b7e87e authored by Jan Trávníček's avatar Jan Trávníček
Browse files

fix and simplify rte traversal

parent 3dc14b78
No related branches found
No related tags found
No related merge requests found
......@@ -16,10 +16,10 @@ std::set < std::ranked_symbol < > > GlushkovFirst::first ( const rte::FormalRTE
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 > ( );
tmp = node.getLeftElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal > ( );
ret.insert ( tmp.begin ( ), tmp.end ( ) );
 
tmp = node.getRightElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal::Formal > ( );
tmp = node.getRightElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal > ( );
ret.insert ( tmp.begin ( ), tmp.end ( ) );
 
return ret;
......@@ -28,7 +28,7 @@ std::set < std::ranked_symbol < > > GlushkovFirst::Formal::visit ( const rte::Fo
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 > ( );
tmp = node.getLeftElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal > ( );
ret.insert ( tmp.begin ( ), tmp.end ( ) );
 
// First::Formal() returns a set. hence only one occurrence.
......@@ -38,7 +38,7 @@ std::set < std::ranked_symbol < > > GlushkovFirst::Formal::visit ( const rte::Fo
 
if ( it != ret.end ( ) ) {
ret.erase ( it );
tmp = node.getRightElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal::Formal > ( );
tmp = node.getRightElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal > ( );
ret.insert ( tmp.begin ( ), tmp.end ( ) );
}
 
......@@ -48,7 +48,7 @@ std::set < std::ranked_symbol < > > GlushkovFirst::Formal::visit ( const rte::Fo
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 = node.getElement ( ).accept < std::set < std::ranked_symbol < > >, GlushkovFirst::Formal > ( );
ret.insert ( node.getSubstitutionSymbol ( ).getSymbol ( ) );
return ret;
}
......
......@@ -49,11 +49,7 @@ std::vector < std::vector < T > > cartesian ( const std::vector < std::vector <
}
 
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 ( bool change = true; 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;
 
......@@ -67,7 +63,6 @@ void preprocessSubMap ( const std::set < std::ranked_symbol < > > & alphabetK, s
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 ) {
......@@ -118,14 +113,10 @@ std::set < std::vector < std::ranked_symbol < > > > GlushkovFollow::Formal::visi
* 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 );
return 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;
return node.getRightElement ( ).accept < std::set < std::vector < std::ranked_symbol < > > >, GlushkovFollow::Formal > ( symbolF, alphabetK, subMap );
}
 
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 ) {
......@@ -135,9 +126,7 @@ std::set < std::vector < std::ranked_symbol < > > > GlushkovFollow::Formal::visi
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;
return node.getElement ( ).accept < std::set < std::vector < std::ranked_symbol < > > >, GlushkovFollow::Formal > ( symbolF, alphabetK, subMap );
}
 
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 ) {
......@@ -150,8 +139,7 @@ std::set < std::vector < std::ranked_symbol < > > > GlushkovFollow::Formal::visi
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;
return replaceConstants ( alphabetK, children, subMap );
}
 
for ( const auto & c : node.getElements ( ) ) {
......
......@@ -30,7 +30,7 @@ std::rvalue_ref < FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > G
FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > * ns = new FormalRTESymbolAlphabet < alphabet::Symbol, primitive::Unsigned > ( std::ranked_symbol < > ( alphabet::Symbol ( sps ), node.getSymbol ( ).getRank ( ) ) );
 
for ( const std::smart_ptr < const rte::FormalRTESymbol < alphabet::Symbol, primitive::Unsigned > > & e : node.getElements ( ) ) {
std::rvalue_ref < FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > child = e->accept < std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > >, GlushkovIndexate::Formal::Formal > ( i );
std::rvalue_ref < FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > child = e->accept < std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > >, GlushkovIndexate::Formal > ( i );
ns->appendElement ( * static_cast < FormalRTESymbol < alphabet::Symbol, primitive::Unsigned > * > ( child->clone ( ) ) ); // FIXME typecast
}
 
......@@ -42,19 +42,19 @@ std::rvalue_ref < FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > G
}
 
std::rvalue_ref < FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > GlushkovIndexate::Formal::visit ( const rte::FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > & node, int & i ) {
std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > left = node.getLeftElement ( ).accept < std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > >, GlushkovIndexate::Formal::Formal > ( i );
std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > right = node.getRightElement ( ).accept < std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > >, GlushkovIndexate::Formal::Formal > ( i );
std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > left = node.getLeftElement ( ).accept < std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > >, GlushkovIndexate::Formal > ( i );
std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > right = node.getRightElement ( ).accept < std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > >, GlushkovIndexate::Formal > ( i );
return std::rvalue_ref < FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > ( new FormalRTEAlternation < alphabet::Symbol, primitive::Unsigned > ( left, right ) );
}
 
std::rvalue_ref < FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > GlushkovIndexate::Formal::visit ( const rte::FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > & node, int & i ) {
std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > left = node.getLeftElement ( ).accept < std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > >, GlushkovIndexate::Formal::Formal > ( i );
std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > right = node.getRightElement ( ).accept < std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > >, GlushkovIndexate::Formal::Formal > ( i );
std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > left = node.getLeftElement ( ).accept < std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > >, GlushkovIndexate::Formal > ( i );
std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > right = node.getRightElement ( ).accept < std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > >, GlushkovIndexate::Formal > ( i );
return std::rvalue_ref < FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > ( new FormalRTESubstitution < alphabet::Symbol, primitive::Unsigned > ( left, right, node.getSubstitutionSymbol ( ) ) );
}
 
std::rvalue_ref < FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > GlushkovIndexate::Formal::visit ( const rte::FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > & node, int & i ) {
std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > element = node.getElement ( ).accept < std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > >, GlushkovIndexate::Formal::Formal > ( i );
std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > element = node.getElement ( ).accept < std::rvalue_ref < rte::FormalRTEElement < alphabet::Symbol, primitive::Unsigned > >, GlushkovIndexate::Formal > ( i );
return std::rvalue_ref < FormalRTEElement < alphabet::Symbol, primitive::Unsigned > > ( new FormalRTEIteration < alphabet::Symbol, primitive::Unsigned > ( element, node.getSubstitutionSymbol ( ) ) );
}
 
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment