From 500130daf70977634f459a2779117df3dd2da2bc Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 26 Nov 2021 18:34:24 +0800 Subject: [PATCH] update fst core struct --- source/libs/index/inc/index_fst.h | 41 ++++++++++++++----------- source/libs/index/src/index_fst.c | 50 ++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 18 deletions(-) diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 44b6162d49..37feb79ac8 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -219,23 +219,6 @@ bool fstNodeFindInput(FstNode *node, uint8_t b, uint64_t *res); bool fstNodeCompile(FstNode *node, void *w, CompiledAddr lastAddr, CompiledAddr addr, FstBuilderNode *builderNode); FstSlice fstNodeAsSlice(FstNode *node); - - -typedef struct FstMeta { - uint64_t version; - CompiledAddr rootAddr; - FstType ty; - uint64_t len; - uint32_t checkSum; -} FstMeta; - -typedef struct Fst { - FstMeta *meta; - void *data; // -} Fst; - -Fst* fstCreate(FstSlice *data); -void fstDestroy(Fst *fst); // ops typedef struct FstIndexedValue { @@ -247,5 +230,29 @@ FstLastTransition *fstLastTransitionCreate(uint8_t inp, Output out); void fstLastTransitionDestroy(FstLastTransition *trn); +typedef struct FstMeta { + uint64_t version; + CompiledAddr rootAddr; + FstType ty; + uint64_t len; + uint32_t checkSum; +} FstMeta; +typedef struct Fst { + FstMeta *meta; + FstSlice *data; // + FstNode *root; // +} Fst; + +// refactor simple function + +Fst* fstCreate(FstSlice *data); +void fstDestroy(Fst *fst); + +bool fstGet(Fst *fst, FstSlice *b, Output *out); +FstNode* fstGetNode(Fst *fst, CompiledAddr); +FstType fstGetType(Fst *fst); +CompiledAddr fstGetRootAddr(Fst *fst); +Output fstEmptyFinalOutput(Fst *fst, bool *null); +bool fstVerify(Fst *fst); #endif diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index c8ff23c1c8..465b6d154a 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -15,6 +15,7 @@ #include "index_fst.h" #include "tcoding.h" +#include "tchecksum.h" static void fstPackDeltaIn(FstCountingWriter *wrt, CompiledAddr nodeAddr, CompiledAddr transAddr, uint8_t nBytes) { @@ -923,7 +924,6 @@ void fstBuilderNodeUnfinishedAddOutputPrefix(FstBuilderNodeUnfinished *unNode, O } Fst* fstCreate(FstSlice *slice) { - char *buf = slice->data; uint64_t skip = 0; uint64_t len = slice->dLen; @@ -968,6 +968,7 @@ Fst* fstCreate(FstSlice *slice) { fst->meta->ty = type; fst->meta->len = fstLen; fst->meta->checkSum = checkSum; + fst->data = slice; return fst; FST_CREAT_FAILED: @@ -976,7 +977,54 @@ FST_CREAT_FAILED: } void fstDestroy(Fst *fst) { + if (fst) { + free(fst->meta); + fstNodeDestroy(fst->root); + } + free(fst); +} +bool fstGet(Fst *fst, FstSlice *b, Output *out) { + + return false; +} + +FstNode* fstGetNode(Fst *fst, CompiledAddr addr) { + if (fst->root != NULL) { + return fst->root; + } + fst->root = fstNodeCreate(fst->meta->version, addr, fst->data); + return fst->root; + +} +FstType fstGetType(Fst *fst) { + return fst->meta->ty; +} +CompiledAddr fstGetRootAddr(Fst *fst) { + return fst->meta->rootAddr; +} + +Output fstEmptyFinalOutput(Fst *fst, bool *null) { + Output res = 0; + FstNode *node = fst->root; + if (FST_NODE_IS_FINAL(node)) { + *null = false; + res = FST_NODE_FINAL_OUTPUT(node); + } else { + *null = true; + } + return res; +} + + +bool fstVerify(Fst *fst) { + uint32_t checkSum = fst->meta->checkSum; + FstSlice *data = fst->data; + TSCKSUM initSum = 0; + if (taosCheckChecksumWhole(data->data, data->dLen)) { + return false; + } + }