diff --git a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx index 1546e14a143919ec402df4dac01e4bc8aed6a87b..0ceb4ff5dfbf47dded2966fa595e54231fbfa7cd 100644 --- a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx +++ b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx @@ -590,7 +590,7 @@ bool RegExpOptimize::V5( UnboundedRegExpAlternation & node ) { if( iterConcat->getChildren().size( ) != ( unsigned ) distance( std::next( itC ), concat->getChildren().end( ) ) || ! equal( iterConcat->getChildren().begin( ), iterConcat->getChildren().end( ), std::next( itC ), [ ]( const std::smart_ptr < UnboundedRegExpElement > & a, const std::smart_ptr < UnboundedRegExpElement > & b ) -> bool{ return *a == *b; } ) ) { - itC++; + ++ itC; continue; } advance( itStartY, (int)iterConcat->getChildren().size( ) ); @@ -769,7 +769,7 @@ bool RegExpOptimize::V8( UnboundedRegExpConcatenation & node ) { UnboundedRegExpIteration* iter = dynamic_cast<UnboundedRegExpIteration*>( it->get() ); if( ! iter ) { - it ++; + ++ it; continue; } @@ -818,64 +818,58 @@ bool RegExpOptimize::V8( UnboundedRegExpConcatenation & node ) { * @param node UnboundedRegExpConcatenation node * @return bool true if optimization applied else false */ -bool RegExpOptimize::V9( UnboundedRegExpConcatenation & /* node */ ) { -/* bool optimized = false; */ +bool RegExpOptimize::V9( UnboundedRegExpConcatenation & node ) { + bool optimized = false; // interpretation: if concat (C1) with iter && iteration's element is concat (C2), then: // simultaneously iterate through C1 and C2. (axy)*axz=ax(yax)*z -> get ax that is same and relocate them... -/* for( auto it = node->elements.begin( ) ; it != node->elements.end( ) ; ) - { + for( auto it = node.getChildren().begin( ) ; it != node.getChildren().end( ) ; ) { UnboundedRegExpIteration * iter = dynamic_cast<UnboundedRegExpIteration*>( it->get() ); - if ( ! iter ) - { - it++; + if ( ! iter ) { + ++ it; continue; } - UnboundedRegExpConcatenation * concat = dynamic_cast<UnboundedRegExpConcatenation*>( iter->element.get() ); - if( ! concat ) - { - it++; + UnboundedRegExpConcatenation * concat = dynamic_cast<UnboundedRegExpConcatenation*>( iter->getChild().get() ); + if( ! concat ) { + ++it; continue; } // find range from <it+1;sth> and <concat.begin;sth> that is equal - auto c1Iter = std::next( it ), c2Iter = concat->elements.begin( ); - while( c1Iter != node->elements.end() && c2Iter != concat->elements.end( ) && **c1Iter == ** c2Iter ) - { - c1Iter ++; - c2Iter ++; + auto c1Iter = std::next( it ), c2Iter = concat->getChildren().begin( ); + while( c1Iter != node.getChildren().end() && c2Iter != concat->getChildren().end( ) && **c1Iter == ** c2Iter ) { + ++ c1Iter; + ++ c2Iter; } - if( c1Iter == std::next( it ) ) - { - it ++; + if( c1Iter == std::next( it ) ) { + ++ it; continue; } // std::cout << "xy" << std::endl; // UnboundedRegExpConcatenation* tmp = new UnboundedRegExpConcatenation( ); - // tmp->elements.insert( tmp->elements.end( ), std::next( it ), c1Iter ); + // tmp->insert( tmp->getChildren().end( ), std::next( it ), c1Iter ); // std::cout << RegExp( tmp ) << std::endl; // copy the range <it;sth>, delete it and go back to the iter node std::vector<std::smart_ptr < UnboundedRegExpElement > > copyRange; copyRange.insert( copyRange.end(), std::next( it ), c1Iter ); - it = node->elements.erase( std::next( it ), c1Iter ); + it = node.getChildren().erase( std::next( it ), c1Iter ); it = std::prev( it ); // insert that range before it position - node->elements.insert( it, copyRange.begin( ), copyRange.end( ) ); + node.insert( it, copyRange.begin( ), copyRange.end( ) ); // alter the iteration's concat node copyRange.clear( ); - copyRange.insert( copyRange.end(), concat->elements.begin( ), c2Iter ); - concat->elements.erase( concat->elements.begin( ), c2Iter ); - concat->elements.insert( concat->elements.end(), copyRange.begin( ), copyRange.end( ) ); + copyRange.insert( copyRange.end(), concat->getChildren().begin( ), c2Iter ); + concat->getChildren().erase( concat->getChildren().begin( ), c2Iter ); + concat->insert( concat->getChildren().end(), copyRange.begin( ), copyRange.end( ) ); } - return optimized; */ - return false; // FIXME + return optimized; } /**