diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 01be2f8b2b..8f76c2d5cf 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -251,8 +251,10 @@ 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); diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 1ee364d4ad..94be05d0c1 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -990,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; } @@ -1021,7 +1045,6 @@ Output fstEmptyFinalOutput(Fst *fst, bool *null) { return res; } - bool fstVerify(Fst *fst) { uint32_t checkSum = fst->meta->checkSum; FstSlice *data = fst->data;