Kết quả thực nghiệ m2 tìm mẫu trong file

Một phần của tài liệu (LUẬN văn THẠC sĩ) một họ thuật toán đối sánh mẫu chính xác nhanh SSABS TVSBS FQS và thực nghiệm (Trang 59 - 74)

Nhận xét

Kết quả này cho thấy thuật toán SSABS và TVSBS thi hành tốt việc tìm kiếm một mẫu trong chuỗi và trong file. Đồng thời, số lần xuất hiện của mẫu trong văn bản cũng được chỉ ra. Có được kết quả này là do lệnh đếm lần xuất hiện sự xuất hiện của mẫu trong văn bản của chương trình (Phụ lục 2, 3) đã được bổ sung thêm các thao tác ghi nhận vị trí xuất hiện mẫu trong chuỗi (file) và in ra kết quả số lần xuất hiện sau khi kết thúc duyệt mẫu trong văn bản.

3.5. Kết luận chương 3

Chương 3 của luận văn đã trình bày những nghiên cứu về công cụ sánh xâu SMART, các thành phần chính của nó và cách khởi động, thi hành hệ thống. Công cụ SMART được xây dựng nhằm cung cấp một khung chuẩn cho các nhà nghiên cứu về sánh xâu. Bộ công cụ giúp người sử dụng kiểm tra, thiết kế, đánh giá và hiểu biết các giải pháp hiện có đối với bài toán sánh xâu. Hơn nữa, nó cung cấp một bộ công cụ cho việc triển khai hầu hết các thuật toán sánh xâu và một kho ngữ liệu rộng của các bộ đệm văn bản.

Các thử nghiệm hai thuật toán sánh mẫu SSABS và TVSBS để giải quyết bài toán sánh mẫu ngoại tuyến bằng công cụ SMART thông qua bộ trung gian PUTTY. Các kết quả thực nghiệm cho thấy thuật toán SSABS và TVSBS đã thi hành thành

công bài toán sánh mẫu với thời gian hợp lý. Khi chạy thực nghiệm trong chương trình SMART chỉ tính về hiệu năng để biết được vị trí mẫu trùng với vị trí của văn bản. Không chỉ có vậy, ở Thực nghiệm 2 còn tiến hành thực nghiệm đểtìm sự xuất hiện của mẫu trong văn bản và mẫu trong file dữ liệu mà còn cho ra được số lần xuất hiện, bổ sung đếm lên 1, vị trí xuất hiện mẫu trong chuỗi, trong file và in ra kết quả từ vị trí mẫu được tìm thấy cho đến cuối văn bản bằng việc phải vào dữ liệu gốc để chỉnh sửa. Tuy nhiên thuật toán có hạn chế là vẫn chưa thi hành được tất cả các mẫu, một số trường hợp chưa ra kết quả.

KẾT LUẬN VÀ HƯỚNG NGHIÊN CỨU TIẾP THEO

Kết quả luận văn đạt được

Luận văn đã trình bày các nội dung cơ bản nhất về các bài toán sánh mẫu cũng như ứng dụng của bài toán sánh mẫu. Luận văn tập trung khảo sát một nhóm ba thuật toán sánh mẫu chính xác là SSABS, TVSBS, FQS. Đồng thời, luận văn cũng nghiên cứu bộ công cụ phần mềm nguồn mở sánh mẫu SMART. Luận văn đã tiến hành thực nghiệm trên cơ sở dữ liệu của bộ công cụ SMART để từ đó có một số nhận xét và so sánh các thuật toán sánh mẫu chính nhanh SSABS và TVSBS về thời gian thực hiện thuật toán. Luận văn cũng tiến hành thực nghiệm trực quan hoạt động của hai thuật toán này và kết quả cho thấy hai thuật toán hoạt động chính xác.

Hạn chế

Thuật toán thứ ba trong họ các thuật toán sánh mẫu chính xác được luận văn đề cập (thuật toán FQS) mới được đề xuất năm 2014 nên chưa được đưa vào bộ công cụ SMART. Vì vậy, do năng lực của bản thân và thời gian có hạn, tôi chưa thể trình bày thực nghiệm thuật toán FQS trong phạm vi luận văn này.

Hướng nghiên cứu tiếp theo

Nếu điều kiện cho phép, tôi sẽ tiếp tục nghiên cứu thuật toán thứ FQS để thi hành thử nghiệm thuật toán này trong bộ công cụ sánh mẫu SMART.

