update fst write

This commit is contained in:
yihaoDeng 2021-12-02 10:32:58 +08:00
parent 716c0045f8
commit e3ccb28c09
3 changed files with 20 additions and 13 deletions

View File

@ -268,9 +268,6 @@ 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);
@ -304,6 +301,7 @@ typedef struct StreamWithStateResult {
} StreamWithStateResult;
StreamWithStateResult *swsResultCreate(FstSlice *data, FstOutput fOut, void *state);
void swsResultDestroy(StreamWithStateResult *result);
typedef void* (*StreamCallback)(void *);
StreamWithState *streamWithStateCreate(Fst *fst, Automation *automation, FstBoundWithData *min, FstBoundWithData *max) ;

View File

@ -1301,12 +1301,16 @@ StreamWithStateResult *streamWithStateNextWith(StreamWithState *sws, StreamCallb
if (fstBoundWithDataExceededBy(sws->endAt, &slice)) {
taosArrayDestroyEx(sws->stack, streamStateDestroy);
sws->stack = (SArray *)taosArrayInit(256, sizeof(StreamState));
fstSliceDestroy(&slice);
return NULL;
}
if (FST_NODE_IS_FINAL(nextNode) && isMatch) {
FstOutput fOutput = {.null = false, .out = out + FST_NODE_FINAL_OUTPUT(nextNode)};
return swsResultCreate(&slice, fOutput , tState);
StreamWithStateResult *result = swsResultCreate(&slice, fOutput , tState);
fstSliceDestroy(&slice);
return result;
}
fstSliceDestroy(&slice);
}
return NULL;
@ -1321,8 +1325,14 @@ StreamWithStateResult *swsResultCreate(FstSlice *data, FstOutput fOut, void *sta
result->state = state;
return result;
}
void swsResultDestroy(StreamWithStateResult *result) {
if (NULL == result) { return; }
fstSliceDestroy(&result->data);
free(result);
}
void streamStateDestroy(void *s) {
if (NULL == s) { return; }
StreamState *ss = (StreamState *)s;

View File

@ -107,7 +107,6 @@ FstSlice fstSliceCreate(uint8_t *data, uint64_t len) {
FstSlice fstSliceCopy(FstSlice *s, int32_t start, int32_t end) {
FstString *str = s->str;
str->ref++;
int32_t alen;
//uint8_t *buf = fstSliceData(s, &alen);
//start = buf + start - (buf - s->start);
//end = buf + end - (buf - s->start);
@ -117,9 +116,10 @@ FstSlice fstSliceCopy(FstSlice *s, int32_t start, int32_t end) {
}
FstSlice fstSliceDeepCopy(FstSlice *s, int32_t start, int32_t end) {
int32_t alen, tlen = end - start + 1;
uint8_t *data = fstSliceData(s, &alen);
assert(tlen <= alen);
int32_t tlen = end - start + 1;
int32_t slen;
uint8_t *data = fstSliceData(s, &slen);
assert(tlen <= slen);
uint8_t *buf = malloc(sizeof(uint8_t) * tlen);
memcpy(buf, data + start, tlen);
@ -136,7 +136,7 @@ FstSlice fstSliceDeepCopy(FstSlice *s, int32_t start, int32_t end) {
return ans;
}
bool fstSliceIsEmpty(FstSlice *s) {
return s->str == NULL || s->start < 0 || s->end < 0;
return s->str == NULL || s->str->len == 0 || s->start < 0 || s->end < 0;
}
uint8_t *fstSliceData(FstSlice *s, int32_t *size) {
@ -161,7 +161,6 @@ int fstSliceCompare(FstSlice *a, FstSlice *b) {
uint8_t *aBuf = fstSliceData(a, &alen);
uint8_t *bBuf = fstSliceData(b, &blen);
uint32_t i, j;
for (i = 0, j = 0; i < alen && j < blen; i++, j++) {
uint8_t x = aBuf[i];