refactor builder struct

This commit is contained in:
yihaoDeng 2021-12-01 17:29:59 +08:00
parent 7ee1cf62ca
commit 716c0045f8
3 changed files with 8 additions and 8 deletions

View File

@ -82,8 +82,8 @@ typedef struct FstSlice {
FstSlice fstSliceCreate(uint8_t *data, uint64_t len); FstSlice fstSliceCreate(uint8_t *data, uint64_t len);
FstSlice fstSliceCopy(FstSlice *s, int32_t start, int32_t end); FstSlice fstSliceCopy(FstSlice *s, int32_t start, int32_t end);
FstSlice fstSliceDeepCopy(FstSlice *s, int32_t start, int32_t end); FstSlice fstSliceDeepCopy(FstSlice *s, int32_t start, int32_t end);
bool fstSliceEmpty(FstSlice *s); bool fstSliceIsEmpty(FstSlice *s);
int fstSliceCompare(FstSlice *s1, FstSlice *s2); int fstSliceCompare(FstSlice *s1, FstSlice *s2);
void fstSliceDestroy(FstSlice *s); void fstSliceDestroy(FstSlice *s);
uint8_t *fstSliceData(FstSlice *s, int32_t *sz); uint8_t *fstSliceData(FstSlice *s, int32_t *sz);

View File

@ -92,7 +92,7 @@ void fstUnFinishedNodesTopLastFreeze(FstUnFinishedNodes *nodes, CompiledAddr add
} }
void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output out) { void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output out) {
FstSlice *s = &bs; FstSlice *s = &bs;
if (fstSliceEmpty(s)) { if (fstSliceIsEmpty(s)) {
return; return;
} }
size_t sz = taosArrayGetSize(nodes->stack) - 1; size_t sz = taosArrayGetSize(nodes->stack) - 1;
@ -801,7 +801,7 @@ bool fstBuilderInsert(FstBuilder *b, FstSlice bs, Output in) {
void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) { void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) {
FstSlice *s = &bs; FstSlice *s = &bs;
if (fstSliceEmpty(s)) { if (fstSliceIsEmpty(s)) {
b->len = 1; b->len = 1;
fstUnFinishedNodesSetRootOutput(b->unfinished, in); fstUnFinishedNodesSetRootOutput(b->unfinished, in);
return; return;
@ -831,7 +831,7 @@ void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) {
OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup) { OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup) {
FstSlice *input = &bs; FstSlice *input = &bs;
if (fstSliceEmpty(&b->last)) { if (fstSliceIsEmpty(&b->last)) {
// deep copy or not // deep copy or not
b->last = fstSliceCopy(&bs, input->start, input->end); b->last = fstSliceCopy(&bs, input->start, input->end);
} else { } else {
@ -1115,7 +1115,7 @@ bool fstBoundWithDataIsEmpty(FstBoundWithData *bound) {
if (bound->type == Unbounded) { if (bound->type == Unbounded) {
return true; return true;
} else { } else {
return fstSliceEmpty(&bound->data); return fstSliceIsEmpty(&bound->data);
} }
} }

View File

@ -122,7 +122,7 @@ FstSlice fstSliceDeepCopy(FstSlice *s, int32_t start, int32_t end) {
assert(tlen <= alen); assert(tlen <= alen);
uint8_t *buf = malloc(sizeof(uint8_t) * tlen); uint8_t *buf = malloc(sizeof(uint8_t) * tlen);
memcpy(buf, data, tlen); memcpy(buf, data + start, tlen);
FstString *str = malloc(sizeof(FstString)); FstString *str = malloc(sizeof(FstString));
str->data = buf; str->data = buf;
@ -135,7 +135,7 @@ FstSlice fstSliceDeepCopy(FstSlice *s, int32_t start, int32_t end) {
ans.end = tlen - 1; ans.end = tlen - 1;
return ans; return ans;
} }
bool fstSliceEmpty(FstSlice *s) { bool fstSliceIsEmpty(FstSlice *s) {
return s->str == NULL || s->start < 0 || s->end < 0; return s->str == NULL || s->start < 0 || s->end < 0;
} }