//Matches finds if the given target has any substring match with the kmp pattern
Matches finds if the given target has any substring match with the kmp pattern
// Matches finds if the given target has any substring match with the kmp pattern
func (k KMP) Matches(target []Type) []int {
	i, j := 0, 0
	n, m := len(target), len(k.Pattern)
	var ret []int
	if m > n || m == 0 || n == 0 {
		return ret
	}
	for i < n {
		if k.Pattern[j] == target[i] {
			i++
			j++
		}
		if j == m {
			ret = append(ret, i-j)
			j = k.Pos[j-1]
		} else if i < n && k.Pattern[j] != target[i] {
			if j != 0 {
				j = k.Pos[j-1]
			} else {
				i++
			}
		}
	}
	return ret
}
func ( k KMP ) Matches ( target [ ] Type ) [ ] int { i , j := 0 , 0 n , m := len ( target ) , len ( k . Pattern ) var ret [ ] int if m > n || m == 0 || n == 0 { return ret } for i < n { if k . Pattern [ j ] == target [ i ] { i ++ j ++ } if j == m { ret = append ( ret , i - j ) j = k . Pos [ j - 1 ] } else if i < n && k . Pattern [ j ] != target [ i ] { if j != 0 { j = k . Pos [ j - 1 ] } else { i ++ } } } return ret }
Matches finds if the given target has any substring match with the kmp pattern
Matches finds if the given target has any substring match with the kmp pattern
//got zero target or want, just return empty result