refactor builder struct
This commit is contained in:
parent
7e1f68f86f
commit
db2bf567c2
|
@ -17,6 +17,7 @@
|
||||||
#define _TD_INDEX_INT_H_
|
#define _TD_INDEX_INT_H_
|
||||||
|
|
||||||
#include "index.h"
|
#include "index.h"
|
||||||
|
#include "tlog.h"
|
||||||
|
|
||||||
#ifdef USE_LUCENE
|
#ifdef USE_LUCENE
|
||||||
#include <lucene++/Lucene_c.h>
|
#include <lucene++/Lucene_c.h>
|
||||||
|
@ -60,6 +61,16 @@ typedef struct SIndexTermQuery {
|
||||||
|
|
||||||
SIndexTerm *indexTermCreate(const char *key, int32_t nKey, const char *val, int32_t nVal);
|
SIndexTerm *indexTermCreate(const char *key, int32_t nKey, const char *val, int32_t nVal);
|
||||||
void indexTermDestroy(SIndexTerm *p);
|
void indexTermDestroy(SIndexTerm *p);
|
||||||
|
|
||||||
|
|
||||||
|
#define indexFatal(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("index FATAL ", 255, __VA_ARGS__); }} while(0)
|
||||||
|
#define indexError(...) do { if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("index ERROR ", 255, __VA_ARGS__); }} while(0)
|
||||||
|
#define indexWarn(...) do { if (sDebugFlag & DEBUG_WARN) { taosPrintLog("index WARN ", 255, __VA_ARGS__); }} while(0)
|
||||||
|
#define indexInfo(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLog("index ", 255, __VA_ARGS__); }} while(0)
|
||||||
|
#define indexDebug(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("index ", sDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
|
#define indexTrace(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("index ", sDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,7 +25,7 @@ extern "C" {
|
||||||
|
|
||||||
#define DefaultMem 1024*1024
|
#define DefaultMem 1024*1024
|
||||||
|
|
||||||
static char tmpFile[] = "/tmp/index";
|
static char tmpFile[] = "./index";
|
||||||
typedef enum WriterType {TMemory, TFile} WriterType;
|
typedef enum WriterType {TMemory, TFile} WriterType;
|
||||||
|
|
||||||
typedef struct WriterCtx {
|
typedef struct WriterCtx {
|
||||||
|
|
|
@ -148,7 +148,7 @@ uint64_t fstUnFinishedNodesFindCommPrefixAndSetOutput(FstUnFinishedNodes *node,
|
||||||
|
|
||||||
size_t lsz = (size_t)(s->end - s->start + 1); // data len
|
size_t lsz = (size_t)(s->end - s->start + 1); // data len
|
||||||
size_t ssz = taosArrayGetSize(node->stack); // stack size
|
size_t ssz = taosArrayGetSize(node->stack); // stack size
|
||||||
|
*out = in;
|
||||||
uint64_t i = 0;
|
uint64_t i = 0;
|
||||||
for (i = 0; i < lsz && i < ssz; i++) {
|
for (i = 0; i < lsz && i < ssz; i++) {
|
||||||
FstBuilderNodeUnfinished *un = taosArrayGet(node->stack, i);
|
FstBuilderNodeUnfinished *un = taosArrayGet(node->stack, i);
|
||||||
|
@ -776,6 +776,17 @@ FstBuilder *fstBuilderCreate(void *w, FstType ty) {
|
||||||
b->last = fstSliceCreate(NULL, 0);
|
b->last = fstSliceCreate(NULL, 0);
|
||||||
b->lastAddr = NONE_ADDRESS;
|
b->lastAddr = NONE_ADDRESS;
|
||||||
b->len = 0;
|
b->len = 0;
|
||||||
|
|
||||||
|
char buf64[8] = {0};
|
||||||
|
void *pBuf64 = buf64;
|
||||||
|
taosEncodeFixedU64(&pBuf64, VERSION);
|
||||||
|
fstCountingWriterWrite(b->wrt, buf64, sizeof(buf64));
|
||||||
|
|
||||||
|
memset(buf64, 0, sizeof(buf64));
|
||||||
|
pBuf64 = buf64;
|
||||||
|
taosEncodeFixedU64(&pBuf64, ty);
|
||||||
|
fstCountingWriterWrite(b->wrt, buf64, sizeof(buf64));
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
void fstBuilderDestroy(FstBuilder *b) {
|
void fstBuilderDestroy(FstBuilder *b) {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
#include "indexInt.h"
|
||||||
#include "index_fst_util.h"
|
#include "index_fst_util.h"
|
||||||
#include "index_fst_counting_writer.h"
|
#include "index_fst_counting_writer.h"
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ static int writeCtxDoWrite(WriterCtx *ctx, uint8_t *buf, int len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->type == TFile) {
|
if (ctx->type == TFile) {
|
||||||
assert(len != tfWrite(ctx->fd, buf, len));
|
assert(len == tfWrite(ctx->fd, buf, len));
|
||||||
} else {
|
} else {
|
||||||
memcpy(ctx->mem + ctx->offset, buf, len);
|
memcpy(ctx->mem + ctx->offset, buf, len);
|
||||||
}
|
}
|
||||||
|
@ -54,9 +55,10 @@ WriterCtx* writerCtxCreate(WriterType type) {
|
||||||
|
|
||||||
ctx->type = type;
|
ctx->type = type;
|
||||||
if (ctx->type == TFile) {
|
if (ctx->type == TFile) {
|
||||||
|
tfInit();
|
||||||
ctx->fd = tfOpenCreateWriteAppend(tmpFile);
|
ctx->fd = tfOpenCreateWriteAppend(tmpFile);
|
||||||
if (ctx->fd < 0) {
|
if (ctx->fd < 0) {
|
||||||
|
indexError("open file error %d", errno);
|
||||||
}
|
}
|
||||||
} else if (ctx->type == TMemory) {
|
} else if (ctx->type == TMemory) {
|
||||||
ctx->mem = calloc(1, DefaultMem * sizeof(uint8_t));
|
ctx->mem = calloc(1, DefaultMem * sizeof(uint8_t));
|
||||||
|
@ -74,6 +76,7 @@ void writerCtxDestroy(WriterCtx *ctx) {
|
||||||
if (ctx->type == TMemory) {
|
if (ctx->type == TMemory) {
|
||||||
free(ctx->mem);
|
free(ctx->mem);
|
||||||
} else {
|
} else {
|
||||||
|
tfCleanup();
|
||||||
tfClose(ctx->fd);
|
tfClose(ctx->fd);
|
||||||
}
|
}
|
||||||
free(ctx);
|
free(ctx);
|
||||||
|
|
|
@ -75,10 +75,10 @@ int main(int argc, char** argv) {
|
||||||
//FstSlice key1 = fstSliceCreate((uint8_t *)str1.c_str(), str1.size());
|
//FstSlice key1 = fstSliceCreate((uint8_t *)str1.c_str(), str1.size());
|
||||||
//Output val2 = 10;
|
//Output val2 = 10;
|
||||||
{
|
{
|
||||||
std::string str("bcd");
|
//std::string str("bcd");
|
||||||
FstSlice key = fstSliceCreate((uint8_t *)str.c_str(), str.size());
|
//FstSlice key = fstSliceCreate((uint8_t *)str.c_str(), str.size());
|
||||||
Output val = 1;
|
//Output val = 1;
|
||||||
fstBuilderInsert(b, key, val);
|
//fstBuilderInsert(b, key, val);
|
||||||
}
|
}
|
||||||
//fstBuilderInsert(b, key1, val2);
|
//fstBuilderInsert(b, key1, val2);
|
||||||
fstBuilderFinish(b);
|
fstBuilderFinish(b);
|
||||||
|
|
Loading…
Reference in New Issue