view regexParser/threadedSearch.cc @ 251:e22e3475f664

fix
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Sat, 23 Jan 2016 14:10:28 +0900
parents 2b1fbfb92d54
children 2b276fdd99bd
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>

#include "regexParser.h"
#include "subsetConstruction.h"

void stateSkip(TSValue tsv) {
    tsv.buff.matchBegin = tsv.buff.buffptr;
    tsv.current->stateSkip(tsv);
}

TStatePtr generateTState(StatePtr state) {
    TStatePtr tState = NEW(TState);
    int ccvSize = 0;
    CharClassWalkerPtr ccw = createCharClassWalker(state->cc);
    while (hasNext(ccw)) {
        CharClassPtr cc = getNext(ccw);
        ccvSize++;
    }
    if (ccvSize == 0) return tState;
    else tState->ccv = (ccv*)malloc(sizeof(ccv)*ccvSize);
    ccw = createCharClassWalker(state->cc);
    int i = 0;
    while (hasNext(ccw)) {
        CharClassPtr cc = getNext(ccw);
        unsigned long begin = cc->cond.range.begin;
        unsigned long end = cc->cond.range.end;
        struct ccv *ccv = &tState->ccv[i++];
        ccv->begin = begin;
        ccv->end = end;
        ccv->tState = NULL;
        ccv->state = cc->nextState;
        ccv->w = cc->cond.w;
    }
    free(ccw);
    return tState;
}

void tSearch(TSValue tsv) {
    next: while (tsv.buff.buffptr < tsv.buff.buffend) {
        unsigned char c = *tsv.buff.buffptr++;
        for (int i = 0; i < tsv.current->ccvSize; i++) {
            CCVPtr ccv = &tsv.current->ccv[i];
            if (c<ccv->begin) tsv.current->stateSkip(tsv);
            else if (c<=ccv->end) {
                // range matched.
                if (ccv->w.word) {
                    // match the word.
                    // if (not match) continue;
                }
                TStatePtr current = ccv->tState;
                if (current == NULL) {
                    // create tSearch in next state.
                    StatePtr state = tsv.tg->stateArray[ccv->state.bitContainer];
                    if (state == NULL) {
                        // on the fly subset construction.
                        state = createState(tsv.tg,bi);
                        tsv.tg->stateArray[bi.bitContainer] = state;
                        determinize(state,tsv.tg);
                    }
                    if (state->tState == NULL) {
                        current = generateTState(state);
                        ccv->tState = current;
                    } else {
                        ccv->tState = state->tState;
                    }
                }
                tsv.current = ccv->tState;
                goto next;
            }
        }
        tsv.current->stateSkip(tsv);
    }
}