BM算法概念(2)

2019-04-09 21:54

ptrn => 模式串P

PLen => 模式串P长度 skip => 坏字符表 shift => 好后缀表 返回:

int - 1表示成功(文本串包含模式串),0表示失败(文本串不包含模式串)。 ****************************************************************/ int BMSearch(char *buf, int blen, char *ptrn, int plen, int *skip, int *shift) {

int b_idx = plen; if (plen == 0) return 1;

while (b_idx <= blen)//计算字符串是否匹配到了尽头 {

int p_idx = plen, skip_stride, shift_stride;

while (buf[--b_idx] == ptrn[--p_idx])//开始匹配 {

if (b_idx < 0) return 0; if (p_idx == 0) return 1; }

skip_stride = skip[(unsigned char)buf[b_idx]];//根据坏字符规则计算跳 跃的距离 shift_stride = shift[p_idx];//根据好后缀规则计算跳跃的距离

b_idx += (skip_stride > shift_stride) ? skip_stride : shift_stride;//取大者 }

return 0; }

int main(int argc, char* argv[]) {

//char test[] = \ //char find[] = \ //printf(\/* char test[] = \\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\ char find[] = \*/ char test[] = \ char find[] = \ // int i; // int toks; int *shift; int *skip;

shift=MakeShift(find,sizeof(find)-1);

skip=makeskip(find,sizeof(find)-1);

int ret = BMSearch(test, sizeof(test)-1, find, sizeof(find)-1, skip,shift); printf (\ printf (\ printf (\ if(ret ==0)

printf(\ if (ret == 1)

printf(\ getchar(); return 0; }


BM算法概念(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:蒸气云爆炸冲击波uvce

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: