KMP: compute prefix function