Knuth-Morris-Pratt: prefix function