Mercurial > hg > Members > masakoha > testcode
annotate regexParser/threadedSearch.cc @ 252:2b276fdd99bd
remove error (not working)
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jan 2016 11:48:06 +0900 |
parents | e22e3475f664 |
children | 21b9ba76f91b |
rev | line source |
---|---|
247 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
246 | 4 #include "regexParser.h" |
5 #include "subsetConstruction.h" | |
6 | |
245
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 void stateSkip(TSValue tsv) { |
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 tsv.buff.matchBegin = tsv.buff.buffptr; |
246 | 9 tsv.current->stateSkip(tsv); |
245
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 } |
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 |
251 | 12 TStatePtr generateTState(StatePtr state) { |
247 | 13 TStatePtr tState = NEW(TState); |
14 int ccvSize = 0; | |
251 | 15 CharClassWalkerPtr ccw = createCharClassWalker(state->cc); |
247 | 16 while (hasNext(ccw)) { |
17 CharClassPtr cc = getNext(ccw); | |
18 ccvSize++; | |
19 } | |
20 if (ccvSize == 0) return tState; | |
21 else tState->ccv = (ccv*)malloc(sizeof(ccv)*ccvSize); | |
251 | 22 ccw = createCharClassWalker(state->cc); |
247 | 23 int i = 0; |
24 while (hasNext(ccw)) { | |
25 CharClassPtr cc = getNext(ccw); | |
26 unsigned long begin = cc->cond.range.begin; | |
27 unsigned long end = cc->cond.range.end; | |
28 struct ccv *ccv = &tState->ccv[i++]; | |
29 ccv->begin = begin; | |
30 ccv->end = end; | |
31 ccv->tState = NULL; | |
32 ccv->state = cc->nextState; | |
248
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
33 ccv->w = cc->cond.w; |
247 | 34 } |
35 free(ccw); | |
36 return tState; | |
37 } | |
38 | |
245
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 void tSearch(TSValue tsv) { |
247 | 40 next: while (tsv.buff.buffptr < tsv.buff.buffend) { |
41 unsigned char c = *tsv.buff.buffptr++; | |
245
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 for (int i = 0; i < tsv.current->ccvSize; i++) { |
248
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
43 CCVPtr ccv = &tsv.current->ccv[i]; |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
44 if (c<ccv->begin) tsv.current->stateSkip(tsv); |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
45 else if (c<=ccv->end) { |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
46 // range matched. |
251 | 47 if (ccv->w.word) { |
248
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
48 // match the word. |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
49 // if (not match) continue; |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
50 } |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
51 TStatePtr current = ccv->tState; |
245
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 if (current == NULL) { |
248
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
53 // create tSearch in next state. |
251 | 54 StatePtr state = tsv.tg->stateArray[ccv->state.bitContainer]; |
248
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
55 if (state == NULL) { |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
56 // on the fly subset construction. |
252
2b276fdd99bd
remove error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
251
diff
changeset
|
57 state = createState(tsv.tg,state->bitState); |
2b276fdd99bd
remove error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
251
diff
changeset
|
58 tsv.tg->stateArray[state->bitState.bitContainer] = state; |
248
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
59 determinize(state,tsv.tg); |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
60 } |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
61 if (state->tState == NULL) { |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
62 current = generateTState(state); |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
63 ccv->tState = current; |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
64 } else { |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
65 ccv->tState = state->tState; |
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
66 } |
245
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 } |
248
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
247
diff
changeset
|
68 tsv.current = ccv->tState; |
245
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 goto next; |
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 } |
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 } |
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 tsv.current->stateSkip(tsv); |
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 } |
d34de5edaa96
add threadedSearch.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 } |