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

update test case

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