Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fbb9d515
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fbb9d515
编写于
11月 30, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update fst core struct
上级
23c9ea68
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
108 addition
and
12 deletion
+108
-12
source/libs/index/inc/index_fst.h
source/libs/index/inc/index_fst.h
+12
-1
source/libs/index/inc/index_fst_automation.h
source/libs/index/inc/index_fst_automation.h
+3
-3
source/libs/index/src/index_fst.c
source/libs/index/src/index_fst.c
+93
-8
未找到文件。
source/libs/index/inc/index_fst.h
浏览文件 @
fbb9d515
...
...
@@ -291,6 +291,8 @@ typedef struct StreamState {
void
*
autState
;
}
StreamState
;
void
streamStateDestroy
(
void
*
s
);
typedef
struct
StreamWithState
{
Fst
*
fst
;
Automation
*
aut
;
...
...
@@ -300,9 +302,18 @@ typedef struct StreamWithState {
FstBoundWithData
*
endAt
;
}
StreamWithState
;
typedef
struct
StreamWithStateResult
{
FstSlice
data
;
FstOutput
out
;
void
*
state
;
}
StreamWithStateResult
;
StreamWithStateResult
*
swsResultCreate
(
FstSlice
*
data
,
FstOutput
fOut
,
void
*
state
);
typedef
void
*
(
*
StreamCallback
)(
void
*
);
StreamWithState
*
streamWithStateCreate
(
Fst
*
fst
,
Automation
*
automation
,
FstBoundWithData
*
min
,
FstBoundWithData
*
max
)
;
void
streamWithStateDestroy
(
StreamWithState
*
sws
);
bool
streamWithStateSeekMin
(
StreamWithState
*
sws
,
FstBoundWithData
*
min
);
void
*
streamWithStateNextWith
(
StreamWithState
*
sws
,
StreamCallback
callback
);
StreamWithStateResult
*
streamWithStateNextWith
(
StreamWithState
*
sws
,
StreamCallback
callback
);
#endif
source/libs/index/inc/index_fst_automation.h
浏览文件 @
fbb9d515
...
...
@@ -34,11 +34,11 @@ typedef struct AutomationCtx {
typedef
struct
Automation
{
void
*
(
*
start
)()
;
bool
(
*
isMatch
)();
bool
(
*
isMatch
)(
void
*
);
bool
(
*
canMatch
)(
void
*
data
);
bool
(
*
willAlwaysMatch
)(
void
*
state
);
void
*
(
*
acc
pe
t
)(
void
*
state
,
uint8_t
byte
);
void
*
(
*
acc
pe
tEof
)(
void
*
state
);
void
*
(
*
acc
ep
t
)(
void
*
state
,
uint8_t
byte
);
void
*
(
*
acc
ep
tEof
)(
void
*
state
);
void
*
data
;
}
Automation
;
...
...
source/libs/index/src/index_fst.c
浏览文件 @
fbb9d515
...
...
@@ -1014,16 +1014,15 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) {
}
FstNode
*
fstGetRoot
(
Fst
*
fst
)
{
CompiledAddr
root
=
fstGetRootAddr
(
fst
);
return
fstGetNode
(
fst
,
root
);
}
FstNode
*
fstGetNode
(
Fst
*
fst
,
CompiledAddr
addr
)
{
if
(
fst
->
root
!=
NULL
)
{
return
fst
->
root
;
}
fst
->
root
=
fstNodeCreate
(
fst
->
meta
->
version
,
addr
,
fst
->
data
);
CompiledAddr
rAddr
=
fstGetRootAddr
(
fst
);
fst
->
root
=
fstGetNode
(
fst
,
rAddr
);
return
fst
->
root
;
}
FstNode
*
fstGetNode
(
Fst
*
fst
,
CompiledAddr
addr
)
{
return
fstNodeCreate
(
fst
->
meta
->
version
,
addr
,
fst
->
data
);
}
FstType
fstGetType
(
Fst
*
fst
)
{
...
...
@@ -1113,7 +1112,7 @@ void streamWithStateDestroy(StreamWithState *sws) {
if
(
sws
==
NULL
)
{
return
;
}
taosArrayDestroy
(
sws
->
inp
);
taosArrayDestroy
(
sws
->
stack
);
taosArrayDestroy
Ex
(
sws
->
stack
,
streamStateDestroy
);
free
(
sws
);
}
...
...
@@ -1154,7 +1153,7 @@ bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min) {
FstTransition
trn
;
fstNodeGetTransitionAt
(
node
,
res
,
&
trn
);
void
*
preState
=
autState
;
autState
=
sws
->
aut
->
acc
pe
t
(
preState
,
b
);
autState
=
sws
->
aut
->
acc
ep
t
(
preState
,
b
);
taosArrayPush
(
sws
->
inp
,
&
b
);
StreamState
s
=
{.
node
=
node
,
.
trans
=
res
+
1
,
...
...
@@ -1209,4 +1208,90 @@ bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min) {
}
}
StreamWithStateResult
*
streamWithStateNextWith
(
StreamWithState
*
sws
,
StreamCallback
callback
)
{
FstOutput
output
=
sws
->
emptyOutput
;
if
(
output
.
null
==
false
)
{
FstSlice
emptySlice
=
fstSliceCreate
(
NULL
,
0
);
if
(
fstBoundWithDataExceededBy
(
sws
->
endAt
,
&
emptySlice
))
{
taosArrayDestroyEx
(
sws
->
stack
,
streamStateDestroy
);
sws
->
stack
=
(
SArray
*
)
taosArrayInit
(
256
,
sizeof
(
StreamState
));
return
NULL
;
}
void
*
start
=
sws
->
aut
->
start
();
if
(
sws
->
aut
->
isMatch
(
start
))
{
FstSlice
s
=
fstSliceCreate
(
NULL
,
0
);
return
swsResultCreate
(
&
s
,
output
,
callback
(
start
));
}
}
while
(
taosArrayGetSize
(
sws
->
stack
)
>
0
)
{
StreamState
*
p
=
(
StreamState
*
)
taosArrayPop
(
sws
->
stack
);
if
(
p
->
trans
>=
FST_NODE_LEN
(
p
->
node
)
||
!
sws
->
aut
->
canMatch
(
p
->
autState
))
{
if
(
FST_NODE_ADDR
(
p
->
node
)
!=
fstGetRootAddr
(
sws
->
fst
))
{
taosArrayPop
(
sws
->
inp
);
}
streamStateDestroy
(
p
);
continue
;
}
FstTransition
trn
;
fstNodeGetTransitionAt
(
p
->
node
,
p
->
trans
,
&
trn
);
Output
out
=
p
->
out
.
out
+
trn
.
out
;
void
*
nextState
=
sws
->
aut
->
accept
(
p
->
autState
,
trn
.
inp
);
void
*
tState
=
callback
(
nextState
);
bool
isMatch
=
sws
->
aut
->
isMatch
(
nextState
);
FstNode
*
nextNode
=
fstGetNode
(
sws
->
fst
,
trn
.
addr
);
taosArrayPush
(
sws
->
inp
,
&
(
trn
.
inp
));
if
(
FST_NODE_IS_FINAL
(
nextNode
))
{
void
*
eofState
=
sws
->
aut
->
acceptEof
(
nextState
);
if
(
eofState
!=
NULL
)
{
isMatch
=
sws
->
aut
->
isMatch
(
eofState
);
}
}
StreamState
s1
=
{
.
node
=
p
->
node
,
.
trans
=
p
->
trans
+
1
,
.
out
=
p
->
out
,
.
autState
=
p
->
autState
};
taosArrayPush
(
sws
->
stack
,
&
s1
);
StreamState
s2
=
{.
node
=
nextNode
,
.
trans
=
0
,
.
out
=
{.
null
=
false
,
.
out
=
out
},
.
autState
=
nextState
};
taosArrayPush
(
sws
->
stack
,
&
s2
);
uint8_t
*
buf
=
(
uint8_t
*
)
malloc
(
taosArrayGetSize
(
sws
->
inp
)
*
sizeof
(
uint8_t
));
for
(
uint32_t
i
=
0
;
i
<
taosArrayGetSize
(
sws
->
inp
);
i
++
)
{
uint8_t
*
t
=
(
uint8_t
*
)
taosArrayGet
(
sws
->
inp
,
i
);
buf
[
i
]
=
*
t
;
}
FstSlice
slice
=
fstSliceCreate
(
buf
,
taosArrayGetSize
(
sws
->
inp
));
if
(
fstBoundWithDataExceededBy
(
sws
->
endAt
,
&
slice
))
{
taosArrayDestroyEx
(
sws
->
stack
,
streamStateDestroy
);
sws
->
stack
=
(
SArray
*
)
taosArrayInit
(
256
,
sizeof
(
StreamState
));
return
NULL
;
}
if
(
FST_NODE_IS_FINAL
(
nextNode
)
&&
isMatch
)
{
FstOutput
fOutput
=
{.
null
=
false
,
out
=
out
+
FST_NODE_FINAL_OUTPUT
(
nextNode
)};
return
swsResultCreate
(
&
slice
,
fOutput
,
tState
);
}
}
return
NULL
;
}
StreamWithStateResult
*
swsResultCreate
(
FstSlice
*
data
,
FstOutput
fOut
,
void
*
state
)
{
StreamWithStateResult
*
result
=
calloc
(
1
,
sizeof
(
StreamWithStateResult
));
if
(
result
==
NULL
)
{
return
NULL
;
}
FstSlice
slice
=
fstSliceCopy
(
data
,
0
,
data
->
dLen
-
1
);
result
->
data
=
slice
;
result
->
out
=
fOut
;
result
->
state
=
state
;
return
result
;
}
void
streamStateDestroy
(
void
*
s
)
{
if
(
NULL
==
s
)
{
return
;
}
StreamState
*
ss
=
(
StreamState
*
)
s
;
fstNodeDestroy
(
ss
->
node
);
//free(s->autoState);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录