diff --git a/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.cpp b/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.cpp index f5b7c51880ef8d1c4b01f97ab51d31c0f3e97da1..57f28681430abfca902fa9bd6c848f150af4fb99 100644 --- a/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.cpp +++ b/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.cpp @@ -25,45 +25,50 @@ namespace arbology { namespace exact { automaton::Automaton ExactPatternMatchingAutomaton::construct ( const tree::RankedTreeWrapper & pattern ) { - return getInstance().dispatch(pattern.getData()); + return getInstance ( ).dispatch ( pattern.getData ( ) ); } -automaton::InputDrivenNPDA ExactPatternMatchingAutomaton::construct(const tree::PrefixRankedTree& pattern) { - automaton::InputDrivenNPDA res(automaton::State(0), alphabet::symbolFrom('S')); +automaton::InputDrivenNPDA ExactPatternMatchingAutomaton::construct ( const tree::PrefixRankedTree & pattern ) { + automaton::InputDrivenNPDA res ( automaton::State ( 0 ), alphabet::symbolFrom ( 'S' ) ); - for(const alphabet::RankedSymbol& symbol : pattern.getAlphabet()) { - res.addInputSymbol(alphabet::Symbol{symbol}); - res.setPushdownStoreOperation(alphabet::Symbol{symbol}, std::vector<alphabet::Symbol>{1, alphabet::symbolFrom('S')}, std::vector<alphabet::Symbol>{symbol.getRank().getData(), alphabet::symbolFrom('S')}); + for ( const alphabet::RankedSymbol & symbol : pattern.getAlphabet ( ) ) { + res.addInputSymbol ( alphabet::Symbol { symbol } ); + res.setPushdownStoreOperation ( alphabet::Symbol { symbol }, std::vector < alphabet::Symbol > { 1, alphabet::symbolFrom ( 'S' ) }, std::vector < alphabet::Symbol > { symbol.getRank ( ).getData ( ), alphabet::symbolFrom ( 'S' ) } ); } - for(const alphabet::RankedSymbol& symbol : pattern.getAlphabet()) { - res.addTransition(automaton::State(0), alphabet::Symbol{symbol}, automaton::State(0)); + for ( const alphabet::RankedSymbol & symbol : pattern.getAlphabet ( ) ) { + res.addTransition ( automaton::State ( 0 ), alphabet::Symbol { symbol }, automaton::State ( 0 ) ); } + int i = 1; - for(const alphabet::RankedSymbol& symbol : pattern.getContent()) { - res.addState(automaton::State(i)); - res.addTransition(automaton::State(i-1), alphabet::Symbol{symbol}, automaton::State(i)); + + for ( const alphabet::RankedSymbol & symbol : pattern.getContent ( ) ) { + res.addState ( automaton::State ( i ) ); + res.addTransition ( automaton::State ( i - 1 ), alphabet::Symbol { symbol }, automaton::State ( i ) ); i++; } - res.addFinalState(automaton::State(i-1)); + + res.addFinalState ( automaton::State ( i - 1 ) ); return res; } -auto ExactPatternMatchingAutomatonPrefixRankedTree = ExactPatternMatchingAutomaton::RegistratorWrapper<automaton::InputDrivenNPDA, tree::PrefixRankedTree>(ExactPatternMatchingAutomaton::getInstance(), ExactPatternMatchingAutomaton::construct); +auto ExactPatternMatchingAutomatonPrefixRankedTree = ExactPatternMatchingAutomaton::RegistratorWrapper < automaton::InputDrivenNPDA, tree::PrefixRankedTree > ( ExactPatternMatchingAutomaton::getInstance ( ), ExactPatternMatchingAutomaton::construct ); + +std::vector < alphabet::Symbol > computeRHS ( const tree::PrefixRankedPattern & pattern, const std::vector < int > & patternSubtreeJumpTable, int i ) { + const std::vector < alphabet::RankedSymbol > & content = pattern.getContent ( ); -std::vector<alphabet::Symbol> computeRHS(const tree::PrefixRankedPattern& pattern, const std::vector<int>& patternSubtreeJumpTable, int i) { - const std::vector<alphabet::RankedSymbol>& content = pattern.getContent(); + unsigned rank = content[i].getRank ( ).getData ( ); - unsigned rank = content[i].getRank().getData(); i++; - std::vector<alphabet::Symbol> res; - for(unsigned ranki = 0; ranki < rank; ranki++) { - if(content[i] == pattern.getSubtreeWildcard()) { - res.push_back(alphabet::symbolFrom('R')); + std::vector < alphabet::Symbol > res; + + for ( unsigned ranki = 0; ranki < rank; ranki++ ) { + if ( content[i] == pattern.getSubtreeWildcard ( ) ) { + res.push_back ( alphabet::symbolFrom ( 'R' ) ); i++; } else { - res.push_back(alphabet::symbolFrom('T')); + res.push_back ( alphabet::symbolFrom ( 'T' ) ); i = patternSubtreeJumpTable[i]; } @@ -72,127 +77,143 @@ std::vector<alphabet::Symbol> computeRHS(const tree::PrefixRankedPattern& patter return res; } -automaton::NPDA ExactPatternMatchingAutomaton::construct(const tree::PrefixRankedPattern& pattern) { - automaton::NPDA res(automaton::State(0), alphabet::symbolFrom('T')); - for(const alphabet::RankedSymbol& symbol : pattern.getAlphabet()) { - res.addInputSymbol(alphabet::Symbol{symbol}); +automaton::NPDA ExactPatternMatchingAutomaton::construct ( const tree::PrefixRankedPattern & pattern ) { + automaton::NPDA res ( automaton::State ( 0 ), alphabet::symbolFrom ( 'T' ) ); + + for ( const alphabet::RankedSymbol & symbol : pattern.getAlphabet ( ) ) { + res.addInputSymbol ( alphabet::Symbol { symbol } ); } - res.setStackAlphabet({alphabet::symbolFrom('T'), alphabet::symbolFrom('R')}); - for(const alphabet::RankedSymbol& symbol : pattern.getAlphabet()) { - if(symbol == pattern.getSubtreeWildcard()) continue; + res.setStackAlphabet ( { alphabet::symbolFrom ( 'T' ), alphabet::symbolFrom ( 'R' ) } ); - res.addTransition(automaton::State(0), alphabet::Symbol{symbol}, std::vector<alphabet::Symbol>{1, alphabet::symbolFrom('T')}, automaton::State(0), std::vector<alphabet::Symbol>{symbol.getRank().getData(), alphabet::symbolFrom('T')}); + for ( const alphabet::RankedSymbol & symbol : pattern.getAlphabet ( ) ) { + if ( symbol == pattern.getSubtreeWildcard ( ) ) continue; + + res.addTransition ( automaton::State ( 0 ), alphabet::Symbol { symbol }, std::vector < alphabet::Symbol > { 1, alphabet::symbolFrom ( 'T' ) }, automaton::State ( 0 ), std::vector < alphabet::Symbol > { symbol.getRank ( ).getData ( ), alphabet::symbolFrom ( 'T' ) } ); } std::vector < int > patternSubtreeJumpTable = SubtreeJumpTable::compute ( pattern ); int i = 1; - for(const alphabet::RankedSymbol& symbol : pattern.getContent()) { - res.addState(automaton::State(i)); - if(symbol == pattern.getSubtreeWildcard()) { - for(const alphabet::RankedSymbol& symbol : pattern.getAlphabet()) { - if(symbol == pattern.getSubtreeWildcard()) continue; - if(symbol.getRank().getData() == 0) { - res.addTransition(automaton::State(i-1), alphabet::Symbol{symbol}, std::vector<alphabet::Symbol>{1, alphabet::symbolFrom('T')}, automaton::State(i-1), std::vector<alphabet::Symbol>{}); + for ( const alphabet::RankedSymbol & symbol : pattern.getContent ( ) ) { + res.addState ( automaton::State ( i ) ); + + if ( symbol == pattern.getSubtreeWildcard ( ) ) + for ( const alphabet::RankedSymbol & symbol : pattern.getAlphabet ( ) ) { + if ( symbol == pattern.getSubtreeWildcard ( ) ) continue; - res.addTransition(automaton::State(i-1), alphabet::Symbol{symbol}, std::vector<alphabet::Symbol>{1, alphabet::symbolFrom('R')}, automaton::State(i), std::vector<alphabet::Symbol>{}); + if ( symbol.getRank ( ).getData ( ) == 0 ) { + res.addTransition ( automaton::State ( i - 1 ), alphabet::Symbol { symbol }, std::vector < alphabet::Symbol > { 1, alphabet::symbolFrom ( 'T' ) }, automaton::State ( i - 1 ), std::vector < alphabet::Symbol > { } ); + + res.addTransition ( automaton::State ( i - 1 ), alphabet::Symbol { symbol }, std::vector < alphabet::Symbol > { 1, alphabet::symbolFrom ( 'R' ) }, automaton::State ( i ), std::vector < alphabet::Symbol > { } ); } else { - std::vector<alphabet::Symbol> push{symbol.getRank().getData(), alphabet::symbolFrom('T')}; - res.addTransition(automaton::State(i-1), alphabet::Symbol{symbol}, std::vector<alphabet::Symbol>{1, alphabet::symbolFrom('T')}, automaton::State(i-1), push); + std::vector < alphabet::Symbol > push { + symbol.getRank ( ).getData ( ), alphabet::symbolFrom ( 'T' ) + }; + res.addTransition ( automaton::State ( i - 1 ), alphabet::Symbol { symbol }, std::vector < alphabet::Symbol > { 1, alphabet::symbolFrom ( 'T' ) }, automaton::State ( i - 1 ), push ); - push[symbol.getRank().getData() - 1] = alphabet::symbolFrom('R'); - res.addTransition(automaton::State(i-1), alphabet::Symbol{symbol}, std::vector<alphabet::Symbol>{1, alphabet::symbolFrom('R')}, automaton::State(i-1), push); + push[symbol.getRank ( ).getData ( ) - 1] = alphabet::symbolFrom ( 'R' ); + res.addTransition ( automaton::State ( i - 1 ), alphabet::Symbol { symbol }, std::vector < alphabet::Symbol > { 1, alphabet::symbolFrom ( 'R' ) }, automaton::State ( i - 1 ), push ); } } - } else { - res.addTransition(automaton::State(i-1), alphabet::Symbol{symbol}, std::vector<alphabet::Symbol>{1, alphabet::symbolFrom('T')}, automaton::State(i), computeRHS(pattern, patternSubtreeJumpTable, i-1)); - } + else + res.addTransition ( automaton::State ( i - 1 ), alphabet::Symbol { symbol }, std::vector < alphabet::Symbol > { 1, alphabet::symbolFrom ( 'T' ) }, automaton::State ( i ), computeRHS ( pattern, patternSubtreeJumpTable, i - 1 ) ); + i++; } - res.addFinalState(automaton::State(i-1)); + res.addFinalState ( automaton::State ( i - 1 ) ); return res; } -auto ExactPatternMatchingAutomatonPrefixRankedPattern = ExactPatternMatchingAutomaton::RegistratorWrapper<automaton::NPDA, tree::PrefixRankedPattern>(ExactPatternMatchingAutomaton::getInstance(), ExactPatternMatchingAutomaton::construct); +auto ExactPatternMatchingAutomatonPrefixRankedPattern = ExactPatternMatchingAutomaton::RegistratorWrapper < automaton::NPDA, tree::PrefixRankedPattern > ( ExactPatternMatchingAutomaton::getInstance ( ), ExactPatternMatchingAutomaton::construct ); -automaton::State constructRecursiveTree(const tree::RankedNode & node, automaton::NFTA & res, int & nextState) { - std::vector<automaton::State> states; - states.reserve(node.getSymbol().getRank().getData()); - for(const auto & child : node.getChildren()) { - states.push_back(constructRecursiveTree(*child, res, nextState)); - } - automaton::State state (nextState++); - res.addState(state); - res.addTransition(node.getSymbol(), states, state); +automaton::State constructRecursiveTree ( const tree::RankedNode & node, automaton::NFTA & res, int & nextState ) { + std::vector < automaton::State > states; + + states.reserve ( node.getSymbol ( ).getRank ( ).getData ( ) ); + + for ( const auto & child : node.getChildren ( ) ) + states.push_back ( constructRecursiveTree ( * child, res, nextState ) ); + + automaton::State state ( nextState++ ); + res.addState ( state ); + res.addTransition ( node.getSymbol ( ), states, state ); return state; } -automaton::NFTA ExactPatternMatchingAutomaton::construct(const tree::RankedTree & pattern) { - const std::set<alphabet::RankedSymbol>& alphabet = pattern.getAlphabet(); +automaton::NFTA ExactPatternMatchingAutomaton::construct ( const tree::RankedTree & pattern ) { + const std::set < alphabet::RankedSymbol > & alphabet = pattern.getAlphabet ( ); automaton::NFTA res; - res.setInputSymbols(alphabet); + + res.setInputSymbols ( alphabet ); int nextState = 0; - res.addFinalState(constructRecursiveTree(pattern.getRoot(), res, nextState)); + res.addFinalState ( constructRecursiveTree ( pattern.getRoot ( ), res, nextState ) ); return res; } -auto ExactPatternMatchingAutomatonRankedTree = ExactPatternMatchingAutomaton::RegistratorWrapper<automaton::NFTA, tree::RankedTree>(ExactPatternMatchingAutomaton::getInstance(), ExactPatternMatchingAutomaton::construct); - -automaton::State constructRecursivePattern(const tree::RankedNode & node, automaton::NFTA & res, const alphabet::RankedSymbol& subtreeWildcard, const automaton::State& loopState, int & nextState) { - if(node.getSymbol() == subtreeWildcard) { - automaton::State state (nextState++); - res.addState(state); - for(const alphabet::RankedSymbol& symbol : res.getInputAlphabet()) { - std::vector<automaton::State> states; - states.reserve(symbol.getRank().getData()); - for(unsigned i = 0; i < symbol.getRank().getData(); i++) { - states.push_back(loopState); - } - res.addTransition(symbol, states, state); +auto ExactPatternMatchingAutomatonRankedTree = ExactPatternMatchingAutomaton::RegistratorWrapper < automaton::NFTA, tree::RankedTree > ( ExactPatternMatchingAutomaton::getInstance ( ), ExactPatternMatchingAutomaton::construct ); + +automaton::State constructRecursivePattern ( const tree::RankedNode & node, automaton::NFTA & res, const alphabet::RankedSymbol & subtreeWildcard, const automaton::State & loopState, int & nextState ) { + if ( node.getSymbol ( ) == subtreeWildcard ) { + automaton::State state ( nextState++ ); + res.addState ( state ); + + for ( const alphabet::RankedSymbol & symbol : res.getInputAlphabet ( ) ) { + std::vector < automaton::State > states; + states.reserve ( symbol.getRank ( ).getData ( ) ); + + for ( unsigned i = 0; i < symbol.getRank ( ).getData ( ); i++ ) + states.push_back ( loopState ); + + res.addTransition ( symbol, states, state ); } + return state; } else { - std::vector<automaton::State> states; - states.reserve(node.getSymbol().getRank().getData()); - for(const auto & child : node.getChildren()) { - states.push_back(constructRecursivePattern(*child, res, subtreeWildcard, loopState, nextState)); - } - automaton::State state (nextState++); - res.addState(state); - res.addTransition(node.getSymbol(), states, state); + std::vector < automaton::State > states; + states.reserve ( node.getSymbol ( ).getRank ( ).getData ( ) ); + + for ( const auto & child : node.getChildren ( ) ) + states.push_back ( constructRecursivePattern ( * child, res, subtreeWildcard, loopState, nextState ) ); + + automaton::State state ( nextState++ ); + res.addState ( state ); + res.addTransition ( node.getSymbol ( ), states, state ); return state; } } -automaton::NFTA ExactPatternMatchingAutomaton::construct(const tree::RankedPattern & pattern) { - std::set<alphabet::RankedSymbol> alphabet = pattern.getAlphabet(); - alphabet.erase(pattern.getSubtreeWildcard()); +automaton::NFTA ExactPatternMatchingAutomaton::construct ( const tree::RankedPattern & pattern ) { + std::set < alphabet::RankedSymbol > alphabet = pattern.getAlphabet ( ); + + alphabet.erase ( pattern.getSubtreeWildcard ( ) ); automaton::NFTA res; - res.setInputSymbols(alphabet); + res.setInputSymbols ( alphabet ); int nextState = 0; - automaton::State loopState (nextState++); - res.addState(loopState); - for(const alphabet::RankedSymbol& symbol : res.getInputAlphabet()) { - std::vector<automaton::State> states; - states.reserve(symbol.getRank().getData()); - for(unsigned i = 0; i < symbol.getRank().getData(); i++) { - states.push_back(loopState); - } - res.addTransition(symbol, states, loopState); + automaton::State loopState ( nextState++ ); + res.addState ( loopState ); + + for ( const alphabet::RankedSymbol & symbol : res.getInputAlphabet ( ) ) { + std::vector < automaton::State > states; + states.reserve ( symbol.getRank ( ).getData ( ) ); + + for ( unsigned i = 0; i < symbol.getRank ( ).getData ( ); i++ ) + states.push_back ( loopState ); + + res.addTransition ( symbol, states, loopState ); } - res.addFinalState(constructRecursivePattern(pattern.getRoot(), res, pattern.getSubtreeWildcard(), loopState, nextState)); + res.addFinalState ( constructRecursivePattern ( pattern.getRoot ( ), res, pattern.getSubtreeWildcard ( ), loopState, nextState ) ); return res; } -auto ExactPatternMatchingAutomatonRankedPattern = ExactPatternMatchingAutomaton::RegistratorWrapper<automaton::NFTA, tree::RankedPattern>(ExactPatternMatchingAutomaton::getInstance(), ExactPatternMatchingAutomaton::construct); +auto ExactPatternMatchingAutomatonRankedPattern = ExactPatternMatchingAutomaton::RegistratorWrapper < automaton::NFTA, tree::RankedPattern > ( ExactPatternMatchingAutomaton::getInstance ( ), ExactPatternMatchingAutomaton::construct ); } /* namespace exact */ diff --git a/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.h b/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.h index bf365fe36ae2127f585c4bd4abe953e26d469af2..45595dd7d6f659d0f0ed2838c33e180622746c96 100644 --- a/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.h +++ b/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.h @@ -18,9 +18,9 @@ namespace arbology { namespace exact { -class ExactPatternMatchingAutomaton : public std::SingleDispatch<automaton::Automaton, tree::RankedTreeBase> { +class ExactPatternMatchingAutomaton : public std::SingleDispatch < automaton::Automaton, tree::RankedTreeBase > { public: - ExactPatternMatchingAutomaton() {} + ExactPatternMatchingAutomaton ( ) { } /** * Performs conversion. @@ -28,15 +28,17 @@ public: */ static automaton::Automaton construct ( const tree::RankedTreeWrapper & pattern ); - static automaton::NPDA construct(const tree::PrefixRankedPattern& pattern); - static automaton::InputDrivenNPDA construct(const tree::PrefixRankedTree& pattern); - static automaton::NFTA construct(const tree::RankedTree& pattern); - static automaton::NFTA construct(const tree::RankedPattern& pattern); + static automaton::NPDA construct ( const tree::PrefixRankedPattern & pattern ); + static automaton::InputDrivenNPDA construct ( const tree::PrefixRankedTree & pattern ); + static automaton::NFTA construct ( const tree::RankedTree & pattern ); + static automaton::NFTA construct ( const tree::RankedPattern & pattern ); - static ExactPatternMatchingAutomaton& getInstance() { + static ExactPatternMatchingAutomaton & getInstance ( ) { static ExactPatternMatchingAutomaton res; + return res; } + }; } /* namespace exact */ diff --git a/alib2algo/src/arbology/exact/ExactSubtreeMatchingAutomaton.cpp b/alib2algo/src/arbology/exact/ExactSubtreeMatchingAutomaton.cpp index 736ca7509506f263cb8ac7cb2a5b3a498ad6dd4d..f624c50fe52678cec32c6d6c344def5965ea3df1 100644 --- a/alib2algo/src/arbology/exact/ExactSubtreeMatchingAutomaton.cpp +++ b/alib2algo/src/arbology/exact/ExactSubtreeMatchingAutomaton.cpp @@ -19,54 +19,60 @@ namespace arbology { namespace exact { -automaton::Automaton ExactSubtreeMatchingAutomaton::construct(const tree::Tree& pattern) { - return getInstance().dispatch(pattern.getData()); +automaton::Automaton ExactSubtreeMatchingAutomaton::construct ( const tree::Tree & pattern ) { + return getInstance ( ).dispatch ( pattern.getData ( ) ); } -automaton::InputDrivenNPDA ExactSubtreeMatchingAutomaton::construct(const tree::PrefixRankedTree& pattern) { - automaton::InputDrivenNPDA res(automaton::State(0), alphabet::symbolFrom('S')); +automaton::InputDrivenNPDA ExactSubtreeMatchingAutomaton::construct ( const tree::PrefixRankedTree & pattern ) { + automaton::InputDrivenNPDA res ( automaton::State ( 0 ), alphabet::symbolFrom ( 'S' ) ); - for(const alphabet::RankedSymbol& symbol : pattern.getAlphabet()) { - res.addInputSymbol(alphabet::Symbol{symbol}); - res.setPushdownStoreOperation(alphabet::Symbol{symbol}, std::vector<alphabet::Symbol>{1, alphabet::symbolFrom('S')}, std::vector<alphabet::Symbol>{symbol.getRank().getData(), alphabet::symbolFrom('S')}); + for ( const alphabet::RankedSymbol & symbol : pattern.getAlphabet ( ) ) { + res.addInputSymbol ( alphabet::Symbol { symbol } ); + res.setPushdownStoreOperation ( alphabet::Symbol { symbol }, std::vector < alphabet::Symbol > { 1, alphabet::symbolFrom ( 'S' ) }, std::vector < alphabet::Symbol > { symbol.getRank ( ).getData ( ), alphabet::symbolFrom ( 'S' ) } ); } - for(const alphabet::RankedSymbol& symbol : pattern.getAlphabet()) { - res.addTransition(automaton::State(0), alphabet::Symbol{symbol}, automaton::State(0)); + for ( const alphabet::RankedSymbol & symbol : pattern.getAlphabet ( ) ) { + res.addTransition ( automaton::State ( 0 ), alphabet::Symbol { symbol }, automaton::State ( 0 ) ); } + int i = 1; - for(const alphabet::RankedSymbol& symbol : pattern.getContent()) { - res.addState(automaton::State(i)); - res.addTransition(automaton::State(i-1), alphabet::Symbol{symbol}, automaton::State(i)); + + for ( const alphabet::RankedSymbol & symbol : pattern.getContent ( ) ) { + res.addState ( automaton::State ( i ) ); + res.addTransition ( automaton::State ( i - 1 ), alphabet::Symbol { symbol }, automaton::State ( i ) ); i++; } - res.addFinalState(automaton::State(i-1)); + + res.addFinalState ( automaton::State ( i - 1 ) ); return res; } -auto ExactSubtreeMatchingAutomatonPrefixRankedTree = ExactSubtreeMatchingAutomaton::RegistratorWrapper<automaton::InputDrivenNPDA, tree::PrefixRankedTree>(ExactSubtreeMatchingAutomaton::getInstance(), ExactSubtreeMatchingAutomaton::construct); +auto ExactSubtreeMatchingAutomatonPrefixRankedTree = ExactSubtreeMatchingAutomaton::RegistratorWrapper < automaton::InputDrivenNPDA, tree::PrefixRankedTree > ( ExactSubtreeMatchingAutomaton::getInstance ( ), ExactSubtreeMatchingAutomaton::construct ); -automaton::State constructRecursive(const tree::RankedNode & node, automaton::NFTA & res, int & nextState) { - std::vector<automaton::State> states; - states.reserve(node.getSymbol().getRank().getData()); - for(const auto & child : node.getChildren()) { - states.push_back(constructRecursive(*child, res, nextState)); - } - automaton::State state (nextState++); - res.addState(state); - res.addTransition(node.getSymbol(), states, state); +automaton::State constructRecursive ( const tree::RankedNode & node, automaton::NFTA & res, int & nextState ) { + std::vector < automaton::State > states; + + states.reserve ( node.getSymbol ( ).getRank ( ).getData ( ) ); + + for ( const auto & child : node.getChildren ( ) ) + states.push_back ( constructRecursive ( * child, res, nextState ) ); + + automaton::State state ( nextState++ ); + res.addState ( state ); + res.addTransition ( node.getSymbol ( ), states, state ); return state; } -automaton::NFTA ExactSubtreeMatchingAutomaton::construct(const tree::RankedTree & pattern) { +automaton::NFTA ExactSubtreeMatchingAutomaton::construct ( const tree::RankedTree & pattern ) { automaton::NFTA res; - res.setInputSymbols(pattern.getAlphabet()); + + res.setInputSymbols ( pattern.getAlphabet ( ) ); int nextState = 0; - res.addFinalState(constructRecursive(pattern.getRoot(), res, nextState)); + res.addFinalState ( constructRecursive ( pattern.getRoot ( ), res, nextState ) ); return res; } -auto ExactSubtreeMatchingAutomatonRankedTree = ExactSubtreeMatchingAutomaton::RegistratorWrapper<automaton::NFTA, tree::RankedTree>(ExactSubtreeMatchingAutomaton::getInstance(), ExactSubtreeMatchingAutomaton::construct); +auto ExactSubtreeMatchingAutomatonRankedTree = ExactSubtreeMatchingAutomaton::RegistratorWrapper < automaton::NFTA, tree::RankedTree > ( ExactSubtreeMatchingAutomaton::getInstance ( ), ExactSubtreeMatchingAutomaton::construct ); } /* namespace exact */ diff --git a/alib2algo/src/arbology/exact/ExactSubtreeMatchingAutomaton.h b/alib2algo/src/arbology/exact/ExactSubtreeMatchingAutomaton.h index 3082f7f5e17ae54fb5b8738168cfe61c4595ef1c..24cc730c379de5d19848813a61786fdf1e9579f5 100644 --- a/alib2algo/src/arbology/exact/ExactSubtreeMatchingAutomaton.h +++ b/alib2algo/src/arbology/exact/ExactSubtreeMatchingAutomaton.h @@ -18,23 +18,25 @@ namespace arbology { namespace exact { -class ExactSubtreeMatchingAutomaton : public std::SingleDispatch<automaton::Automaton, tree::TreeBase> { +class ExactSubtreeMatchingAutomaton : public std::SingleDispatch < automaton::Automaton, tree::TreeBase > { public: - ExactSubtreeMatchingAutomaton() {} + ExactSubtreeMatchingAutomaton ( ) { } /** * Performs conversion. * @return left regular grammar equivalent to source automaton. */ - static automaton::Automaton construct(const tree::Tree& pattern); + static automaton::Automaton construct ( const tree::Tree & pattern ); - static automaton::InputDrivenNPDA construct(const tree::PrefixRankedTree& pattern); - static automaton::NFTA construct(const tree::RankedTree& pattern); + static automaton::InputDrivenNPDA construct ( const tree::PrefixRankedTree & pattern ); + static automaton::NFTA construct ( const tree::RankedTree & pattern ); - static ExactSubtreeMatchingAutomaton& getInstance() { + static ExactSubtreeMatchingAutomaton & getInstance ( ) { static ExactSubtreeMatchingAutomaton res; + return res; } + }; } /* namespace exact */