提交 f07045c1 编写于 作者: dengyihao's avatar dengyihao

update fst search frame

上级 a9a06841
...@@ -26,10 +26,24 @@ extern "C" { ...@@ -26,10 +26,24 @@ extern "C" {
#include "index_fst_counting_writer.h" #include "index_fst_counting_writer.h"
#include "index_fst_automation.h" #include "index_fst_automation.h"
#define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a)
typedef struct Fst Fst;
typedef struct FstNode FstNode; 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 { typedef struct FstRange {
uint64_t start; uint64_t start;
...@@ -39,16 +53,9 @@ typedef struct FstRange { ...@@ -39,16 +53,9 @@ typedef struct FstRange {
typedef enum {GE, GT, LE, LT} RangeType; typedef enum {GE, GT, LE, LT} RangeType;
typedef enum { OneTransNext, OneTrans, AnyTrans, EmptyFinal} State; typedef enum { OneTransNext, OneTrans, AnyTrans, EmptyFinal} State;
typedef enum {Ordered, OutOfOrdered, DuplicateKey} OrderType; 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); FstBoundWithData* fstBoundStateCreate(FstBound type, FstSlice *data);
bool fstBoundWithDataExceededBy(FstBoundWithData *bound, FstSlice *slice); bool fstBoundWithDataExceededBy(FstBoundWithData *bound, FstSlice *slice);
bool fstBoundWithDataIsEmpty(FstBoundWithData *bound); bool fstBoundWithDataIsEmpty(FstBoundWithData *bound);
...@@ -60,8 +67,6 @@ typedef struct FstOutput { ...@@ -60,8 +67,6 @@ typedef struct FstOutput {
Output out; Output out;
} FstOutput; } FstOutput;
/* /*
* *
* UnFinished node and helper function * UnFinished node and helper function
...@@ -275,6 +280,8 @@ FstNode* fstGetRoot(Fst *fst); ...@@ -275,6 +280,8 @@ FstNode* fstGetRoot(Fst *fst);
FstType fstGetType(Fst *fst); FstType fstGetType(Fst *fst);
CompiledAddr fstGetRootAddr(Fst *fst); CompiledAddr fstGetRootAddr(Fst *fst);
Output fstEmptyFinalOutput(Fst *fst, bool *null); Output fstEmptyFinalOutput(Fst *fst, bool *null);
FstStreamBuilder *fstSearch(Fst *fst, AutomationCtx *ctx);
FstStreamWithStateBuilder *fstSearchWithState(Fst *fst, AutomationCtx *ctx);
bool fstVerify(Fst *fst); bool fstVerify(Fst *fst);
...@@ -298,7 +305,7 @@ typedef struct StreamWithState { ...@@ -298,7 +305,7 @@ typedef struct StreamWithState {
FstOutput emptyOutput; FstOutput emptyOutput;
SArray *stack; // <StreamState> SArray *stack; // <StreamState>
FstBoundWithData *endAt; FstBoundWithData *endAt;
} StreamWithState ; } StreamWithState;
typedef struct StreamWithStateResult { typedef struct StreamWithStateResult {
FstSlice data; FstSlice data;
...@@ -314,14 +321,8 @@ typedef void* (*StreamCallback)(void *); ...@@ -314,14 +321,8 @@ typedef void* (*StreamCallback)(void *);
StreamWithState *streamWithStateCreate(Fst *fst, AutomationCtx *automation, FstBoundWithData *min, FstBoundWithData *max) ; StreamWithState *streamWithStateCreate(Fst *fst, AutomationCtx *automation, FstBoundWithData *min, FstBoundWithData *max) ;
void streamWithStateDestroy(StreamWithState *sws); void streamWithStateDestroy(StreamWithState *sws);
bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min); bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min);
StreamWithStateResult* streamWithStateNextWith(StreamWithState *sws, StreamCallback callback);
typedef struct FstStreamBuilder { StreamWithStateResult* streamWithStateNextWith(StreamWithState *sws, StreamCallback callback);
Fst *fst;
AutomationCtx *aut;
FstBoundWithData *min;
FstBoundWithData *max;
} FstStreamBuilder;
FstStreamBuilder *fstStreamBuilderCreate(Fst *fst, AutomationCtx *aut); FstStreamBuilder *fstStreamBuilderCreate(Fst *fst, AutomationCtx *aut);
// set up bound range // set up bound range
......
...@@ -50,7 +50,7 @@ typedef struct AutomationFunc { ...@@ -50,7 +50,7 @@ typedef struct AutomationFunc {
} AutomationFunc; } AutomationFunc;
AutomationCtx *automCtxCreate(void *data, AutomationType type); AutomationCtx *automCtxCreate(void *data, AutomationType type);
void autoCtxDestroy(AutomationCtx *ctx); void automCtxDestroy(AutomationCtx *ctx);
extern AutomationFunc automFuncs[]; extern AutomationFunc automFuncs[];
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -1090,6 +1090,12 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) { ...@@ -1090,6 +1090,12 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) {
return true; 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) { FstNode *fstGetRoot(Fst *fst) {
if (fst->root != NULL) { if (fst->root != NULL) {
...@@ -1440,3 +1446,5 @@ FstStreamBuilder *fstStreamBuilderRange(FstStreamBuilder *b, FstSlice *val, Rang ...@@ -1440,3 +1446,5 @@ FstStreamBuilder *fstStreamBuilderRange(FstStreamBuilder *b, FstSlice *val, Rang
...@@ -92,6 +92,6 @@ AutomationCtx* automCtxCreate(void *data, AutomationType type) { ...@@ -92,6 +92,6 @@ AutomationCtx* automCtxCreate(void *data, AutomationType type) {
} }
return ctx; return ctx;
} }
void autoCtxDestroy(AutomationCtx *ctx) { void automCtxDestroy(AutomationCtx *ctx) {
free(ctx); free(ctx);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册