Mercurial > hg > Applications > Grep
diff regexParser/subsetConstraction.cc @ 202:39ca25ed0607
add searchBit test
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 26 Dec 2015 19:49:34 +0900 |
parents | b8bc24abaf8a |
children | e809a2dd0731 |
line wrap: on
line diff
--- a/regexParser/subsetConstraction.cc Sat Dec 26 18:13:32 2015 +0900 +++ b/regexParser/subsetConstraction.cc Sat Dec 26 19:49:34 2015 +0900 @@ -349,3 +349,58 @@ putchar('\n'); } } + +SCValue createSCValue(TGValue tgv) { + SCValue scv; + scv.stateTop = tgv.tg->stateList; + scv.stateEnd = scv.stateTop; + while (scv.stateEnd->next) { + scv.stateEnd = scv.stateEnd->next; + } + return; +} + +SCValue createState(SCValue scv,BitVector bi) { + StatePtr s = NEW(State); + s->stateNum = ++scv.tg->totalStateCount; + s->next = NULL; + scv.stateEnd->next = s; + scv.stateEnd = s; + s->bitState = bi; + s->cc = NULL; + return scv; +} + +/** + 現在のステートに含まれる組み合わせ状態をとってくる + 組み合わされた個々の charclass をmerge して新しい charclass をつくり、組み合わせ状態に登録する + 生成した状態は stateArray に格納するA + 新しい状態ができなくなったら終了 + + charClassMerge の段階で新しい状態をリストに登録したら、charclasswalk をする必要がなくなる + */ +SCValue subsetConstraction(SCValue scv) { + for (;scv.stateTop;scv.stateTop = scv.stateTop->next) { + CharClassWalker cw = createCharClassWalker(scv.stateTop->cc); + while (hasNext(cw)) { + CharClassPtr cc = getNext(cw); + unsigned long bi = cc->nextState.bitContainer; + if (scv.stateArray[bi]) continue; + scv = createState(scv,bi); + StatePtr s = scv.stateEnd; + for (;bi.bitContainer;) { + int bitPosition = searchBit(bi); + unsigned long baseNum = 1 << bitPosition; + bi.bitContainer ^= baseNum; + StatePtr base = scv.stateArray[baseNum]; + if (base == NULL) {// error + continue; + } + CharClassPtr merge = mergeTransition(s,base->cc); + s->cc = merge; + } + scv.stateArray[bi] = s; + } + } + return; +}