Mercurial > hg > Members > masakoha > testcode
view regex/bmsearch.cc @ 111:1d30f70702df pairPro
add determinize.cc and transition.cc
author | masa |
---|---|
date | Sat, 21 Nov 2015 18:04:25 +0900 |
parents | ead0a307449e |
children |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <math.h> #include <string.h> #include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #include "regex.h" //Boyer Moore法に使用するテーブルを作成 int * createBMskiptable(BMDataPtr bmdata) { int searchWordLen = bmdata->searchWordLen; char *searchWord = bmdata->searchWord; int* skipTable = (int*)malloc(sizeof(int)*256); for(int i = 0; i < 256; ++i){ bmdata->skipTable[i] = searchWordLen; } for(int j = 0; j < searchWordLen - 1; ++j){ bmdata->skipTable[(u_char)searchWord[j]] = searchWordLen - j - 1; } return skipTable; } //Boyer Moore法による文字列検索アルゴリズム void* BMmethod(BMDataPtr bmdata,ResultPtr result) { int i = bmdata->searchWordLen - 1; int matchCounter = 0; while ( i < bmdata->readTextLen){ int j = bmdata->searchWordLen - 1; while (bmdata->readText[i] == bmdata->searchWord[j]){ if (j == 0){ matchCounter++; } --i; --j; } i = i + fmax(bmdata->skipTable[(u_char)bmdata->readText[i]],bmdata->searchWordLen - j); } result->matchNum = matchCounter; return result; }