Skip to content
Snippets Groups Projects
Unverified Commit 9c5a13fe authored by Jan Trávníček's avatar Jan Trávníček Committed by Tomáš Pecka
Browse files

algo: simplify regular equations solver

parent 37fa8e73
No related branches found
No related tags found
1 merge request!185Z automata merge
...@@ -189,14 +189,10 @@ void RegularEquationSolver < TerminalSymbolType, VariableSymbolType >::addEquati ...@@ -189,14 +189,10 @@ void RegularEquationSolver < TerminalSymbolType, VariableSymbolType >::addEquati
   
template < class TerminalSymbolType, class VariableSymbolType > template < class TerminalSymbolType, class VariableSymbolType >
void RegularEquationSolver < TerminalSymbolType, VariableSymbolType >::sortSymbolsByDepth ( const VariableSymbolType & solveFor ) { void RegularEquationSolver < TerminalSymbolType, VariableSymbolType >::sortSymbolsByDepth ( const VariableSymbolType & solveFor ) {
ext::map < VariableSymbolType, bool > visited; ext::set < VariableSymbolType > visited;
std::queue < VariableSymbolType > queue; std::queue < VariableSymbolType > queue;
   
for(const VariableSymbolType & symbol : nonterminalSymbols ) { visited.insert ( solveFor );
visited [ symbol ] = false;
}
visited [ solveFor ] = true;
queue.push ( solveFor ); queue.push ( solveFor );
   
while ( ! queue.empty ( ) ) { while ( ! queue.empty ( ) ) {
...@@ -205,13 +201,10 @@ void RegularEquationSolver < TerminalSymbolType, VariableSymbolType >::sortSymbo ...@@ -205,13 +201,10 @@ void RegularEquationSolver < TerminalSymbolType, VariableSymbolType >::sortSymbo
   
nonterminalSymbolsByDepth.push_back ( variable ); nonterminalSymbolsByDepth.push_back ( variable );
   
for ( const auto & kv : equationTransition ) { for ( const auto & kv : equationTransition )
// find all transitions from current symbol that are non-empty, enqueue transition'variable target symbol // find all transitions from current symbol that are non-empty, enqueue transition'variable target symbol
if ( kv.first.first == variable && ! visited [ kv.first.second ] && !kv.second.getElements ( ).empty ( ) ) { if ( kv.first.first == variable && !kv.second.getElements ( ).empty ( ) && visited.insert ( kv.first.second ).second )
visited [ kv.first.second ] = true;
queue.push ( kv.first.second ); queue.push ( kv.first.second );
}
}
} }
} }
   
......
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