Mercurial > hg > Game > Cerium
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 |
rev | line source |
---|---|
1598 | 1 #include <stdio.h> |
2 #include <string.h> | |
3 #include "Exec.h" | |
4 #include "Func.h" | |
1638 | 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 | 7 |
1598 | 8 /* これは必須 */ |
9 SchedDefineTask(Exec); | |
1630 | 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 | 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 | 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 | 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 | 31 |
32 static int | |
33 run(SchedTask *s, void *rbuf, void *wbuf) | |
34 { | |
1778 | 35 //set_inData |
1740 | 36 unsigned char *i_data = (unsigned char *)s->get_input(rbuf,0); |
1784 | 37 unsigned char *search_word = (unsigned char*)s->get_input(rbuf,1); |
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 | 40 int length = (int)s->get_inputSize(0); |
41 int sw_len = (int)s->get_inputSize(1); | |
1778 | 42 //set_param |
43 s->printf("length %d\n",length); | |
1784 | 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 | 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 | 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 | 51 s->printf("aft o_data :%d\n",o_data[0]); |
1662 | 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 | 54 return 0; |
55 } |