update fst build struct
This commit is contained in:
parent
5441bab5dc
commit
260588b692
|
@ -75,6 +75,8 @@ typedef struct FstBuilder {
|
||||||
|
|
||||||
|
|
||||||
FstBuilder *fstBuilderCreate(void *w, FstType ty);
|
FstBuilder *fstBuilderCreate(void *w, FstType ty);
|
||||||
|
void fstBuilderDestroy(FstBuilder *b);
|
||||||
|
void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in);
|
||||||
OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup);
|
OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup);
|
||||||
void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate);
|
void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate);
|
||||||
CompiledAddr fstBuilderCompile(FstBuilder *b, FstBuilderNode *bn);
|
CompiledAddr fstBuilderCompile(FstBuilder *b, FstBuilderNode *bn);
|
||||||
|
|
|
@ -77,8 +77,9 @@ typedef struct FstSlice {
|
||||||
FstSlice fstSliceCopy(FstSlice *slice, int32_t start, int32_t end);
|
FstSlice fstSliceCopy(FstSlice *slice, int32_t start, int32_t end);
|
||||||
FstSlice fstSliceCreate(uint8_t *data, uint64_t dLen);
|
FstSlice fstSliceCreate(uint8_t *data, uint64_t dLen);
|
||||||
bool fstSliceEmpty(FstSlice *slice);
|
bool fstSliceEmpty(FstSlice *slice);
|
||||||
|
|
||||||
int fstSliceCompare(FstSlice *a, FstSlice *b);
|
int fstSliceCompare(FstSlice *a, FstSlice *b);
|
||||||
|
|
||||||
|
#define FST_SLICE_LEN(s) (s->end - s->start + 1)
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,7 +29,7 @@ void unFinishedNodeDestroyElem(void* elem) {
|
||||||
fstBuilderNodeDestroy(b->node);
|
fstBuilderNodeDestroy(b->node);
|
||||||
free(b->last);
|
free(b->last);
|
||||||
}
|
}
|
||||||
void fstUnFinishedNodeDestroy(FstUnFinishedNodes *nodes) {
|
void fstUnFinishedNodesDestroy(FstUnFinishedNodes *nodes) {
|
||||||
if (nodes == NULL) { return; }
|
if (nodes == NULL) { return; }
|
||||||
|
|
||||||
taosArrayDestroyEx(nodes->stack, unFinishedNodeDestroyElem);
|
taosArrayDestroyEx(nodes->stack, unFinishedNodeDestroyElem);
|
||||||
|
@ -305,7 +305,42 @@ FstBuilder *fstBuilderCreate(void *w, FstType ty) {
|
||||||
b->len = 0;
|
b->len = 0;
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
void fstBuilderDestroy(FstBuilder *b) {
|
||||||
|
if (b == NULL) { return; }
|
||||||
|
|
||||||
|
fstCountingWriterDestroy(b->wrt);
|
||||||
|
fstUnFinishedNodesDestroy(b->unfinished);
|
||||||
|
fstRegistryDestroy(b->registry);
|
||||||
|
free(b);
|
||||||
|
}
|
||||||
|
void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) {
|
||||||
|
FstSlice *s = &bs;
|
||||||
|
if (fstSliceEmpty(s)) {
|
||||||
|
b->len = 1;
|
||||||
|
fstUnFinishedNodesSetRootOutput(b->unfinished, in);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Output out;
|
||||||
|
uint64_t prefixLen;
|
||||||
|
if (in != 0) { //if let Some(in) = in
|
||||||
|
prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out);
|
||||||
|
} else {
|
||||||
|
prefixLen = fstUnFinishedNodesFindCommPrefix(b->unfinished, bs);
|
||||||
|
out = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefixLen == FST_SLICE_LEN(s)) {
|
||||||
|
assert(out != 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
b->len += 1;
|
||||||
|
fstBuilderCompileFrom(b, prefixLen);
|
||||||
|
|
||||||
|
FstSlice sub = fstSliceCopy(s, prefixLen, s->end);
|
||||||
|
fstUnFinishedNodesAddSuffix(b->unfinished, sub, out);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup) {
|
OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup) {
|
||||||
FstSlice *input = &bs;
|
FstSlice *input = &bs;
|
||||||
|
|
Loading…
Reference in New Issue