Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
55282bbf
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看板
提交
55282bbf
编写于
11月 25, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add index test example
上级
21592f57
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
98 addition
and
7 deletion
+98
-7
source/libs/index/inc/index_fst_counting_writer.h
source/libs/index/inc/index_fst_counting_writer.h
+3
-0
source/libs/index/inc/index_fst_util.h
source/libs/index/inc/index_fst_util.h
+2
-2
source/libs/index/src/index_fst.c
source/libs/index/src/index_fst.c
+89
-4
source/libs/index/src/index_fst_counting_writer.c
source/libs/index/src/index_fst_counting_writer.c
+4
-1
未找到文件。
source/libs/index/inc/index_fst_counting_writer.h
浏览文件 @
55282bbf
...
...
@@ -34,6 +34,9 @@ FstCountingWriter *fstCountingWriterCreate(void *wtr);
void
fstCountingWriterDestroy
(
FstCountingWriter
*
w
);
void
fstCountingWriterPackUintIn
(
FstCountingWriter
*
writer
,
uint64_t
n
,
uint8_t
nBytes
);
#define FST_WRITER_COUNT(writer) (writer->count)
#define FST_WRITER_INTER_WRITER(writer) (writer->wtr)
#define FST_WRITE_CHECK_SUMMER(writer) (writer->summer)
...
...
source/libs/index/inc/index_fst_util.h
浏览文件 @
55282bbf
...
...
@@ -45,9 +45,9 @@ extern const uint64_t TRANS_INDEX_THRESHOLD;
// `0` is a legal value which means there are no transitions/outputs
#define FST_SET_TRANSITION_PACK_SIZE(v, sz) do {v = (v & 0b00001111) | (sz << 4} while(0)
#define FST_SET_TRANSITION_PACK_SIZE(v, sz) do {v = (v & 0b00001111) | (sz << 4
);
} while(0)
#define FST_GET_TRANSITION_PACK_SIZE(v) (((v) & 0b11110000) >> 4)
#define FST_SET_OUTPUT_PACK_SIZE(v, sz) do { v = (v & 0b11110000) | sz } while(0)
#define FST_SET_OUTPUT_PACK_SIZE(v, sz) do { v = (v & 0b11110000) | sz
;
} while(0)
#define FST_GET_OUTPUT_PACK_SIZE(v) ((v) & 0b00001111)
#define COMMON_INPUT(idx) COMMON_INPUTS_INV[(idx) - 1]
...
...
source/libs/index/src/index_fst.c
浏览文件 @
55282bbf
...
...
@@ -16,6 +16,12 @@
#include "index_fst.h"
static
void
fstPackDeltaIn
(
FstCountingWriter
*
wrt
,
CompiledAddr
nodeAddr
,
CompiledAddr
transAddr
,
uint8_t
nBytes
)
{
CompiledAddr
deltaAddr
=
(
transAddr
==
EMPTY_ADDRESS
)
?
EMPTY_ADDRESS
:
nodeAddr
-
transAddr
;
fstCountingWriterPackUintIn
(
wrt
,
deltaAddr
,
nBytes
);
}
FstUnFinishedNodes
*
fstUnFinishedNodesCreate
()
{
FstUnFinishedNodes
*
nodes
=
malloc
(
sizeof
(
FstUnFinishedNodes
));
if
(
nodes
==
NULL
)
{
return
NULL
;
}
...
...
@@ -175,18 +181,18 @@ FstState fstStateCreateFrom(FstSlice* slice, CompiledAddr addr) {
return
fs
;
}
static
FstState
s
tateDict
[]
=
{
static
FstState
fstS
tateDict
[]
=
{
{.
state
=
OneTransNext
,
.
val
=
0
b11000000
},
{.
state
=
OneTrans
,
.
val
=
0
b10000000
},
{.
state
=
AnyTrans
,
.
val
=
0
b00000000
},
{.
state
=
EmptyFinal
,
.
val
=
0
b00000000
}
};
// debug
static
c
har
*
fS
tStateStr
[]
=
{
"ONE_TRANS_NEXT"
,
"ONE_TRANS"
,
"ANY_TRANS"
,
"EMPTY_FINAL"
};
static
c
onst
char
*
fs
tStateStr
[]
=
{
"ONE_TRANS_NEXT"
,
"ONE_TRANS"
,
"ANY_TRANS"
,
"EMPTY_FINAL"
};
FstState
fstStateCreate
(
State
state
){
uint8_t
idx
=
(
uint8_t
)
state
;
return
s
tateDict
[
idx
];
return
fstS
tateDict
[
idx
];
}
//compile
void
fstStateCompileForOneTransNext
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
uint8_t
inp
)
{
...
...
@@ -209,6 +215,77 @@ void fstStateCompileForOneTrans(FstCountingWriter *w, CompiledAddr addr, FstTran
}
void
fstStateCompileForAnyTrans
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
FstBuilderNode
*
node
)
{
size_t
sz
=
taosArrayGetSize
(
node
->
trans
);
assert
(
sz
<=
256
);
uint8_t
tSize
=
0
;
uint8_t
oSize
=
packSize
(
node
->
finalOutput
)
;
// finalOutput.is_zero()
bool
anyOuts
=
(
node
->
finalOutput
!=
0
)
;
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
FstTransition
*
t
=
taosArrayGet
(
node
->
trans
,
i
);
tSize
=
MAX
(
tSize
,
packDeltaSize
(
addr
,
t
->
addr
));
oSize
=
MAX
(
oSize
,
packSize
(
t
->
out
));
anyOuts
=
anyOuts
||
(
t
->
out
!=
0
);
}
PackSizes
packSizes
=
0
;
if
(
anyOuts
)
{
FST_SET_OUTPUT_PACK_SIZE
(
packSizes
,
oSize
);
}
else
{
FST_SET_OUTPUT_PACK_SIZE
(
packSizes
,
0
);
}
FST_SET_TRANSITION_PACK_SIZE
(
packSizes
,
tSize
);
FstState
st
=
fstStateCreate
(
AnyTrans
);
fstStateSetFinalState
(
&
st
,
node
->
isFinal
);
fstStateSetStateNtrans
(
&
st
,
(
uint8_t
)
sz
);
if
(
anyOuts
)
{
if
(
FST_BUILDER_NODE_IS_FINAL
(
node
))
{
fstCountingWriterPackUintIn
(
w
,
node
->
finalOutput
,
oSize
);
}
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
FstTransition
*
t
=
taosArrayGet
(
node
->
trans
,
i
);
fstCountingWriterPackUintIn
(
w
,
t
->
out
,
oSize
);
}
}
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
FstTransition
*
t
=
taosArrayGet
(
node
->
trans
,
i
);
fstPackDeltaIn
(
w
,
addr
,
t
->
addr
,
tSize
);
}
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
FstTransition
*
t
=
taosArrayGet
(
node
->
trans
,
i
);
fstCountingWriterWrite
(
w
,
(
char
*
)
&
t
->
inp
,
1
);
//fstPackDeltaIn(w, addr, t->addr, tSize);
}
if
(
sz
>
TRANS_INDEX_THRESHOLD
)
{
// A value of 255 indicates that no transition exists for the byte
// at that index. (Except when there are 256 transitions.) Namely,
// any value greater than or equal to the number of transitions in
// this node indicates an absent transition.
uint8_t
*
index
=
malloc
(
sizeof
(
uint8_t
)
*
256
);
for
(
uint8_t
i
=
0
;
i
<
256
;
i
++
)
{
index
[
i
]
=
255
;
}
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
FstTransition
*
t
=
taosArrayGet
(
node
->
trans
,
i
);
index
[
t
->
inp
]
=
i
;
fstCountingWriterWrite
(
w
,
(
char
*
)
index
,
sizeof
(
index
));
//fstPackDeltaIn(w, addr, t->addr, tSize);
}
}
fstCountingWriterWrite
(
w
,
(
char
*
)
&
packSizes
,
1
);
bool
null
=
false
;
fstStateStateNtrans
(
&
st
,
&
null
);
if
(
null
==
true
)
{
// 256 can't be represented in a u8, so we abuse the fact that
// the # of transitions can never be 1 here, since 1 is always
// encoded in the state byte.
uint8_t
v
=
1
;
if
(
sz
==
256
)
{
fstCountingWriterWrite
(
w
,
(
char
*
)
&
v
,
1
);
}
else
{
fstCountingWriterWrite
(
w
,
(
char
*
)
&
sz
,
1
);
}
}
fstCountingWriterWrite
(
w
,
(
char
*
)(
&
(
st
.
val
)),
1
);
return
;
}
...
...
@@ -218,7 +295,7 @@ void fstStateSetCommInput(FstState* s, uint8_t inp) {
uint8_t
val
;
COMMON_INDEX
(
inp
,
0x111111
,
val
);
s
->
val
=
(
s
->
val
&
s
tateDict
[
s
->
state
].
val
)
|
val
;
s
->
val
=
(
s
->
val
&
fstS
tateDict
[
s
->
state
].
val
)
|
val
;
}
// comm_input
...
...
@@ -523,6 +600,14 @@ FstNode *fstNodeCreate(int64_t version, CompiledAddr addr, FstSlice *slice) {
}
return
n
;
}
// debug state transition
static
const
char
*
fstNodeState
(
FstNode
*
node
)
{
FstState
*
st
=
&
node
->
state
;
return
fstStateStr
[
st
->
state
];
}
void
fstNodeDestroy
(
FstNode
*
node
)
{
free
(
node
);
}
...
...
source/libs/index/src/index_fst_counting_writer.c
浏览文件 @
55282bbf
...
...
@@ -36,10 +36,13 @@ uint64_t fstCountingWriterWrite(FstCountingWriter *write, uint8_t *buf, uint32_t
return
bufLen
;
}
int
F
stCountingWriterFlush
(
FstCountingWriter
*
write
)
{
int
f
stCountingWriterFlush
(
FstCountingWriter
*
write
)
{
//write->wtr->flush
return
1
;
}
void
fstCountingWriterPackUintIn
(
FstCountingWriter
*
writer
,
uint64_t
n
,
uint8_t
nBytes
)
{
return
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录