Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
NondeterministicApproximateSuffixAutomatonForHammingDistance.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <automaton/FSM/NFA.h>
9#include <string/LinearString.h>
10
11namespace stringology::indexing {
12
14public:
19 template < class SymbolType >
21};
22
23template < class SymbolType >
26 result.addFinalState ( result.getInitialState ( ) );
27 result.setInputAlphabet( pattern.getAlphabet ( ) );
28
29 // create states
30 for ( size_t j = 0; j <= k; j ++ ) {
31 for ( size_t i = j ; i <= pattern.getContent ( ).size ( ) ; i++ ) {
32 result.addState ( ext::make_pair ( i, j ) );
33
34 if ( i == pattern.getContent ( ).size ( ) )
35 result.addFinalState ( ext::make_pair ( pattern.getContent ( ).size ( ), j ) );
36 }
37
38 }
39
40 // horizontal transitions
41 for ( size_t j = 0 ; j <= k ; j ++ ) {
42 for ( size_t i = j; i < pattern.getContent ( ).size ( ); i ++ ) {
43 auto from = ext::make_pair ( i, j );
44 auto to = ext::make_pair ( i + 1, j );
45 result.addTransition ( from, pattern.getContent ( ) [ i ], to );
46 }
47 }
48
49 // diagonal transitions
50 for ( size_t j = 0 ; j < k ; j ++ ) {
51 for ( size_t i = j ; i < pattern.getContent ( ).size ( ); i ++ ) {
52 auto from = ext::make_pair ( i, j );
53 auto to = ext::make_pair ( i + 1, j + 1 );
54
55 for ( const SymbolType & symbol : pattern.getAlphabet ( ) ) {
56 if ( symbol != pattern.getContent ( ) [ i ] ) {
57 result.addTransition ( from, symbol, to );
58 }
59 }
60 }
61 }
62
63 // removed epsilon transitions
64 for ( unsigned int i = 1 ; i < pattern.getContent ( ).size ( ); i ++ ) {
65 auto from = ext::make_pair ( 0, 0 );
66 result.addTransition ( from, pattern.getContent ( ) [ i ], ext::make_pair ( i + 1, 0 ) );
67
68 if ( k > 0 ) {
69 for ( const SymbolType & symbol : pattern.getAlphabet ( ) ) {
70 if ( symbol != pattern.getContent ( ) [ i ] ) {
71 result.addTransition ( from, symbol, ext::make_pair ( i + 1, 1 ) );
72 }
73 }
74 }
75 }
76
77 return result;
78}
79
80} /* namespace stringology::indexing */
81
Nondeterministic finite automaton. Accepts regular languages.
Definition: NFA.h:66
Linear string.
Definition: LinearString.h:57
const ext::set< SymbolType > & getAlphabet() const &
Definition: LinearString.h:103
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
Definition: NondeterministicApproximateSuffixAutomatonForHammingDistance.h:13
static automaton::NFA< SymbolType, ext::pair< unsigned int, unsigned int > > construct(const string::LinearString< SymbolType > &pattern, unsigned int k)
Definition: NondeterministicApproximateSuffixAutomatonForHammingDistance.h:24
int i
Definition: AllEpsilonClosure.h:118
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
for(const StateType &state :fsm.getStates()) renamingData.insert(std Rename::RenamedAutomaton< T > result(renamingData.at(fsm.getInitialState()))
Definition: Rename.h:253
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: BitParallelIndexConstruction.h:14