public int search(byte[] text){
  int M=pattern.length;
  int N=text.length;
  int skip;
  for (int i=0; i <= N - M; i+=skip) {
    skip=0;
    for (int j=M - 1; j >= 0; j--) {
      if (pattern[j] != text[i + j]) {
        skip=Math.max(1,j - right[text[i + j]]);
        break;
      }
    }
    if (skip == 0)     return i;
  }
  return N;
}

public int search ( byte [ ] text ) { int M = pattern . length ; int N = text . length ; int skip ; for ( int i = 0 ; i <= N - M ; i += skip ) { skip = 0 ; for ( int j = M - 1 ; j >= 0 ; j -- ) { if ( pattern [ j ] != text [ i + j ] ) { skip = Math . max ( 1 , j - right [ text [ i + j ] ] ) ; break ; } } if ( skip == 0 ) return i ; } return N ; }
returns the index of the first occurrrence of the pattern string in the text string .
