comparison regexParser/threadedSearch.cc @ 245:d34de5edaa96

add threadedSearch.cc
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Thu, 21 Jan 2016 19:35:33 +0900
parents
children 58de1744d7a9
comparison
equal deleted inserted replaced
244:a3cddb32b87f 245:d34de5edaa96
1 struct tsValue;
2
3 typedef struct tState {
4 State *state;
5 void stateSkip(struct TSValue);
6 int ccvSize;
7 struct ccv{
8 unsigned long begin;
9 unsigned long end;
10 BitVector state;
11 struct tState *tState;
12 } *ccv;
13 } TState, *TStatePtr;
14
15 typedef struct result {
16 unsigned char begin;
17 unsigned char end;
18 struct result *next;
19 } Result, *ResultPtr;
20
21 typedef struct tsValue {
22 Buffer buff;
23 ResultPtr result;
24 TState *current;
25 TState *blockBegin;
26 TState *blockEnd;
27 } TSValue, *TSValuePtr;
28
29 void stateSkip(TSValue tsv) {
30 tsv.buff.matchBegin = tsv.buff.buffptr;
31 tsv.(tsv);
32 }
33
34 void tSearch(TSValue tsv) {
35 next; while (buff.buffptr < buff.buffend) {
36 unsigned char c = *buff.buffptr++;
37 for (int i = 0; i < tsv.current->ccvSize; i++) {
38 if (c<tsv.current->ccv[i].begin) tsv.current->stateSkip(tsv);
39 else if (c<=tsv.current->ccv[i].end) {
40 TStatePtr current = tsv.current->ccv[i].tState;
41 if (current == NULL) {
42 current = generateTState(tsv.stateArray[tsv.current->ccv[i].state.bitContainer]);
43 tsv.current->ccv[i].tState = current;
44 }
45 tsv.current = tsv.current->ccv[i].tState;
46 goto next;
47 }
48 }
49 tsv.current->stateSkip(tsv);
50 }
51 }
52
53 TStatePtr generateTState(StatePtr state) {
54 TState tState = NEW(TState);
55 int ccvSize = 0;
56 CharClassWalkerPtr ccw = createCharClassWalker(state->cc);
57 while (hasNext(ccw)) {
58 CharClassPtr cc = getNext(ccw);
59 ccvSize++;
60 }
61 if (ccvSize == 0) return tState;
62 else tState->ccv = (struct ccv*)malloc(sizeof(struct ccv)*ccvSize);
63 CharClassWalkerPtr ccw = createCharClassWalker(state->cc);
64 while (hasNext(ccw)) {
65 CharClassPtr cc = getNext(ccw);
66 unsigned long begin = cc->cond.range.begin;
67 unsigned long end = cc->cond.range.end;
68 struct ccv *ccv = &tState->ccv[i++];
69 ccv->begin = begin;
70 ccv->end = end;
71 ccv->tState = NULL;
72 ccv->state = cc->nextState;
73 }
74 free(ccw);
75 return tState;
76 }