diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index b26bd227f828969db17b6731b5ffbf1d7b06ff32..a1d4962e8be815847ca1a25689588dcb157c318f 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -26,10 +26,24 @@ extern "C" { #include "index_fst_counting_writer.h" #include "index_fst_automation.h" +#define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a) +typedef struct Fst Fst; typedef struct FstNode FstNode; -#define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a) +typedef enum { Included, Excluded, Unbounded} FstBound; + +typedef struct FstBoundWithData { + FstSlice data; + FstBound type; +} FstBoundWithData; + +typedef struct FstStreamBuilder { + Fst *fst; + AutomationCtx *aut; + FstBoundWithData *min; + FstBoundWithData *max; +} FstStreamBuilder, FstStreamWithStateBuilder; typedef struct FstRange { uint64_t start; @@ -39,16 +53,9 @@ typedef struct FstRange { typedef enum {GE, GT, LE, LT} RangeType; typedef enum { OneTransNext, OneTrans, AnyTrans, EmptyFinal} State; - typedef enum {Ordered, OutOfOrdered, DuplicateKey} OrderType; -typedef enum { Included, Excluded, Unbounded} FstBound; -typedef struct FstBoundWithData { - FstSlice data; - FstBound type; -} FstBoundWithData; - FstBoundWithData* fstBoundStateCreate(FstBound type, FstSlice *data); bool fstBoundWithDataExceededBy(FstBoundWithData *bound, FstSlice *slice); bool fstBoundWithDataIsEmpty(FstBoundWithData *bound); @@ -60,8 +67,6 @@ typedef struct FstOutput { Output out; } FstOutput; - - /* * * UnFinished node and helper function @@ -275,6 +280,8 @@ FstNode* fstGetRoot(Fst *fst); FstType fstGetType(Fst *fst); CompiledAddr fstGetRootAddr(Fst *fst); Output fstEmptyFinalOutput(Fst *fst, bool *null); +FstStreamBuilder *fstSearch(Fst *fst, AutomationCtx *ctx); +FstStreamWithStateBuilder *fstSearchWithState(Fst *fst, AutomationCtx *ctx); bool fstVerify(Fst *fst); @@ -298,7 +305,7 @@ typedef struct StreamWithState { FstOutput emptyOutput; SArray *stack; // FstBoundWithData *endAt; -} StreamWithState ; +} StreamWithState; typedef struct StreamWithStateResult { FstSlice data; @@ -314,14 +321,8 @@ typedef void* (*StreamCallback)(void *); StreamWithState *streamWithStateCreate(Fst *fst, AutomationCtx *automation, FstBoundWithData *min, FstBoundWithData *max) ; void streamWithStateDestroy(StreamWithState *sws); bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min); -StreamWithStateResult* streamWithStateNextWith(StreamWithState *sws, StreamCallback callback); -typedef struct FstStreamBuilder { - Fst *fst; - AutomationCtx *aut; - FstBoundWithData *min; - FstBoundWithData *max; -} FstStreamBuilder; +StreamWithStateResult* streamWithStateNextWith(StreamWithState *sws, StreamCallback callback); FstStreamBuilder *fstStreamBuilderCreate(Fst *fst, AutomationCtx *aut); // set up bound range diff --git a/source/libs/index/inc/index_fst_automation.h b/source/libs/index/inc/index_fst_automation.h index 4a29f2e3a6df82235afa343f9745bac8e95e4883..6deeb1878a4d2af53dc2b7e076a04264c9556b18 100644 --- a/source/libs/index/inc/index_fst_automation.h +++ b/source/libs/index/inc/index_fst_automation.h @@ -50,7 +50,7 @@ typedef struct AutomationFunc { } AutomationFunc; AutomationCtx *automCtxCreate(void *data, AutomationType type); -void autoCtxDestroy(AutomationCtx *ctx); +void automCtxDestroy(AutomationCtx *ctx); extern AutomationFunc automFuncs[]; #ifdef __cplusplus diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 18e617f6aea951161d8a6edab7d32024645277c0..07f1e343bd8014607939db357aab756c4c7b22ef 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -1090,6 +1090,12 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) { return true; } +FstStreamBuilder *fstSearch(Fst *fst, AutomationCtx *ctx) { + return fstStreamBuilderCreate(fst, ctx); +} +FstStreamWithStateBuilder *fstSearchWithState(Fst *fst, AutomationCtx *ctx) { + return fstStreamBuilderCreate(fst, ctx); +} FstNode *fstGetRoot(Fst *fst) { if (fst->root != NULL) { @@ -1440,3 +1446,5 @@ FstStreamBuilder *fstStreamBuilderRange(FstStreamBuilder *b, FstSlice *val, Rang + + diff --git a/source/libs/index/src/index_fst_automation.c b/source/libs/index/src/index_fst_automation.c index 748c55c29d4b76a71dd1495de18f6b35bd834e3a..392d8e6e8d6bb0c86faab142fc8bddc294c65d9d 100644 --- a/source/libs/index/src/index_fst_automation.c +++ b/source/libs/index/src/index_fst_automation.c @@ -92,6 +92,6 @@ AutomationCtx* automCtxCreate(void *data, AutomationType type) { } return ctx; } -void autoCtxDestroy(AutomationCtx *ctx) { +void automCtxDestroy(AutomationCtx *ctx) { free(ctx); }