update fst core struct
This commit is contained in:
parent
16f089c39a
commit
500130daf7
|
@ -219,23 +219,6 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct FstMeta {
|
|
||||||
uint64_t version;
|
|
||||||
CompiledAddr rootAddr;
|
|
||||||
FstType ty;
|
|
||||||
uint64_t len;
|
|
||||||
uint32_t checkSum;
|
|
||||||
} FstMeta;
|
|
||||||
|
|
||||||
typedef struct Fst {
|
|
||||||
FstMeta *meta;
|
|
||||||
void *data; //
|
|
||||||
} Fst;
|
|
||||||
|
|
||||||
Fst* fstCreate(FstSlice *data);
|
|
||||||
void fstDestroy(Fst *fst);
|
|
||||||
// ops
|
// ops
|
||||||
|
|
||||||
typedef struct FstIndexedValue {
|
typedef struct FstIndexedValue {
|
||||||
|
@ -247,5 +230,29 @@ FstLastTransition *fstLastTransitionCreate(uint8_t inp, Output out);
|
||||||
void fstLastTransitionDestroy(FstLastTransition *trn);
|
void fstLastTransitionDestroy(FstLastTransition *trn);
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct FstMeta {
|
||||||
|
uint64_t version;
|
||||||
|
CompiledAddr rootAddr;
|
||||||
|
FstType ty;
|
||||||
|
uint64_t len;
|
||||||
|
uint32_t checkSum;
|
||||||
|
} FstMeta;
|
||||||
|
|
||||||
|
typedef struct Fst {
|
||||||
|
FstMeta *meta;
|
||||||
|
FstSlice *data; //
|
||||||
|
FstNode *root; //
|
||||||
|
} Fst;
|
||||||
|
|
||||||
|
// refactor simple function
|
||||||
|
|
||||||
|
Fst* fstCreate(FstSlice *data);
|
||||||
|
void fstDestroy(Fst *fst);
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -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,7 +977,54 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue