From 1f554ac43363fc1cf0c6dfe991d375d779049240 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 3 Dec 2019 13:29:40 +0100 Subject: [PATCH] improve bottom up NFTA pattern matching construction algo --- .../exact/ExactPatternMatchingAutomaton.h | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.h b/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.h index a5087a8ec0..6b098de11b 100644 --- a/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.h +++ b/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.h @@ -216,7 +216,7 @@ automaton::NFTA < SymbolType, unsigned > ExactPatternMatchingAutomaton::construc } template < class SymbolType > -unsigned constructRecursivePattern ( const ext::tree < common::ranked_symbol < SymbolType > > & node, automaton::NFTA < SymbolType, unsigned > & res, const common::ranked_symbol < SymbolType > & subtreeWildcard, unsigned loopState, unsigned & nextState ) { +unsigned constructRecursivePattern ( const ext::tree < common::ranked_symbol < SymbolType > > & node, automaton::NFTA < SymbolType, unsigned > & res, const common::ranked_symbol < SymbolType > & subtreeWildcard, unsigned & nextState ) { if ( node.getData ( ) == subtreeWildcard ) { unsigned state = nextState++; res.addState ( state ); @@ -226,7 +226,7 @@ unsigned constructRecursivePattern ( const ext::tree < common::ranked_symbol < S states.reserve ( ( size_t ) symbol.getRank ( ) ); for ( unsigned i = 0; i < ( unsigned ) symbol.getRank ( ); i++ ) - states.push_back ( loopState ); + states.push_back ( state ); res.addTransition ( symbol, states, state ); } @@ -237,7 +237,7 @@ unsigned constructRecursivePattern ( const ext::tree < common::ranked_symbol < S states.reserve ( ( size_t ) node.getData ( ).getRank ( ) ); for ( const ext::tree < common::ranked_symbol < SymbolType > > & child : node.getChildren ( ) ) - states.push_back ( constructRecursivePattern ( child, res, subtreeWildcard, loopState, nextState ) ); + states.push_back ( constructRecursivePattern ( child, res, subtreeWildcard, nextState ) ); unsigned state = nextState++; res.addState ( state ); @@ -257,20 +257,7 @@ automaton::NFTA < SymbolType, unsigned > ExactPatternMatchingAutomaton::construc unsigned nextState = 0; - unsigned loopState = nextState++; - res.addState ( loopState ); - - for ( const common::ranked_symbol < SymbolType > & symbol : res.getInputAlphabet ( ) ) { - ext::vector < unsigned > states; - states.reserve ( ( size_t ) symbol.getRank ( ) ); - - for ( unsigned i = 0; i < ( unsigned ) symbol.getRank ( ); i++ ) - states.push_back ( loopState ); - - res.addTransition ( symbol, states, loopState ); - } - - res.addFinalState ( constructRecursivePattern ( pattern.getContent ( ), res, pattern.getSubtreeWildcard ( ), loopState, nextState ) ); + res.addFinalState ( constructRecursivePattern ( pattern.getContent ( ), res, pattern.getSubtreeWildcard ( ), nextState ) ); return res; } -- GitLab