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

template remaining algorithms from stringology

parent cf66cff5
No related branches found
No related tags found
No related merge requests found
...@@ -6,10 +6,6 @@ ...@@ -6,10 +6,6 @@
*/ */
   
#include "ExactNondeterministicSubsequenceAutomaton.h" #include "ExactNondeterministicSubsequenceAutomaton.h"
#include <string/LinearString.h>
#include <string/Epsilon.h>
#include <deque>
   
namespace stringology { namespace stringology {
   
...@@ -19,24 +15,7 @@ automaton::Automaton ExactNondeterministicSubsequenceAutomaton::construct(const ...@@ -19,24 +15,7 @@ automaton::Automaton ExactNondeterministicSubsequenceAutomaton::construct(const
return dispatch(text.getData()); return dispatch(text.getData());
} }
   
automaton::EpsilonNFA < > ExactNondeterministicSubsequenceAutomaton::construct(const string::LinearString < >& text) { auto ExactNondeterministicSubsequenceAutomatonLinearString = ExactNondeterministicSubsequenceAutomaton::RegistratorWrapper < automaton::EpsilonNFA < DefaultSymbolType, DefaultEpsilonType, unsigned >, string::LinearString < > > ( ExactNondeterministicSubsequenceAutomaton::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(i-1), DefaultStateType(i));
i++;
}
return res;
}
auto ExactNondeterministicSubsequenceAutomatonLinearString = ExactNondeterministicSubsequenceAutomaton::RegistratorWrapper<automaton::EpsilonNFA < >, string::LinearString < >>( ExactNondeterministicSubsequenceAutomaton::construct );
   
} /* namespace exact */ } /* namespace exact */
   
......
...@@ -26,9 +26,28 @@ public: ...@@ -26,9 +26,28 @@ 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 > ExactNondeterministicSubsequenceAutomaton::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 ( i - 1, i );
i++;
}
return res;
}
} /* namespace exact */ } /* namespace exact */
   
} /* namespace stringology */ } /* namespace stringology */
......
...@@ -6,10 +6,6 @@ ...@@ -6,10 +6,6 @@
*/ */
   
#include "ExactSubsequenceAutomaton.h" #include "ExactSubsequenceAutomaton.h"
#include <string/LinearString.h>
#include <string/Epsilon.h>
#include <deque>
   
namespace stringology { namespace stringology {
   
...@@ -19,31 +15,7 @@ automaton::Automaton ExactSubsequenceAutomaton::construct(const string::String& ...@@ -19,31 +15,7 @@ automaton::Automaton ExactSubsequenceAutomaton::construct(const string::String&
return dispatch(text.getData()); return dispatch(text.getData());
} }
   
automaton::DFA<> ExactSubsequenceAutomaton::construct(const string::LinearString < >& text) { auto ExactSubsequenceAutomatonLinearString = ExactSubsequenceAutomaton::RegistratorWrapper < automaton::DFA < DefaultSymbolType, unsigned >, string::LinearString < > > ( ExactSubsequenceAutomaton::construct );
std::map<DefaultSymbolType, int> f;
for(const DefaultSymbolType& symbol : text.getAlphabet()) {
f[symbol] = 0;
}
automaton::DFA<> 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));
for(int j = f[symbol]; j < i; j++) {
res.addTransition(DefaultStateType(j), symbol, DefaultStateType(i));
}
f[symbol] = i;
i++;
}
return res;
}
auto ExactSubsequenceAutomatonLinearString = ExactSubsequenceAutomaton::RegistratorWrapper<automaton::DFA<>, string::LinearString < >>(ExactSubsequenceAutomaton::construct);
   
} /* namespace exact */ } /* namespace exact */
   
......
...@@ -24,11 +24,38 @@ public: ...@@ -24,11 +24,38 @@ public:
* Performs conversion. * Performs conversion.
* @return left regular grammar equivalent to source automaton. * @return left regular grammar equivalent to source automaton.
*/ */
static automaton::Automaton construct(const string::String& text); static automaton::Automaton construct ( const string::String & text );
   
static automaton::DFA<> construct(const string::LinearString < >& text); template < class SymbolType >
static automaton::DFA < SymbolType, unsigned > construct ( const string::LinearString < SymbolType > & text );
}; };
   
template < class SymbolType >
automaton::DFA < SymbolType, unsigned > ExactSubsequenceAutomaton::construct ( const string::LinearString < SymbolType > & text ) {
std::map < SymbolType, unsigned > f;
for(const SymbolType & symbol : text.getAlphabet ( ) ) {
f[symbol] = 0;
}
automaton::DFA < SymbolType, 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 );
for ( unsigned j = f [ symbol ]; j < i; j++ ) {
res.addTransition ( j, symbol, i );
}
f[symbol] = 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