diff --git a/source/libs/index/inc/index_fst_util.h b/source/libs/index/inc/index_fst_util.h index 4af885816f..24b2508678 100644 --- a/source/libs/index/inc/index_fst_util.h +++ b/source/libs/index/inc/index_fst_util.h @@ -93,6 +93,28 @@ uint8_t *fstSliceData(FstSlice *s, int32_t *sz); #define FST_SLICE_LEN(s) (s->end - s->start + 1) +//// stack +// +//typedef (*StackFreeElemFn)(void *elem); +// +//typedef struct FstStack { +// void *first; +// void *end; +// size_t elemSize; +// size_t nElem; +// StackFreeElemFn fn; +//} FstStack; +// +// +//FstStack* fstStackCreate(size_t elemSize, stackFreeElem); +//void *fstStackPush(FstStack *s, void *elem); +//void *fstStackTop(FstStack *s); +//size_t fstStackLen(FstStack *s); +//void fstStackDestory(FstStack *); +// + + + #ifdef __cplusplus } #endif diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 418d1f2bda..4f6a5a236e 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -40,6 +40,7 @@ void unFinishedNodeDestroyElem(void* elem) { FstBuilderNodeUnfinished *b = (FstBuilderNodeUnfinished*)elem; fstBuilderNodeDestroy(b->node); free(b->last); + b->last = NULL; } void fstUnFinishedNodesDestroy(FstUnFinishedNodes *nodes) { if (nodes == NULL) { return; } @@ -62,15 +63,15 @@ FstBuilderNode *fstUnFinishedNodesPopRoot(FstUnFinishedNodes *nodes) { assert(taosArrayGetSize(nodes->stack) == 1); FstBuilderNodeUnfinished *un = taosArrayPop(nodes->stack); - //assert(un->last == NULL); + assert(un->last == NULL); return un->node; } FstBuilderNode *fstUnFinishedNodesPopFreeze(FstUnFinishedNodes *nodes, CompiledAddr addr) { FstBuilderNodeUnfinished *un = taosArrayPop(nodes->stack); fstBuilderNodeUnfinishedLastCompiled(un, addr); - free(un->last); // TODO add func FstLastTransitionFree() - un->last = NULL; + //free(un->last); // TODO add func FstLastTransitionFree() + //un->last = NULL; return un->node; } @@ -937,9 +938,10 @@ void fstLastTransitionDestroy(FstLastTransition *trn) { void fstBuilderNodeUnfinishedLastCompiled(FstBuilderNodeUnfinished *unNode, CompiledAddr addr) { FstLastTransition *trn = unNode->last; if (trn == NULL) { return; } - FstTransition t = {.inp = trn->inp, .out = trn->out, .addr = addr}; taosArrayPush(unNode->node->trans, &t); + fstLastTransitionDestroy(trn); + unNode->last = NULL; return; } diff --git a/source/libs/index/src/index_fst_util.c b/source/libs/index/src/index_fst_util.c index 532b0b8ac3..ab74a76eb9 100644 --- a/source/libs/index/src/index_fst_util.c +++ b/source/libs/index/src/index_fst_util.c @@ -174,5 +174,18 @@ int fstSliceCompare(FstSlice *a, FstSlice *b) { else { return 0; } } +//FstStack* fstStackCreate(size_t elemSize, StackFreeElem freeFn) { +// FstStack *s = calloc(1, sizeof(FstStack)); +// if (s == NULL) { return NULL; } +// s-> +// s->freeFn +// +//} +//void *fstStackPush(FstStack *s, void *elem); +//void *fstStackTop(FstStack *s); +//size_t fstStackLen(FstStack *s); +//void *fstStackGetAt(FstStack *s, size_t i); +//void fstStackDestory(FstStack *); + diff --git a/source/libs/index/test/indexTests.cpp b/source/libs/index/test/indexTests.cpp index 14ff2caf12..a575fb3878 100644 --- a/source/libs/index/test/indexTests.cpp +++ b/source/libs/index/test/indexTests.cpp @@ -63,19 +63,26 @@ //} int main(int argc, char** argv) { - std::string str("abc"); - FstSlice key = fstSliceCreate((uint8_t *)str.c_str(), str.size()); - Output val = 1; + FstBuilder *b = fstBuilderCreate(NULL, 1); + { + std::string str("abc"); + FstSlice key = fstSliceCreate((uint8_t *)str.c_str(), str.size()); + Output val = 1; + fstBuilderInsert(b, key, val); + } //std::string str1("bcd"); //FstSlice key1 = fstSliceCreate((uint8_t *)str1.c_str(), str1.size()); //Output val2 = 10; - FstBuilder *b = fstBuilderCreate(NULL, 1); - fstBuilderInsert(b, key, val); + { + std::string str("bcd"); + FstSlice key = fstSliceCreate((uint8_t *)str.c_str(), str.size()); + Output val = 1; + fstBuilderInsert(b, key, val); + } //fstBuilderInsert(b, key1, val2); fstBuilderFinish(b); fstBuilderDestroy(b); - fstSliceDestroy(&key); return 1; }