update fst core struct

This commit is contained in:
yihaoDeng 2021-11-29 14:01:25 +08:00
parent a09dcbdd85
commit 2082e86476
2 changed files with 27 additions and 2 deletions

View File

@ -251,8 +251,10 @@ void fstDestroy(Fst *fst);
bool fstGet(Fst *fst, FstSlice *b, Output *out);
FstNode* fstGetNode(Fst *fst, CompiledAddr);
FstNode* fstGetRoot(Fst *fst);
FstType fstGetType(Fst *fst);
CompiledAddr fstGetRootAddr(Fst *fst);
Output fstEmptyFinalOutput(Fst *fst, bool *null);
bool fstVerify(Fst *fst);

View File

@ -990,15 +990,39 @@ void fstDestroy(Fst *fst) {
}
bool fstGet(Fst *fst, FstSlice *b, Output *out) {
FstNode *root = fstGetRoot(fst);
Output tOut = 0;
for (uint32_t i = 0; i < b->dLen; i++) {
uint8_t inp = b->data[i];
Output res = 0;
bool null = fstNodeFindInput(root, inp, &res);
if (null) { return false; }
FstTransition trn;
fstNodeGetTransitionAt(root, res, &trn);
tOut += trn.out;
root = fstGetNode(fst, trn.addr);
}
if (!FST_NODE_IS_FINAL(root)) {
return false;
} else {
tOut = tOut + FST_NODE_FINAL_OUTPUT(root);
}
*out = tOut;
return false;
}
FstNode *fstGetRoot(Fst *fst) {
CompiledAddr root = fstGetRootAddr(fst);
return fstGetNode(fst, root);
}
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;
}
@ -1021,7 +1045,6 @@ Output fstEmptyFinalOutput(Fst *fst, bool *null) {
return res;
}
bool fstVerify(Fst *fst) {
uint32_t checkSum = fst->meta->checkSum;
FstSlice *data = fst->data;