Mercurial > hg > Applications > Grep
comparison regexParser/threadedSearch.cc @ 321:a1b65d39b947
bmSearch fix
author | mir3636 |
---|---|
date | Mon, 16 May 2016 17:03:17 +0900 |
parents | da02a7258d54 |
children | 62f4628d2c0d |
comparison
equal
deleted
inserted
replaced
320:da02a7258d54 | 321:a1b65d39b947 |
---|---|
4 | 4 |
5 #include "regexParser.h" | 5 #include "regexParser.h" |
6 #include "CharClass.h" | 6 #include "CharClass.h" |
7 #include "threadedSearch.h" | 7 #include "threadedSearch.h" |
8 #include "subsetConstruction.h" | 8 #include "subsetConstruction.h" |
9 #include "bmSearch.h" | |
9 | 10 |
10 #define max(a,b)((a)>(b)?a:b) | 11 #define max(a,b)((a)>(b)?a:b) |
11 #define min(a,b)((a)<(b)?a:b) | 12 #define min(a,b)((a)<(b)?a:b) |
12 | 13 |
13 TStatePtr nextTState(BitVector bi,TransitionGeneratorPtr tg); | 14 TStatePtr nextTState(BitVector bi,TransitionGeneratorPtr tg); |
24 puts(""); | 25 puts(""); |
25 tsv.matchEnd = NULL; | 26 tsv.matchEnd = NULL; |
26 } | 27 } |
27 tsv.matchBegin = tsv.buff.buffptr; // next char may be matchBegin | 28 tsv.matchBegin = tsv.buff.buffptr; // next char may be matchBegin |
28 // if possible use bmsearch | 29 // if possible use bmsearch |
30 if (!tsv.current || !tsv.current->ccv[0].w.bm ) return tsv; | |
29 while (tsv.buff.buffptr < tsv.buff.buffend) { | 31 while (tsv.buff.buffptr < tsv.buff.buffend) { |
30 long skip = tsv.tg->maxWordLen; | 32 long skip = tsv.tg->maxWordLen; |
31 for (int k = 0; k < tsv.current->ccvSize; k++) { | 33 for (int k = 0; k < tsv.current->ccvSize; k++) { |
32 CCVPtr ccv = &tsv.current->ccv[k]; | 34 CCVPtr ccv = &tsv.current->ccv[k]; |
33 if (ccv->w.word) { | 35 if (ccv->w.bm) { |
34 int i = ccv->w.length - 1; | 36 int i = ccv->w.length - 1; |
35 while (tsv.buff.buffptr[i] == ccv->w.word[i]) { | 37 while (tsv.buff.buffptr[i] == ccv->w.word[i]) { |
36 if (i == 0) { | 38 if (i == 0) { |
37 if (ccv->tState) { | 39 if (ccv->tState) { |
38 tsv.current = ccv->tState; | 40 tsv.current = ccv->tState; |
39 } else { | 41 } else { |
40 tsv.current = nextTState(ccv->state,tsv.tg); | 42 tsv.current = nextTState(ccv->state,tsv.tg); |
41 ccv->tState = tsv.current; | 43 ccv->tState = tsv.current; |
42 } | 44 } |
43 tsv.buff.buffptr += ccv->w.length - 1; | 45 tsv.matchBegin = tsv.buff.buffptr; |
46 tsv.buff.buffptr += ccv->w.length; | |
44 return tsv; | 47 return tsv; |
45 } | 48 } |
46 --i; | 49 --i; |
47 } | 50 } |
48 skip = min(skip,max(ccv->w.bm->skip_table[tsv.buff.buffptr[i]],ccv->w.length - i)); | 51 skip = min(skip,max(ccv->w.bm->skip_table[tsv.buff.buffptr[i]],ccv->w.length - i)); |
49 } | 52 } |
50 } | 53 } |
51 tsv.buff.buffptr += skip; | 54 tsv.buff.buffptr += skip; |
52 } | 55 } |
56 tsv.matchBegin = tsv.buff.buffptr; | |
53 return tsv; | 57 return tsv; |
54 } | 58 } |
55 | 59 |
56 static | 60 static |
57 TSValue stateMatch(TSValue tsv) { | 61 TSValue stateMatch(TSValue tsv) { |
177 tsv.matchBegin = buff.buffptr; | 181 tsv.matchBegin = buff.buffptr; |
178 tsv.matchEnd = NULL; | 182 tsv.matchEnd = NULL; |
179 tsv.tg->stateSkip = stateSkip; | 183 tsv.tg->stateSkip = stateSkip; |
180 tsv.tg->stateMatch = stateMatch; | 184 tsv.tg->stateMatch = stateMatch; |
181 tsv.tg->stateNothing = stateNothing; | 185 tsv.tg->stateNothing = stateNothing; |
186 tsv.current = NULL; | |
182 return tsv; | 187 return tsv; |
183 } | 188 } |
184 | 189 |
185 | 190 |
186 void threadedSearch(TransitionGeneratorPtr tg, Buffer buff) { | 191 void threadedSearch(TransitionGeneratorPtr tg, Buffer buff) { |
187 TSValue tsv = createTSValue(tg,buff); | 192 TSValue tsv = createTSValue(tg,buff); |
188 tsv.current = generateTState(tg->stateList,tg); | 193 generateTState(tg->stateList,tg); |
189 tg->stateStart = NEW(State); | 194 tg->stateStart = NEW(State); |
190 *tg->stateStart = *tg->stateList; | 195 *tg->stateStart = *tg->stateList; |
191 tg->stateStart->accept = false; // Start state never accept | 196 tg->stateStart->accept = false; // Start state never accept |
192 generateTState(tg->stateStart,tg); | 197 StatePtr state = tg->stateStart; |
198 checkBMSearch(state->cc); | |
199 tsv.current = generateTState(tg->stateStart,tg); | |
193 tSearch(tsv); | 200 tSearch(tsv); |
194 } | 201 } |
195 | 202 |
196 /* end */ | 203 /* end */ |