commit
6be44a6d3d
|
@ -30,6 +30,7 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct Fst Fst;
|
typedef struct Fst Fst;
|
||||||
typedef struct FstNode FstNode;
|
typedef struct FstNode FstNode;
|
||||||
|
typedef struct StreamWithState StreamWithState;
|
||||||
|
|
||||||
typedef enum { Included, Excluded, Unbounded} FstBound;
|
typedef enum { Included, Excluded, Unbounded} FstBound;
|
||||||
|
|
||||||
|
@ -283,6 +284,9 @@ Output fstEmptyFinalOutput(Fst *fst, bool *null);
|
||||||
FstStreamBuilder *fstSearch(Fst *fst, AutomationCtx *ctx);
|
FstStreamBuilder *fstSearch(Fst *fst, AutomationCtx *ctx);
|
||||||
FstStreamWithStateBuilder *fstSearchWithState(Fst *fst, AutomationCtx *ctx);
|
FstStreamWithStateBuilder *fstSearchWithState(Fst *fst, AutomationCtx *ctx);
|
||||||
|
|
||||||
|
// into stream to expand later
|
||||||
|
StreamWithState* streamBuilderIntoStream(FstStreamBuilder *sb);
|
||||||
|
|
||||||
bool fstVerify(Fst *fst);
|
bool fstVerify(Fst *fst);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1094,6 +1094,10 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) {
|
||||||
FstStreamBuilder *fstSearch(Fst *fst, AutomationCtx *ctx) {
|
FstStreamBuilder *fstSearch(Fst *fst, AutomationCtx *ctx) {
|
||||||
return fstStreamBuilderCreate(fst, ctx);
|
return fstStreamBuilderCreate(fst, ctx);
|
||||||
}
|
}
|
||||||
|
StreamWithState* streamBuilderIntoStream(FstStreamBuilder *sb) {
|
||||||
|
if (sb == NULL) { return NULL; }
|
||||||
|
return streamWithStateCreate(sb->fst, sb->aut, sb->min, sb->max);
|
||||||
|
}
|
||||||
FstStreamWithStateBuilder *fstSearchWithState(Fst *fst, AutomationCtx *ctx) {
|
FstStreamWithStateBuilder *fstSearchWithState(Fst *fst, AutomationCtx *ctx) {
|
||||||
return fstStreamBuilderCreate(fst, ctx);
|
return fstStreamBuilderCreate(fst, ctx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,9 +59,22 @@ class FstReadMemory {
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
// add later
|
// add later
|
||||||
bool Search(const std::string &key, std::vector<uint64_t> &result) {
|
bool Search(AutomationCtx *ctx, std::vector<uint64_t> &result) {
|
||||||
|
FstStreamBuilder *sb = fstSearch(_fst, ctx);
|
||||||
|
StreamWithState *st = streamBuilderIntoStream(sb);
|
||||||
|
StreamWithStateResult *rt = NULL;
|
||||||
|
|
||||||
|
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
||||||
|
result.push_back((uint64_t)(rt->out.out));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
bool SearchWithTimeCostUs(AutomationCtx *ctx, std::vector<uint64_t> &result) {
|
||||||
|
int64_t s = taosGetTimestampUs();
|
||||||
|
bool ok = this->Search(ctx, result);
|
||||||
|
int64_t e = taosGetTimestampUs();
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
~FstReadMemory() {
|
~FstReadMemory() {
|
||||||
fstCountingWriterDestroy(_w);
|
fstCountingWriterDestroy(_w);
|
||||||
|
@ -186,11 +199,43 @@ void checkFstPerf() {
|
||||||
printf("success to init fst read");
|
printf("success to init fst read");
|
||||||
}
|
}
|
||||||
Performance_fstReadRecords(m);
|
Performance_fstReadRecords(m);
|
||||||
|
|
||||||
delete m;
|
delete m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkFstPrefixSearch() {
|
||||||
|
FstWriter *fw = new FstWriter;
|
||||||
|
int64_t s = taosGetTimestampUs();
|
||||||
|
int count = 2;
|
||||||
|
std::string key("ab");
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
key[1] = key[1] + i;
|
||||||
|
fw->Put(key, i);
|
||||||
|
}
|
||||||
|
int64_t e = taosGetTimestampUs();
|
||||||
|
|
||||||
|
std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl;
|
||||||
|
delete fw;
|
||||||
|
|
||||||
|
FstReadMemory *m = new FstReadMemory(1024 * 64);
|
||||||
|
if (m->init() == false) {
|
||||||
|
std::cout << "init readMemory failed" << std::endl;
|
||||||
|
delete m;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prefix search
|
||||||
|
std::vector<uint64_t> result;
|
||||||
|
AutomationCtx *ctx = automCtxCreate((void *)"ab", AUTOMATION_PREFIX);
|
||||||
|
m->Search(ctx, result);
|
||||||
|
assert(result.size() == count);
|
||||||
|
for (int i = 0; i < result.size(); i++) {
|
||||||
|
assert(result[i] == i); // check result
|
||||||
|
}
|
||||||
|
|
||||||
|
free(ctx);
|
||||||
|
delete m;
|
||||||
|
}
|
||||||
void validateFst() {
|
void validateFst() {
|
||||||
int val = 100;
|
int val = 100;
|
||||||
int count = 100;
|
int count = 100;
|
||||||
|
@ -209,6 +254,8 @@ void validateFst() {
|
||||||
FstReadMemory *m = new FstReadMemory(1024 * 64);
|
FstReadMemory *m = new FstReadMemory(1024 * 64);
|
||||||
if (m->init() == false) {
|
if (m->init() == false) {
|
||||||
std::cout << "init readMemory failed" << std::endl;
|
std::cout << "init readMemory failed" << std::endl;
|
||||||
|
delete m;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -230,10 +277,12 @@ void validateFst() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete m;
|
delete m;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
checkFstPerf();
|
checkFstPerf();
|
||||||
|
//checkFstPrefixSearch();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue