add test case
This commit is contained in:
parent
80e5716d20
commit
aeb8067595
|
@ -28,7 +28,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum { MATCH, JUMP, SPLIT, RANGE } InstType;
|
||||
typedef enum { INS_MATCH, INS_JUMP, INS_SPLIT, INS_RANGE } InstType;
|
||||
|
||||
typedef struct MatchValue {
|
||||
#ifdef WINDOWS
|
||||
|
|
|
@ -159,14 +159,14 @@ bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *r
|
|||
if (false == sparSetGet(set, i, &ip)) continue;
|
||||
|
||||
Inst *inst = taosArrayGet(builder->dfa->insts, ip);
|
||||
if (inst->ty == JUMP || inst->ty == SPLIT) {
|
||||
if (inst->ty == INS_JUMP || inst->ty == INS_SPLIT) {
|
||||
continue;
|
||||
} else if (inst->ty == RANGE) {
|
||||
} else if (inst->ty == INS_RANGE) {
|
||||
if (taosArrayPush(tinsts, &ip) == NULL) {
|
||||
code = terrno;
|
||||
goto _exception;
|
||||
}
|
||||
} else if (inst->ty == MATCH) {
|
||||
} else if (inst->ty == INS_MATCH) {
|
||||
isMatch = true;
|
||||
if (taosArrayPush(tinsts, &ip) == NULL) {
|
||||
code = terrno;
|
||||
|
@ -234,11 +234,11 @@ void dfaAdd(FstDfa *dfa, FstSparseSet *set, uint32_t ip) {
|
|||
}
|
||||
bool succ = sparSetAdd(set, ip, NULL);
|
||||
Inst *inst = taosArrayGet(dfa->insts, ip);
|
||||
if (inst->ty == MATCH || inst->ty == RANGE) {
|
||||
if (inst->ty == INS_MATCH || inst->ty == INS_RANGE) {
|
||||
// do nothing
|
||||
} else if (inst->ty == JUMP) {
|
||||
} else if (inst->ty == INS_JUMP) {
|
||||
dfaAdd(dfa, set, inst->jv.step);
|
||||
} else if (inst->ty == SPLIT) {
|
||||
} else if (inst->ty == INS_SPLIT) {
|
||||
dfaAdd(dfa, set, inst->sv.len1);
|
||||
dfaAdd(dfa, set, inst->sv.len2);
|
||||
}
|
||||
|
@ -253,11 +253,11 @@ bool dfaRun(FstDfa *dfa, FstSparseSet *from, FstSparseSet *to, uint8_t byte) {
|
|||
if (false == sparSetGet(from, i, &ip)) continue;
|
||||
|
||||
Inst *inst = taosArrayGet(dfa->insts, ip);
|
||||
if (inst->ty == JUMP || inst->ty == SPLIT) {
|
||||
if (inst->ty == INS_JUMP || inst->ty == INS_SPLIT) {
|
||||
continue;
|
||||
} else if (inst->ty == MATCH) {
|
||||
} else if (inst->ty == INS_MATCH) {
|
||||
isMatch = true;
|
||||
} else if (inst->ty == RANGE) {
|
||||
} else if (inst->ty == INS_RANGE) {
|
||||
if (inst->rv.start <= byte && byte <= inst->rv.end) {
|
||||
dfaAdd(dfa, to, ip + 1);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "tglobal.h"
|
||||
#include "tskiplist.h"
|
||||
#include "tutil.h"
|
||||
#include "indexFstDfa.h"
|
||||
|
||||
class UtilEnv : public ::testing::Test {
|
||||
protected:
|
||||
|
@ -404,6 +405,23 @@ TEST_F(UtilComm, testCompress) {
|
|||
}
|
||||
}
|
||||
}
|
||||
TEST_F(UtilComm, testfstDfa) {
|
||||
{
|
||||
FstDfaBuilder *builder = dfaBuilderCreate(NULL);
|
||||
ASSERT_TRUE(builder != NULL);
|
||||
dfaBuilderDestroy(builder);
|
||||
}
|
||||
{
|
||||
SArray *pInst = taosArrayInit(32, sizeof(uint8_t));
|
||||
for (int32_t i = 0; i < 26; i++) {
|
||||
uint8_t v = 'a' + i;
|
||||
taosArrayPush(pInst, &v);
|
||||
}
|
||||
FstDfaBuilder *builder = dfaBuilderCreate(pInst);
|
||||
FstDfa *dfa = dfaBuilderBuild(builder);
|
||||
dfaBuilderDestroy(builder);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue