update index query
This commit is contained in:
parent
3f23495983
commit
30d49687e9
|
@ -21,9 +21,9 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "indexInt.h"
|
||||
#include "index_fst_node.h"
|
||||
#include "index_fst_automation.h"
|
||||
#include "index_fst_counting_writer.h"
|
||||
#include "index_fst_node.h"
|
||||
#include "index_fst_registry.h"
|
||||
#include "index_fst_util.h"
|
||||
|
||||
|
@ -257,9 +257,9 @@ typedef struct FstMeta {
|
|||
} FstMeta;
|
||||
|
||||
typedef struct Fst {
|
||||
FstMeta* meta;
|
||||
FstSlice* data; //
|
||||
FstNode* root; //
|
||||
FstMeta* meta;
|
||||
FstSlice* data; //
|
||||
FstNode* root; //
|
||||
TdThreadMutex mtx;
|
||||
} Fst;
|
||||
|
||||
|
@ -325,10 +325,10 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb
|
|||
FstStreamBuilder* fstStreamBuilderCreate(Fst* fst, AutomationCtx* aut);
|
||||
|
||||
void fstStreamBuilderDestroy(FstStreamBuilder* b);
|
||||
// set up bound range
|
||||
// refator, simple code by marco
|
||||
|
||||
FstStreamBuilder* fstStreamBuilderRange(FstStreamBuilder* b, FstSlice* val, RangeType type);
|
||||
// set up bound range
|
||||
// refator later: to simple code by marco
|
||||
void fstStreamBuilderSetRange(FstStreamBuilder* b, FstSlice* val, RangeType type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1425,9 +1425,9 @@ void fstStreamBuilderDestroy(FstStreamBuilder* b) {
|
|||
taosMemoryFreeClear(b->max);
|
||||
taosMemoryFree(b);
|
||||
}
|
||||
FstStreamBuilder* fstStreamBuilderRange(FstStreamBuilder* b, FstSlice* val, RangeType type) {
|
||||
void fstStreamBuilderSetRange(FstStreamBuilder* b, FstSlice* val, RangeType type) {
|
||||
if (b == NULL) {
|
||||
return NULL;
|
||||
return;
|
||||
}
|
||||
if (type == GE) {
|
||||
b->min->type = Included;
|
||||
|
@ -1446,5 +1446,4 @@ FstStreamBuilder* fstStreamBuilderRange(FstStreamBuilder* b, FstSlice* val, Rang
|
|||
fstSliceDestroy(&(b->max->data));
|
||||
b->max->data = fstSliceDeepCopy(val, 0, FST_SLICE_LEN(val) - 1);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
|
|
@ -96,12 +96,36 @@ class FstReadMemory {
|
|||
char* ch = (char*)fstSliceData(s, &sz);
|
||||
std::string key(ch, sz);
|
||||
printf("key: %s, val: %" PRIu64 "\n", key.c_str(), (uint64_t)(rt->out.out));
|
||||
swsResultDestroy(rt);
|
||||
result.push_back(rt->out.out);
|
||||
swsResultDestroy(rt);
|
||||
}
|
||||
for (size_t i = 0; i < result.size(); i++) {
|
||||
return true;
|
||||
}
|
||||
bool SearchRange(AutomationCtx* ctx, const std::string& low, const std::string& high, std::vector<uint64_t>& result) {
|
||||
FstStreamBuilder* sb = fstSearch(_fst, ctx);
|
||||
|
||||
FstSlice l = fstSliceCreate((uint8_t*)low.c_str(), low.size());
|
||||
FstSlice h = fstSliceCreate((uint8_t*)high.c_str(), high.size());
|
||||
|
||||
// range [low, high);
|
||||
fstStreamBuilderSetRange(sb, &l, GE);
|
||||
fstStreamBuilderSetRange(sb, &h, LT);
|
||||
|
||||
fstSliceDestroy(&l);
|
||||
fstSliceDestroy(&h);
|
||||
|
||||
StreamWithState* st = streamBuilderIntoStream(sb);
|
||||
StreamWithStateResult* rt = NULL;
|
||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
||||
// result.push_back((uint64_t)(rt->out.out));
|
||||
FstSlice* s = &rt->data;
|
||||
int32_t sz = 0;
|
||||
char* ch = (char*)fstSliceData(s, &sz);
|
||||
std::string key(ch, sz);
|
||||
printf("key: %s, val: %" PRIu64 "\n", key.c_str(), (uint64_t)(rt->out.out));
|
||||
result.push_back(rt->out.out);
|
||||
swsResultDestroy(rt);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return true;
|
||||
}
|
||||
bool SearchWithTimeCostUs(AutomationCtx* ctx, std::vector<uint64_t>& result) {
|
||||
|
@ -322,6 +346,40 @@ void checkFstCheckIteratorPrefix() {
|
|||
}
|
||||
delete m;
|
||||
}
|
||||
void checkFstCheckIteratorRange() {
|
||||
FstWriter* fw = new FstWriter;
|
||||
int64_t s = taosGetTimestampUs();
|
||||
int count = 2;
|
||||
// Performance_fstWriteRecords(fw);
|
||||
int64_t e = taosGetTimestampUs();
|
||||
|
||||
std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl;
|
||||
|
||||
fw->Put("a", 1);
|
||||
fw->Put("b", 2);
|
||||
fw->Put("c", 3);
|
||||
fw->Put("d", 4);
|
||||
fw->Put("e", 5);
|
||||
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*)"he", AUTOMATION_ALWAYS);
|
||||
|
||||
// [b, e)
|
||||
m->SearchRange(ctx, "b", "e", result);
|
||||
// assert(result.size() == 1);
|
||||
taosMemoryFree(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
void fst_get(Fst* fst) {
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
|
@ -386,7 +444,8 @@ int main(int argc, char* argv[]) {
|
|||
// iterTFileReader(argv[1], argv[2], argv[3], argv[4]);
|
||||
//}
|
||||
// checkFstCheckIterator();
|
||||
checkFstCheckIteratorPrefix();
|
||||
// checkFstCheckIteratorPrefix();
|
||||
checkFstCheckIteratorRange();
|
||||
// checkFstLongTerm();
|
||||
// checkFstPrefixSearch();
|
||||
|
||||
|
|
Loading…
Reference in New Issue