update fst core struct
This commit is contained in:
parent
a09dcbdd85
commit
2082e86476
|
@ -251,8 +251,10 @@ void fstDestroy(Fst *fst);
|
||||||
|
|
||||||
bool fstGet(Fst *fst, FstSlice *b, Output *out);
|
bool fstGet(Fst *fst, FstSlice *b, Output *out);
|
||||||
FstNode* fstGetNode(Fst *fst, CompiledAddr);
|
FstNode* fstGetNode(Fst *fst, CompiledAddr);
|
||||||
|
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);
|
||||||
bool fstVerify(Fst *fst);
|
bool fstVerify(Fst *fst);
|
||||||
|
|
||||||
|
|
|
@ -990,15 +990,39 @@ void fstDestroy(Fst *fst) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fstGet(Fst *fst, FstSlice *b, Output *out) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FstNode *fstGetRoot(Fst *fst) {
|
||||||
|
CompiledAddr root = fstGetRootAddr(fst);
|
||||||
|
return fstGetNode(fst, root);
|
||||||
|
}
|
||||||
FstNode* fstGetNode(Fst *fst, CompiledAddr addr) {
|
FstNode* fstGetNode(Fst *fst, CompiledAddr addr) {
|
||||||
if (fst->root != NULL) {
|
if (fst->root != NULL) {
|
||||||
return fst->root;
|
return fst->root;
|
||||||
}
|
}
|
||||||
fst->root = fstNodeCreate(fst->meta->version, addr, fst->data);
|
fst->root = fstNodeCreate(fst->meta->version, addr, fst->data);
|
||||||
|
|
||||||
return fst->root;
|
return fst->root;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1021,7 +1045,6 @@ Output fstEmptyFinalOutput(Fst *fst, bool *null) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool fstVerify(Fst *fst) {
|
bool fstVerify(Fst *fst) {
|
||||||
uint32_t checkSum = fst->meta->checkSum;
|
uint32_t checkSum = fst->meta->checkSum;
|
||||||
FstSlice *data = fst->data;
|
FstSlice *data = fst->data;
|
||||||
|
|
Loading…
Reference in New Issue