320
|
1 #include <stdlib.h>
|
|
2
|
|
3 #include "regexParser.h"
|
319
|
4 #include "CharClass.h"
|
|
5
|
|
6 /**
|
|
7 * if start node contains only words, Boyer-Moore Search can be used.
|
|
8 * if so skip table is created for each word.
|
|
9 */
|
|
10
|
|
11 static void
|
|
12 create_BMskiptable(BMPtr bm,unsigned char *word,int len)
|
|
13 {
|
|
14 bm->skip_table = (int*)malloc(sizeof(int)*256);
|
|
15 for (int i = 0; i < 256; ++i) {
|
|
16 bm->skip_table[i] = len;
|
|
17 }
|
|
18
|
|
19 for (int j = 0; j < len - 1; ++j) {
|
|
20 bm->skip_table[word[j]] = len - j - 1;
|
|
21 }
|
|
22 }
|
|
23
|
320
|
24 void checkBMSearch(CharClassPtr cc) {
|
319
|
25
|
|
26 // first check there is no Chareclass range
|
320
|
27 CharClassWalkerPtr cw = createCharClassWalker(cc);
|
319
|
28 while (hasNext(cw)) {
|
320
|
29 CharClassPtr cc1 = getNext(cw);
|
|
30 if (cc1->cond.w.word == NULL) {
|
319
|
31 free(cw);
|
|
32 return;
|
|
33 }
|
|
34 }
|
|
35 free(cw);
|
|
36
|
|
37 // make skip table for each word
|
320
|
38 cw = createCharClassWalker(cc);
|
319
|
39 while (hasNext(cw)) {
|
320
|
40 CharClassPtr cc1 = getNext(cw);
|
|
41 if (cc1->cond.w.word) {
|
|
42 WordPtr w = &cc1->cond.w;
|
319
|
43 while (w) {
|
|
44 BMPtr bm = NEW(BM);
|
320
|
45 cc1->cond.w.bm = bm;
|
|
46 create_BMskiptable(bm,cc1->cond.w.word,cc1->cond.w.length);
|
319
|
47 w = w->next;
|
|
48 }
|
|
49 }
|
|
50 }
|
|
51 free(cw);
|
|
52 }
|