Mercurial > hg > Members > masakoha > testcode
changeset 277:7b4bcc7b5ae6
nextTState implemented
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 30 Jan 2016 20:44:37 +0900 |
parents | 0faa561ac9ff |
children | 99d635926ef3 |
files | regexParser/cerium/CeriumMain.cc regexParser/subsetConstruction.cc regexParser/threadedSearch.cc |
diffstat | 3 files changed, 32 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/regexParser/cerium/CeriumMain.cc Sat Jan 30 19:08:01 2016 +0900 +++ b/regexParser/cerium/CeriumMain.cc Sat Jan 30 20:44:37 2016 +0900 @@ -27,8 +27,11 @@ char *filename = 0; st_time = getTime(); Search s = grep(argc,argv,true); + createAnyState(s.tg); generateTState(s.tg->anyState,s.tg); + // generateTState for startState. It is used in stateMatch. + generateTState(s.tg->stateList,s.tg); FileMapReduce *fmp = new FileMapReduce(manager,TASK_EXEC,TASK_EXEC_DATA_PARALLEL,TASK_PRINT); filename = fmp->init(argc, argv);
--- a/regexParser/subsetConstruction.cc Sat Jan 30 19:08:01 2016 +0900 +++ b/regexParser/subsetConstruction.cc Sat Jan 30 20:44:37 2016 +0900 @@ -235,6 +235,7 @@ s->bitState = bi; s->cc = NULL; s->node = NULL; + s->tState = NULL; return s; } @@ -364,8 +365,10 @@ void createAnyState(TransitionGeneratorPtr tg) { BitVector anyBi = createBitVector(tg->totalBasicState); - anyBi.bitContainer = anyBi.bitContainer * 2 - 1; // all bit 1 state + anyBi.bitContainer = anyBi.bitContainer - 1; // all bit 1 state + anyBi.bitContainer ^= 2; // exclude Accept State tg->anyState = createState(tg,anyBi); + determinize(tg->anyState,tg); tg->stateArray[tg->anyState->bitState.bitContainer] = tg->anyState; } @@ -412,6 +415,7 @@ } StatePtr base = tg->stateArray[baseNum]; if (base == NULL) { + fprintf(stderr,"baseNum=%lx ",baseNum); errorMassege("No base state",__LINE__,__FILE__); break; } CharClassPtr merge = mergeTransition(s,base->cc);
--- a/regexParser/threadedSearch.cc Sat Jan 30 19:08:01 2016 +0900 +++ b/regexParser/threadedSearch.cc Sat Jan 30 20:44:37 2016 +0900 @@ -46,8 +46,10 @@ tState->stateSkip = tg->stateSkip; tState->stateContinue = tg->stateNothing; } - if (ccvSize == 0) return tState; - else tState->ccv = (ccv*)malloc(sizeof(ccv)*ccvSize); + if (ccvSize == 0) { + tState->ccv = NULL; + return tState; + } else tState->ccv = (ccv*)malloc(sizeof(ccv)*ccvSize); ccw = createCharClassWalker(state->cc); int i = 0; while (hasNext(ccw)) { @@ -65,6 +67,21 @@ return tState; } +TStatePtr nextTState(BitVector bi,TransitionGeneratorPtr tg) { + // create tSearch in next state. + StatePtr state = tg->stateArray[bi.bitContainer]; + if (state == NULL) { + // on the fly subset construction. + state = createState(tg,bi); + determinize(state,tg); + tg->stateArray[bi.bitContainer] = state; + } + if (state->tState == NULL) { + generateTState(state,tg); + } + return state->tState; +} + void tSearch(TSValue tsv) { next: while (tsv.buff.buffptr < tsv.buff.buffend) { unsigned char c = *tsv.buff.buffptr++; @@ -79,24 +96,12 @@ // match the word. // if (not match) continue; } - TStatePtr current = ccv->tState; - if (current == NULL) { - // create tSearch in next state. - StatePtr state = tsv.tg->stateArray[ccv->state.bitContainer]; - if (state == NULL) { - // on the fly subset construction. - state = createState(tsv.tg,state->bitState); - determinize(state,tsv.tg); - tsv.tg->stateArray[state->bitState.bitContainer] = state; - } - if (state->tState == NULL) { - current = generateTState(state,tsv.tg); - ccv->tState = current; - } else { - ccv->tState = state->tState; - } + if (ccv->tState) { + tsv.current = ccv->tState; + } else { + tsv.current = nextTState(ccv->state,tsv.tg); + ccv->tState = tsv.current; } - tsv.current = ccv->tState; // tsv = tsv.current->stateContinue(tsv); goto next; }