|
ADS
Algorithms and Data Structures
|
The suffix automaton (the directed acyclic word graph, DAWG) of a string \( S \) of \( n \) bytes, beyond the book: the smallest deterministic automaton that accepts the suffixes of \( S \), whose paths from the start spell exactly the substrings of \( S \). More...
#include "ADS/Contract.h"#include <cstddef>#include <cstdint>#include <string_view>#include <utility>#include <vector>#include "ADS/string/impl/SuffixAutomaton.tpp"Go to the source code of this file.
Classes | |
| class | ADS::SuffixAutomaton |
| the suffix automaton of a string, built a byte at a time More... | |
Namespaces | |
| namespace | ADS |
The suffix automaton (the directed acyclic word graph, DAWG) of a string \( S \) of \( n \) bytes, beyond the book: the smallest deterministic automaton that accepts the suffixes of \( S \), whose paths from the start spell exactly the substrings of \( S \).
Its states are the classes of the substrings by their sets of end places,
\[ \mathrm{endpos}( u ) = \{ j : S[ j - |u| + 1 .. j ] = u \} , \]
a class holding the suffixes of its longest member of lengths in \( ( \mathit{len}( \mathit{link}( v ) ) , \mathit{len}( v ) ] \), where the suffix link of \( v \) is the class of the longest suffix in another class. It has at most \( 2 n - 1 \) states (\( n \ge 2 \)) and \( 3 n - 4 \) transitions (\( n \ge 3 \)), and the construction of Blumer et al. adds the bytes one at a time: the new state of \( S c \) gets the transitions on \( c \) from the suffix path of the last state, which stops at the first state \( p \) that has one; if it leads to \( q \) with \( \mathit{len}( q ) = \mathit{len}( p ) + 1 \), then \( q \) is the new link, otherwise \( q \) is cloned with that length, in \( O( n ) \) amortized time for a constant alphabet. Here the transitions of a state are a short vector of pairs (byte, state), searched linearly, so that the time is \( O( n \sigma ) \) for \( \sigma \) distinct bytes.
The contracts [see Contract.h]: at most \( 2 n \) states (an invariant), and the results equal those of the definitions on the substrings (the audits of the tests). The functions are defined in SuffixAutomaton.tpp.