func stringSearch(haystack, needle []byte) int { n := len(needle) if n == 0 { return 0 } var ( confirm [256]uint64 prefix = uint64(1) ) for _, b := range needle { confirm[b] |= prefix prefix <<= 1 } var ( prefixes = uint64(0) found = uint64(1) << (n - 1) ) for i, b := range haystack { maybe := prefixes << 1 prefixes = maybe & confirm[b] if prefixes >= found { return i + 1 - n } } return -1 }
To receive a hint, submit unfixed code.