提交 db2bf567 编写于 作者: dengyihao's avatar dengyihao

refactor builder struct

上级 7e1f68f8
......@@ -17,6 +17,7 @@
#define _TD_INDEX_INT_H_
#include "index.h"
#include "tlog.h"
#ifdef USE_LUCENE
#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);
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
}
#endif
......
......@@ -25,7 +25,7 @@ extern "C" {
#define DefaultMem 1024*1024
static char tmpFile[] = "/tmp/index";
static char tmpFile[] = "./index";
typedef enum WriterType {TMemory, TFile} WriterType;
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 ssz = taosArrayGetSize(node->stack); // stack size
*out = in;
uint64_t i = 0;
for (i = 0; i < lsz && i < ssz; i++) {
FstBuilderNodeUnfinished *un = taosArrayGet(node->stack, i);
......@@ -776,6 +776,17 @@ FstBuilder *fstBuilderCreate(void *w, FstType ty) {
b->last = fstSliceCreate(NULL, 0);
b->lastAddr = NONE_ADDRESS;
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;
}
void fstBuilderDestroy(FstBuilder *b) {
......
......@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tutil.h"
#include "indexInt.h"
#include "index_fst_util.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) {
assert(len != tfWrite(ctx->fd, buf, len));
assert(len == tfWrite(ctx->fd, buf, len));
} else {
memcpy(ctx->mem + ctx->offset, buf, len);
}
......@@ -54,9 +55,10 @@ WriterCtx* writerCtxCreate(WriterType type) {
ctx->type = type;
if (ctx->type == TFile) {
tfInit();
ctx->fd = tfOpenCreateWriteAppend(tmpFile);
if (ctx->fd < 0) {
indexError("open file error %d", errno);
}
} else if (ctx->type == TMemory) {
ctx->mem = calloc(1, DefaultMem * sizeof(uint8_t));
......@@ -74,6 +76,7 @@ void writerCtxDestroy(WriterCtx *ctx) {
if (ctx->type == TMemory) {
free(ctx->mem);
} else {
tfCleanup();
tfClose(ctx->fd);
}
free(ctx);
......
......@@ -75,10 +75,10 @@ int main(int argc, char** argv) {
//FstSlice key1 = fstSliceCreate((uint8_t *)str1.c_str(), str1.size());
//Output val2 = 10;
{
std::string str("bcd");
FstSlice key = fstSliceCreate((uint8_t *)str.c_str(), str.size());
Output val = 1;
fstBuilderInsert(b, key, val);
//std::string str("bcd");
//FstSlice key = fstSliceCreate((uint8_t *)str.c_str(), str.size());
//Output val = 1;
//fstBuilderInsert(b, key, val);
}
//fstBuilderInsert(b, key1, val2);
fstBuilderFinish(b);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册