knuth morris pratt implementation