//NewKMP initializes a kmp pattern and does the precomputation and returns the pointer to it
NewKMP initializes a kmp pattern and does the precomputation and returns the pointer to it
// NewKMP initializes a kmp pattern and does the precomputation and returns the pointer to it
func NewKMP(pattern []Type) *KMP {
	result := &KMP{Pos: make([]int, len(pattern)), Pattern: pattern}
	j, i := 0, 1
	result.Pos[0] = 0
	for i < len(pattern) {
		if pattern[i] == pattern[j] {
			j++
			result.Pos[i] = j
			i++
			continue
		}
		if j != 0 {
			j = result.Pos[j-1]
			continue
		}
		i++
	}
	return result
}
func NewKMP ( pattern [ ] Type ) * KMP { result := & KMP { Pos : make ( [ ] int , len ( pattern ) ) , Pattern : pattern } j , i := 0 , 1 result . Pos [ 0 ] = 0 for i < len ( pattern ) { if pattern [ i ] == pattern [ j ] { j ++ result . Pos [ i ] = j i ++ continue } if j != 0 { j = result . Pos [ j - 1 ] continue } i ++ } return result }
NewKMP initializes a kmp pattern and does the precomputation and returns the pointer to it
NewKMP initializes a kmp pattern and does the precomputation and returns the pointer to it