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

GlushkovRTE: Simplify subMap processing.

parent 278e747a
No related branches found
No related tags found
No related merge requests found
...@@ -204,76 +204,60 @@ void preprocessSubMap ( const std::set < alphabet::RankedSymbol > & alphabetK, s ...@@ -204,76 +204,60 @@ void preprocessSubMap ( const std::set < alphabet::RankedSymbol > & alphabetK, s
while ( change ) { while ( change ) {
change = false; change = false;
   
for ( auto & kv : subMap ) { for ( std::pair < const alphabet::RankedSymbol, std::set < alphabet::RankedSymbol > > & kv : subMap ) {
std::set < alphabet::RankedSymbol > & value = kv.second; std::set < alphabet::RankedSymbol > & substSet = kv.second;
   
for ( const auto & v : value ) { for ( const auto & e : substSet ) {
if ( alphabetK.find ( v ) == alphabetK.end ( ) ) continue; if ( alphabetK.count ( e ) == 0 ) continue;
   
// std::cerr << "Gonna replace in submap: " << kv.first << ": " << v->getSymbol() << std::endl; auto it = subMap.find ( e );
size_t oldSize = substSet.size ( );
auto it = subMap.find ( v ); substSet.insert ( it->second.begin ( ), it->second.end ( ) );
size_t vsize = value.size ( ); change = ( oldSize != substSet.size ( ) ); // something was added
value.insert ( it->second.begin ( ), it->second.end ( ) ); substSet.erase ( e );
change = ( vsize != value.size ( ) );
value.erase ( v );
/*
* for(const auto& x : it->second)
* std::cerr << "\t" << x->getSymbol() << std::endl;
*/
} }
} }
} }
} }
   
std::set < std::vector < alphabet::RankedSymbol > > replaceConstants ( const std::set < alphabet::RankedSymbol > & alphabetK, const std::vector < alphabet::RankedSymbol > & f, const std::map < alphabet::RankedSymbol, std::set < alphabet::RankedSymbol > > & subMap2 ) { template < class T >
std::set < std::vector < alphabet::RankedSymbol > > ret; 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 ( ) )
if ( f.size ( ) == 0 ) return ret; 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 );
}
   
std::map < alphabet::RankedSymbol, std::set < alphabet::RankedSymbol > > subMap ( subMap2 ); }
preprocessSubMap ( alphabetK, subMap );
   
auto subIt = subMap.find ( f[0] ); 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 ( ), alphabet::RankedSymbol ( 0, 0 ) );
   
if ( subIt == subMap.end ( ) ) { cartesian_rec ( input, ret, current, 0 );
std::vector < alphabet::RankedSymbol > v;
v.push_back ( f[0] );
ret.insert ( v );
} else {
for ( const auto & subSymbol : subIt->second ) {
std::vector < alphabet::RankedSymbol > v;
v.push_back ( subSymbol );
ret.insert ( v );
}
}
   
for ( size_t i = 1; i < f.size ( ); i++ ) { return ret;
std::set < std::vector < alphabet::RankedSymbol > > tmp; }
   
subIt = subMap.find ( f[i] ); std::set < std::vector < alphabet::RankedSymbol > > replaceConstants ( const std::set < alphabet::RankedSymbol > & alphabetK, const std::vector < alphabet::RankedSymbol > & follow, const std::map < alphabet::RankedSymbol, std::set < alphabet::RankedSymbol > > & subMap2 ) {
std::map < alphabet::RankedSymbol, std::set < alphabet::RankedSymbol > > subMap ( subMap2 );
preprocessSubMap ( alphabetK, subMap );
   
if ( subIt == subMap.end ( ) ) std::vector < std::vector < alphabet::RankedSymbol > > input;
for ( const auto & r : ret ) {
std::vector < alphabet::RankedSymbol > v = r;
v.push_back ( f[i] );
tmp.insert ( v );
}
   
for ( const alphabet::RankedSymbol & e : follow ) {
if ( alphabetK.count ( e ) > 0 )
input.push_back ( std::vector < alphabet::RankedSymbol > ( subMap.at ( e ).begin ( ), subMap.at ( e ).end ( ) ) );
else else
input.push_back ( std::vector < alphabet::RankedSymbol > { e } );
for ( const auto & r : ret )
for ( const auto & subSymbol : subIt->second ) {
std::vector < alphabet::RankedSymbol > v = r;
v.push_back ( subSymbol );
tmp.insert ( v );
}
ret = tmp;
} }
   
return ret; /* now do the cartesian product on "input" */
std::vector < std::vector < alphabet::RankedSymbol > > followSet = cartesian ( input );
return std::set < std::vector < alphabet::RankedSymbol > > ( followSet.begin ( ), followSet.end ( ) );
} }
   
std::set < std::vector < alphabet::RankedSymbol > > GlushkovTraversal::follow ( const rte::FormalRTESymbolAlphabet & node, const alphabet::RankedSymbol & symbolF, const std::set < alphabet::RankedSymbol > & alphabetK, std::map < alphabet::RankedSymbol, std::set < alphabet::RankedSymbol > > & subMap ) { std::set < std::vector < alphabet::RankedSymbol > > GlushkovTraversal::follow ( const rte::FormalRTESymbolAlphabet & node, const alphabet::RankedSymbol & symbolF, const std::set < alphabet::RankedSymbol > & alphabetK, std::map < alphabet::RankedSymbol, std::set < alphabet::RankedSymbol > > & subMap ) {
......
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