diff regexParser/bmSearch.cc @ 319:7b8234c090f7

bmSearch
author mir3636
date Sun, 08 May 2016 22:53:20 +0900
parents
children da02a7258d54
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regexParser/bmSearch.cc	Sun May 08 22:53:20 2016 +0900
@@ -0,0 +1,50 @@
+#include "regexPaser.h"
+#include "CharClass.h"
+
+/**
+ * if start node contains only words, Boyer-Moore Search can be used.
+ * if so skip table is created for each word. 
+*/
+
+static void
+create_BMskiptable(BMPtr bm,unsigned char *word,int len)
+{
+    bm->skip_table = (int*)malloc(sizeof(int)*256);
+    for (int i = 0; i < 256; ++i) {
+        bm->skip_table[i] = len;
+    }
+
+    for (int j = 0; j < len - 1; ++j) {
+        bm->skip_table[word[j]] = len - j - 1;
+    }
+}
+
+void checkBMSearch(CharaClassPtr cc) {
+
+    // first check there is no Chareclass range
+    CharClassWalkerPtr cw = createCharClassWalker(st->cc);
+    while (hasNext(cw)) {
+        CharClassPtr cc = getNext(cw);
+        if (cc->cond.w.word == NULL) {
+            free(cw);
+            return;
+        }
+    }
+    free(cw);
+
+    // make skip table for each word
+    cw = createCharClassWalker(st->cc);
+    while (hasNext(cw)) {
+        CharClassPtr cc = getNext(cw);
+        if (cc->cond.w.word) {
+            WordPtr w = &cc->cond.w;
+            while (w) {
+                BMPtr bm = NEW(BM);
+                cc->cond.w.bm = bm;
+                create_BMskiptable(bm,cc->cond.w.word,cc->cond.length);
+                w = w->next;
+            }
+        } 
+    }
+    free(cw);
+}