Mercurial > hg > Members > masakoha > testcode
changeset 176:c092dd0e1ae0 pairPro
implement appendState() and serchState()
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 23 Dec 2015 15:41:27 +0900 |
parents | 3be0fbcd4b52 |
children | 8de9a33f6ae5 |
files | regexParser/subsetConstraction.cc regexParser/transition.cc regexParser/transition.h |
diffstat | 3 files changed, 39 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/regexParser/subsetConstraction.cc Tue Dec 22 20:27:26 2015 +0900 +++ b/regexParser/subsetConstraction.cc Wed Dec 23 15:41:27 2015 +0900 @@ -148,6 +148,7 @@ CharClassPtr next = findLeftMost(current->right,walk)->next; walk->next = next; } else { + /* TransitionPtr tsOld = ts; ts = ts->next; free(tsOld); @@ -155,6 +156,7 @@ if (ts) ret = ts->cc; else ret = NULL; walk->next = ret; + */ } return current; } @@ -222,13 +224,16 @@ tg.ts = NEW(Transition); tg.state = NEW(State); tg.transitionList = NEW(Transition); + // Init State : 00...00(64bit) BitVectorPtr initStateBi = NEW(BitVector); bitSet(initStateBi,INIT_STATE_BIT); - tg.stateArray = createState(tg.stateArray,*initStateBi); + StatePtr initState = createState(tg.stateArray,*initStateBi); + // Last State : 10...00(64bit) BitVectorPtr lastStateBi = NEW(BitVector); bitSet(lastStateBi,END_STATE_BIT); - tg.stateArray = createState(tg.stateArray,*lastStateBi); - tg.stateArrayLast = NEW(State); + StatePtr lastState = createState(tg.stateArray,*lastStateBi); + tg.stateArray = appendState(initState,lastState); + tg.stateArrayLast = lastState; tg.currentState = NEW(State); tg.nextState = NEW(State); return tg;
--- a/regexParser/transition.cc Tue Dec 22 20:27:26 2015 +0900 +++ b/regexParser/transition.cc Wed Dec 23 15:41:27 2015 +0900 @@ -1,13 +1,23 @@ #include <stdlib.h> #include "transition.h" +StatePtr searchState(StatePtr stateArray, StatePtr state) { + while(stateArray) { + if (stateArray->bitState.bitContainer == state->bitState.bitContainer) { + return stateArray; + } + if (stateArray->next == NULL) { + StatePtr s = createState(state,state->bitState); + stateArray = appendState(stateArray,s); + return stateArray; + } + stateArray = stateArray->next; + } + return stateArray; +} + StatePtr createState(StatePtr state,BitVector bi) { StatePtr s = state; - if (state != NULL) { - while (state->next) { - state = state->next; - } - } state = NEW(State); state->bitState = bi; state->transition = NEW(Transition); @@ -15,6 +25,21 @@ return s; } +StatePtr appendState(StatePtr x,StatePtr y) { + StatePtr x0 = createState(x,x->bitState); + StatePtr x1 = x0; + for(;;) { + if (x->next == NULL) { + x1->next = y; + return x0; + } + x = x->next; + x1->next = createState(x,x->bitState); + x1 = x1->next; + } + return x0; +} + TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state) { TransitionPtr transition = NEW(Transition); transition->condition = cc;
--- a/regexParser/transition.h Tue Dec 22 20:27:26 2015 +0900 +++ b/regexParser/transition.h Wed Dec 23 15:41:27 2015 +0900 @@ -13,6 +13,7 @@ } State, *StatePtr; StatePtr createState(StatePtr state,BitVector bi); +StatePtr appendState(StatePtr x,StatePtr y); TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state); TransitionPtr appendTransition0(TransitionPtr curr,TransitionPtr next); TransitionPtr appendTransition(TransitionPtr curr,TransitionPtr next);