TÀI LIỆU THAM KHẢO Tiếng Việt:

[1] Nguyễn Thị Thúy (2012). Một họ thuật toán sánh mẫu WU-MANBER và thực nghiệm. Luận văn Thạc sỹ, Trường Đại học Công nghệ.

Tiếng Anh:

[2] C. Charras and T. Lecroq (2004). Handbook of exact string matching algorithms. King’s College Publications.

[3] Jie Lin, Donald A. Adjeroh, Yue Jiang (2014). A Faster Quick Search Algorithm. Algorithms 7(2): 253-275.

[4] Rahul Thathoo and Ashish Virmani and Sai S Lakshmi, and N. Balakrishnan, and K. Sekar (2006). TVSBS: A fast exact pattern matching algorithm for biological sequences. Current Science 91 (1). pp. 47-53.

[5] Simone Faro, Thierry Lecroq (2010). The Exact String Matching Problem: a Comprehensive Experimental Evaluation. CoRR abs/1012.2547.

[6] Simone Faro, Thierry Lecroq (2011). 2001-2010: Ten Years of Exact String Matching Algorithms. Stringology 2011: 1-2.

[7] Simone Faro, Thierry Lecroq (2013). The exact online string matching problem: A review of the most recent results. ACM Comput. Surv. 45(2): 13.

[8] S. S. Sheik, Sumit K. Aggarwal, Anindya Poddar, N. Balakrishnan, Krishna Sekar (2004). A FAST Pattern Matching Algorithm. Journal of Chemical Information and Modeling 44(4): 1251-1256.

[9] Timo Raita (1992). Tuning the Boyer-Moore-Horspool String Searching Algorithm. Softw., Pract. Exper. 22(10): 879-884.

Trang web:

[10] http://www-igm.univ-mlv.fr/~lecroq/lec_en.html (Thierry Lecroq) và http://www.dmi.unict.it/~faro/ (Simone Faro)

[11] Bộ công cụ smart tại trang web: http://www.dmi.unict.it/~faro/smart/, địa chỉ tải bộ công cụ:http://www.dmi.unict.it/~faro/smart/download.php.

PHỤ LỤC

Phụ lục 1. Phiên bản thi hành thuật toán SSABS và TVSBS trong SMART Phụ lục 1.1. Thuật toán SSABS

/*SSABS

* SMART: string matching algorithms research tool. * Copyright 2012Simone Faro and Thierry Lecroq

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or *(at your option) any later version.

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the * GNU General Public License for more details.

* You should have received a copy of the GNU General Public License * along with this program.If not, see <http://www.gnu.org/licenses/> * contact the authors at: faro@dmi.unict.it, thierry.lecroq@univ-rouen.fr * download the tool at: http://www.dmi.unict.it/~faro/smart/

*/

#include "include/define.h" #include "include/main.h"

void preQsBc (unsigned char *P, int m, int qbc[]) {

int i;

for (i=0;i<SIGMA;i++) qbc[i]=m+1; for (i=0;i<m;i++) qbc[P[i]]=m-i; }

////////////Searching Phase/////////////////////////////////////// int search (unsigned char *x, int m, unsigned char *y, int n)

