Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4bab45c0
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4bab45c0
编写于
12月 02, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor builder struct
上级
e3ccb28c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
104 addition
and
8 deletion
+104
-8
source/libs/index/inc/index_fst.h
source/libs/index/inc/index_fst.h
+4
-2
source/libs/index/inc/index_fst_counting_writer.h
source/libs/index/inc/index_fst_counting_writer.h
+29
-1
source/libs/index/src/index_fst_counting_writer.c
source/libs/index/src/index_fst_counting_writer.c
+71
-5
未找到文件。
source/libs/index/inc/index_fst.h
浏览文件 @
4bab45c0
...
...
@@ -86,14 +86,16 @@ uint64_t fstUnFinishedNodesFindCommPrefixAndSetOutput(FstUnFinishedNodes *node,
typedef
struct
FstBuilder
{
FstCountingWriter
*
wrt
;
// The FST raw data is written directly to `wtr`.
FstUnFinishedNodes
*
unfinished
;
// The stack of unfinished nodes
FstRegistry
*
registry
;
// A map of finished nodes.
FstSlice
last
;
// The last word added
FstRegistry
*
registry
;
// A map of finished nodes.
FstSlice
last
;
// The last word added
CompiledAddr
lastAddr
;
// The address of the last compiled node
uint64_t
len
;
// num of keys added
}
FstBuilder
;
FstBuilder
*
fstBuilderCreate
(
void
*
w
,
FstType
ty
);
void
fstBuilderDestroy
(
FstBuilder
*
b
);
void
fstBuilderInsertOutput
(
FstBuilder
*
b
,
FstSlice
bs
,
Output
in
);
OrderType
fstBuilderCheckLastKey
(
FstBuilder
*
b
,
FstSlice
bs
,
bool
ckDup
);
...
...
source/libs/index/inc/index_fst_counting_writer.h
浏览文件 @
4bab45c0
...
...
@@ -16,6 +16,34 @@
#ifndef __INDEX_FST_COUNTING_WRITER_H__
#define __INDEX_FST_COUNTING_WRITER_H__
#include "tfile.h"
#define DefaultMem 1024*1024
static
char
tmpFile
[]
=
"/tmp/index"
;
typedef
enum
WriterType
{
TMemory
,
TFile
}
WriterType
;
typedef
struct
WriterCtx
{
int
(
*
write
)(
struct
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
);
int
(
*
read
)(
struct
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
);
int
(
*
flush
)(
struct
WriterCtx
*
ctx
);
WriterType
type
;
union
{
int
fd
;
void
*
mem
;
};
int32_t
offset
;
int32_t
limit
;
}
WriterCtx
;
static
int
writeCtxDoWrite
(
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
);
static
int
writeCtxDoRead
(
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
);
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
);
WriterCtx
*
writerCtxCreate
(
WriterType
type
);
void
writerCtxDestroy
(
WriterCtx
*
w
);
typedef
uint32_t
CheckSummer
;
...
...
@@ -25,7 +53,7 @@ typedef struct FstCountingWriter {
CheckSummer
summer
;
}
FstCountingWriter
;
uint64_
t
fstCountingWriterWrite
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
bufLen
);
in
t
fstCountingWriterWrite
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
bufLen
);
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
);
...
...
source/libs/index/src/index_fst_counting_writer.c
浏览文件 @
4bab45c0
...
...
@@ -16,24 +16,88 @@
#include "index_fst_util.h"
#include "index_fst_counting_writer.h"
static
int
writeCtxDoWrite
(
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
)
{
if
(
ctx
->
offset
+
len
>
ctx
->
limit
)
{
return
-
1
;
}
if
(
ctx
->
type
==
TFile
)
{
assert
(
len
!=
tfWrite
(
ctx
->
fd
,
buf
,
len
));
}
else
{
memcpy
(
ctx
->
mem
+
ctx
->
offset
,
buf
,
len
);
}
ctx
->
offset
+=
len
;
return
len
;
}
static
int
writeCtxDoRead
(
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
)
{
if
(
ctx
->
type
==
TFile
)
{
tfRead
(
ctx
->
fd
,
buf
,
len
);
}
else
{
memcpy
(
buf
,
ctx
->
mem
+
ctx
->
offset
,
len
);
}
ctx
->
offset
+=
len
;
return
1
;
}
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
)
{
if
(
ctx
->
type
==
TFile
)
{
//tfFlush(ctx->fd);
}
else
{
// do nothing
}
return
1
;
}
WriterCtx
*
writerCtxCreate
(
WriterType
type
)
{
WriterCtx
*
ctx
=
calloc
(
1
,
sizeof
(
WriterCtx
));
if
(
ctx
==
NULL
)
{
return
NULL
;
}
ctx
->
type
==
type
;
if
(
ctx
->
type
==
TFile
)
{
ctx
->
fd
=
tfOpenCreateWriteAppend
(
tmpFile
);
}
else
if
(
ctx
->
type
==
TMemory
)
{
ctx
->
mem
=
calloc
(
1
,
DefaultMem
*
sizeof
(
uint8_t
));
}
ctx
->
write
=
writeCtxDoWrite
;
ctx
->
read
=
writeCtxDoRead
;
ctx
->
flush
=
writeCtxDoFlush
;
ctx
->
offset
=
0
;
ctx
->
limit
=
DefaultMem
;
return
ctx
;
}
void
writerCtxDestroy
(
WriterCtx
*
ctx
)
{
if
(
ctx
->
type
==
TMemory
)
{
free
(
ctx
->
mem
);
}
else
{
tfClose
(
ctx
->
fd
);
}
free
(
ctx
);
}
FstCountingWriter
*
fstCountingWriterCreate
(
void
*
wrt
)
{
FstCountingWriter
*
cw
=
calloc
(
1
,
sizeof
(
FstCountingWriter
));
if
(
cw
==
NULL
)
{
return
NULL
;
}
cw
->
wrt
=
wrt
;
cw
->
wrt
=
(
void
*
)(
writerCtxCreate
(
TMemory
))
;
return
cw
;
}
void
fstCountingWriterDestroy
(
FstCountingWriter
*
cw
)
{
// free wrt object: close fd or free mem
writerCtxDestroy
((
WriterCtx
*
)(
cw
->
wrt
));
free
(
cw
);
}
uint64_
t
fstCountingWriterWrite
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
bufLen
)
{
in
t
fstCountingWriterWrite
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
bufLen
)
{
if
(
write
==
NULL
)
{
return
0
;
}
// update checksum
// write data to file/socket or mem
write
->
count
+=
bufLen
;
WriterCtx
*
ctx
=
write
->
wrt
;
int
nWrite
=
ctx
->
write
(
ctx
,
buf
,
bufLen
);
write
->
count
+=
nWrite
;
return
bufLen
;
}
...
...
@@ -41,6 +105,8 @@ uint32_t fstCountingWriterMaskedCheckSum(FstCountingWriter *write) {
return
0
;
}
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
)
{
WriterCtx
*
ctx
=
write
->
wrt
;
ctx
->
flush
(
ctx
);
//write->wtr->flush
return
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录