annotate example/regex_mas/ppe/Exec.cc @ 1786:ba6ffc679a8f draft

minor fix
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Sat, 30 Nov 2013 21:06:44 +0900
parents a9ff87220a68
children 5cde37f02c66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <string.h>
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "Exec.h"
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "Func.h"
1638
aa967337bda2 fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1634
diff changeset
5 #include "SchedTask.h"
1621
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
6 #define max(a,b)((a)>(b)?a:b)
1630
d2581892b8ad fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1623
diff changeset
7
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 /* これは必須 */
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 SchedDefineTask(Exec);
1630
d2581892b8ad fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1623
diff changeset
10
1621
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
11 //ボイヤームーア法による文字列検索アルゴリズム
1775
72e8c18bfbf6 End moving BMskip_table
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1774
diff changeset
12 static int BM_method(unsigned char *text,int text_len,
72e8c18bfbf6 End moving BMskip_table
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1774
diff changeset
13 unsigned char *pattern,int sw_len,int *skip)
1621
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
14 {
1775
72e8c18bfbf6 End moving BMskip_table
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1774
diff changeset
15 int i = sw_len - 1;
1662
d865530672fa fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1660
diff changeset
16 int match_counter = 0;
1621
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
17
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
18 while ( i < text_len){
1775
72e8c18bfbf6 End moving BMskip_table
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1774
diff changeset
19 int j = sw_len - 1;
1621
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
20 while (text[i] == pattern[j]){
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
21 if (j == 0){
1662
d865530672fa fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1660
diff changeset
22 match_counter++;
1621
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
23 }
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
24 --i;
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
25 --j;
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
26 }
1775
72e8c18bfbf6 End moving BMskip_table
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1774
diff changeset
27 i = i + max((int)skip[(int)text[i]],sw_len - j);
1621
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
28 }
1662
d865530672fa fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1660
diff changeset
29 return match_counter;
1621
f907bbac14f2 Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1620
diff changeset
30 }
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 static int
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 run(SchedTask *s, void *rbuf, void *wbuf)
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 {
1778
0e6ca13d2ed0 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1776
diff changeset
35 //set_inData
1740
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1739
diff changeset
36 unsigned char *i_data = (unsigned char *)s->get_input(rbuf,0);
1784
a9ff87220a68 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1778
diff changeset
37 unsigned char *search_word = (unsigned char*)s->get_input(rbuf,1);
a9ff87220a68 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1778
diff changeset
38 //unsigned char search_word[] = "doing";
1774
39734c8cbcfe To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1761
diff changeset
39 int *skip_table = (int *)s->get_input(rbuf,2);
1784
a9ff87220a68 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1778
diff changeset
40 int length = (int)s->get_inputSize(0);
a9ff87220a68 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1778
diff changeset
41 int sw_len = (int)s->get_inputSize(1);
1778
0e6ca13d2ed0 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1776
diff changeset
42 //set_param
0e6ca13d2ed0 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1776
diff changeset
43 s->printf("length %d\n",length);
1784
a9ff87220a68 minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1778
diff changeset
44 s->printf("sw_len %d\n",sw_len);
1774
39734c8cbcfe To created BMsearch skip table method move Exec.cc to main.cc:run_start
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1761
diff changeset
45
1761
b98e23499add refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1759
diff changeset
46 unsigned long long *o_data = (unsigned long long*)wbuf;
1786
ba6ffc679a8f minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1784
diff changeset
47 o_data[0] = 0;
1761
b98e23499add refactoring in regex_mas
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1759
diff changeset
48
1786
ba6ffc679a8f minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1784
diff changeset
49 s->printf("pre o_data :%d\n",o_data[0]);
1775
72e8c18bfbf6 End moving BMskip_table
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1774
diff changeset
50 o_data[0] = BM_method(i_data,length,search_word,sw_len,skip_table);
1786
ba6ffc679a8f minor fix
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1784
diff changeset
51 s->printf("aft o_data :%d\n",o_data[0]);
1662
d865530672fa fix regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1660
diff changeset
52
1645
4698c92bf2ca Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1644
diff changeset
53 //s->printf("in Exec.cc\n");
1598
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 return 0;
0f94d9d580f9 add regex_mas
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 }