Skip to content
Snippets Groups Projects
Commit 12fed0c1 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

template exact factor automaton algorithm

parent 7be9597b
No related branches found
No related tags found
No related merge requests found
...@@ -19,22 +19,7 @@ automaton::Automaton ExactFactorAutomaton::construct(const string::String& text) ...@@ -19,22 +19,7 @@ automaton::Automaton ExactFactorAutomaton::construct(const string::String& text)
return dispatch(text.getData()); return dispatch(text.getData());
} }
   
automaton::EpsilonNFA < > ExactFactorAutomaton::construct(const string::LinearString < >& text) { auto ExactFactorAutomatonLinearString = ExactFactorAutomaton::RegistratorWrapper<automaton::EpsilonNFA < DefaultSymbolType, DefaultEpsilonType, unsigned >, string::LinearString < > >(ExactFactorAutomaton::construct);
automaton::EpsilonNFA < > res(DefaultStateType(0));
res.addFinalState(DefaultStateType(0));
res.setInputAlphabet(text.getAlphabet());
int i = 1;
for(const DefaultSymbolType& symbol : text.getContent()) {
res.addState(DefaultStateType(i));
res.addFinalState(DefaultStateType(i));
res.addTransition(DefaultStateType(i-1), symbol, DefaultStateType(i));
res.addTransition(DefaultStateType(0), DefaultStateType(i));
i++;
}
return res;
}
auto ExactFactorAutomatonLinearString = ExactFactorAutomaton::RegistratorWrapper<automaton::EpsilonNFA < >, string::LinearString < >>(ExactFactorAutomaton::construct);
   
} /* namespace exact */ } /* namespace exact */
   
......
...@@ -26,9 +26,26 @@ public: ...@@ -26,9 +26,26 @@ public:
*/ */
static automaton::Automaton construct(const string::String& text); static automaton::Automaton construct(const string::String& text);
   
static automaton::EpsilonNFA < > construct(const string::LinearString < >& text); template < class SymbolType >
static automaton::EpsilonNFA < SymbolType, DefaultEpsilonType, unsigned > construct(const string::LinearString < SymbolType > & text);
}; };
   
template < class SymbolType >
automaton::EpsilonNFA < SymbolType, DefaultEpsilonType, unsigned > ExactFactorAutomaton::construct(const string::LinearString < SymbolType > & text) {
automaton::EpsilonNFA < SymbolType, DefaultEpsilonType, unsigned > res ( 0 );
res.addFinalState ( 0 );
res.setInputAlphabet(text.getAlphabet());
unsigned i = 1;
for(const SymbolType & symbol : text.getContent()) {
res.addState ( i );
res.addFinalState ( i );
res.addTransition ( i - 1, symbol, i );
res.addTransition ( 0, i );
i++;
}
return res;
}
} /* namespace exact */ } /* namespace exact */
   
} /* namespace stringology */ } /* namespace stringology */
......
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