未验证 提交 71469389 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #10370 from taosdata/feature/revertIndexImpl

add more UT
...@@ -235,6 +235,7 @@ void fstStateCompileForOneTrans(FstCountingWriter* w, CompiledAddr addr, FstTran ...@@ -235,6 +235,7 @@ void fstStateCompileForOneTrans(FstCountingWriter* w, CompiledAddr addr, FstTran
FstState st = fstStateCreate(OneTrans); FstState st = fstStateCreate(OneTrans);
fstStateSetCommInput(&st, trn->inp); fstStateSetCommInput(&st, trn->inp);
bool null = false; bool null = false;
uint8_t inp = fstStateCommInput(&st, &null); uint8_t inp = fstStateCommInput(&st, &null);
if (null == true) { if (null == true) {
...@@ -936,6 +937,7 @@ FstLastTransition* fstLastTransitionCreate(uint8_t inp, Output out) { ...@@ -936,6 +937,7 @@ FstLastTransition* fstLastTransitionCreate(uint8_t inp, Output out) {
} }
void fstLastTransitionDestroy(FstLastTransition* trn) { free(trn); } void fstLastTransitionDestroy(FstLastTransition* trn) { free(trn); }
void fstBuilderNodeUnfinishedLastCompiled(FstBuilderNodeUnfinished* unNode, CompiledAddr addr) { void fstBuilderNodeUnfinishedLastCompiled(FstBuilderNodeUnfinished* unNode, CompiledAddr addr) {
FstLastTransition* trn = unNode->last; FstLastTransition* trn = unNode->last;
if (trn == NULL) { if (trn == NULL) {
......
...@@ -16,24 +16,24 @@ ...@@ -16,24 +16,24 @@
#include "index_fst_automation.h" #include "index_fst_automation.h"
StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueType ty, void* val) { StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueType ty, void* val) {
StartWithStateValue* nsv = calloc(1, sizeof(StartWithStateValue)); StartWithStateValue* sv = calloc(1, sizeof(StartWithStateValue));
if (nsv == NULL) { if (sv == NULL) {
return NULL; return NULL;
} }
nsv->kind = kind; sv->kind = kind;
nsv->type = ty; sv->type = ty;
if (ty == FST_INT) { if (ty == FST_INT) {
nsv->val = *(int*)val; sv->val = *(int*)val;
} else if (ty == FST_CHAR) { } else if (ty == FST_CHAR) {
size_t len = strlen((char*)val); size_t len = strlen((char*)val);
nsv->ptr = (char*)calloc(1, len + 1); sv->ptr = (char*)calloc(1, len + 1);
memcpy(nsv->ptr, val, len); memcpy(sv->ptr, val, len);
} else if (ty == FST_ARRAY) { } else if (ty == FST_ARRAY) {
// TODO, // TODO,
// nsv->arr = taosArrayFromList() // nsv->arr = taosArrayFromList()
} }
return nsv; return sv;
} }
void startWithStateValueDestroy(void* val) { void startWithStateValueDestroy(void* val) {
StartWithStateValue* sv = (StartWithStateValue*)val; StartWithStateValue* sv = (StartWithStateValue*)val;
...@@ -146,11 +146,9 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) { ...@@ -146,11 +146,9 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) {
if (atype == AUTOMATION_ALWAYS) { if (atype == AUTOMATION_ALWAYS) {
int val = 0; int val = 0;
sv = startWithStateValueCreate(Running, FST_INT, &val); sv = startWithStateValueCreate(Running, FST_INT, &val);
ctx->stdata = (void*)sv;
} else if (atype == AUTOMATION_PREFIX) { } else if (atype == AUTOMATION_PREFIX) {
int val = 0; int val = 0;
sv = startWithStateValueCreate(Running, FST_INT, &val); sv = startWithStateValueCreate(Running, FST_INT, &val);
ctx->stdata = (void*)sv;
} else if (atype == AUTMMATION_MATCH) { } else if (atype == AUTMMATION_MATCH) {
} else { } else {
// add more search type // add more search type
...@@ -160,9 +158,8 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) { ...@@ -160,9 +158,8 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) {
if (data != NULL) { if (data != NULL) {
char* src = (char*)data; char* src = (char*)data;
size_t len = strlen(src); size_t len = strlen(src);
dst = (char*)malloc(len * sizeof(char) + 1); dst = (char*)calloc(1, len * sizeof(char) + 1);
memcpy(dst, src, len); memcpy(dst, src, len);
dst[len] = 0;
} }
ctx->data = dst; ctx->data = dst;
......
...@@ -99,6 +99,7 @@ class FstReadMemory { ...@@ -99,6 +99,7 @@ class FstReadMemory {
fstSliceDestroy(&skey); fstSliceDestroy(&skey);
return ok; return ok;
} }
bool GetWithTimeCostUs(const std::string& key, uint64_t* val, uint64_t* elapse) { bool GetWithTimeCostUs(const std::string& key, uint64_t* val, uint64_t* elapse) {
int64_t s = taosGetTimestampUs(); int64_t s = taosGetTimestampUs();
bool ok = this->Get(key, val); bool ok = this->Get(key, val);
...@@ -120,8 +121,6 @@ class FstReadMemory { ...@@ -120,8 +121,6 @@ class FstReadMemory {
printf("key: %s, val: %" PRIu64 "\n", key.c_str(), (uint64_t)(rt->out.out)); printf("key: %s, val: %" PRIu64 "\n", key.c_str(), (uint64_t)(rt->out.out));
swsResultDestroy(rt); swsResultDestroy(rt);
} }
for (size_t i = 0; i < result.size(); i++) {
}
std::cout << std::endl; std::cout << std::endl;
return true; return true;
} }
...@@ -137,7 +136,7 @@ class FstReadMemory { ...@@ -137,7 +136,7 @@ class FstReadMemory {
fstDestroy(_fst); fstDestroy(_fst);
fstSliceDestroy(&_s); fstSliceDestroy(&_s);
writerCtxDestroy(_wc, false); writerCtxDestroy(_wc, false);
tfCleanup(); // tfCleanup();
} }
private: private:
...@@ -196,6 +195,10 @@ class TFst { ...@@ -196,6 +195,10 @@ class TFst {
} }
return fr->Get(k, v); return fr->Get(k, v);
} }
bool Search(AutomationCtx* ctx, std::vector<uint64_t>& result) {
// add more
return fr->Search(ctx, result);
}
private: private:
FstWriter* fw; FstWriter* fw;
...@@ -229,5 +232,9 @@ TEST_F(FstEnv, writeNormal) { ...@@ -229,5 +232,9 @@ TEST_F(FstEnv, writeNormal) {
assert(fst->Get("a", &val) == false); assert(fst->Get("a", &val) == false);
assert(fst->Get("aa", &val) == true); assert(fst->Get("aa", &val) == true);
assert(val == 0); assert(val == 0);
std::vector<uint64_t> rlt;
AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS);
assert(fst->Search(ctx, rlt) == true);
} }
TEST_F(FstEnv, writeExcpet) {} TEST_F(FstEnv, WriteMillonrRecord) {}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册