update fst build struct

This commit is contained in:
yihaoDeng 2021-11-23 20:01:19 +08:00
parent 93c102e294
commit 0aa47daf89
2 changed files with 41 additions and 3 deletions

View File

@ -95,7 +95,32 @@ typedef struct FstState {
uint8_t val;
} FstState;
FstState fstStateCreate(FstSlice* data, CompiledAddr addr);
FstState fstStateCreateFrom(FstSlice* data, CompiledAddr addr);
FstState fstStateCreate(State state);
//compile
void fstStateCompileForOneTransNext(FstState state, FstCountingWriter *w, CompiledAddr addr, uint8_t inp);
void fstStateCompileForOneTrans(FstState state, FstCountingWriter *w, CompiledAddr addr, FstTransition trn);
void fstStateCompileForAnyTrans(FstState state, FstCountingWriter *w, CompiledAddr addr, FstBuilderNode *node);
// set_comm_input
void fstStateSetCommInputForOneTransNext(FstState state, uint8_t inp);
void fstStateSetCommInputForOneTrans(FstState state, uint8_t inp);
// comm_input
uint8_t fstStateCommInputForOneTransNext(FstState state);
uint8_t fstStateCommInputForOneTrans(FstState state);
// input_len
uint64_t fstStateInputLenForOneTransNext(FstState state);
uint64_t fstStateInputLenForOneTrans(FstState state);
#define FST_STATE_ONE_TRNAS_NEXT(node) (node->state.state == OneTransNext)
#define FST_STATE_ONE_TRNAS(node) (node->state.state == OneTrans)

View File

@ -156,7 +156,7 @@ uint64_t fstUnFinishedNodesFindCommPrefixAndSetOutput(FstUnFinishedNodes *node,
}
FstState fstStateCreate(FstSlice* slice, CompiledAddr addr) {
FstState fstStateCreateFrom(FstSlice* slice, CompiledAddr addr) {
FstState fs = {.state = EmptyFinal, .val = 0};
if (addr == EMPTY_ADDRESS) {
return fs;
@ -175,13 +175,26 @@ FstState fstStateCreate(FstSlice* slice, CompiledAddr addr) {
return fs;
}
static FstState stateDict[] = {
{.state = OneTransNext, .val = 0b11000000},
{.state = OneTrans, .val = 0b10000000},
{.state = AnyTrans, .val = 0b00000000},
{.state = EmptyFinal, .val = 0b00000000}
};
FstState fstStateCreate(State state){
uint8_t idx = (uint8_t)state;
return stateDict[idx];
}
// fst node function
FstNode *fstNodeCreate(int64_t version, CompiledAddr addr, FstSlice *slice) {
FstNode *n = (FstNode *)malloc(sizeof(FstNode));
if (n == NULL) { return NULL; }
FstState st = fstStateCreate(slice, addr);
FstState st = fstStateCreateFrom(slice, addr);
if (st.state == EmptyFinal) {
n->data = fstSliceCreate(NULL, 0);