summaryrefslogtreecommitdiff
path: root/string/suffixAutomaton.cpp
diff options
context:
space:
mode:
authorPaul Jungeblut <paul.jungeblut@gmail.com>2016-10-15 16:44:01 +0200
committerPaul Jungeblut <paul.jungeblut@gmail.com>2016-10-15 16:44:01 +0200
commitf78fa78909c2254ac9cfd7d835cd12c20dbc77e7 (patch)
tree868a9862f3a8b80e2ce0b3957b187ef88b32ebd5 /string/suffixAutomaton.cpp
parent53d83644c3bf9c37152aadee500e5e9bdb0514e1 (diff)
Added terminals and comments to suffix automaton code.
Diffstat (limited to 'string/suffixAutomaton.cpp')
-rw-r--r--string/suffixAutomaton.cpp16
1 files changed, 13 insertions, 3 deletions
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<int> calculateTerminals() {
+ vector<int> terminals;
+ int pos = last;
+ while (pos != -1) {
+ terminals.push_back(pos);
+ pos = states[pos].link;
+ }
+ return terminals;
+ }
+};