15#include <string/LinearString.h>
27 template <
class SymbolType >
31 template <
class SymbolType >
36template <
class SymbolType >
42 std::vector < std::pair < unsigned, int > > suffixLinks = { { infinity, 0 } };
43 unsigned lastState = 0;
52 suffixAutomatonAddSymbol ( suffixAutomaton, symbol, suffixLinks, lastState );
55 while ( lastState != infinity ) {
57 lastState = suffixLinks [ lastState ].first;
63template <
class SymbolType >
65 unsigned newState = suffixAutomaton.
getStates ( ).size ( );
67 suffixAutomaton.
addState ( newState );
69 int lastSuffixLength = suffixLinks [ lastState ].second;
71 suffixLinks.emplace_back ( infinity, lastSuffixLength + 1 );
73 unsigned kState = lastState;
75 while ( kState != infinity && suffixAutomaton.
getTransitions ( ).find ( { kState, symbol } ) == suffixAutomaton.
getTransitions ( ).end ( ) ) {
77 kState = suffixLinks [ kState ].first;
80 if ( kState == infinity ) {
81 suffixLinks [ newState ].first = 0;
85 int kSuffixLength = suffixLinks [ kState ].second;
86 int qSuffixLength = suffixLinks [ qState ].second;
88 if ( kSuffixLength + 1 == qSuffixLength ) {
89 suffixLinks [ newState ].first = qState;
91 unsigned cloneState = suffixAutomaton.
getStates ( ).size ( );
92 suffixAutomaton.
addState ( cloneState );
94 suffixLinks.emplace_back ( suffixLinks [ qState ].first, kSuffixLength + 1 );
97 suffixAutomaton.
addTransition ( cloneState, transition.first.second, transition.second );
99 while ( kState != infinity && suffixAutomaton.
removeTransition ( kState, symbol, qState ) ) {
100 suffixAutomaton.
addTransition ( kState, symbol, cloneState );
101 kState = suffixLinks [ kState ].first;
104 suffixLinks [ qState ].first = cloneState;
105 suffixLinks [ newState ].first = cloneState;
108 lastState = newState;
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
bool removeTransition(const StateType &from, const SymbolType &input, const StateType &to)
Removes a transition from the automaton.
Definition: DFA.h:457
const ext::map< ext::pair< StateType, SymbolType >, StateType > & getTransitions() const &
Definition: DFA.h:473
bool addFinalState(StateType state)
Definition: DFA.h:203
const ext::set< StateType > & getStates() const &
Definition: DFA.h:134
bool addTransition(StateType from, SymbolType input, StateType to)
Add a transition to the automaton.
Definition: DFA.h:432
bool addState(StateType state)
Definition: DFA.h:154
void setInputAlphabet(ext::set< SymbolType > symbols)
Definition: DFA.h:270
ext::iterator_range< typename ext::map< ext::pair< StateType, SymbolType >, StateType >::const_iterator > getTransitionsFromState(const StateType &from) const
Definition: DFA.h:483
static bool verbose
Verbose flag. Some algorithms print additional runtime information about internal datastructures or t...
Definition: GlobalData.h:24
static ext::reference_wrapper< ext::ostream > log
Standard loging stream. Mapped to descriptor 4.
Definition: GlobalData.h:78
Suffix automaton string index. Automaton representation of all suffixes. The automaton is general det...
Definition: SuffixAutomaton.h:50
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: ExactSuffixAutomaton.h:23
static indexes::stringology::SuffixAutomaton< SymbolType > construct(const string::LinearString< SymbolType > &pattern)
Definition: ExactSuffixAutomaton.h:37
p second
Definition: ToRegExpAlgebraic.h:126
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
constexpr const T & max(const T &a)
Root case of maximum computation. The maximum from one value is the value itself.
Definition: algorithm.hpp:278
Definition: ArithmeticCompression.h:18