提交 06fe7f6a 编写于 作者: dengyihao's avatar dengyihao

update test case

上级 f52038db
...@@ -51,7 +51,7 @@ FstDfa *dfaBuilderBuild(FstDfaBuilder *builder); ...@@ -51,7 +51,7 @@ FstDfa *dfaBuilderBuild(FstDfaBuilder *builder);
bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet *next, uint32_t state, uint8_t bytes, bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet *next, uint32_t state, uint8_t bytes,
uint32_t *result); uint32_t *result);
bool dfaBuilderCachedState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result); bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result);
/* /*
* dfa related func * dfa related func
......
...@@ -64,7 +64,7 @@ void dfaBuilderDestroy(FstDfaBuilder *builder) { ...@@ -64,7 +64,7 @@ void dfaBuilderDestroy(FstDfaBuilder *builder) {
taosMemoryFree(builder); taosMemoryFree(builder);
} }
FstDfa *dfaBuilder(FstDfaBuilder *builder) { FstDfa *dfaBuilderBuild(FstDfaBuilder *builder) {
uint32_t sz = taosArrayGetSize(builder->dfa->insts); uint32_t sz = taosArrayGetSize(builder->dfa->insts);
FstSparseSet *cur = sparSetCreate(sz); FstSparseSet *cur = sparSetCreate(sz);
FstSparseSet *nxt = sparSetCreate(sz); FstSparseSet *nxt = sparSetCreate(sz);
...@@ -73,7 +73,7 @@ FstDfa *dfaBuilder(FstDfaBuilder *builder) { ...@@ -73,7 +73,7 @@ FstDfa *dfaBuilder(FstDfaBuilder *builder) {
SArray *states = taosArrayInit(0, sizeof(uint32_t)); SArray *states = taosArrayInit(0, sizeof(uint32_t));
uint32_t result; uint32_t result;
if (dfaBuilderCachedState(builder, cur, &result)) { if (dfaBuilderCacheState(builder, cur, &result)) {
taosArrayPush(states, &result); taosArrayPush(states, &result);
} }
SHashObj *seen = taosHashInit(12, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); SHashObj *seen = taosHashInit(12, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
...@@ -98,8 +98,6 @@ FstDfa *dfaBuilder(FstDfaBuilder *builder) { ...@@ -98,8 +98,6 @@ FstDfa *dfaBuilder(FstDfaBuilder *builder) {
return builder->dfa; return builder->dfa;
} }
FstDfa *dfaBuilderBuild(FstDfaBuilder *builer) { return NULL; }
bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet *next, uint32_t state, uint8_t byte, bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet *next, uint32_t state, uint8_t byte,
uint32_t *result) { uint32_t *result) {
sparSetClear(cur); sparSetClear(cur);
...@@ -114,7 +112,7 @@ bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet ...@@ -114,7 +112,7 @@ bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet
t = taosArrayGet(builder->dfa->states, state); t = taosArrayGet(builder->dfa->states, state);
uint32_t nxtState; uint32_t nxtState;
if (dfaBuilderCachedState(builder, next, &nxtState)) { if (dfaBuilderCacheState(builder, next, &nxtState)) {
t->next[byte] = nxtState; t->next[byte] = nxtState;
*result = nxtState; *result = nxtState;
return true; return true;
...@@ -122,7 +120,7 @@ bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet ...@@ -122,7 +120,7 @@ bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet
return false; return false;
} }
bool dfaBuilderCachedState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result) { bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result) {
SArray *tinsts = taosArrayInit(4, sizeof(uint32_t)); SArray *tinsts = taosArrayInit(4, sizeof(uint32_t));
bool isMatch = false; bool isMatch = false;
...@@ -190,7 +188,7 @@ void dfaAdd(FstDfa *dfa, FstSparseSet *set, uint32_t ip) { ...@@ -190,7 +188,7 @@ void dfaAdd(FstDfa *dfa, FstSparseSet *set, uint32_t ip) {
return; return;
} }
bool succ = sparSetAdd(set, ip, NULL); bool succ = sparSetAdd(set, ip, NULL);
assert(succ == true); // assert(succ == true);
Inst *inst = taosArrayGet(dfa->insts, ip); Inst *inst = taosArrayGet(dfa->insts, ip);
if (inst->ty == MATCH || inst->ty == RANGE) { if (inst->ty == MATCH || inst->ty == RANGE) {
// do nothing // do nothing
......
...@@ -29,8 +29,11 @@ FstRegex *regexCreate(const char *str) { ...@@ -29,8 +29,11 @@ FstRegex *regexCreate(const char *str) {
regex->orig = orig; regex->orig = orig;
// construct insts based on str // construct insts based on str
SArray *insts = NULL; SArray *insts = taosArrayInit(256, sizeof(uint8_t));
for (int i = 0; i < strlen(str); i++) {
uint8_t v = str[i];
taosArrayPush(insts, &v);
}
FstDfaBuilder *builder = dfaBuilderCreate(insts); FstDfaBuilder *builder = dfaBuilderCreate(insts);
regex->dfa = dfaBuilderBuild(builder); regex->dfa = dfaBuilderBuild(builder);
return regex; return regex;
......
...@@ -15,6 +15,11 @@ ...@@ -15,6 +15,11 @@
#include "indexFstSparse.h" #include "indexFstSparse.h"
static void sparSetUtil(int32_t *buf, int32_t cap) {
for (int32_t i = 0; i < cap; i++) {
buf[i] = -1;
}
}
FstSparseSet *sparSetCreate(int32_t sz) { FstSparseSet *sparSetCreate(int32_t sz) {
FstSparseSet *ss = taosMemoryCalloc(1, sizeof(FstSparseSet)); FstSparseSet *ss = taosMemoryCalloc(1, sizeof(FstSparseSet));
if (ss == NULL) { if (ss == NULL) {
...@@ -22,9 +27,10 @@ FstSparseSet *sparSetCreate(int32_t sz) { ...@@ -22,9 +27,10 @@ FstSparseSet *sparSetCreate(int32_t sz) {
} }
ss->dense = (int32_t *)taosMemoryMalloc(sz * sizeof(int32_t)); ss->dense = (int32_t *)taosMemoryMalloc(sz * sizeof(int32_t));
memset(ss->dense, -1, sz * sizeof(int32_t));
ss->sparse = (int32_t *)taosMemoryMalloc(sz * sizeof(int32_t)); ss->sparse = (int32_t *)taosMemoryMalloc(sz * sizeof(int32_t));
memset(ss->sparse, -1, sz * sizeof(int32_t)); sparSetUtil(ss->dense, sz);
sparSetUtil(ss->sparse, sz);
ss->cap = sz; ss->cap = sz;
ss->size = 0; ss->size = 0;
...@@ -84,7 +90,7 @@ void sparSetClear(FstSparseSet *ss) { ...@@ -84,7 +90,7 @@ void sparSetClear(FstSparseSet *ss) {
if (ss == NULL) { if (ss == NULL) {
return; return;
} }
memset(ss->dense, -1, ss->cap * sizeof(int32_t)); sparSetUtil(ss->dense, ss->cap);
memset(ss->sparse, -1, ss->cap * sizeof(int32_t)); sparSetUtil(ss->sparse, ss->cap);
ss->size = 0; ss->size = 0;
} }
...@@ -66,7 +66,10 @@ TEST_F(FstUtilEnv, test4) { ...@@ -66,7 +66,10 @@ TEST_F(FstUtilEnv, test4) {
// test FstRegex // test FstRegex
TEST_F(FstRegexEnv, test1) {} TEST_F(FstRegexEnv, test1) {
//
EXPECT_EQ(regex != NULL, true);
}
TEST_F(FstRegexEnv, test2) {} TEST_F(FstRegexEnv, test2) {}
TEST_F(FstRegexEnv, test3) {} TEST_F(FstRegexEnv, test3) {}
TEST_F(FstRegexEnv, test4) {} TEST_F(FstRegexEnv, test4) {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册