From c70317d5e203e9277e694898eded11740d03b5c4 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Thu, 28 May 2020 12:48:47 +0200 Subject: [PATCH] fixes and simplifications in ExactPatternMatch --- .../src/arbology/exact/ExactPatternMatch.h | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/alib2algo/src/arbology/exact/ExactPatternMatch.h b/alib2algo/src/arbology/exact/ExactPatternMatch.h index 824fbe3ff8..608f31a756 100644 --- a/alib2algo/src/arbology/exact/ExactPatternMatch.h +++ b/alib2algo/src/arbology/exact/ExactPatternMatch.h @@ -73,10 +73,8 @@ private: template < class SymbolType > static void matchInternal ( unsigned & index, ext::set < unsigned > & occ, const ext::tree < SymbolType > & subject, const ext::tree < SymbolType > & pattern, const SymbolType & subtreeVariable ); - template < class SymbolType > - static void matchInternal ( unsigned & index, ext::set < unsigned > & occ, const ext::tree < common::ranked_symbol < SymbolType > > & subject, const ext::tree < common::ranked_symbol < SymbolType > > & pattern, const common::ranked_symbol < SymbolType > & subtreeVariable ); - template < class SymbolType > - static void matchInternal ( unsigned & index, ext::set < unsigned > & occ, const ext::tree < common::ranked_symbol < SymbolType > > & subject, const ext::tree < common::ranked_symbol < SymbolType > > & pattern, const common::ranked_symbol < SymbolType > & subtreeVariable, const ext::set < common::ranked_symbol < SymbolType > > & nonlinearVariables, const ext::tree < common::ranked_symbol < unsigned > > & repeats ); + template < class SymbolType, class RepeatsType > + static void matchInternal ( unsigned & index, ext::set < unsigned > & occ, const ext::tree < SymbolType > & subject, const ext::tree < SymbolType > & pattern, const SymbolType & subtreeVariable, const ext::set < SymbolType > & nonlinearVariables, const ext::tree < RepeatsType > & repeats ); template < class SymbolType > static bool matchUnorderedHelper ( const ext::tree < common::ranked_symbol < SymbolType > > & subject, const ext::tree < common::ranked_symbol < SymbolType > > & pattern, const common::ranked_symbol < SymbolType > & subtreeVariable ); @@ -95,7 +93,7 @@ bool ExactPatternMatch::matchHelper ( const ext::tree < SymbolType > & subject, auto patternIter = pattern.getChildren ( ).begin ( ); auto subjectIter = subject.getChildren ( ).begin ( ); - while ( patternIter != pattern.getChildren ( ).end ( ) || subjectIter != subject.getChildren ( ).end ( ) ) { + while ( patternIter != pattern.getChildren ( ).end ( ) && subjectIter != subject.getChildren ( ).end ( ) ) { if ( matchHelper ( * subjectIter, * patternIter, subtreeVariable ) ) ++ patternIter; @@ -151,25 +149,15 @@ void ExactPatternMatch::matchInternal ( unsigned & index, ext::set < unsigned > matchInternal ( index, occ, child, pattern, subtreeVariable ); } -template < class SymbolType > -void ExactPatternMatch::matchInternal ( unsigned & index, ext::set < unsigned > & occ, const ext::tree < common::ranked_symbol < SymbolType > > & subject, const ext::tree < common::ranked_symbol < SymbolType > > & pattern, const common::ranked_symbol < SymbolType > & subtreeVariable ) { - if ( matchHelper ( subject, pattern, subtreeVariable ) ) occ.insert ( index ); - - index++; - - for ( const ext::tree < common::ranked_symbol < SymbolType > > & child : subject.getChildren ( ) ) - matchInternal ( index, occ, child, pattern, subtreeVariable ); -} - -template < class SymbolType > -void ExactPatternMatch::matchInternal ( unsigned & index, ext::set < unsigned > & occ, const ext::tree < common::ranked_symbol < SymbolType > > & subject, const ext::tree < common::ranked_symbol < SymbolType > > & pattern, const common::ranked_symbol < SymbolType > & subtreeVariable, const ext::set < common::ranked_symbol < SymbolType > > & nonlinearVariables, const ext::tree < common::ranked_symbol < unsigned > > & repeats ) { - ext::map < common::ranked_symbol < SymbolType >, unsigned > variablesSetting; +template < class SymbolType, class RepeatsType > +void ExactPatternMatch::matchInternal ( unsigned & index, ext::set < unsigned > & occ, const ext::tree < SymbolType > & subject, const ext::tree < SymbolType > & pattern, const SymbolType & subtreeVariable, const ext::set < SymbolType > & nonlinearVariables, const ext::tree < RepeatsType > & repeats ) { + ext::map < SymbolType, unsigned > variablesSetting; if ( matchHelper ( subject, pattern, subtreeVariable, nonlinearVariables, repeats, variablesSetting ) ) occ.insert ( index ); index++; - for ( const ext::tuple < const ext::tree < common::ranked_symbol < SymbolType > > &, const ext::tree < common::ranked_symbol < unsigned > > & > & childs : ext::make_tuple_foreach ( subject.getChildren ( ), repeats.getChildren ( ) ) ) + for ( const ext::tuple < const ext::tree < SymbolType > &, const ext::tree < RepeatsType > & > & childs : ext::make_tuple_foreach ( subject.getChildren ( ), repeats.getChildren ( ) ) ) matchInternal ( index, occ, std::get < 0 > ( childs ), pattern, subtreeVariable, nonlinearVariables, std::get < 1 > ( childs ) ); } -- GitLab