From f78fa78909c2254ac9cfd7d835cd12c20dbc77e7 Mon Sep 17 00:00:00 2001 From: Paul Jungeblut Date: Sat, 15 Oct 2016 16:44:01 +0200 Subject: Added terminals and comments to suffix automaton code. --- string/suffixAutomaton.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'string/suffixAutomaton.cpp') diff --git a/string/suffixAutomaton.cpp b/string/suffixAutomaton.cpp index 4e8abcf..7f4885c 100644 --- a/string/suffixAutomaton.cpp +++ b/string/suffixAutomaton.cpp @@ -15,8 +15,8 @@ struct SuffixAutomaton { for (auto c : s) extend(c); } - void extend(char c) { // Werte von c müssen bei 0 beginnen. - c -= 'a'; + void extend(char c) { + c -= 'a'; // Werte von c müssen bei 0 beginnen. int current = size++; states[current].length = states[last].length + 1; int pos = last; @@ -58,5 +58,15 @@ struct SuffixAutomaton { } return ii(bestpos - best + 1, best); } -}; + // Berechnet die Terminale des Automaten. + vector calculateTerminals() { + vector terminals; + int pos = last; + while (pos != -1) { + terminals.push_back(pos); + pos = states[pos].link; + } + return terminals; + } +}; -- cgit v1.2.3