comparison 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
comparison
equal deleted inserted replaced
175:3be0fbcd4b52 176:c092dd0e1ae0
1 #include <stdlib.h> 1 #include <stdlib.h>
2 #include "transition.h" 2 #include "transition.h"
3 3
4 StatePtr searchState(StatePtr stateArray, StatePtr state) {
5 while(stateArray) {
6 if (stateArray->bitState.bitContainer == state->bitState.bitContainer) {
7 return stateArray;
8 }
9 if (stateArray->next == NULL) {
10 StatePtr s = createState(state,state->bitState);
11 stateArray = appendState(stateArray,s);
12 return stateArray;
13 }
14 stateArray = stateArray->next;
15 }
16 return stateArray;
17 }
18
4 StatePtr createState(StatePtr state,BitVector bi) { 19 StatePtr createState(StatePtr state,BitVector bi) {
5 StatePtr s = state; 20 StatePtr s = state;
6 if (state != NULL) {
7 while (state->next) {
8 state = state->next;
9 }
10 }
11 state = NEW(State); 21 state = NEW(State);
12 state->bitState = bi; 22 state->bitState = bi;
13 state->transition = NEW(Transition); 23 state->transition = NEW(Transition);
14 state->nextNode = NEW(Node); 24 state->nextNode = NEW(Node);
15 return s; 25 return s;
26 }
27
28 StatePtr appendState(StatePtr x,StatePtr y) {
29 StatePtr x0 = createState(x,x->bitState);
30 StatePtr x1 = x0;
31 for(;;) {
32 if (x->next == NULL) {
33 x1->next = y;
34 return x0;
35 }
36 x = x->next;
37 x1->next = createState(x,x->bitState);
38 x1 = x1->next;
39 }
40 return x0;
16 } 41 }
17 42
18 TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state) { 43 TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state) {
19 TransitionPtr transition = NEW(Transition); 44 TransitionPtr transition = NEW(Transition);
20 transition->condition = cc; 45 transition->condition = cc;