update fst core struct

This commit is contained in:
yihaoDeng 2021-11-26 18:34:24 +08:00
parent 16f089c39a
commit 500130daf7
2 changed files with 73 additions and 18 deletions

View File

@ -219,6 +219,15 @@ bool fstNodeFindInput(FstNode *node, uint8_t b, uint64_t *res);
bool fstNodeCompile(FstNode *node, void *w, CompiledAddr lastAddr, CompiledAddr addr, FstBuilderNode *builderNode); bool fstNodeCompile(FstNode *node, void *w, CompiledAddr lastAddr, CompiledAddr addr, FstBuilderNode *builderNode);
FstSlice fstNodeAsSlice(FstNode *node); FstSlice fstNodeAsSlice(FstNode *node);
// ops
typedef struct FstIndexedValue {
uint64_t index;
uint64_t value;
} FstIndexedValue;
FstLastTransition *fstLastTransitionCreate(uint8_t inp, Output out);
void fstLastTransitionDestroy(FstLastTransition *trn);
typedef struct FstMeta { typedef struct FstMeta {
@ -231,21 +240,19 @@ typedef struct FstMeta {
typedef struct Fst { typedef struct Fst {
FstMeta *meta; FstMeta *meta;
void *data; // FstSlice *data; //
FstNode *root; //
} Fst; } Fst;
// refactor simple function
Fst* fstCreate(FstSlice *data); Fst* fstCreate(FstSlice *data);
void fstDestroy(Fst *fst); void fstDestroy(Fst *fst);
// ops
typedef struct FstIndexedValue {
uint64_t index;
uint64_t value;
} FstIndexedValue;
FstLastTransition *fstLastTransitionCreate(uint8_t inp, Output out);
void fstLastTransitionDestroy(FstLastTransition *trn);
bool fstGet(Fst *fst, FstSlice *b, Output *out);
FstNode* fstGetNode(Fst *fst, CompiledAddr);
FstType fstGetType(Fst *fst);
CompiledAddr fstGetRootAddr(Fst *fst);
Output fstEmptyFinalOutput(Fst *fst, bool *null);
bool fstVerify(Fst *fst);
#endif #endif

View File

@ -15,6 +15,7 @@
#include "index_fst.h" #include "index_fst.h"
#include "tcoding.h" #include "tcoding.h"
#include "tchecksum.h"
static void fstPackDeltaIn(FstCountingWriter *wrt, CompiledAddr nodeAddr, CompiledAddr transAddr, uint8_t nBytes) { static void fstPackDeltaIn(FstCountingWriter *wrt, CompiledAddr nodeAddr, CompiledAddr transAddr, uint8_t nBytes) {
@ -923,7 +924,6 @@ void fstBuilderNodeUnfinishedAddOutputPrefix(FstBuilderNodeUnfinished *unNode, O
} }
Fst* fstCreate(FstSlice *slice) { Fst* fstCreate(FstSlice *slice) {
char *buf = slice->data; char *buf = slice->data;
uint64_t skip = 0; uint64_t skip = 0;
uint64_t len = slice->dLen; uint64_t len = slice->dLen;
@ -968,6 +968,7 @@ Fst* fstCreate(FstSlice *slice) {
fst->meta->ty = type; fst->meta->ty = type;
fst->meta->len = fstLen; fst->meta->len = fstLen;
fst->meta->checkSum = checkSum; fst->meta->checkSum = checkSum;
fst->data = slice;
return fst; return fst;
FST_CREAT_FAILED: FST_CREAT_FAILED:
@ -976,6 +977,53 @@ FST_CREAT_FAILED:
} }
void fstDestroy(Fst *fst) { void fstDestroy(Fst *fst) {
if (fst) {
free(fst->meta);
fstNodeDestroy(fst->root);
}
free(fst);
}
bool fstGet(Fst *fst, FstSlice *b, Output *out) {
return false;
}
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;
}
FstType fstGetType(Fst *fst) {
return fst->meta->ty;
}
CompiledAddr fstGetRootAddr(Fst *fst) {
return fst->meta->rootAddr;
}
Output fstEmptyFinalOutput(Fst *fst, bool *null) {
Output res = 0;
FstNode *node = fst->root;
if (FST_NODE_IS_FINAL(node)) {
*null = false;
res = FST_NODE_FINAL_OUTPUT(node);
} else {
*null = true;
}
return res;
}
bool fstVerify(Fst *fst) {
uint32_t checkSum = fst->meta->checkSum;
FstSlice *data = fst->data;
TSCKSUM initSum = 0;
if (taosCheckChecksumWhole(data->data, data->dLen)) {
return false;
}
} }