Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
DeterministicApproximateSuffixAutomatonForHammingDistanceFactory.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <automaton/FSM/DFA.h>
9#include <string/LinearString.h>
11#include <stack>
12
13namespace stringology::seed
14{
21{
22private:
24
25 template<class SymbolType>
26 static void processState( const StateType & node, automaton::DFA < SymbolType, StateType > & result,
27 const automaton::NFA < SymbolType, ext::pair < unsigned, unsigned > > & ndSuffixAutomaton,
28 std::stack < StateType > & stack )
29 {
30 for ( const auto & symb : result.getInputAlphabet() )
31 {
32 StateType newNode;
33 for ( const auto & n : node )
34 {
35 auto transitionsOnSymb = ndSuffixAutomaton.getTransitions ( ).equal_range( ext::make_pair( n, symb ) );
36 for ( const auto & it : transitionsOnSymb )
37 newNode.insert( it.second );
38 }
39 if ( ! newNode.empty() )
40 {
41 result.addState( newNode );
42 result.addTransition( node, symb, newNode );
43 stack.push( newNode );
44 }
45 }
46 }
47
48public:
57 template<class SymbolType>
59 {
61
62 /* automaton creation */
63 StateType initialState;
64 initialState.insert( ext::pair < unsigned, unsigned >( 0, 0 ) );
66 result.setInputAlphabet( pattern.getAlphabet() );
67
68 /* stack initialization */
69 std::stack < StateType > stack;
70 stack.push( initialState );
71
72 /* visiting the nodes, adding states, transitions, finalStates */
73 while ( ! stack.empty() )
74 {
75 auto node = stack.top();
76 stack.pop();
77
78 if ( std::any_of( node.begin(), node.end(), [&] ( auto x ) { return ndSuffixAutomaton.getFinalStates().find( x ) != ndSuffixAutomaton.getFinalStates().end(); } ) )
79 result.addFinalState( node );
80
81 processState( node, result, ndSuffixAutomaton, stack );
82 }
83 return result;
84 }
85};
86}
87
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
Nondeterministic finite automaton. Accepts regular languages.
Definition: NFA.h:66
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Definition: set.hpp:44
auto equal_range(K &&key) const &
Make range of elements with key equal to the key.
Definition: set.hpp:200
Linear string.
Definition: LinearString.h:57
const ext::set< SymbolType > & getAlphabet() const &
Definition: LinearString.h:103
static automaton::NFA< SymbolType, ext::pair< unsigned int, unsigned int > > construct(const string::LinearString< SymbolType > &pattern, unsigned int k)
Definition: NondeterministicApproximateSuffixAutomatonForHammingDistance.h:24
Definition: DeterministicApproximateSuffixAutomatonForHammingDistanceFactory.h:21
static automaton::DFA< SymbolType, StateType > construct(const string::LinearString< SymbolType > &pattern, unsigned k)
Definition: DeterministicApproximateSuffixAutomatonForHammingDistanceFactory.h:58
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
std::stack< ext::tuple< StateType, StateType, SymbolType > > stack
Definition: Compaction.h:83
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
any_of(T &&...) -> any_of< T... >
Definition: Node.cpp:11
Definition: ApproximateSeedComputation.cpp:10