diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 37feb79ac8..8f76c2d5cf 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -251,8 +251,14 @@ void fstDestroy(Fst *fst); bool fstGet(Fst *fst, FstSlice *b, Output *out); FstNode* fstGetNode(Fst *fst, CompiledAddr); +FstNode* fstGetRoot(Fst *fst); FstType fstGetType(Fst *fst); CompiledAddr fstGetRootAddr(Fst *fst); + Output fstEmptyFinalOutput(Fst *fst, bool *null); bool fstVerify(Fst *fst); + + +//refactor this function +bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr); #endif diff --git a/source/libs/index/inc/index_fst_node.h b/source/libs/index/inc/index_fst_node.h index ddd7e1f450..0645aa1158 100644 --- a/source/libs/index/inc/index_fst_node.h +++ b/source/libs/index/inc/index_fst_node.h @@ -41,7 +41,7 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src); void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src); -bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr); +//bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr); void fstBuilderNodeDestroy(FstBuilderNode *node); diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 6c1ea8cfeb..94be05d0c1 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -733,6 +733,11 @@ bool fstNodeCompile(FstNode *node, void *w, CompiledAddr lastAddr, CompiledAddr return true; } +bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) { + return fstNodeCompile(NULL, wrt, lastAddr, startAddr, b); +} + + FstBuilder *fstBuilderCreate(void *w, FstType ty) { FstBuilder *b = malloc(sizeof(FstBuilder)); @@ -985,15 +990,39 @@ void fstDestroy(Fst *fst) { } bool fstGet(Fst *fst, FstSlice *b, Output *out) { - + FstNode *root = fstGetRoot(fst); + Output tOut = 0; + for (uint32_t i = 0; i < b->dLen; i++) { + uint8_t inp = b->data[i]; + Output res = 0; + bool null = fstNodeFindInput(root, inp, &res); + if (null) { return false; } + + FstTransition trn; + fstNodeGetTransitionAt(root, res, &trn); + tOut += trn.out; + root = fstGetNode(fst, trn.addr); + } + if (!FST_NODE_IS_FINAL(root)) { + return false; + } else { + tOut = tOut + FST_NODE_FINAL_OUTPUT(root); + } + *out = tOut; + return false; } +FstNode *fstGetRoot(Fst *fst) { + CompiledAddr root = fstGetRootAddr(fst); + return fstGetNode(fst, root); +} 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; } @@ -1016,15 +1045,14 @@ Output fstEmptyFinalOutput(Fst *fst, bool *null) { 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)) { + if (!taosCheckChecksumWhole(data->data, data->dLen)) { return false; } - + return true; } diff --git a/source/libs/index/src/index_fst_node.c b/source/libs/index/src/index_fst_node.c index 5452f9cb89..b33b8e4428 100644 --- a/source/libs/index/src/index_fst_node.c +++ b/source/libs/index/src/index_fst_node.c @@ -59,26 +59,27 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src) { src->trans = NULL; } -bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) { - size_t sz = taosArrayGetSize(b->trans); - assert(sz < 256); - if (FST_BUILDER_NODE_IS_FINAL(b) - && FST_BUILDER_NODE_TRANS_ISEMPTY(b) - && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) { - return true; - } else if (sz != 1 || b->isFinal) { - // AnyTrans->Compile(w, addr, node); - } else { - FstTransition *tran = taosArrayGet(b->trans, 0); - if (tran->addr == lastAddr && tran->out == 0) { - //OneTransNext::compile(w, lastAddr, tran->inp); - return true; - } else { - //OneTrans::Compile(w, lastAddr, *tran); - return true; - } - } - return true; -} +//bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) { + + //size_t sz = taosArrayGetSize(b->trans); + //assert(sz < 256); + //if (FST_BUILDER_NODE_IS_FINAL(b) + // && FST_BUILDER_NODE_TRANS_ISEMPTY(b) + // && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) { + // return true; + //} else if (sz != 1 || b->isFinal) { + // // AnyTrans->Compile(w, addr, node); + //} else { + // FstTransition *tran = taosArrayGet(b->trans, 0); + // if (tran->addr == lastAddr && tran->out == 0) { + // //OneTransNext::compile(w, lastAddr, tran->inp); + // return true; + // } else { + // //OneTrans::Compile(w, lastAddr, *tran); + // return true; + // } + //} + //return true; +//}