diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 87d740ddd9..44b6162d49 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -230,10 +230,12 @@ typedef struct FstMeta { } FstMeta; typedef struct Fst { - FstMeta meta; + FstMeta *meta; void *data; // } Fst; +Fst* fstCreate(FstSlice *data); +void fstDestroy(Fst *fst); // ops typedef struct FstIndexedValue { diff --git a/source/libs/index/inc/index_fst_util.h b/source/libs/index/inc/index_fst_util.h index 5b84632418..ff0946063d 100644 --- a/source/libs/index/inc/index_fst_util.h +++ b/source/libs/index/inc/index_fst_util.h @@ -32,9 +32,9 @@ extern const CompiledAddr EMPTY_ADDRESS; extern const CompiledAddr NONE_ADDRESS; // This version number is written to every finite state transducer created by -// this crate. When a finite state transducer is read, its version number is +// this version When a finite state transducer is read, its version number is // checked against this value. -extern const uint64_t version; +extern const uint64_t VERSION; // The threshold (in number of transitions) at which an index is created for // a node's transitions. This speeds up lookup time at the expense of FST size diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index f8fc40fcb6..70633de0e8 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -919,4 +919,61 @@ void fstBuilderNodeUnfinishedAddOutputPrefix(FstBuilderNodeUnfinished *unNode, O return; } +Fst* fstCreate(FstSlice *slice) { + + char *buf = slice->data; + uint64_t skip = 0; + uint64_t len = slice->dLen; + if (len < 36) { + return NULL; + } + + uint64_t version; + taosDecodeFixedU64(buf, &version); + skip += sizeof(version); + if (version == 0 || version > VERSION) { + return NULL; + } + + uint64_t type; + taosDecodeFixedU64(buf + skip, &type); + skip += sizeof(type); + + uint32_t checkSum = 0; + len -= sizeof(checkSum); + taosDecodeFixedU32(buf + len, &checkSum); + + CompiledAddr rootAddr; + len -= sizeof(rootAddr); + taosDecodeFixedU64(buf + len, &rootAddr); + + uint64_t fstLen; + len -= sizeof(fstLen); + taosDecodeFixedU64(buf + len, &fstLen); + //TODO(validat root addr) + // + Fst *fst= (Fst *)calloc(1, sizeof(Fst)); + if (fst == NULL) { return NULL; } + + fst->meta = (FstMeta *)malloc(sizeof(FstMeta)); + if (NULL == fst->meta) { + goto FST_CREAT_FAILED; + } + + fst->meta->version = version; + fst->meta->rootAddr = rootAddr; + fst->meta->ty = type; + fst->meta->len = fstLen; + fst->meta->checkSum = checkSum; + return fst; + +FST_CREAT_FAILED: + free(fst->meta); + free(fst); + +} +void fstDestroy(Fst *fst) { + +} + diff --git a/source/libs/index/src/index_fst_util.c b/source/libs/index/src/index_fst_util.c index c4499f8e0d..94bf650acd 100644 --- a/source/libs/index/src/index_fst_util.c +++ b/source/libs/index/src/index_fst_util.c @@ -25,7 +25,7 @@ const CompiledAddr NONE_ADDRESS = 1; // This version number is written to every finite state transducer created by // this crate. When a finite state transducer is read, its version number is // checked against this value. -const uint64_t version = 3; +const uint64_t VERSION = 3; // The threshold (in number of transitions) at which an index is created for // a node's transitions. This speeds up lookup time at the expense of FST size