|
void HORSPOOL( char *y , сhar *x ,int n , int m )
{
int a, i, j, bm_bc[ ASIZE ];
char ch, lastch;
/* Preprocessing */
for ( a=0; a < ASIZE; a++ ) bm_bc[ a ] = m;
for ( j=0; j < m-1; j++ ) bm_bc[ x[ j ] ] = m - j - 1;
/* Searching */
lastch = x[ m-1 ];
i = 0;
while ( i <= n-m ) {
ch = y[ i + m - 1 ];
if ( ch == lastch )
if ( memcmp( &y[ i ], x, m-1 ) == 0 ) OUTPUT( i );
i += bm_bc[ ch ];
}
}
|