public int indexOf ( byte [ ] data , int start , int max ) { int j = 0 ; if ( data . length == 0 ) return - 1 ; if ( start + max > data . length ) System . out . println ( "HEY KMPMatch" ) ; for ( int i = start ; i < start + max ; i ++ ) { while ( j > 0 && match [ j ] != data [ i ] ) j = failure [ j - 1 ] ; if ( match [ j ] == data [ i ] ) j ++ ; if ( j == match . length ) return i - match . length + 1 ; } return - 1 ; }
Finds the first occurrence of match in data .