From 5441bab5dc111a15ad166336163d8ce4958dab13 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 22 Nov 2021 19:27:41 +0800 Subject: [PATCH] refactor builder struct --- source/libs/index/inc/index_fst.h | 2 ++ source/libs/index/src/index_fst.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 86346f64ff..6fbf9ded57 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -73,8 +73,10 @@ typedef struct FstBuilder { uint64_t len; // num of keys added } FstBuilder; + FstBuilder *fstBuilderCreate(void *w, FstType ty); OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup); +void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate); CompiledAddr fstBuilderCompile(FstBuilder *b, FstBuilderNode *bn); diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 6206180668..4b6fdeb079 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -307,7 +307,6 @@ FstBuilder *fstBuilderCreate(void *w, FstType ty) { } - OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup) { FstSlice *input = &bs; if (fstSliceEmpty(&b->last)) { @@ -325,6 +324,22 @@ OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup) { } return Ordered; } +void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate) { + CompiledAddr addr = NONE_ADDRESS; + while (istate + 1 < FST_UNFINISHED_NODES_LEN(b->unfinished)) { + FstBuilderNode *n = NULL; + if (addr == NONE_ADDRESS) { + n = fstUnFinishedNodesPopEmpty(b->unfinished); + } else { + n = fstUnFinishedNodesPopFreeze(b->unfinished, addr); + } + addr = fstBuilderCompile(b, n); + assert(addr != NONE_ADDRESS); + fstBuilderNodeDestroy(n); + } + fstUnFinishedNodesTopLastFreeze(b->unfinished, addr); + return; +} CompiledAddr fstBuilderCompile(FstBuilder *b, FstBuilderNode *bn) { if (FST_BUILDER_NODE_IS_FINAL(bn) && FST_BUILDER_NODE_TRANS_ISEMPTY(bn)