Mercurial > hg > Applications > Grep
diff regexParser/transition.cc @ 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 |
line wrap: on
line diff
--- 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;