public int search(String txt){
  int n=txt.length();
  if (n < m)   return n;
  long txtHash=hash(txt,m);
  if ((patHash == txtHash) && check(txt,0))   return 0;
  for (int i=m; i < n; i++) {
    txtHash=(txtHash + q - RM * txt.charAt(i - m) % q) % q;
    txtHash=(txtHash * R + txt.charAt(i)) % q;
    int offset=i - m + 1;
    if ((patHash == txtHash) && check(txt,offset))     return offset;
  }
  return n;
}

public int search ( String txt ) { int n = txt . length ( ) ; if ( n < m ) return n ; long txtHash = hash ( txt , m ) ; if ( ( patHash == txtHash ) && check ( txt , 0 ) ) return 0 ; for ( int i = m ; i < n ; i ++ ) { txtHash = ( txtHash + q - RM * txt . charAt ( i - m ) % q ) % q ; txtHash = ( txtHash * R + txt . charAt ( i ) ) % q ; int offset = i - m + 1 ; if ( ( patHash == txtHash ) && check ( txt , offset ) ) return offset ; } return n ; }
returns the index of the first occurrrence of the pattern string in the text string .
