public KMP(String pat){
  this.R=256;
  this.pat=pat;
  int m=pat.length();
  dfa=new int[R][m];
  dfa[pat.charAt(0)][0]=1;
  for (int x=0, j=1; j < m; j++) {
    for (int c=0; c < R; c++)     dfa[c][j]=dfa[c][x];
    dfa[pat.charAt(j)][j]=j + 1;
    x=dfa[pat.charAt(j)][x];
  }
}

public KMP ( String pat ) { this . R = 256 ; this . pat = pat ; int m = pat . length ( ) ; dfa = new int [ R ] [ m ] ; dfa [ pat . charAt ( 0 ) ] [ 0 ] = 1 ; for ( int x = 0 , j = 1 ; j < m ; j ++ ) { for ( int c = 0 ; c < R ; c ++ ) dfa [ c ] [ j ] = dfa [ c ] [ x ] ; dfa [ pat . charAt ( j ) ] [ j ] = j + 1 ; x = dfa [ pat . charAt ( j ) ] [ x ] ; } }
preprocesses the pattern string .
