add test case
This commit is contained in:
parent
4bab45c039
commit
5f0fd023cb
|
@ -16,6 +16,9 @@
|
||||||
#ifndef __INDEX_FST_H__
|
#ifndef __INDEX_FST_H__
|
||||||
#define __INDEX_FST_H__
|
#define __INDEX_FST_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
#include "index_fst_util.h"
|
#include "index_fst_util.h"
|
||||||
|
@ -98,6 +101,7 @@ FstBuilder *fstBuilderCreate(void *w, FstType ty);
|
||||||
|
|
||||||
void fstBuilderDestroy(FstBuilder *b);
|
void fstBuilderDestroy(FstBuilder *b);
|
||||||
void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in);
|
void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in);
|
||||||
|
bool fstBuilderInsert(FstBuilder *b, FstSlice bs, Output in);
|
||||||
OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup);
|
OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup);
|
||||||
void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate);
|
void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate);
|
||||||
CompiledAddr fstBuilderCompile(FstBuilder *b, FstBuilderNode *bn);
|
CompiledAddr fstBuilderCompile(FstBuilder *b, FstBuilderNode *bn);
|
||||||
|
@ -324,4 +328,9 @@ FstStreamBuilder *fstStreamBuilderCreate(Fst *fst, Automation *aut);
|
||||||
|
|
||||||
FstStreamBuilder *fstStreamBuilderRange(FstStreamBuilder *b, FstSlice *val, RangeType type);
|
FstStreamBuilder *fstStreamBuilderRange(FstStreamBuilder *b, FstSlice *val, RangeType type);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
#ifndef __INDEX_FST_AUTAOMATION_H__
|
#ifndef __INDEX_FST_AUTAOMATION_H__
|
||||||
#define __INDEX_FST_AUTAOMATION_H__
|
#define __INDEX_FST_AUTAOMATION_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct AutomationCtx AutomationCtx;
|
typedef struct AutomationCtx AutomationCtx;
|
||||||
|
|
||||||
typedef struct StartWith {
|
typedef struct StartWith {
|
||||||
|
@ -42,6 +46,8 @@ typedef struct Automation {
|
||||||
void *data;
|
void *data;
|
||||||
} Automation;
|
} Automation;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
#ifndef __INDEX_FST_COMM_H__
|
#ifndef __INDEX_FST_COMM_H__
|
||||||
#define __INDEX_FST_COMM_H__
|
#define __INDEX_FST_COMM_H__
|
||||||
|
|
||||||
|
|
||||||
extern const uint8_t COMMON_INPUTS[];
|
extern const uint8_t COMMON_INPUTS[];
|
||||||
extern char const COMMON_INPUTS_INV[];
|
extern char const COMMON_INPUTS_INV[];
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
#ifndef __INDEX_FST_COUNTING_WRITER_H__
|
#ifndef __INDEX_FST_COUNTING_WRITER_H__
|
||||||
#define __INDEX_FST_COUNTING_WRITER_H__
|
#define __INDEX_FST_COUNTING_WRITER_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "tfile.h"
|
#include "tfile.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,6 +76,10 @@ uint8_t fstCountingWriterPackUint(FstCountingWriter *writer, uint64_t n);
|
||||||
#define FST_WRITER_INTER_WRITER(writer) (writer->wtr)
|
#define FST_WRITER_INTER_WRITER(writer) (writer->wtr)
|
||||||
#define FST_WRITE_CHECK_SUMMER(writer) (writer->summer)
|
#define FST_WRITE_CHECK_SUMMER(writer) (writer->summer)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
#ifndef __INDEX_FST_NODE_H__
|
#ifndef __INDEX_FST_NODE_H__
|
||||||
#define __INDEX_FST_NODE_H__
|
#define __INDEX_FST_NODE_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "index_fst_util.h"
|
#include "index_fst_util.h"
|
||||||
#include "index_fst_counting_writer.h"
|
#include "index_fst_counting_writer.h"
|
||||||
|
|
||||||
|
@ -45,4 +49,8 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src);
|
||||||
|
|
||||||
void fstBuilderNodeDestroy(FstBuilderNode *node);
|
void fstBuilderNodeDestroy(FstBuilderNode *node);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
#ifndef __FST_REGISTRY_H__
|
#ifndef __FST_REGISTRY_H__
|
||||||
#define __FST_REGISTRY_H__
|
#define __FST_REGISTRY_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "index_fst_util.h"
|
#include "index_fst_util.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
#include "index_fst_node.h"
|
#include "index_fst_node.h"
|
||||||
|
@ -59,4 +63,8 @@ void fstRegistryDestroy(FstRegistry *registry);
|
||||||
FstRegistryEntry* fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNode);
|
FstRegistryEntry* fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNode);
|
||||||
void fstRegistryEntryDestroy(FstRegistryEntry *entry);
|
void fstRegistryEntryDestroy(FstRegistryEntry *entry);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,6 +17,10 @@
|
||||||
#ifndef __INDEX_FST_UTIL_H__
|
#ifndef __INDEX_FST_UTIL_H__
|
||||||
#define __INDEX_FST_UTIL_H__
|
#define __INDEX_FST_UTIL_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
#include "index_fst_common.h"
|
#include "index_fst_common.h"
|
||||||
|
|
||||||
|
@ -89,5 +93,8 @@ uint8_t *fstSliceData(FstSlice *s, int32_t *sz);
|
||||||
|
|
||||||
#define FST_SLICE_LEN(s) (s->end - s->start + 1)
|
#define FST_SLICE_LEN(s) (s->end - s->start + 1)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -52,7 +52,7 @@ void fstUnFinishedNodesPushEmpty(FstUnFinishedNodes *nodes, bool isFinal) {
|
||||||
FstBuilderNode *node = malloc(sizeof(FstBuilderNode));
|
FstBuilderNode *node = malloc(sizeof(FstBuilderNode));
|
||||||
node->isFinal = isFinal;
|
node->isFinal = isFinal;
|
||||||
node->finalOutput = 0;
|
node->finalOutput = 0;
|
||||||
node->trans = NULL;
|
node->trans = taosArrayInit(16, sizeof(FstTransition));
|
||||||
|
|
||||||
FstBuilderNodeUnfinished un = {.node = node, .last = NULL};
|
FstBuilderNodeUnfinished un = {.node = node, .last = NULL};
|
||||||
taosArrayPush(nodes->stack, &un);
|
taosArrayPush(nodes->stack, &un);
|
||||||
|
@ -112,7 +112,7 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output
|
||||||
FstBuilderNode *n = malloc(sizeof(FstBuilderNode));
|
FstBuilderNode *n = malloc(sizeof(FstBuilderNode));
|
||||||
n->isFinal = false;
|
n->isFinal = false;
|
||||||
n->finalOutput = 0;
|
n->finalOutput = 0;
|
||||||
n->trans = NULL;
|
n->trans = taosArrayInit(16, sizeof(FstTransition));
|
||||||
|
|
||||||
//FstLastTransition *trn = malloc(sizeof(FstLastTransition));
|
//FstLastTransition *trn = malloc(sizeof(FstLastTransition));
|
||||||
//trn->inp = s->data[i];
|
//trn->inp = s->data[i];
|
||||||
|
@ -806,13 +806,13 @@ void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) {
|
||||||
fstUnFinishedNodesSetRootOutput(b->unfinished, in);
|
fstUnFinishedNodesSetRootOutput(b->unfinished, in);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Output out;
|
|
||||||
//if (in != 0) { //if let Some(in) = in
|
//if (in != 0) { //if let Some(in) = in
|
||||||
// prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out);
|
// prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out);
|
||||||
//} else {
|
//} else {
|
||||||
// prefixLen = fstUnFinishedNodesFindCommPrefix(b->unfinished, bs);
|
// prefixLen = fstUnFinishedNodesFindCommPrefix(b->unfinished, bs);
|
||||||
// out = 0;
|
// out = 0;
|
||||||
//}
|
//}
|
||||||
|
Output out;
|
||||||
uint64_t prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out);
|
uint64_t prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out);
|
||||||
|
|
||||||
if (prefixLen == FST_SLICE_LEN(s)) {
|
if (prefixLen == FST_SLICE_LEN(s)) {
|
||||||
|
@ -857,7 +857,7 @@ void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate) {
|
||||||
}
|
}
|
||||||
addr = fstBuilderCompile(b, n);
|
addr = fstBuilderCompile(b, n);
|
||||||
assert(addr != NONE_ADDRESS);
|
assert(addr != NONE_ADDRESS);
|
||||||
fstBuilderNodeDestroy(n);
|
//fstBuilderNodeDestroy(n);
|
||||||
}
|
}
|
||||||
fstUnFinishedNodesTopLastFreeze(b->unfinished, addr);
|
fstUnFinishedNodesTopLastFreeze(b->unfinished, addr);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -81,7 +81,7 @@ FstCountingWriter *fstCountingWriterCreate(void *wrt) {
|
||||||
FstCountingWriter *cw = calloc(1, sizeof(FstCountingWriter));
|
FstCountingWriter *cw = calloc(1, sizeof(FstCountingWriter));
|
||||||
if (cw == NULL) { return NULL; }
|
if (cw == NULL) { return NULL; }
|
||||||
|
|
||||||
cw->wrt = (void *)(writerCtxCreate(TMemory));
|
cw->wrt = (void *)(writerCtxCreate(TFile));
|
||||||
return cw;
|
return cw;
|
||||||
}
|
}
|
||||||
void fstCountingWriterDestroy(FstCountingWriter *cw) {
|
void fstCountingWriterDestroy(FstCountingWriter *cw) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
add_executable(indexTest "")
|
add_executable(indexTest "")
|
||||||
target_sources(indexTest
|
target_sources(indexTest
|
||||||
PRIVATE
|
PRIVATE
|
||||||
"../src/index.c"
|
|
||||||
"indexTests.cpp"
|
"indexTests.cpp"
|
||||||
)
|
)
|
||||||
target_include_directories ( indexTest
|
target_include_directories ( indexTest
|
||||||
|
|
|
@ -3,58 +3,79 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "index.h"
|
#include "index.h"
|
||||||
#include "indexInt.h"
|
#include "indexInt.h"
|
||||||
|
#include "index_fst.h"
|
||||||
|
#include "index_fst_util.h"
|
||||||
|
#include "index_fst_counting_writer.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST(IndexTest, index_create_test) {
|
//TEST(IndexTest, index_create_test) {
|
||||||
SIndexOpts *opts = indexOptsCreate();
|
// SIndexOpts *opts = indexOptsCreate();
|
||||||
SIndex *index = indexOpen(opts, "./test");
|
// SIndex *index = indexOpen(opts, "./test");
|
||||||
if (index == NULL) {
|
// if (index == NULL) {
|
||||||
std::cout << "index open failed" << std::endl;
|
// std::cout << "index open failed" << std::endl;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
// write
|
|
||||||
for (int i = 0; i < 100000; i++) {
|
|
||||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
|
||||||
std::string val = "field";
|
|
||||||
|
|
||||||
indexMultiTermAdd(terms, "tag1", strlen("tag1"), val.c_str(), val.size());
|
|
||||||
|
|
||||||
val.append(std::to_string(i));
|
|
||||||
indexMultiTermAdd(terms, "tag2", strlen("tag2"), val.c_str(), val.size());
|
|
||||||
|
|
||||||
val.insert(0, std::to_string(i));
|
|
||||||
indexMultiTermAdd(terms, "tag3", strlen("tag3"), val.c_str(), val.size());
|
|
||||||
|
|
||||||
val.append("const");
|
|
||||||
indexMultiTermAdd(terms, "tag4", strlen("tag4"), val.c_str(), val.size());
|
|
||||||
|
|
||||||
|
|
||||||
indexPut(index, terms, i);
|
|
||||||
indexMultiTermDestroy(terms);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// query
|
|
||||||
SIndexMultiTermQuery *multiQuery = indexMultiTermQueryCreate(MUST);
|
|
||||||
|
|
||||||
indexMultiTermQueryAdd(multiQuery, "tag1", strlen("tag1"), "field", strlen("field"), QUERY_PREFIX);
|
|
||||||
indexMultiTermQueryAdd(multiQuery, "tag3", strlen("tag3"), "0field0", strlen("0field0"), QUERY_TERM);
|
|
||||||
|
|
||||||
SArray *result = (SArray *)taosArrayInit(10, sizeof(int));
|
|
||||||
indexSearch(index, multiQuery, result);
|
|
||||||
|
|
||||||
std::cout << "taos'size : " << taosArrayGetSize(result) << std::endl;
|
|
||||||
for (int i = 0; i < taosArrayGetSize(result); i++) {
|
|
||||||
int *v = (int *)taosArrayGet(result, i);
|
|
||||||
std::cout << "value --->" << *v << std::endl;
|
|
||||||
}
|
|
||||||
// add more test case
|
|
||||||
indexMultiTermQueryDestroy(multiQuery);
|
|
||||||
|
|
||||||
indexOptsDestroy(opts);
|
|
||||||
indexClose(index);
|
|
||||||
//
|
//
|
||||||
|
//
|
||||||
|
// // write
|
||||||
|
// for (int i = 0; i < 100000; i++) {
|
||||||
|
// SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||||
|
// std::string val = "field";
|
||||||
|
//
|
||||||
|
// indexMultiTermAdd(terms, "tag1", strlen("tag1"), val.c_str(), val.size());
|
||||||
|
//
|
||||||
|
// val.append(std::to_string(i));
|
||||||
|
// indexMultiTermAdd(terms, "tag2", strlen("tag2"), val.c_str(), val.size());
|
||||||
|
//
|
||||||
|
// val.insert(0, std::to_string(i));
|
||||||
|
// indexMultiTermAdd(terms, "tag3", strlen("tag3"), val.c_str(), val.size());
|
||||||
|
//
|
||||||
|
// val.append("const");
|
||||||
|
// indexMultiTermAdd(terms, "tag4", strlen("tag4"), val.c_str(), val.size());
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// indexPut(index, terms, i);
|
||||||
|
// indexMultiTermDestroy(terms);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // query
|
||||||
|
// SIndexMultiTermQuery *multiQuery = indexMultiTermQueryCreate(MUST);
|
||||||
|
//
|
||||||
|
// indexMultiTermQueryAdd(multiQuery, "tag1", strlen("tag1"), "field", strlen("field"), QUERY_PREFIX);
|
||||||
|
// indexMultiTermQueryAdd(multiQuery, "tag3", strlen("tag3"), "0field0", strlen("0field0"), QUERY_TERM);
|
||||||
|
//
|
||||||
|
// SArray *result = (SArray *)taosArrayInit(10, sizeof(int));
|
||||||
|
// indexSearch(index, multiQuery, result);
|
||||||
|
//
|
||||||
|
// std::cout << "taos'size : " << taosArrayGetSize(result) << std::endl;
|
||||||
|
// for (int i = 0; i < taosArrayGetSize(result); i++) {
|
||||||
|
// int *v = (int *)taosArrayGet(result, i);
|
||||||
|
// std::cout << "value --->" << *v << std::endl;
|
||||||
|
// }
|
||||||
|
// // add more test case
|
||||||
|
// indexMultiTermQueryDestroy(multiQuery);
|
||||||
|
//
|
||||||
|
// indexOptsDestroy(opts);
|
||||||
|
// indexClose(index);
|
||||||
|
// //
|
||||||
|
//}
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
std::string str("Hello world");
|
||||||
|
FstSlice key = fstSliceCreate((uint8_t *)str.c_str(), str.size());
|
||||||
|
Output val = 10;
|
||||||
|
FstBuilder *b = fstBuilderCreate(NULL, 1);
|
||||||
|
fstBuilderInsert(b, key, val);
|
||||||
|
fstBuilderFinish(b);
|
||||||
|
fstBuilderDestroy(b);
|
||||||
|
fstSliceDestroy(&key);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TEST(IndexFstBuilder, IndexFstInput) {
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue