update fst core struct
This commit is contained in:
parent
e10b4bc05e
commit
c0ca718eed
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue