Mercurial > hg > Applications > Grep
changeset 166:96854eba17e5 pairPro
implement mergeCCTree()
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 19 Dec 2015 15:02:02 +0900 |
parents | 42f4ee38196e |
children | 3bf2c6d6d53e |
files | c/regexParser/subsetConstraction.cc |
diffstat | 1 files changed, 19 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/subsetConstraction.cc Sat Dec 19 14:38:33 2015 +0900 +++ b/c/regexParser/subsetConstraction.cc Sat Dec 19 15:02:02 2015 +0900 @@ -8,6 +8,17 @@ return cc; } +CharClassPtr mergeCCTree(CharClassPtr cc,unsigned char mBegin,unsigned char mEnd,BitVector nextState) { + CharClassPtr cc1; + if (cc) { + cc1 = charClassMerge(cc,mBegin,mEnd,nextState); + } else { + cc1 = createCharClassRange(mBegin,mEnd,NULL,NULL); + cc1->nextState = nextState; + } + return cc1; +} + CharClassPtr charClassMerge(CharClassPtr cc,unsigned long begin, unsigned long end, BitVector nextState) { // 重なっているccの領域を分割する // 必要ならばnextStateを重ねあわせる @@ -21,13 +32,7 @@ return cc1; } } else if (end == cc->cond.range.begin && begin != end ) { // 2 - CharClassPtr cc1; - if (cc->left) { - cc1 = charClassMerge(cc->left,begin,end-1,nextState); - } else { - cc1 = createCharClassRange(begin,end-1,NULL,NULL); - cc1->nextState = nextState; - } + CharClassPtr cc1 = mergeCCTree(cc->left,begin,end-1,nextState); if (cc->cond.range.begin == cc->cond.range.end) { CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc1,cc->right); cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; @@ -40,13 +45,7 @@ return cc2; } else if (end < cc->cond.range.end) { // range.begin < end if (begin < cc->cond.range.begin) { // 3 - CharClassPtr cc1; - if (cc->left) { - cc1 = charClassMerge(cc->left,begin,cc->cond.range.begin-1,nextState); - } else { - cc1 = createCharClassRange(begin,cc->cond.range.begin-1,NULL,NULL); - cc1->nextState = nextState; - } + CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,nextState); CharClassPtr cc3 = createCharClassRange(end+1,cc->cond.range.end,cc->left,cc->right); cc3->nextState = cc->nextState; CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,end,cc1,cc3); @@ -74,13 +73,7 @@ cc1->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; return cc1; } else if (begin < cc->cond.range.begin) { // 4 - CharClassPtr cc1; - if (cc->left) { - cc1 = charClassMerge(cc->left,begin,cc->cond.range.begin-1,nextState); - } else { - cc1 = createCharClassRange(begin,cc->cond.range.begin-1,NULL,NULL); - cc1->nextState = nextState; - } + CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,nextState); CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,end,cc1,cc->right); cc3->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; return cc3; @@ -104,25 +97,13 @@ if (begin >= cc->cond.range.begin && begin <= cc->cond.range.end) { if (end > cc->cond.range.end) { // cond.range.end < end if (begin == cc->cond.range.begin) { // 8 - CharClassPtr cc1; - if (cc->right) { - cc1 = charClassMerge(cc->right,cc->cond.range.end+1,end,nextState); - } else { - cc1 = createCharClassRange(cc->cond.range.end+1,end,NULL,NULL); - cc1->nextState = nextState; - } + CharClassPtr cc1 = mergeCCTree(cc->right,cc->cond.range.end+1,end,nextState); CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->left,cc1); cc3->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; return cc3; } if (begin > cc->cond.range.begin) { // 11 - CharClassPtr cc1; - if (cc->right) { - cc1 = charClassMerge(cc->right,cc->cond.range.end+1,end,nextState); - } else { - cc1 = createCharClassRange(cc->cond.range.end+1,end,NULL,NULL); - cc1->nextState = nextState; - } + CharClassPtr cc1 = mergeCCTree(cc->right,cc->cond.range.end+1,end,nextState); CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,begin-1,cc->left,NULL); cc3->nextState = cc->nextState; CharClassPtr cc2 = createCharClassRange(begin,cc->cond.range.end,cc3,cc1); @@ -132,13 +113,7 @@ } // begin != end && end != cc->cond.range.end if (begin == cc->cond.range.end) { // 12 - CharClassPtr cc1; - if (cc->right) { - cc1 = charClassMerge(cc->right,begin+1,end,nextState); - } else { - cc1 = createCharClassRange(begin+1,end,NULL,NULL); - cc1->nextState = nextState; - } + CharClassPtr cc1 = mergeCCTree(cc->right,begin+1,end,nextState); if (cc->cond.range.begin == cc->cond.range.end) { CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc1,cc->right); cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; @@ -151,20 +126,8 @@ return cc2; } } else if (begin < cc->cond.range.begin) { // 5 - CharClassPtr cc1; - if (cc->left) { - cc1 = charClassMerge(cc->left,begin,cc->cond.range.begin-1,nextState); - } else { - cc1 = createCharClassRange(begin,cc->cond.range.begin-1,NULL,NULL); - cc1->nextState = nextState; - } - CharClassPtr cc3; - if (cc->right) { - cc3 = charClassMerge(cc->right,cc->cond.range.end+1,end,nextState); - } else { - cc3 = createCharClassRange(cc->cond.range.end+1,end,NULL,NULL); - cc3->nextState = nextState; - } + CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,nextState); + CharClassPtr cc3 = mergeCCTree(cc->right,cc->cond.range.end+1,end,nextState); CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc1,cc3); cc2->nextState.bitContainer = cc->nextState.bitContainer | nextState.bitContainer; return cc2;