Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
081cc7cf
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
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看板
未验证
提交
081cc7cf
编写于
11月 22, 2021
作者:
dengyihao
提交者:
GitHub
11月 22, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #8763 from taosdata/origin/3.0/fst
Origin/3.0/fst
上级
29eb9432
0bbe42df
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
256 addition
and
37 deletion
+256
-37
source/libs/index/inc/index_fst.h
source/libs/index/inc/index_fst.h
+11
-10
source/libs/index/inc/index_fst_counting_writer.h
source/libs/index/inc/index_fst_counting_writer.h
+43
-0
source/libs/index/inc/index_fst_node.h
source/libs/index/inc/index_fst_node.h
+8
-0
source/libs/index/inc/index_fst_registry.h
source/libs/index/inc/index_fst_registry.h
+6
-1
source/libs/index/src/index.c
source/libs/index/src/index.c
+1
-0
source/libs/index/src/index_fst.c
source/libs/index/src/index_fst.c
+82
-13
source/libs/index/src/index_fst_counting_writer.c
source/libs/index/src/index_fst_counting_writer.c
+45
-0
source/libs/index/src/index_fst_node.c
source/libs/index/src/index_fst_node.c
+34
-5
source/libs/index/src/index_fst_registry.c
source/libs/index/src/index_fst_registry.c
+25
-8
source/libs/index/test/indexTests.cpp
source/libs/index/test/indexTests.cpp
+1
-0
未找到文件。
source/libs/index/inc/index_fst.h
浏览文件 @
081cc7cf
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include "tarray.h"
#include "tarray.h"
#include "index_fst_util.h"
#include "index_fst_util.h"
#include "index_fst_registry.h"
#include "index_fst_registry.h"
#include "index_fst_counting_writer.h"
typedef
struct
FstNode
FstNode
;
typedef
struct
FstNode
FstNode
;
...
@@ -35,7 +36,6 @@ typedef struct FstRange {
...
@@ -35,7 +36,6 @@ typedef struct FstRange {
typedef
enum
{
OneTransNext
,
OneTrans
,
AnyTrans
,
EmptyFinal
}
State
;
typedef
enum
{
OneTransNext
,
OneTrans
,
AnyTrans
,
EmptyFinal
}
State
;
typedef
enum
{
Included
,
Excluded
,
Unbounded
}
FstBound
;
typedef
enum
{
Included
,
Excluded
,
Unbounded
}
FstBound
;
typedef
uint32_t
CheckSummer
;
/*
/*
...
@@ -49,7 +49,8 @@ typedef struct FstUnFinishedNodes {
...
@@ -49,7 +49,8 @@ typedef struct FstUnFinishedNodes {
#define FST_UNFINISHED_NODES_LEN(nodes) taosArrayGetSize(nodes->stack)
#define FST_UNFINISHED_NODES_LEN(nodes) taosArrayGetSize(nodes->stack)
FstUnFinishedNodes
*
FstUnFinishedNodesCreate
();
FstUnFinishedNodes
*
fstUnFinishedNodesCreate
();
void
fstUnFinishedNodesDestroy
(
FstUnFinishedNodes
*
node
);
void
fstUnFinishedNodesPushEmpty
(
FstUnFinishedNodes
*
nodes
,
bool
isFinal
);
void
fstUnFinishedNodesPushEmpty
(
FstUnFinishedNodes
*
nodes
,
bool
isFinal
);
FstBuilderNode
*
fstUnFinishedNodesPopRoot
(
FstUnFinishedNodes
*
nodes
);
FstBuilderNode
*
fstUnFinishedNodesPopRoot
(
FstUnFinishedNodes
*
nodes
);
FstBuilderNode
*
fstUnFinishedNodesPopFreeze
(
FstUnFinishedNodes
*
nodes
,
CompiledAddr
addr
);
FstBuilderNode
*
fstUnFinishedNodesPopFreeze
(
FstUnFinishedNodes
*
nodes
,
CompiledAddr
addr
);
...
@@ -58,18 +59,13 @@ void fstUnFinishedNodesSetRootOutput(FstUnFinishedNodes *node, Output out);
...
@@ -58,18 +59,13 @@ void fstUnFinishedNodesSetRootOutput(FstUnFinishedNodes *node, Output out);
void
fstUnFinishedNodesTopLastFreeze
(
FstUnFinishedNodes
*
node
,
CompiledAddr
addr
);
void
fstUnFinishedNodesTopLastFreeze
(
FstUnFinishedNodes
*
node
,
CompiledAddr
addr
);
void
fstUnFinishedNodesAddSuffix
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
,
Output
out
);
void
fstUnFinishedNodesAddSuffix
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
,
Output
out
);
uint64_t
fstUnFinishedNodesFindCommPrefix
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
);
uint64_t
fstUnFinishedNodesFindCommPrefix
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
);
uint64_t
FstUnFinishedNodesFindCommPreif
xAndSetOutput
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
,
Output
in
,
Output
*
out
);
uint64_t
fstUnFinishedNodesFindCommPrefi
xAndSetOutput
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
,
Output
in
,
Output
*
out
);
typedef
struct
FstCountingWriter
{
void
*
wtr
;
// wrap any writer that counts and checksum bytes written
uint64_t
count
;
CheckSummer
summer
;
}
FstCountingWriter
;
typedef
struct
FstBuilder
{
typedef
struct
FstBuilder
{
FstCountingWriter
wtr
;
// The FST raw data is written directly to `wtr`.
FstCountingWriter
*
wrt
;
// The FST raw data is written directly to `wtr`.
FstUnFinishedNodes
*
unfinished
;
// The stack of unfinished nodes
FstUnFinishedNodes
*
unfinished
;
// The stack of unfinished nodes
FstRegistry
registry
;
// A map of finished nodes.
FstRegistry
*
registry
;
// A map of finished nodes.
SArray
*
last
;
// The last word added
SArray
*
last
;
// The last word added
CompiledAddr
lastAddr
;
// The address of the last compiled node
CompiledAddr
lastAddr
;
// The address of the last compiled node
uint64_t
len
;
// num of keys added
uint64_t
len
;
// num of keys added
...
@@ -127,6 +123,8 @@ typedef struct FstNode {
...
@@ -127,6 +123,8 @@ typedef struct FstNode {
#define FST_NODE_ADDR(node) node->start
#define FST_NODE_ADDR(node) node->start
FstNode
*
fstNodeCreate
(
int64_t
version
,
CompiledAddr
addr
,
FstSlice
*
data
);
FstNode
*
fstNodeCreate
(
int64_t
version
,
CompiledAddr
addr
,
FstSlice
*
data
);
void
fstNodeDestroy
(
FstNode
*
fstNode
);
FstTransitions
fstNodeTransitionIter
(
FstNode
*
node
);
FstTransitions
fstNodeTransitionIter
(
FstNode
*
node
);
FstTransitions
*
fstNodeTransitions
(
FstNode
*
node
);
FstTransitions
*
fstNodeTransitions
(
FstNode
*
node
);
bool
fstNodeGetTransitionAt
(
FstNode
*
node
,
uint64_t
i
,
FstTransition
*
res
);
bool
fstNodeGetTransitionAt
(
FstNode
*
node
,
uint64_t
i
,
FstTransition
*
res
);
...
@@ -157,6 +155,9 @@ typedef struct FstIndexedValue {
...
@@ -157,6 +155,9 @@ typedef struct FstIndexedValue {
uint64_t
value
;
uint64_t
value
;
}
FstIndexedValue
;
}
FstIndexedValue
;
FstLastTransition
*
fstLastTransitionCreate
(
uint8_t
inp
,
Output
out
);
void
fstLastTransitionDestroy
(
FstLastTransition
*
trn
);
...
...
source/libs/index/inc/index_fst_counting_writer.h
0 → 100644
浏览文件 @
081cc7cf
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __INDEX_FST_COUNTING_WRITER_H__
#define __INDEX_FST_COUNTING_WRITER_H__
typedef
uint32_t
CheckSummer
;
typedef
struct
FstCountingWriter
{
void
*
wrt
;
// wrap any writer that counts and checksum bytes written
uint64_t
count
;
CheckSummer
summer
;
}
FstCountingWriter
;
uint64_t
fstCountingWriterWrite
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
bufLen
);
int
FstCountingWriterFlush
(
FstCountingWriter
*
write
);
FstCountingWriter
*
fstCountingWriterCreate
(
void
*
wtr
);
void
fstCountingWriterDestroy
(
FstCountingWriter
*
w
);
#define FST_WRITER_COUNT(writer) (writer->count)
#define FST_WRITER_INTER_WRITER(writer) (writer->wtr)
#define FST_WRITE_CHECK_SUMMER(writer) (writer->summer)
#endif
source/libs/index/inc/index_fst_node.h
浏览文件 @
081cc7cf
...
@@ -17,7 +17,11 @@
...
@@ -17,7 +17,11 @@
#define __INDEX_FST_NODE_H__
#define __INDEX_FST_NODE_H__
#include "index_fst_util.h"
#include "index_fst_util.h"
#include "index_fst_counting_writer.h"
#define FST_BUILDER_NODE_IS_FINAL(bn) (bn->isFinal)
#define FST_BUILDER_NODE_TRANS_ISEMPTY(bn) (taosArrayGetSize(bn->trans) == 0)
#define FST_BUILDER_NODE_FINALOUTPUT_ISZERO(bn) (bn->finalOutput == 0)
typedef
struct
FstTransition
{
typedef
struct
FstTransition
{
uint8_t
inp
;
//The byte input associated with this transition.
uint8_t
inp
;
//The byte input associated with this transition.
...
@@ -37,4 +41,8 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src);
...
@@ -37,4 +41,8 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src);
void
fstBuilderNodeCloneFrom
(
FstBuilderNode
*
dst
,
FstBuilderNode
*
src
);
void
fstBuilderNodeCloneFrom
(
FstBuilderNode
*
dst
,
FstBuilderNode
*
src
);
bool
fstBuilderNodeCompileTo
(
FstBuilderNode
*
b
,
FstCountingWriter
*
wrt
,
CompiledAddr
lastAddr
,
CompiledAddr
startAddr
);
void
fstBuilderNodeDestroy
(
FstBuilderNode
*
node
);
#endif
#endif
source/libs/index/inc/index_fst_registry.h
浏览文件 @
081cc7cf
...
@@ -24,6 +24,8 @@ typedef struct FstRegistryCell {
...
@@ -24,6 +24,8 @@ typedef struct FstRegistryCell {
FstBuilderNode
*
node
;
FstBuilderNode
*
node
;
}
FstRegistryCell
;
}
FstRegistryCell
;
#define FST_REGISTRY_CELL_IS_EMPTY(cell) (cell->addr == NONE_ADDRESS)
#define FST_REGISTRY_CELL_INSERT(cell, tAddr) do {cell->addr = tAddr;} while(0)
//typedef struct FstRegistryCache {
//typedef struct FstRegistryCache {
...
@@ -44,14 +46,17 @@ typedef struct FstRegistryEntry {
...
@@ -44,14 +46,17 @@ typedef struct FstRegistryEntry {
// Registry relation function
// Registry relation function
typedef
struct
FstRegistry
{
typedef
struct
FstRegistry
{
SArray
*
table
;
SArray
*
table
;
//<FstRegistryCell>
uint64_t
tableSize
;
// num of rows
uint64_t
tableSize
;
// num of rows
uint64_t
mruSize
;
// num of columns
uint64_t
mruSize
;
// num of columns
}
FstRegistry
;
}
FstRegistry
;
//
//
FstRegistry
*
fstRegistryCreate
(
uint64_t
tableSize
,
uint64_t
mruSize
);
FstRegistry
*
fstRegistryCreate
(
uint64_t
tableSize
,
uint64_t
mruSize
);
void
fstRegistryDestroy
(
FstRegistry
*
registry
);
FstRegistryEntry
*
fstRegistryGetEntry
(
FstRegistry
*
registry
,
FstBuilderNode
*
bNode
);
FstRegistryEntry
*
fstRegistryGetEntry
(
FstRegistry
*
registry
,
FstBuilderNode
*
bNode
);
void
fstRegistryEntryDestroy
(
FstRegistryEntry
*
entry
);
#endif
#endif
source/libs/index/src/index.c
浏览文件 @
081cc7cf
...
@@ -183,6 +183,7 @@ void indexMultiTermDestroy(SArray *array) {
...
@@ -183,6 +183,7 @@ void indexMultiTermDestroy(SArray *array) {
}
}
taosArrayDestroy
(
array
);
taosArrayDestroy
(
array
);
}
}
void
indexInit
()
{
void
indexInit
()
{
//do nothing
//do nothing
}
}
source/libs/index/src/index_fst.c
浏览文件 @
081cc7cf
...
@@ -24,6 +24,18 @@ FstUnFinishedNodes *fstUnFinishedNodesCreate() {
...
@@ -24,6 +24,18 @@ FstUnFinishedNodes *fstUnFinishedNodesCreate() {
fstUnFinishedNodesPushEmpty
(
nodes
,
false
);
fstUnFinishedNodesPushEmpty
(
nodes
,
false
);
return
nodes
;
return
nodes
;
}
}
void
unFinishedNodeDestroyElem
(
void
*
elem
)
{
FstBuilderNodeUnfinished
*
b
=
(
FstBuilderNodeUnfinished
*
)
elem
;
fstBuilderNodeDestroy
(
b
->
node
);
free
(
b
->
last
);
}
void
fstUnFinishedNodeDestroy
(
FstUnFinishedNodes
*
nodes
)
{
if
(
nodes
==
NULL
)
{
return
;
}
taosArrayDestroyEx
(
nodes
->
stack
,
unFinishedNodeDestroyElem
);
free
(
nodes
);
}
void
fstUnFinishedNodesPushEmpty
(
FstUnFinishedNodes
*
nodes
,
bool
isFinal
)
{
void
fstUnFinishedNodesPushEmpty
(
FstUnFinishedNodes
*
nodes
,
bool
isFinal
)
{
FstBuilderNode
*
node
=
malloc
(
sizeof
(
FstBuilderNode
));
FstBuilderNode
*
node
=
malloc
(
sizeof
(
FstBuilderNode
));
node
->
isFinal
=
isFinal
;
node
->
isFinal
=
isFinal
;
...
@@ -76,11 +88,11 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output
...
@@ -76,11 +88,11 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output
assert
(
un
->
last
==
NULL
);
assert
(
un
->
last
==
NULL
);
FstLastTransition
*
trn
=
malloc
(
sizeof
(
FstLastTransition
));
trn
->
inp
=
s
->
data
[
s
->
start
];
trn
->
out
=
out
;
un
->
last
=
trn
;
//FstLastTransition *trn = malloc(sizeof(FstLastTransition));
//trn->inp = s->data[s->start];
//trn->out = out;
un
->
last
=
fstLastTransitionCreate
(
s
->
data
[
s
->
start
],
out
);
for
(
uint64_t
i
=
s
->
start
;
i
<=
s
->
end
;
i
++
)
{
for
(
uint64_t
i
=
s
->
start
;
i
<=
s
->
end
;
i
++
)
{
FstBuilderNode
*
n
=
malloc
(
sizeof
(
FstBuilderNode
));
FstBuilderNode
*
n
=
malloc
(
sizeof
(
FstBuilderNode
));
...
@@ -88,9 +100,10 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output
...
@@ -88,9 +100,10 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output
n
->
finalOutput
=
0
;
n
->
finalOutput
=
0
;
n
->
trans
=
NULL
;
n
->
trans
=
NULL
;
FstLastTransition
*
trn
=
malloc
(
sizeof
(
FstLastTransition
));
//FstLastTransition *trn = malloc(sizeof(FstLastTransition));
trn
->
inp
=
s
->
data
[
i
];
//trn->inp = s->data[i];
trn
->
out
=
out
;
//trn->out = out;
FstLastTransition
*
trn
=
fstLastTransitionCreate
(
s
->
data
[
i
],
out
);
FstBuilderNodeUnfinished
un
=
{.
node
=
n
,
.
last
=
trn
};
FstBuilderNodeUnfinished
un
=
{.
node
=
n
,
.
last
=
trn
};
taosArrayPush
(
nodes
->
stack
,
&
un
);
taosArrayPush
(
nodes
->
stack
,
&
un
);
...
@@ -116,7 +129,7 @@ uint64_t fstUnFinishedNodesFindCommPrefix(FstUnFinishedNodes *node, FstSlice bs)
...
@@ -116,7 +129,7 @@ uint64_t fstUnFinishedNodesFindCommPrefix(FstUnFinishedNodes *node, FstSlice bs)
}
}
return
count
;
return
count
;
}
}
uint64_t
F
stUnFinishedNodesFindCommPrefixAndSetOutput
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
,
Output
in
,
Output
*
out
)
{
uint64_t
f
stUnFinishedNodesFindCommPrefixAndSetOutput
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
,
Output
in
,
Output
*
out
)
{
FstSlice
*
s
=
&
bs
;
FstSlice
*
s
=
&
bs
;
size_t
lsz
=
(
size_t
)(
s
->
end
-
s
->
start
+
1
);
// data len
size_t
lsz
=
(
size_t
)(
s
->
end
-
s
->
start
+
1
);
// data len
...
@@ -199,6 +212,10 @@ FstNode *fstNodeCreate(int64_t version, CompiledAddr addr, FstSlice *slice) {
...
@@ -199,6 +212,10 @@ FstNode *fstNodeCreate(int64_t version, CompiledAddr addr, FstSlice *slice) {
}
}
return
n
;
return
n
;
}
}
void
fstNodeDestroy
(
FstNode
*
node
)
{
if
(
node
==
NULL
)
{
return
;
}
free
(
node
);
}
FstTransitions
*
fstNodeTransitions
(
FstNode
*
node
)
{
FstTransitions
*
fstNodeTransitions
(
FstNode
*
node
)
{
FstTransitions
*
t
=
malloc
(
sizeof
(
FstTransitions
));
FstTransitions
*
t
=
malloc
(
sizeof
(
FstTransitions
));
if
(
NULL
==
t
)
{
if
(
NULL
==
t
)
{
...
@@ -275,22 +292,74 @@ bool fstNodeCompile(FstNode *node, void *w, CompiledAddr lastAddr, CompiledAddr
...
@@ -275,22 +292,74 @@ bool fstNodeCompile(FstNode *node, void *w, CompiledAddr lastAddr, CompiledAddr
}
}
FstBuilder
*
fstBuilderCreate
(
void
*
w
,
FstType
ty
)
{
FstBuilder
*
fstBuilderCreate
(
void
*
w
,
FstType
ty
)
{
FstBuilder
*
b
=
malloc
(
sizeof
(
FstBuilder
));
FstBuilder
*
b
=
malloc
(
sizeof
(
FstBuilder
));
if
(
NULL
==
b
)
{
return
b
;
}
if
(
NULL
==
b
)
{
return
b
;
}
FstCountingWriter
wtr
=
{.
wtr
=
w
,
.
count
=
0
,
.
summer
=
0
};
b
->
wtr
=
wtr
;
b
->
wrt
=
fstCountingWriterCreate
(
w
);
b
->
unfinished
=
malloc
(
sizeof
(
FstUnFinishedNodes
));
b
->
unfinished
=
fstUnFinishedNodesCreate
();
b
->
registry
=
fstRegistryCreate
(
10000
,
2
)
;
b
->
last
=
NULL
;
b
->
lastAddr
=
NONE_ADDRESS
;
b
->
len
=
0
;
return
b
;
return
b
;
}
void
fstBuilderCheckLastKey
(
FstBuilder
*
b
,
FstSlice
bs
,
bool
ckDupe
)
{
return
;
}
CompiledAddr
fstBuilderCompile
(
FstBuilder
*
b
,
FstBuilderNode
*
bn
)
{
if
(
FST_BUILDER_NODE_IS_FINAL
(
bn
)
&&
FST_BUILDER_NODE_TRANS_ISEMPTY
(
bn
)
&&
FST_BUILDER_NODE_FINALOUTPUT_ISZERO
(
bn
))
{
return
EMPTY_ADDRESS
;
}
FstRegistryEntry
*
entry
=
fstRegistryGetEntry
(
b
->
registry
,
bn
);
if
(
entry
->
state
==
FOUND
)
{
CompiledAddr
ret
=
entry
->
addr
;
fstRegistryEntryDestroy
(
entry
);
return
ret
;
}
CompiledAddr
startAddr
=
(
CompiledAddr
)(
FST_WRITER_COUNT
(
b
->
wrt
));
fstBuilderNodeCompileTo
(
bn
,
b
->
wrt
,
b
->
lastAddr
,
startAddr
);
b
->
lastAddr
=
(
CompiledAddr
)(
FST_WRITER_COUNT
(
b
->
wrt
)
-
1
);
if
(
entry
->
state
==
NOTFOUND
)
{
FST_REGISTRY_CELL_INSERT
(
entry
->
cell
,
b
->
lastAddr
);
}
fstRegistryEntryDestroy
(
entry
);
return
b
->
lastAddr
;
}
}
FstSlice
fstNodeAsSlice
(
FstNode
*
node
)
{
FstSlice
fstNodeAsSlice
(
FstNode
*
node
)
{
FstSlice
*
slice
=
&
node
->
data
;
FstSlice
*
slice
=
&
node
->
data
;
FstSlice
s
=
fstSliceCopy
(
slice
,
slice
->
end
,
slice
->
dLen
-
1
);
FstSlice
s
=
fstSliceCopy
(
slice
,
slice
->
end
,
slice
->
dLen
-
1
);
return
s
;
return
s
;
}
}
FstLastTransition
*
fstLastTransitionCreate
(
uint8_t
inp
,
Output
out
)
{
FstLastTransition
*
trn
=
malloc
(
sizeof
(
FstLastTransition
));
if
(
trn
==
NULL
)
{
return
NULL
;
}
trn
->
inp
=
inp
;
trn
->
out
=
out
;
return
trn
;
}
void
fstLastTransitionDestroy
(
FstLastTransition
*
trn
)
{
free
(
trn
);
}
void
fstBuilderNodeUnfinishedLastCompiled
(
FstBuilderNodeUnfinished
*
node
,
CompiledAddr
addr
)
{
return
;
}
void
fstBuilderNodeUnfinishedAddOutputPrefix
(
FstBuilderNodeUnfinished
*
node
,
CompiledAddr
addr
)
{
return
;
}
source/libs/index/src/index_fst_counting_writer.c
0 → 100644
浏览文件 @
081cc7cf
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tutil.h"
#include "index_fst_counting_writer.h"
FstCountingWriter
*
fstCountingWriterCreate
(
void
*
wrt
)
{
FstCountingWriter
*
cw
=
calloc
(
1
,
sizeof
(
FstCountingWriter
));
if
(
cw
==
NULL
)
{
return
NULL
;
}
cw
->
wrt
=
wrt
;
return
cw
;
}
void
fstCountingWriterDestroy
(
FstCountingWriter
*
cw
)
{
// free wrt object: close fd or free mem
free
(
cw
);
}
uint64_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
;
return
bufLen
;
}
int
FstCountingWriterFlush
(
FstCountingWriter
*
write
)
{
//write->wtr->flush
return
1
;
}
source/libs/index/src/index_fst_node.c
浏览文件 @
081cc7cf
...
@@ -21,19 +21,23 @@ FstBuilderNode *fstBuilderNodeDefault() {
...
@@ -21,19 +21,23 @@ FstBuilderNode *fstBuilderNodeDefault() {
bn
->
trans
=
NULL
;
bn
->
trans
=
NULL
;
return
bn
;
return
bn
;
}
}
void
fstBuilderNodeDestroy
(
FstBuilderNode
*
node
)
{
if
(
node
==
NULL
)
{
return
;
}
taosArrayDestroy
(
node
->
trans
);
free
(
node
);
}
FstBuilderNode
*
fstBuilderNodeClone
(
FstBuilderNode
*
src
)
{
FstBuilderNode
*
fstBuilderNodeClone
(
FstBuilderNode
*
src
)
{
FstBuilderNode
*
node
=
malloc
(
sizeof
(
FstBuilderNode
));
FstBuilderNode
*
node
=
malloc
(
sizeof
(
FstBuilderNode
));
if
(
node
==
NULL
)
{
return
NULL
;
}
if
(
node
==
NULL
)
{
return
NULL
;
}
//
size_t
sz
=
taosArrayGetSize
(
src
->
trans
);
size_t
sz
=
taosArrayGetSize
(
src
->
trans
);
SArray
*
trans
=
taosArrayInit
(
sz
,
sizeof
(
FstTransition
));
SArray
*
trans
=
taosArrayInit
(
sz
,
sizeof
(
FstTransition
));
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
FstTransition
*
tran
=
taosArrayGet
(
src
->
trans
,
i
);
FstTransition
*
tran
=
taosArrayGet
(
src
->
trans
,
i
);
FstTransition
t
=
*
tran
;
taosArrayPush
(
trans
,
tran
);
taosArrayPush
(
trans
,
&
t
);
}
}
node
->
trans
=
trans
;
node
->
trans
=
trans
;
...
@@ -47,9 +51,34 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src) {
...
@@ -47,9 +51,34 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src) {
if
(
dst
==
NULL
||
src
==
NULL
)
{
return
;
}
if
(
dst
==
NULL
||
src
==
NULL
)
{
return
;
}
dst
->
isFinal
=
src
->
isFinal
;
dst
->
isFinal
=
src
->
isFinal
;
dst
->
finalOutput
=
src
->
finalOutput
;
dst
->
finalOutput
=
src
->
finalOutput
;
dst
->
trans
=
src
->
trans
;
// avoid mem leak
taosArrayDestroy
(
dst
->
trans
);
dst
->
trans
=
src
->
trans
;
src
->
trans
=
NULL
;
src
->
trans
=
NULL
;
}
}
bool
fstBuilderNodeCompileTo
(
FstBuilderNode
*
b
,
FstCountingWriter
*
wrt
,
CompiledAddr
lastAddr
,
CompiledAddr
startAddr
)
{
size_t
sz
=
taosArrayGetSize
(
b
->
trans
);
assert
(
sz
<
256
);
if
(
FST_BUILDER_NODE_IS_FINAL
(
b
)
&&
FST_BUILDER_NODE_TRANS_ISEMPTY
(
b
)
&&
FST_BUILDER_NODE_FINALOUTPUT_ISZERO
(
b
))
{
return
true
;
}
else
if
(
sz
!=
1
||
b
->
isFinal
)
{
// AnyTrans->Compile(w, addr, node);
}
else
{
FstTransition
*
tran
=
taosArrayGet
(
b
->
trans
,
0
);
if
(
tran
->
addr
==
lastAddr
&&
tran
->
out
==
0
)
{
//OneTransNext::compile(w, lastAddr, tran->inp);
return
true
;
}
else
{
//OneTrans::Compile(w, lastAddr, *tran);
return
true
;
}
}
return
true
;
}
source/libs/index/src/index_fst_registry.c
浏览文件 @
081cc7cf
...
@@ -32,6 +32,7 @@ uint64_t fstRegistryHash(FstRegistry *registry, FstBuilderNode *bNode) {
...
@@ -32,6 +32,7 @@ uint64_t fstRegistryHash(FstRegistry *registry, FstBuilderNode *bNode) {
h
=
(
h
^
(
uint64_t
)(
trn
->
addr
))
*
FNV_PRIME
;
h
=
(
h
^
(
uint64_t
)(
trn
->
addr
))
*
FNV_PRIME
;
}
}
return
h
%
(
registry
->
tableSize
);
return
h
%
(
registry
->
tableSize
);
}
}
static
void
fstRegistryCellSwap
(
SArray
*
arr
,
uint32_t
a
,
uint32_t
b
)
{
static
void
fstRegistryCellSwap
(
SArray
*
arr
,
uint32_t
a
,
uint32_t
b
)
{
size_t
sz
=
taosArrayGetSize
(
arr
);
size_t
sz
=
taosArrayGetSize
(
arr
);
...
@@ -63,8 +64,6 @@ static void fstRegistryCellPromote(SArray *arr, uint32_t start, uint32_t end) {
...
@@ -63,8 +64,6 @@ static void fstRegistryCellPromote(SArray *arr, uint32_t start, uint32_t end) {
s
-=
1
;
s
-=
1
;
}
}
}
}
#define FST_REGISTRY_CELL_IS_EMPTY(cell) (cell->addr == NONE_ADDRESS)
#define FST_REGISTRY_CELL_INSERT(cell, addr) do {cell->addr = addr;} while(0)
FstRegistry
*
fstRegistryCreate
(
uint64_t
tableSize
,
uint64_t
mruSize
)
{
FstRegistry
*
fstRegistryCreate
(
uint64_t
tableSize
,
uint64_t
mruSize
)
{
FstRegistry
*
registry
=
malloc
(
sizeof
(
FstRegistry
));
FstRegistry
*
registry
=
malloc
(
sizeof
(
FstRegistry
));
...
@@ -72,10 +71,14 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) {
...
@@ -72,10 +71,14 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) {
uint64_t
nCells
=
tableSize
*
mruSize
;
uint64_t
nCells
=
tableSize
*
mruSize
;
SArray
*
tb
=
(
SArray
*
)
taosArrayInit
(
nCells
,
sizeof
(
FstRegistryCell
));
SArray
*
tb
=
(
SArray
*
)
taosArrayInit
(
nCells
,
sizeof
(
FstRegistryCell
));
if
(
NULL
==
tb
)
{
free
(
registry
);
return
NULL
;
}
for
(
uint64_t
i
=
0
;
i
<
nCells
;
i
++
)
{
for
(
uint64_t
i
=
0
;
i
<
nCells
;
i
++
)
{
FstRegistryCell
*
cell
=
taosArrayGet
(
tb
,
i
);
FstRegistryCell
cell
=
{.
addr
=
NONE_ADDRESS
,
.
node
=
fstBuilderNodeDefault
()};
cell
->
addr
=
NONE_ADDRESS
;
taosArrayPush
(
tb
,
&
cell
);
cell
->
node
=
fstBuilderNodeDefault
();
}
}
registry
->
table
=
tb
;
registry
->
table
=
tb
;
...
@@ -84,6 +87,19 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) {
...
@@ -84,6 +87,19 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) {
return
registry
;
return
registry
;
}
}
void
fstRegistryDestroy
(
FstRegistry
*
registry
)
{
if
(
registry
==
NULL
)
{
return
;
}
SArray
*
tb
=
registry
->
table
;
size_t
sz
=
taosArrayGetSize
(
tb
);
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
FstRegistryCell
*
cell
=
taosArrayGet
(
tb
,
i
);
fstBuilderNodeDestroy
(
cell
->
node
);
}
taosArrayDestroy
(
tb
);
free
(
registry
);
}
FstRegistryEntry
*
fstRegistryGetEntry
(
FstRegistry
*
registry
,
FstBuilderNode
*
bNode
)
{
FstRegistryEntry
*
fstRegistryGetEntry
(
FstRegistry
*
registry
,
FstBuilderNode
*
bNode
)
{
if
(
taosArrayGetSize
(
registry
->
table
)
<=
0
)
{
if
(
taosArrayGetSize
(
registry
->
table
)
<=
0
)
{
return
NULL
;
return
NULL
;
...
@@ -98,11 +114,9 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
...
@@ -98,11 +114,9 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
//cell->isNode &&
//cell->isNode &&
if
(
cell
->
addr
!=
NONE_ADDRESS
&&
cell
->
node
==
bNode
)
{
if
(
cell
->
addr
!=
NONE_ADDRESS
&&
cell
->
node
==
bNode
)
{
entry
->
state
=
FOUND
;
entry
->
state
=
FOUND
;
entry
->
addr
=
cell
->
addr
;
entry
->
addr
=
cell
->
addr
;
return
entry
;
return
entry
;
}
else
{
}
else
{
// clone from bNode, refactor later
//
fstBuilderNodeCloneFrom
(
cell
->
node
,
bNode
);
fstBuilderNodeCloneFrom
(
cell
->
node
,
bNode
);
entry
->
state
=
NOTFOUND
;
entry
->
state
=
NOTFOUND
;
entry
->
cell
=
cell
;
// copy or not
entry
->
cell
=
cell
;
// copy or not
...
@@ -154,5 +168,8 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
...
@@ -154,5 +168,8 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
}
}
return
entry
;
return
entry
;
}
}
void
fstRegistryEntryDestroy
(
FstRegistryEntry
*
entry
)
{
free
(
entry
);
}
source/libs/index/test/indexTests.cpp
浏览文件 @
081cc7cf
...
@@ -51,6 +51,7 @@ TEST(IndexTest, index_create_test) {
...
@@ -51,6 +51,7 @@ TEST(IndexTest, index_create_test) {
int
*
v
=
(
int
*
)
taosArrayGet
(
result
,
i
);
int
*
v
=
(
int
*
)
taosArrayGet
(
result
,
i
);
std
::
cout
<<
"value --->"
<<
*
v
<<
std
::
endl
;
std
::
cout
<<
"value --->"
<<
*
v
<<
std
::
endl
;
}
}
// add more test case
indexMultiTermQueryDestroy
(
multiQuery
);
indexMultiTermQueryDestroy
(
multiQuery
);
indexOptsDestroy
(
opts
);
indexOptsDestroy
(
opts
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录