Mercurial > hg > Applications > Grep
comparison regexParser/bmSearch.cc @ 320:da02a7258d54
fix
author | mir3636 |
---|---|
date | Sun, 08 May 2016 23:31:14 +0900 |
parents | 7b8234c090f7 |
children |
comparison
equal
deleted
inserted
replaced
319:7b8234c090f7 | 320:da02a7258d54 |
---|---|
1 #include "regexPaser.h" | 1 #include <stdlib.h> |
2 | |
3 #include "regexParser.h" | |
2 #include "CharClass.h" | 4 #include "CharClass.h" |
3 | 5 |
4 /** | 6 /** |
5 * if start node contains only words, Boyer-Moore Search can be used. | 7 * if start node contains only words, Boyer-Moore Search can be used. |
6 * if so skip table is created for each word. | 8 * if so skip table is created for each word. |
17 for (int j = 0; j < len - 1; ++j) { | 19 for (int j = 0; j < len - 1; ++j) { |
18 bm->skip_table[word[j]] = len - j - 1; | 20 bm->skip_table[word[j]] = len - j - 1; |
19 } | 21 } |
20 } | 22 } |
21 | 23 |
22 void checkBMSearch(CharaClassPtr cc) { | 24 void checkBMSearch(CharClassPtr cc) { |
23 | 25 |
24 // first check there is no Chareclass range | 26 // first check there is no Chareclass range |
25 CharClassWalkerPtr cw = createCharClassWalker(st->cc); | 27 CharClassWalkerPtr cw = createCharClassWalker(cc); |
26 while (hasNext(cw)) { | 28 while (hasNext(cw)) { |
27 CharClassPtr cc = getNext(cw); | 29 CharClassPtr cc1 = getNext(cw); |
28 if (cc->cond.w.word == NULL) { | 30 if (cc1->cond.w.word == NULL) { |
29 free(cw); | 31 free(cw); |
30 return; | 32 return; |
31 } | 33 } |
32 } | 34 } |
33 free(cw); | 35 free(cw); |
34 | 36 |
35 // make skip table for each word | 37 // make skip table for each word |
36 cw = createCharClassWalker(st->cc); | 38 cw = createCharClassWalker(cc); |
37 while (hasNext(cw)) { | 39 while (hasNext(cw)) { |
38 CharClassPtr cc = getNext(cw); | 40 CharClassPtr cc1 = getNext(cw); |
39 if (cc->cond.w.word) { | 41 if (cc1->cond.w.word) { |
40 WordPtr w = &cc->cond.w; | 42 WordPtr w = &cc1->cond.w; |
41 while (w) { | 43 while (w) { |
42 BMPtr bm = NEW(BM); | 44 BMPtr bm = NEW(BM); |
43 cc->cond.w.bm = bm; | 45 cc1->cond.w.bm = bm; |
44 create_BMskiptable(bm,cc->cond.w.word,cc->cond.length); | 46 create_BMskiptable(bm,cc1->cond.w.word,cc1->cond.w.length); |
45 w = w->next; | 47 w = w->next; |
46 } | 48 } |
47 } | 49 } |
48 } | 50 } |
49 free(cw); | 51 free(cw); |