diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 7ab9358cd15a33b051f67b0b17eb599491fab42d..87d740ddd9ad86f08cae75347ba33bf15f6f020c 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -80,6 +80,9 @@ void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in); OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup); void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate); CompiledAddr fstBuilderCompile(FstBuilder *b, FstBuilderNode *bn); +void* fstBuilerIntoInner(FstBuilder *b); +void fstBuilderFinish(FstBuilder *b); + diff --git a/source/libs/index/inc/index_fst_counting_writer.h b/source/libs/index/inc/index_fst_counting_writer.h index fbb2f1cff7b643c710e0d2f551e7d2a2c05b543b..465080403482c6022900eed2e3a4fe98aecb30de 100644 --- a/source/libs/index/inc/index_fst_counting_writer.h +++ b/source/libs/index/inc/index_fst_counting_writer.h @@ -27,9 +27,11 @@ typedef struct FstCountingWriter { uint64_t fstCountingWriterWrite(FstCountingWriter *write, uint8_t *buf, uint32_t bufLen); -int FstCountingWriterFlush(FstCountingWriter *write); +int fstCountingWriterFlush(FstCountingWriter *write); +uint32_t fstCountingWriterMaskedCheckSum(FstCountingWriter *write); + FstCountingWriter *fstCountingWriterCreate(void *wtr); void fstCountingWriterDestroy(FstCountingWriter *w); diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 8b9aa22fc689adb48887cdc493c69ffb266b769b..f8fc40fcb6f6116d3ceba7d5f24ba1ab40065293 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -14,7 +14,7 @@ */ #include "index_fst.h" - +#include "tcoding.h" static void fstPackDeltaIn(FstCountingWriter *wrt, CompiledAddr nodeAddr, CompiledAddr transAddr, uint8_t nBytes) { @@ -98,7 +98,7 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output FstBuilderNodeUnfinished *un = taosArrayGet(nodes->stack, sz); assert(un->last == NULL); - + //FstLastTransition *trn = malloc(sizeof(FstLastTransition)); //trn->inp = s->data[s->start]; @@ -849,6 +849,31 @@ CompiledAddr fstBuilderCompile(FstBuilder *b, FstBuilderNode *bn) { return b->lastAddr; } +void* fstBuilderInsertInner(FstBuilder *b) { + fstBuilderCompileFrom(b, 0); + FstBuilderNode *rootNode = fstUnFinishedNodesPopRoot(b->unfinished); + CompiledAddr rootAddr = fstBuilderCompile(b, rootNode); + + uint8_t buf64[8] = {0}; + + taosEncodeFixedU64((void **)&buf64, b->len); + fstCountingWriterWrite(b->wrt, buf64, sizeof(buf64)); + + taosEncodeFixedU64((void **)&buf64, rootAddr); + fstCountingWriterWrite(b->wrt, buf64, sizeof(buf64)); + + uint8_t buf32[4] = {0}; + uint32_t sum = fstCountingWriterMaskedCheckSum(b->wrt); + taosEncodeFixedU32((void **)&buf32, sum); + fstCountingWriterWrite(b->wrt, buf32, sizeof(buf32)); + + fstCountingWriterFlush(b->wrt); + return b->wrt; + +} +void fstBuilderFinish(FstBuilder *b) { + fstBuilderInsertInner(b); +} diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index b253db986a1612fc1322e9d049bd9690a401a5d1..a0a2c380f170724984dae7bc9e12864d4ce16f24 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -37,6 +37,9 @@ uint64_t fstCountingWriterWrite(FstCountingWriter *write, uint8_t *buf, uint32_t return bufLen; } +uint32_t fstCountingWriterMaskedCheckSum(FstCountingWriter *write) { + return 0; +} int fstCountingWriterFlush(FstCountingWriter *write) { //write->wtr->flush return 1;