MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / table

Function table

strings/kmp/kmp.go:36–49  ·  view source on GitHub ↗

table building for kmp algorithm.

(w string)

Source from the content-addressed store, hash-verified

34
35// table building for kmp algorithm.
36func table(w string) []int {
37 var (
38 t []int = []int{-1}
39 k int
40 )
41 for j := 1; j < len(w); j++ {
42 k = j - 1
43 for w[0:k] != w[j-k:j] && k > 0 {
44 k--
45 }
46 t = append(t, k)
47 }
48 return t
49}

Callers 2

TestKmpFunction · 0.85
TestTableFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestKmpFunction · 0.68
TestTableFunction · 0.68