From 0aa47daf89c409b869a2539a6a98092a2cca5815 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 23 Nov 2021 20:01:19 +0800 Subject: [PATCH] update fst build struct --- source/libs/index/inc/index_fst.h | 27 ++++++++++++++++++++++++++- source/libs/index/src/index_fst.c | 17 +++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 4e2bee3f97..40e79b716e 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -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) diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 3362dbbad7..5031c071fa 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -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);