MCPcopy Create free account
hub / github.com/ShahjalalShohag/code-library / extend

Method extend

Strings/Suffix Automaton.cpp:28–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26 t[0].len = 0; t[0].link = -1; t[0].firstpos = 0;
27 }
28 void extend(char c) {
29 int p = last;
30 if (t[p].nxt.count(c)) {
31 int q = t[p].nxt[c];
32 if (t[q].len == t[p].len + 1) {
33 last = q;
34 return;
35 }
36 int clone = sz++;
37 t[clone] = t[q];
38 t[clone].len = t[p].len + 1;
39 t[q].link = clone;
40 last = clone;
41 while (p != -1 && t[p].nxt[c] == q) {
42 t[p].nxt[c] = clone;
43 p = t[p].link;
44 }
45 return;
46 }
47 int cur = sz++;
48 t[cur].len = t[last].len + 1;
49 t[cur].firstpos = t[cur].len;
50 p = last;
51 while (p != -1 && !t[p].nxt.count(c)) {
52 t[p].nxt[c] = cur;
53 p = t[p].link;
54 }
55 if (p == -1) t[cur].link = 0;
56 else {
57 int q = t[p].nxt[c];
58 if (t[p].len + 1 == t[q].len) t[cur].link = q;
59 else {
60 int clone = sz++;
61 t[clone] = t[q];
62 t[clone].len = t[p].len + 1;
63 while (p != -1 && t[p].nxt[c] == q) {
64 t[p].nxt[c] = clone;
65 p = t[p].link;
66 }
67 t[q].link = t[cur].link = clone;
68 }
69 }
70 last = cur;
71 }
72 void build_tree() {
73 for (int i = 1; i < sz; i++) g[t[i].link].push_back(i);
74 }

Callers

nothing calls this directly

Calls 1

countMethod · 0.45

Tested by

no test coverage detected