changeset 1621:f907bbac14f2 draft

Implement Boyer-Moore String Search Algorithm.(But incomplete divided file point)
author Masa <e085726@ie.u-ryukyu.ac.jp>
date Tue, 21 May 2013 17:03:53 +0900
parents bb0384fb5a56
children 4401690b4513
files example/regex_mas/b.txt example/regex_mas/ppe/Exec.cc example/regex_mas/ppe/Print.cc
diffstat 3 files changed, 44 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/example/regex_mas/b.txt	Sat May 18 20:20:10 2013 +0900
+++ b/example/regex_mas/b.txt	Tue May 21 17:03:53 2013 +0900
@@ -1,4 +1,3 @@
 1cb aaa dddd ssss ababx
 2ab bbbbbbbbbb aaaaaaa
 3aaaaaaa aaaaaaaaa aaa
-4ab aaaab
--- a/example/regex_mas/ppe/Exec.cc	Sat May 18 20:20:10 2013 +0900
+++ b/example/regex_mas/ppe/Exec.cc	Tue May 21 17:03:53 2013 +0900
@@ -2,11 +2,43 @@
 #include <string.h>
 #include "Exec.h"
 #include "Func.h"
-//void line_print(int,int,char*);
-#define BUFFER_SIZE 4096
-
+#define max(a,b)((a)>(b)?a:b) 
 /* これは必須 */
 SchedDefineTask(Exec);
+//ボイヤームーア法による文字列検索アルゴリズム
+int BM_method(char *text,int text_length,char *pattern,unsigned long long *match_string)
+{
+    int skip[256];
+    int i,j,text_len,pattern_len;
+    int k = 0;
+    //text_len = strlen(text);
+    text_len = text_length;
+    pattern_len = strlen(pattern);
+
+    for (i = 0; i < 256; ++i){
+        skip[i] = pattern_len;
+    }
+
+    for (i = 0; i < pattern_len-1 ; ++i){
+        skip[(int)pattern[i]] = pattern_len - i - 1;
+    }
+
+    i = pattern_len - 1;
+
+    while ( i < text_len){
+        j = pattern_len - 1;
+        while (text[i] == pattern[j]){
+            if (j == 0){
+                match_string[k] = text[i];
+                k++;
+            }
+            --i;
+            --j;
+        }
+        i = i + max((int)skip[(int)text[i]],pattern_len - j);
+    }
+    return 0;
+}
 
 static int
 run(SchedTask *s, void *rbuf, void *wbuf)
@@ -14,33 +46,12 @@
     char *i_data = (char *)rbuf;
     unsigned long long *o_data = (unsigned long long*)wbuf;
     int length = (int)s->get_inputSize(0);
-    int *offset = (int*)s->get_param(1);
-    printf("offset = %d\n",offset);
-    int i = 0;
-    int j = 0;
-    bool a_flag = 0;
-    bool match_flag = 0;
-    
-    for (; i < length; i++) {
-         if (i_data[i] == 0x61) {
-             a_flag = true;
-         }else if ((i_data[i] == 0x62) && (a_flag == true)) {
-             o_data[j] = *((char *)rbuf + i - 2);
-             match_flag = true;
-         }else{
-             a_flag = false;
-         }
-    }
+//  int *offset = (int*)s->get_param(1);
+    char search_word[] = "ab";
+//  printf("offset = %d\n",offset);
+
+    BM_method(i_data,length,search_word,o_data);
+
    
     return 0;
 }
-
-//void line_print(int _line_num,int _line_length,char *input_data){
-//
-//    printf("%d : ",_line_num);
-//    for (int k = 0; k < _line_length; k++) {
-//        printf("%c",input_data[k]);
-//    }
-//    printf("\n");
-//}
-//
--- a/example/regex_mas/ppe/Print.cc	Sat May 18 20:20:10 2013 +0900
+++ b/example/regex_mas/ppe/Print.cc	Tue May 21 17:03:53 2013 +0900
@@ -12,7 +12,9 @@
 {
     WordCount *w = *(WordCount**)rbuf;
     unsigned long long *idata = w->o_data;
-    // long task_num = w->task_num;
+    
+    s->printf("task num : %d\n",w->task_spwaned);
+
     for (int i = 0;i < 8;i++) {
         s->printf("%c\n",(char)idata[i]);
     }