From f07045c1d8dbc29712f791153d5f72ba391a2b18 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 11 Dec 2021 17:28:58 +0800 Subject: [PATCH] update fst search frame --- source/libs/index/inc/index_fst.h | 37 ++++++++++---------- source/libs/index/inc/index_fst_automation.h | 2 +- source/libs/index/src/index_fst.c | 8 +++++ source/libs/index/src/index_fst_automation.c | 2 +- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index b26bd227f8..a1d4962e8b 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 4a29f2e3a6..6deeb1878a 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 18e617f6ae..07f1e343bd 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 748c55c29d..392d8e6e8d 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); } -- GitLab