{

int count,i,j =0; int qsBc[SIGMA];

unsigned char firstCh, lastCh; count = 0;

preQsBc (x, m, qsBc); firstCh = x[0];

lastCh = x[m -1];

for (i=0; i<m; i++) y[n+i]=lastCh; while (j <= n - m){

// Stage 1

if (lastCh == y[j + m - 1] && firstCh == y[j]) {

//Stage 2

for (i = m-2; i > 0 && x[i] == y[j + i]; i--); if (i <= 0) count++; } // Stage 3 j += qsBc[y[j + m]]; } return count; }

Phụ lục 1.2. Thuật toán TVSBS

/*TVSBS

* SMART: string matching algorithms research tool. * Copyright  2012Simone Faro and Thierry Lecroq

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or *(at your option) any later version.

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the * GNU General Public License for more details.

* You should have received a copy of the GNU General Public License * along with this program.If not, see <http://www.gnu.org/licenses/> * contact the authors at: faro@dmi.unict.it, thierry.lecroq@univ-rouen.fr * download the tool at: http://www.dmi.unict.it/~faro/smart/

* This is an implementation of the TVSBS algorithm in R.

* Thathoo and A. Virmani and S. S. Lakshmi and N. Balakrishnan and K. Sekar. * TVSBS: A Fast Exact Pattern Matching Algorithm for Biological Sequences. * J. Indian Acad. Sci., Current Sci., vol.91, n.1, pp.47--53,(2006).

*/

#include "include/define.h" #include "include/main.h"

void TVSBSpreBrBc (unsigned char *x, int m, int brBc[SIGMA][SIGMA])

{

int a, b, i;

for (a = 0; a < SIGMA; ++a) for (b = 0; b < SIGMA; ++b)

brBc[a][b] = m + 2; for (a = 0; a < SIGMA; ++a)

brBc[a][x[0]] = m + 1; for (i = 0; i < m - 1; ++i)

brBc[x[i]][x[i + 1]] = m - i; for (a = 0; a < SIGMA; ++a)

brBc[x[m - 1]][a] = 1; }

int search (unsigned char *x, int m, unsigned char *y, int n) {

int count,i,j =0;

int BrBc[SIGMA][SIGMA];

unsigned char firstCh, lastCh; count = 0;

TVSBSpreBrBc (x, m, BrBc); firstCh = x[0];

lastCh = x[m -1];

for (i=0; i<m; i++) y[n+i]=y[n+m+i]=x[i]; while (j <= n - m)

{

if (lastCh == y[j + m - 1] && firstCh == y[j]) {

for (i = m-2; i > 0 && x[i] == y[j + i]; i--); if (i <= 0) count++;

}

j += BrBc[y[j + m]][y[j+m+1]]; }

Phụ lục 1.3. Chương trình chính main.h trong file chương trình smart

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

//mandatory parameters

char *filename = (char*) malloc (sizeof(char) * (100)); //non mandatory parameters

PATT_SIZE = PATT_LARGE_SIZE; //the set of pattern legths int alpha = 256; //size of the alphabet int VOLTE = 500; //number of runs for each pattern length

int TSIZE = 1048576;

int SIMPLE = 0; //set to 1 if we run a single search with custom pattern and text

int occ = 0; //set to 1 for

printing number of occurrences

int dif = 0; //set to 1 for

printing the best and the worst running time

int txt = 0; //set to 1 for

printing results in txt format

int tex = 0; //set to 1 for

printing results in latex format

int php = 0; //set to 1 for

printing results in php format

int std = 0; //set to 1 for

printing the standard deviation value

int limit = 300; //set to 300 running time bound

char *simplePattern = (char*) malloc (sizeof(char) * (100)); //used for the simple run of SMART

char *simpleText = (char*) malloc (sizeof(char) * (1000)); //used for the simple run of SMART

/* useful variables */

unsigned char *T ; //text and pattern int n, tshmid,try;

//length of the text

FILE *ip; //file pointer for

input text

char parameter[1000]; char c;

srand( time(NULL) );

/* processing of input parameters */

if (argc==1) {printf("No parameter given. Use -h for help.\n\n"); return 0;}

if (!strcmp("-h", argv[1])) {printManual(); return 0;} int par = 1;

while(par<argc) {

if (par<argc && !strcmp("-pset", argv[par])) { par++;

if(par>=argc) {printf("Error in input parameters. Use -h for help.\n\n"); return 0;}

strcpy(parameter, argv[par++]);

if(!isInt(parameter)) {printf("Error in input parameters. Use -h for help.\n\n"); return 0;}

VOLTE = string2decimal(parameter); }

par++;

if(par>=argc) {printf("Error in input parameters. Use -h for help.\n\n"); return 0;}

strcpy(parameter, argv[par++]);

if(!isInt(parameter)) {printf("Error in input parameters. Use -h for help.\n\n"); return 0;}

TSIZE = string2decimal(parameter); TSIZE *= MG; }

if (par<argc && !strcmp("-tb", argv[par])) { par++;

if(par>=argc) {printf("Error in input parameters. Use -h for help.\n\n"); return 0;}

strcpy(parameter, argv[par++]);

if(!isInt(parameter)) {printf("Error in input parameters. Use -h for help.\n\n"); return 0;}

limit = string2decimal(parameter); }

if (par<argc && !strcmp("-text", argv[par])) { par++;

if(par>=argc) {printf("Error in input parameters. Use -h for help.\n\n"); return 0;}

strcpy(parameter, argv[par++]); strcat(filename, parameter); }

if (par<argc && !strcmp("-plen", argv[par])) { par++;

if(par>=argc) {printf("Error in input parameters. Use -h for help.\n\n"); return 0;}

strcpy(parameter, argv[par++]); MINLEN = string2decimal(parameter);;

if(MINLEN<1 || MINLEN>4200) {printf("Error in input parameters. The minimum length is not a valid

argument.\n\n"); return 0;}

if(par>=argc) {printf("Error in input parameters. Use -h for help.\n\n"); return 0;}

strcpy(parameter, argv[par++]); MAXLEN = string2decimal(parameter);;

if(MAXLEN<1 || MINLEN>MAXLEN) {printf("Error in input parameters. The maximum length is not a valid

argument.\n\n"); return 0;} }

if (par<argc && !strcmp("-simple", argv[par])) { par++;

if(par>=argc) {printf("Error in input parameters. Use -h for help.\n\n"); return 0;}

strcpy(parameter, argv[par++]); strcpy(simplePattern, parameter);

if(strlen(simplePattern)>100) {printf("Error in input parameters. Max 100 chars for P parameter.\n\n"); return 0;}

if(par>=argc) {printf("Error in input parameters. Use -h for help.\n\n"); return 0;}

strcpy(parameter, argv[par++]); strcpy(simpleText, parameter);

if(strlen(simpleText)>1000) {printf("Error in input parameters. Max 1000 chars for T parameter.\n\n"); return 0;}

SIMPLE=1; }

par++; occ = 1; }

if (par<argc && !strcmp("-dif", argv[par])) { par++;

dif = 1; }

if (par<argc && !strcmp("-txt", argv[par])) { par++;

txt = 1; }

if (par<argc && !strcmp("-std", argv[par])) { par++;

std = 1; }

if (par<argc && !strcmp("-tex", argv[par])) { par++;

tex = 1; }

if (par<argc && !strcmp("-php", argv[par])) { par++;

php = 1; }

if (par<argc && !strcmp("-short", argv[par])) { par++;

PATT_SIZE = PATT_SHORT_SIZE; }

if (par<argc && !strcmp("-veryshort", argv[par])) { par++;

PATT_SIZE = PATT_VERY_SHORT; }

if (par<argc && strcmp("-text", argv[par])!=0

&& strcmp("-alpha", argv[par])!=0 && strcmp("-tsize", argv[par])!=0 && strcmp("-plen", argv[par])!=0 && strcmp("-occ", argv[par])!=0 && strcmp("-dif", argv[par])!=0 && strcmp("-txt", argv[par])!=0 && strcmp("-tb", argv[par])!=0 && strcmp("-simple",

argv[par])!=0

&& strcmp("-tex", argv[par])!=0 && strcmp("-std", argv[par])!=0

&& strcmp("-php", argv[par])!=0 && strcmp("-pset", argv[par])!=0 && strcmp("-veryshort",

argv[par])!=0

&& strcmp("-short",

argv[par])!=0) {printf("Error in input parameters. Use -h for help.\n\n"); return 0;}

}

if(strcmp(filename,"") && SIMPLE) {printf("Error in input parameters. Both parameters -simple and -text defined.\n\n"); return 0;}

if(!strcmp(filename,"") && !SIMPLE) {printf("Error in input parameters. No filename given.\n\n"); return 0;}

getAlgo(ALGO_NAME,EXECUTE);

//allocate space for text in shered memory key_t tkey = rand()%1000;

size_t size = sizeof(unsigned char) * TSIZE+10; try = 0;

do {

tkey = rand()%1000;

tshmid = shmget(tkey, TSIZE+10, IPC_CREAT | 0666); } while(++try<10 && tshmid<0);

if (tshmid < 0) {

perror("shmget"); exit(1); }

if ((T = shmat(tshmid, NULL, 0)) == (unsigned char *) -1) { printf("\nShared memory allocation failed!\nYou need at least 12Mb of shared memory\nPlease, change your system settings and try again.\n");

perror("shmat");

shmctl(tshmid, IPC_RMID,0); exit(1);

}

if( SIMPLE ) {

//experimental results on a single pattern and a single text n = strlen(simpleText); int m = strlen(simplePattern); strcpy(T,simpleText); alpha = 250; PATT_CUSTOM_SIZE[0] = m; PATT_CUSTOM_SIZE[1] = 0; PATT_SIZE = PATT_CUSTOM_SIZE;

//if ( !(alpha = getAlpha(filename)) ) return 0; printf("\n\tText of %d chars : %s\n", n,T); printf("\tPattern of %d chars : %s\n", m,simplePattern); srand(time(NULL)); char expcode[100]; generateCode(expcode);

printf("\tStarting experimental tests with code %s\n",expcode);

run_setting("", tkey, T, n, alpha, FREQ, VOLTE, occ, dif, expcode, tshmid, txt, tex, php, simplePattern, std, limit);

//no output is given for the simple case; }

else if( strcmp(filename, "all") ) {

//experimental results on a single corpus

printf("\n\tTry to process archive %s\n", filename); char fullpath[100];

strcpy(fullpath,"data/"); strcat(fullpath, filename);

//initialize the frequency vector

if( !(n = getText(T,fullpath,FREQ,TSIZE) ) ) { shmctl(tshmid, IPC_RMID,0); return 0; } if ( !(alpha = getAlpha(filename)) ) { shmctl(tshmid, IPC_RMID,0); return 0;

}

printf("\tText buffer of dimension %d byte\n", n); srand(time(NULL));

char expcode[100]; generateCode(expcode);

printf("\tStarting experimental tests with code %s\n",expcode);

run_setting(filename, tkey, T, n, alpha, FREQ, VOLTE, occ, dif, expcode, tshmid, txt, tex, php, "", std, limit);

outputINDEX(filename,expcode); }

else {

//starts experimental results on all texts srand(time(NULL));

char expcode[100]; generateCode(expcode); int sett;

for(sett=0; sett<NumSetting; sett++) { char fullpath[100];

strcpy(fullpath,"data/");

strcat(fullpath, SETTING_BUFFER[sett]); alpha = SETTING_ALPHA_SIZE[sett];

printf("\n\tTry to process archive %s\n", SETTING_BUFFER[sett]);

//initialize the frequency vector

if( !(n = getText(T,fullpath,FREQ,TSIZE) ) ) { shmctl(tshmid, IPC_RMID,0);

return 0; }

printf("\tText buffer of dimension %d byte\n", n); printf("\tStarting experimental tests with code %s\n",expcode);

run_setting((char*)SETTING_BUFFER[sett], tkey, T, n, alpha, FREQ, VOLTE, occ, dif, expcode, tshmid, txt, tex, php, "", std, limit);

}

outputINDEX(filename,expcode); }

//free shared memory

shmctl(tshmid, IPC_RMID,0); return 0;

Phụ lục 2. Phiên bản thuật toán SSABS và TVSBS trong SMART với chuỗi Phụ lục 2.1. SSABS với chuỗi

#include "include/define.h" #include "include/main.h"

void preQsBc(unsigned char *P, int m, int qbc[]) { int i; for(i=0;i<SIGMA;i++) qbc[i]=m+1; for(i=0;i<m;i++) qbc[P[i]]=m-i; } ////////////Searching Phase///////////////////////////////////// int search(unsigned char *x, int m, unsigned char *y, int n){ int count,i,j =0;

int qsBc[SIGMA];

unsigned char firstCh, lastCh; count = 0;

preQsBc(x, m, qsBc); firstCh = x[0]; lastCh = x[m -1];

for(i=0; i<m; i++) y[n+i]=lastCh; while(j <= n - m){

// Stage 1

if(lastCh == y[j + m - 1] && firstCh == y[j]) {

//Stage 2

for(i = m-2; i > 0 && x[i] == y[j + i]; i--); if(i <= 0) { if(count==0)printf("Found at: "); printf("%d: %s ",(j+1),(y+j)); count++; } } // Stage 3 j += qsBc[y[j + m]]; } return count; } Phụ lục 2.2. TVSBS với chuỗi #include "include/define.h" #include "include/main.h"

void TVSBSpreBrBc(unsigned char *x, int m, int brBc[SIGMA][SIGMA]) {

int a, b, i;

for (a = 0; a < SIGMA; ++a) for (b = 0; b < SIGMA; ++b) brBc[a][b] = m + 2; for (a = 0; a < SIGMA; ++a) brBc[a][x[0]] = m + 1; for (i = 0; i < m - 1; ++i) brBc[x[i]][x[i + 1]] = m - i;

for (a = 0; a < SIGMA; ++a) brBc[x[m - 1]][a] = 1; }

int search(unsigned char *x, int m, unsigned char *y, int n){ int count,i,j =0;

int BrBc[SIGMA][SIGMA];

unsigned char firstCh, lastCh; unsigned char *z=malloc(n+1);

strcpy(z,y); count = 0;

TVSBSpreBrBc(x, m, BrBc); firstCh = x[0];

lastCh = x[m -1];

for(i=0; i<m; i++) y[n+i]=y[n+m+i]=x[i]; while(j <= n - m){

if(lastCh == y[j + m - 1] && firstCh == y[j]) { for(i = m-2; i > 0 && x[i] == y[j + i]; i--); if(i <= 0) {

if(count==0) printf("Found at: "); printf("%d: %s\n",(j+1),(z+j)); count++; } } j += BrBc[y[j + m]][y[j+m+1]]; } return count; }

Phụ lục 2.3. Chương trình chính main.h với chuỗi

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

unsigned char *p,*t; int m,n;

if(argc < 3) {

// int search(unsigned char *x, int m, unsigned char *y, int n){ printf("%s <searching string> <searched string>\n",argv[0]);

return 1; } p = argv[1]; m = strlen(argv[1]); t = argv[2]; n = strlen(argv[2]);

int occ = search(p,m,t,n);

printf(" total of %d occurrences\n",occ); return 0;

Phụ lục 3. Phiên bản thuật toán SSABS và TVSBS trong SMART với file Phụ lục 3.1. SSABS với file

#include "include/define.h" #include "include/mainf.c"

void preQsBc(unsigned char *P, int m, int qbc[]) { int i; for(i=0;i<SIGMA;i++) qbc[i]=m+1; for(i=0;i<m;i++) qbc[P[i]]=m-i; } ////////////Searching Phase/////////////////////////////////////// int search(unsigned char *x, int m, unsigned char *z, int n){

int count,i,j =0; int qsBc[SIGMA];

unsigned char firstCh, lastCh; char * y =malloc(n+1); strcpy(y,z); count = 0; preQsBc(x, m, qsBc); firstCh = x[0]; lastCh = x[m -1];

for(i=0; i<m; i++) y[n+i]=lastCh; while(j <= n - m){

// Stage 1

if(lastCh == y[j + m - 1] && firstCh == y[j]) {

//Stage 2

for(i = m-2; i > 0 && x[i] == y[j + i]; i-- ); if(i <= 0) { if(count==0)printf("Found at: "); printf("%d: %s",(j+1),(z+j)); count++; } } // Stage 3 j += qsBc[y[j + m]]; } return count; } Phụ lục 3.2. TVSBS với file #include "include/define.h" #include "include/mainf.c"

void TVSBSpreBrBc(unsigned char *x, int m, int brBc[SIGMA][SIGMA]) {

int a, b, i;

for (a = 0; a < SIGMA; ++a) for (b = 0; b < SIGMA; ++b) brBc[a][b] = m + 2;

for (a = 0; a < SIGMA; ++a) brBc[a][x[0]] = m + 1; for (i = 0; i < m - 1; ++i) brBc[x[i]][x[i + 1]] = m - i; for (a = 0; a < SIGMA; ++a) brBc[x[m - 1]][a] = 1; }

int search(unsigned char *x, int m, unsigned char *z, int n){ int count,i,j =0;

int BrBc[SIGMA][SIGMA];

unsigned char firstCh, lastCh; unsigned char *y =malloc(n+1); strcpy(y,z);

count = 0;

TVSBSpreBrBc(x, m, BrBc); firstCh = x[0];

lastCh = x[m -1];

for(i=0; i<m; i++) y[n+i]=y[n+m+i]=x[i]; while(j <= n - m){

if(lastCh == y[j + m - 1] && firstCh == y[j]) { for(i = m-2; i > 0 && x[i] == y[j + i]; i--); if(i <= 0) {

if(count==0) printf("Found at: "); printf("%d: %s, ",(j+1),(z+j)); count++; } } j += BrBc[y[j + m]][y[j+m+1]]; } return count; }

Phụ lục 3.3. Chương trình chính main.h với file

#include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h>

Một phần của tài liệu (LUẬN văn THẠC sĩ) một họ thuật toán đối sánh mẫu chính xác nhanh SSABS TVSBS FQS và thực nghiệm (Trang 59 - 74)

Tải bản đầy đủ (PDF)

(74 trang)