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

Function prefix_function

Strings/Prefix Automaton.cpp:15–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13const int mod = 1e9 + 7;
14
15vector<int> prefix_function(string &s) {
16 int n = (int)s.size();
17 vector<int> pi(n, 0);
18 for (int i = 1; i < n; i++) {
19 int j = pi[i-1];
20 while (j > 0 && s[i] != s[j]) j = pi[j-1];
21 if (s[i] == s[j]) j++;
22 pi[i] = j;
23 }
24 return pi;
25}
26int aut[N][26];
27void compute_automaton(string s)
28{

Callers 1

compute_automatonFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected