亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 4043 | 回復(fù): 5
打印 上一主題 下一主題

[C] LINUX內(nèi)核中的BM算法函數(shù)有API可以用不?【已解決】 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2009-05-16 15:45 |只看該作者 |倒序瀏覽
不知道怎樣才能直接調(diào)用bm_find函數(shù),大家給點提示?謝了先

說明看這里:http://blog.chinaunix.net/u1/53217/showart_1934058.html

代碼:
/*
* the boyer-moore algorithm
* for text search of rules cotent
* by zuii||williamzuii@163.com
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BM_TEST

#define LEN 256

/*
* BMMatch()
* match once for each call,if match succeed,return 0
* or else,return the index for the next match
*
*/

int BMMatch(const char *src,const char *pattern,int idx,int po[])
{
    const int slen=strlen(src);
    int i=strlen(pattern)-1;
    int j=idx+i;
    int nidx;
   
    if(j > slen)
        return -1;
        
    for(;i>=0;i--,j--){
        if(src[j] != pattern[i])
            break;   
    }
   
    if(i < 0)
        return 0; /* match succeed */
    else if(po[src[j]] > 0) /* the charector is contained in pattern */
        nidx=idx+(i-po[src[j]]);
    else /* the charector is not contained in pattern */
        nidx=idx+i+1;
        
    return nidx;   
}

/*
* BMSearch()
*    --- the interface of the text search algorithm---Boyer-moore
* Arguments:
*      src:the long text for matching with pattern
*      pattern: the pattern text use to match with src
*      n: the beginning char for matching in src
* Return:
*      0: matching succeed
*      -1:matching failed
*/

int BMSearch(const char *src,const char *pattern,int n)
{
    int po[LEN]={0};
    int i,idx=-2,nidx=n;
    int plen=strlen(pattern);
    if((n+strlen(pattern)) > strlen(src)){
        printf("Ivalid search!\n");
        return -1;
    }
        
    /* assistant array */
    for(i=0;i < plen;i++)
        po[pattern[i]]=i;
  
    /* the first time to match */  
    idx=BMMatch(src,pattern,n,po);

    /* start looping */
    while(idx != -1 && idx != 0){
        nidx=idx;
        idx=BMMatch(src,pattern,nidx,po);   
    }
   
    /* return 0 or -1 */
    return idx;
}

#ifdef BM_TEST
int main(int argc,char **argv)
{
    if(BMSearch("it's a test!Oh yeah!","test",4) == 0){
        printf("Succeed!\n");   
    }else{
        printf("No content!\n");   
    }   
   
    //getch();

    return 0;
}
#endif


[ 本帖最后由 zuii 于 2009-5-20 20:08 編輯 ]

論壇徽章:
0
2 [報告]
發(fā)表于 2009-05-16 18:50 |只看該作者
天呢,怎么都沒人理 。

論壇徽章:
0
3 [報告]
發(fā)表于 2009-05-16 23:45 |只看該作者
原帖由 zuii 于 2009-5-16 15:45 發(fā)表
不知道怎樣才能直接調(diào)用bm_find函數(shù),大家給點提示?謝了先

我沒用過,幫你看你了一下,你無法直接用。
內(nèi)核BM的實現(xiàn)時作為module實現(xiàn)提供給textsearch用的,你只能通過textsearch提供出的接口間接調(diào)用,textsearch.c最上面的注釋已經(jīng)告訴你怎么用了。例如:
*   conf = textsearch_prepare("bm", pattern, strlen(pattern),
*                             GFP_KERNEL, TS_AUTOLOAD);

這里第一個參數(shù)"bm"指定search時使用BM算法

論壇徽章:
0
4 [報告]
發(fā)表于 2009-05-17 15:17 |只看該作者
先謝謝。。。馬上試試

論壇徽章:
0
5 [報告]
發(fā)表于 2009-05-20 20:06 |只看該作者
解決咯。。。網(wǎng)上找了代碼然后自己修改了,改出來一個API  呵呵。。。拿出來需要的朋友可以研究下...

論壇徽章:
0
6 [報告]
發(fā)表于 2011-10-31 18:04 |只看該作者
謝謝樓主分享,
09年到現(xiàn)在很久了,樓主的代碼運行可良好?
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP