Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5f0fd023
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看板
提交
5f0fd023
编写于
12月 03, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test case
上级
4bab45c0
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
129 addition
and
54 deletion
+129
-54
source/libs/index/inc/index_fst.h
source/libs/index/inc/index_fst.h
+9
-0
source/libs/index/inc/index_fst_automation.h
source/libs/index/inc/index_fst_automation.h
+7
-1
source/libs/index/inc/index_fst_common.h
source/libs/index/inc/index_fst_common.h
+9
-0
source/libs/index/inc/index_fst_counting_writer.h
source/libs/index/inc/index_fst_counting_writer.h
+8
-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
+8
-0
source/libs/index/inc/index_fst_util.h
source/libs/index/inc/index_fst_util.h
+7
-0
source/libs/index/src/index_fst.c
source/libs/index/src/index_fst.c
+4
-4
source/libs/index/src/index_fst_counting_writer.c
source/libs/index/src/index_fst_counting_writer.c
+1
-1
source/libs/index/test/CMakeLists.txt
source/libs/index/test/CMakeLists.txt
+0
-1
source/libs/index/test/indexTests.cpp
source/libs/index/test/indexTests.cpp
+68
-47
未找到文件。
source/libs/index/inc/index_fst.h
浏览文件 @
5f0fd023
...
@@ -16,6 +16,9 @@
...
@@ -16,6 +16,9 @@
#ifndef __INDEX_FST_H__
#ifndef __INDEX_FST_H__
#define __INDEX_FST_H__
#define __INDEX_FST_H__
#ifdef __cplusplus
extern
"C"
{
#endif
#include "tarray.h"
#include "tarray.h"
#include "index_fst_util.h"
#include "index_fst_util.h"
...
@@ -98,6 +101,7 @@ FstBuilder *fstBuilderCreate(void *w, FstType ty);
...
@@ -98,6 +101,7 @@ FstBuilder *fstBuilderCreate(void *w, FstType ty);
void
fstBuilderDestroy
(
FstBuilder
*
b
);
void
fstBuilderDestroy
(
FstBuilder
*
b
);
void
fstBuilderInsertOutput
(
FstBuilder
*
b
,
FstSlice
bs
,
Output
in
);
void
fstBuilderInsertOutput
(
FstBuilder
*
b
,
FstSlice
bs
,
Output
in
);
bool
fstBuilderInsert
(
FstBuilder
*
b
,
FstSlice
bs
,
Output
in
);
OrderType
fstBuilderCheckLastKey
(
FstBuilder
*
b
,
FstSlice
bs
,
bool
ckDup
);
OrderType
fstBuilderCheckLastKey
(
FstBuilder
*
b
,
FstSlice
bs
,
bool
ckDup
);
void
fstBuilderCompileFrom
(
FstBuilder
*
b
,
uint64_t
istate
);
void
fstBuilderCompileFrom
(
FstBuilder
*
b
,
uint64_t
istate
);
CompiledAddr
fstBuilderCompile
(
FstBuilder
*
b
,
FstBuilderNode
*
bn
);
CompiledAddr
fstBuilderCompile
(
FstBuilder
*
b
,
FstBuilderNode
*
bn
);
...
@@ -324,4 +328,9 @@ FstStreamBuilder *fstStreamBuilderCreate(Fst *fst, Automation *aut);
...
@@ -324,4 +328,9 @@ FstStreamBuilder *fstStreamBuilderCreate(Fst *fst, Automation *aut);
FstStreamBuilder
*
fstStreamBuilderRange
(
FstStreamBuilder
*
b
,
FstSlice
*
val
,
RangeType
type
);
FstStreamBuilder
*
fstStreamBuilderRange
(
FstStreamBuilder
*
b
,
FstSlice
*
val
,
RangeType
type
);
#ifdef __cplusplus
}
#endif
#endif
#endif
source/libs/index/inc/index_fst_automation.h
浏览文件 @
5f0fd023
...
@@ -15,6 +15,10 @@
...
@@ -15,6 +15,10 @@
#ifndef __INDEX_FST_AUTAOMATION_H__
#ifndef __INDEX_FST_AUTAOMATION_H__
#define __INDEX_FST_AUTAOMATION_H__
#define __INDEX_FST_AUTAOMATION_H__
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
AutomationCtx
AutomationCtx
;
typedef
struct
AutomationCtx
AutomationCtx
;
typedef
struct
StartWith
{
typedef
struct
StartWith
{
...
@@ -42,6 +46,8 @@ typedef struct Automation {
...
@@ -42,6 +46,8 @@ typedef struct Automation {
void
*
data
;
void
*
data
;
}
Automation
;
}
Automation
;
#ifdef __cplusplus
}
#endif
#endif
#endif
source/libs/index/inc/index_fst_common.h
浏览文件 @
5f0fd023
#ifndef __INDEX_FST_COMM_H__
#ifndef __INDEX_FST_COMM_H__
#define __INDEX_FST_COMM_H__
#define __INDEX_FST_COMM_H__
extern
const
uint8_t
COMMON_INPUTS
[];
extern
const
uint8_t
COMMON_INPUTS
[];
extern
char
const
COMMON_INPUTS_INV
[];
extern
char
const
COMMON_INPUTS_INV
[];
#ifdef __cplusplus
extern
"C"
{
#endif
#ifdef __cplusplus
}
#endif
#endif
#endif
source/libs/index/inc/index_fst_counting_writer.h
浏览文件 @
5f0fd023
...
@@ -16,6 +16,10 @@
...
@@ -16,6 +16,10 @@
#ifndef __INDEX_FST_COUNTING_WRITER_H__
#ifndef __INDEX_FST_COUNTING_WRITER_H__
#define __INDEX_FST_COUNTING_WRITER_H__
#define __INDEX_FST_COUNTING_WRITER_H__
#ifdef __cplusplus
extern
"C"
{
#endif
#include "tfile.h"
#include "tfile.h"
...
@@ -72,6 +76,10 @@ uint8_t fstCountingWriterPackUint(FstCountingWriter *writer, uint64_t n);
...
@@ -72,6 +76,10 @@ uint8_t fstCountingWriterPackUint(FstCountingWriter *writer, uint64_t n);
#define FST_WRITER_INTER_WRITER(writer) (writer->wtr)
#define FST_WRITER_INTER_WRITER(writer) (writer->wtr)
#define FST_WRITE_CHECK_SUMMER(writer) (writer->summer)
#define FST_WRITE_CHECK_SUMMER(writer) (writer->summer)
#ifdef __cplusplus
}
#endif
#endif
#endif
source/libs/index/inc/index_fst_node.h
浏览文件 @
5f0fd023
...
@@ -16,6 +16,10 @@
...
@@ -16,6 +16,10 @@
#ifndef __INDEX_FST_NODE_H__
#ifndef __INDEX_FST_NODE_H__
#define __INDEX_FST_NODE_H__
#define __INDEX_FST_NODE_H__
#ifdef __cplusplus
extern
"C"
{
#endif
#include "index_fst_util.h"
#include "index_fst_util.h"
#include "index_fst_counting_writer.h"
#include "index_fst_counting_writer.h"
...
@@ -45,4 +49,8 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src);
...
@@ -45,4 +49,8 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src);
void
fstBuilderNodeDestroy
(
FstBuilderNode
*
node
);
void
fstBuilderNodeDestroy
(
FstBuilderNode
*
node
);
#ifdef __cplusplus
}
#endif
#endif
#endif
source/libs/index/inc/index_fst_registry.h
浏览文件 @
5f0fd023
...
@@ -15,6 +15,10 @@
...
@@ -15,6 +15,10 @@
#ifndef __FST_REGISTRY_H__
#ifndef __FST_REGISTRY_H__
#define __FST_REGISTRY_H__
#define __FST_REGISTRY_H__
#ifdef __cplusplus
extern
"C"
{
#endif
#include "index_fst_util.h"
#include "index_fst_util.h"
#include "tarray.h"
#include "tarray.h"
#include "index_fst_node.h"
#include "index_fst_node.h"
...
@@ -59,4 +63,8 @@ void fstRegistryDestroy(FstRegistry *registry);
...
@@ -59,4 +63,8 @@ void fstRegistryDestroy(FstRegistry *registry);
FstRegistryEntry
*
fstRegistryGetEntry
(
FstRegistry
*
registry
,
FstBuilderNode
*
bNode
);
FstRegistryEntry
*
fstRegistryGetEntry
(
FstRegistry
*
registry
,
FstBuilderNode
*
bNode
);
void
fstRegistryEntryDestroy
(
FstRegistryEntry
*
entry
);
void
fstRegistryEntryDestroy
(
FstRegistryEntry
*
entry
);
#ifdef __cplusplus
}
#endif
#endif
#endif
source/libs/index/inc/index_fst_util.h
浏览文件 @
5f0fd023
...
@@ -17,6 +17,10 @@
...
@@ -17,6 +17,10 @@
#ifndef __INDEX_FST_UTIL_H__
#ifndef __INDEX_FST_UTIL_H__
#define __INDEX_FST_UTIL_H__
#define __INDEX_FST_UTIL_H__
#ifdef __cplusplus
extern
"C"
{
#endif
#include "tarray.h"
#include "tarray.h"
#include "index_fst_common.h"
#include "index_fst_common.h"
...
@@ -89,5 +93,8 @@ uint8_t *fstSliceData(FstSlice *s, int32_t *sz);
...
@@ -89,5 +93,8 @@ uint8_t *fstSliceData(FstSlice *s, int32_t *sz);
#define FST_SLICE_LEN(s) (s->end - s->start + 1)
#define FST_SLICE_LEN(s) (s->end - s->start + 1)
#ifdef __cplusplus
}
#endif
#endif
#endif
source/libs/index/src/index_fst.c
浏览文件 @
5f0fd023
...
@@ -52,7 +52,7 @@ void fstUnFinishedNodesPushEmpty(FstUnFinishedNodes *nodes, bool isFinal) {
...
@@ -52,7 +52,7 @@ void fstUnFinishedNodesPushEmpty(FstUnFinishedNodes *nodes, bool isFinal) {
FstBuilderNode
*
node
=
malloc
(
sizeof
(
FstBuilderNode
));
FstBuilderNode
*
node
=
malloc
(
sizeof
(
FstBuilderNode
));
node
->
isFinal
=
isFinal
;
node
->
isFinal
=
isFinal
;
node
->
finalOutput
=
0
;
node
->
finalOutput
=
0
;
node
->
trans
=
NULL
;
node
->
trans
=
taosArrayInit
(
16
,
sizeof
(
FstTransition
))
;
FstBuilderNodeUnfinished
un
=
{.
node
=
node
,
.
last
=
NULL
};
FstBuilderNodeUnfinished
un
=
{.
node
=
node
,
.
last
=
NULL
};
taosArrayPush
(
nodes
->
stack
,
&
un
);
taosArrayPush
(
nodes
->
stack
,
&
un
);
...
@@ -112,7 +112,7 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output
...
@@ -112,7 +112,7 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output
FstBuilderNode
*
n
=
malloc
(
sizeof
(
FstBuilderNode
));
FstBuilderNode
*
n
=
malloc
(
sizeof
(
FstBuilderNode
));
n
->
isFinal
=
false
;
n
->
isFinal
=
false
;
n
->
finalOutput
=
0
;
n
->
finalOutput
=
0
;
n
->
trans
=
NULL
;
n
->
trans
=
taosArrayInit
(
16
,
sizeof
(
FstTransition
))
;
//FstLastTransition *trn = malloc(sizeof(FstLastTransition));
//FstLastTransition *trn = malloc(sizeof(FstLastTransition));
//trn->inp = s->data[i];
//trn->inp = s->data[i];
...
@@ -806,13 +806,13 @@ void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) {
...
@@ -806,13 +806,13 @@ void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) {
fstUnFinishedNodesSetRootOutput
(
b
->
unfinished
,
in
);
fstUnFinishedNodesSetRootOutput
(
b
->
unfinished
,
in
);
return
;
return
;
}
}
Output
out
;
//if (in != 0) { //if let Some(in) = in
//if (in != 0) { //if let Some(in) = in
// prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out);
// prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out);
//} else {
//} else {
// prefixLen = fstUnFinishedNodesFindCommPrefix(b->unfinished, bs);
// prefixLen = fstUnFinishedNodesFindCommPrefix(b->unfinished, bs);
// out = 0;
// out = 0;
//}
//}
Output
out
;
uint64_t
prefixLen
=
fstUnFinishedNodesFindCommPrefixAndSetOutput
(
b
->
unfinished
,
bs
,
in
,
&
out
);
uint64_t
prefixLen
=
fstUnFinishedNodesFindCommPrefixAndSetOutput
(
b
->
unfinished
,
bs
,
in
,
&
out
);
if
(
prefixLen
==
FST_SLICE_LEN
(
s
))
{
if
(
prefixLen
==
FST_SLICE_LEN
(
s
))
{
...
@@ -857,7 +857,7 @@ void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate) {
...
@@ -857,7 +857,7 @@ void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate) {
}
}
addr
=
fstBuilderCompile
(
b
,
n
);
addr
=
fstBuilderCompile
(
b
,
n
);
assert
(
addr
!=
NONE_ADDRESS
);
assert
(
addr
!=
NONE_ADDRESS
);
fstBuilderNodeDestroy
(
n
);
//
fstBuilderNodeDestroy(n);
}
}
fstUnFinishedNodesTopLastFreeze
(
b
->
unfinished
,
addr
);
fstUnFinishedNodesTopLastFreeze
(
b
->
unfinished
,
addr
);
return
;
return
;
...
...
source/libs/index/src/index_fst_counting_writer.c
浏览文件 @
5f0fd023
...
@@ -81,7 +81,7 @@ FstCountingWriter *fstCountingWriterCreate(void *wrt) {
...
@@ -81,7 +81,7 @@ FstCountingWriter *fstCountingWriterCreate(void *wrt) {
FstCountingWriter
*
cw
=
calloc
(
1
,
sizeof
(
FstCountingWriter
));
FstCountingWriter
*
cw
=
calloc
(
1
,
sizeof
(
FstCountingWriter
));
if
(
cw
==
NULL
)
{
return
NULL
;
}
if
(
cw
==
NULL
)
{
return
NULL
;
}
cw
->
wrt
=
(
void
*
)(
writerCtxCreate
(
T
Memory
));
cw
->
wrt
=
(
void
*
)(
writerCtxCreate
(
T
File
));
return
cw
;
return
cw
;
}
}
void
fstCountingWriterDestroy
(
FstCountingWriter
*
cw
)
{
void
fstCountingWriterDestroy
(
FstCountingWriter
*
cw
)
{
...
...
source/libs/index/test/CMakeLists.txt
浏览文件 @
5f0fd023
add_executable
(
indexTest
""
)
add_executable
(
indexTest
""
)
target_sources
(
indexTest
target_sources
(
indexTest
PRIVATE
PRIVATE
"../src/index.c"
"indexTests.cpp"
"indexTests.cpp"
)
)
target_include_directories
(
indexTest
target_include_directories
(
indexTest
...
...
source/libs/index/test/indexTests.cpp
浏览文件 @
5f0fd023
...
@@ -3,58 +3,79 @@
...
@@ -3,58 +3,79 @@
#include <iostream>
#include <iostream>
#include "index.h"
#include "index.h"
#include "indexInt.h"
#include "indexInt.h"
#include "index_fst.h"
#include "index_fst_util.h"
#include "index_fst_counting_writer.h"
TEST
(
IndexTest
,
index_create_test
)
{
//TEST(IndexTest, index_create_test) {
SIndexOpts
*
opts
=
indexOptsCreate
();
// SIndexOpts *opts = indexOptsCreate();
SIndex
*
index
=
indexOpen
(
opts
,
"./test"
);
// SIndex *index = indexOpen(opts, "./test");
if
(
index
==
NULL
)
{
// if (index == NULL) {
std
::
cout
<<
"index open failed"
<<
std
::
endl
;
// std::cout << "index open failed" << std::endl;
}
// }
//
//
// // write
// for (int i = 0; i < 100000; i++) {
// SIndexMultiTerm* terms = indexMultiTermCreate();
// std::string val = "field";
//
// indexMultiTermAdd(terms, "tag1", strlen("tag1"), val.c_str(), val.size());
//
// val.append(std::to_string(i));
// indexMultiTermAdd(terms, "tag2", strlen("tag2"), val.c_str(), val.size());
//
// val.insert(0, std::to_string(i));
// indexMultiTermAdd(terms, "tag3", strlen("tag3"), val.c_str(), val.size());
//
// val.append("const");
// indexMultiTermAdd(terms, "tag4", strlen("tag4"), val.c_str(), val.size());
//
//
// indexPut(index, terms, i);
// indexMultiTermDestroy(terms);
// }
//
//
// // query
// SIndexMultiTermQuery *multiQuery = indexMultiTermQueryCreate(MUST);
//
// indexMultiTermQueryAdd(multiQuery, "tag1", strlen("tag1"), "field", strlen("field"), QUERY_PREFIX);
// indexMultiTermQueryAdd(multiQuery, "tag3", strlen("tag3"), "0field0", strlen("0field0"), QUERY_TERM);
//
// SArray *result = (SArray *)taosArrayInit(10, sizeof(int));
// indexSearch(index, multiQuery, result);
//
// std::cout << "taos'size : " << taosArrayGetSize(result) << std::endl;
// for (int i = 0; i < taosArrayGetSize(result); i++) {
// int *v = (int *)taosArrayGet(result, i);
// std::cout << "value --->" << *v << std::endl;
// }
// // add more test case
// indexMultiTermQueryDestroy(multiQuery);
//
// indexOptsDestroy(opts);
// indexClose(index);
// //
//}
int
main
(
int
argc
,
char
**
argv
)
{
// write
std
::
string
str
(
"Hello world"
);
for
(
int
i
=
0
;
i
<
100000
;
i
++
)
{
FstSlice
key
=
fstSliceCreate
((
uint8_t
*
)
str
.
c_str
(),
str
.
size
());
SIndexMultiTerm
*
terms
=
indexMultiTermCreate
();
Output
val
=
10
;
std
::
string
val
=
"field"
;
FstBuilder
*
b
=
fstBuilderCreate
(
NULL
,
1
);
fstBuilderInsert
(
b
,
key
,
val
);
indexMultiTermAdd
(
terms
,
"tag1"
,
strlen
(
"tag1"
),
val
.
c_str
(),
val
.
size
());
fstBuilderFinish
(
b
);
fstBuilderDestroy
(
b
);
val
.
append
(
std
::
to_string
(
i
));
fstSliceDestroy
(
&
key
);
indexMultiTermAdd
(
terms
,
"tag2"
,
strlen
(
"tag2"
),
val
.
c_str
(),
val
.
size
());
return
1
;
}
val
.
insert
(
0
,
std
::
to_string
(
i
));
indexMultiTermAdd
(
terms
,
"tag3"
,
strlen
(
"tag3"
),
val
.
c_str
(),
val
.
size
());
val
.
append
(
"const"
);
indexMultiTermAdd
(
terms
,
"tag4"
,
strlen
(
"tag4"
),
val
.
c_str
(),
val
.
size
());
indexPut
(
index
,
terms
,
i
);
indexMultiTermDestroy
(
terms
);
}
// query
SIndexMultiTermQuery
*
multiQuery
=
indexMultiTermQueryCreate
(
MUST
);
indexMultiTermQueryAdd
(
multiQuery
,
"tag1"
,
strlen
(
"tag1"
),
"field"
,
strlen
(
"field"
),
QUERY_PREFIX
);
indexMultiTermQueryAdd
(
multiQuery
,
"tag3"
,
strlen
(
"tag3"
),
"0field0"
,
strlen
(
"0field0"
),
QUERY_TERM
);
SArray
*
result
=
(
SArray
*
)
taosArrayInit
(
10
,
sizeof
(
int
));
//TEST(IndexFstBuilder, IndexFstInput) {
indexSearch
(
index
,
multiQuery
,
result
);
//
//}
std
::
cout
<<
"taos'size : "
<<
taosArrayGetSize
(
result
)
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
result
);
i
++
)
{
int
*
v
=
(
int
*
)
taosArrayGet
(
result
,
i
);
std
::
cout
<<
"value --->"
<<
*
v
<<
std
::
endl
;
}
// add more test case
indexMultiTermQueryDestroy
(
multiQuery
);
indexOptsDestroy
(
opts
);
indexClose
(
index
);
//
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录