unsigned char * sunday( void * a_buf1,
unsigned int len1,
void * a_buf2,
unsigned int len2 ){ unsigned char * buf1 = ( unsigned char * )a_buf1;
unsigned char * buf2 = ( unsigned char * )a_buf2; unsigned int next[];
unsigned int i, j, pos; for( i = ; i < ; ++i ){ next[i] = len2 + ;
} for( i = ; i < len2; ++i ){ next[buf2[i]] = len2 - i;
} pos = ; while( pos < len1 - len2 + ){ i = pos;
j = ; while( j < len2 ){ if( buf1[i] != buf2[j] ){ pos += next[buf1[pos + len2]];
break;
} ++i;
++j;
} if( j == len2 ){ return &buf1[pos];
}
} return NULL;
}
和KMP一样,在查询小串的时候都不如优化过的库函数strstr。