Mercurial > hg > Game > Cerium
annotate example/regex_mas/ppe/Exec.cc @ 1662:d865530672fa draft
fix regex_mas
author | Masa <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 16 Jul 2013 16:42:31 +0900 |
parents | 8b50b1ee068e |
children | 99f8130793b4 |
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 //ボイヤームーア法による文字列検索アルゴリズム |
1655
963d2fc5f685
push (but can't run regex_mas)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1652
diff
changeset
|
12 int BM_method(unsigned char *text,int *offset,int *text_length, |
1662 | 13 unsigned char *pattern,unsigned long long *match_string) |
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 { |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
15 int skip[256]; |
1655
963d2fc5f685
push (but can't run regex_mas)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1652
diff
changeset
|
16 int text_len = (long int)text_length; |
1662 | 17 int pattern_len = strlen((char *)pattern); |
1623
f82467ce38f3
fix regex_mas/ppe/Exec.cc . Convert char to unsigned char.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1621
diff
changeset
|
18 int i = 0; |
1662 | 19 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
|
20 |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
21 for (i = 0; i < 256; ++i){ |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
22 skip[i] = pattern_len; |
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 |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
25 for (i = 0; i < pattern_len-1 ; ++i){ |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
26 skip[(int)pattern[i]] = pattern_len - i - 1; |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
27 } |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
28 |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
29 i = pattern_len - 1; |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
30 |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
31 while ( i < text_len){ |
1623
f82467ce38f3
fix regex_mas/ppe/Exec.cc . Convert char to unsigned char.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1621
diff
changeset
|
32 int j = pattern_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
|
33 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
|
34 if (j == 0){ |
1662 | 35 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
|
36 } |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
37 --i; |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
38 --j; |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
39 } |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
40 i = i + max((int)skip[(int)text[i]],pattern_len - j); |
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
41 } |
1662 | 42 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
|
43 } |
1598 | 44 |
45 static int | |
46 run(SchedTask *s, void *rbuf, void *wbuf) | |
47 { | |
1662 | 48 unsigned char *i_data = (unsigned char *)rbuf; |
49 unsigned long long *o_data = (unsigned long long*)wbuf; | |
1655
963d2fc5f685
push (but can't run regex_mas)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1652
diff
changeset
|
50 int *length = (int*)s->get_param(0); |
1651 | 51 int *offset = (int*)s->get_param(1); |
1662 | 52 unsigned char search_word[] = "aba"; |
1621
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
53 |
1662 | 54 o_data[0] = BM_method(i_data,offset,length,search_word,o_data); |
55 | |
56 s->printf("%d\n",o_data[0]); | |
1645
4698c92bf2ca
Regex_mas implement time measurement.
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1644
diff
changeset
|
57 //s->printf("in Exec.cc\n"); |
1621
f907bbac14f2
Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
Masa <e085726@ie.u-ryukyu.ac.jp>
parents:
1620
diff
changeset
|
58 |
1662 | 59 |
1598 | 60 return 0; |
61 } |