Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a2829971
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
a2829971
编写于
2月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
losertree
上级
9735dcf9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
18 addition
and
15 deletion
+18
-15
include/util/tlosertree.h
include/util/tlosertree.h
+10
-7
include/util/tmacro.h
include/util/tmacro.h
+1
-1
source/util/src/tlosertree.c
source/util/src/tlosertree.c
+7
-7
未找到文件。
include/util/tlosertree.h
浏览文件 @
a2829971
...
@@ -13,14 +13,16 @@
...
@@ -13,14 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#ifndef _TD_UTIL_LOSERTREE_H
#ifndef _TD_UTIL_LOSERTREE_H_
#define _TD_UTIL_LOSERTREE_H
#define _TD_UTIL_LOSERTREE_H_
#include "os.h"
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
#endif
#endif
typedef
int
(
*
__merge_compare_fn_t
)(
const
void
*
,
const
void
*
,
void
*
param
);
typedef
int
32_t
(
*
__merge_compare_fn_t
)(
const
void
*
,
const
void
*
,
void
*
param
);
typedef
struct
STreeNode
{
typedef
struct
STreeNode
{
int32_t
index
;
int32_t
index
;
...
@@ -31,16 +33,17 @@ typedef struct SMultiwayMergeTreeInfo {
...
@@ -31,16 +33,17 @@ typedef struct SMultiwayMergeTreeInfo {
int32_t
numOfSources
;
int32_t
numOfSources
;
int32_t
totalSources
;
int32_t
totalSources
;
__merge_compare_fn_t
comparFn
;
__merge_compare_fn_t
comparFn
;
void
*
param
;
void
*
param
;
struct
STreeNode
*
pNode
;
struct
STreeNode
*
pNode
;
}
SMultiwayMergeTreeInfo
;
}
SMultiwayMergeTreeInfo
;
#define tMergeTreeGetChosenIndex(t_) ((t_)->pNode[0].index)
#define tMergeTreeGetChosenIndex(t_) ((t_)->pNode[0].index)
#define tMergeTreeGetAdjustIndex(t_) (tMergeTreeGetChosenIndex(t_) + (t_)->numOfSources)
#define tMergeTreeGetAdjustIndex(t_) (tMergeTreeGetChosenIndex(t_) + (t_)->numOfSources)
int32_t
tMergeTreeCreate
(
SMultiwayMergeTreeInfo
**
pTree
,
uint32_t
numOfEntries
,
void
*
param
,
__merge_compare_fn_t
compareFn
);
int32_t
tMergeTreeCreate
(
SMultiwayMergeTreeInfo
**
pTree
,
uint32_t
numOfEntries
,
void
*
param
,
__merge_compare_fn_t
compareFn
);
void
tMergeTreeDestroy
(
SMultiwayMergeTreeInfo
*
pTree
);
void
tMergeTreeDestroy
(
SMultiwayMergeTreeInfo
*
pTree
);
void
tMergeTreeAdjust
(
SMultiwayMergeTreeInfo
*
pTree
,
int32_t
idx
);
void
tMergeTreeAdjust
(
SMultiwayMergeTreeInfo
*
pTree
,
int32_t
idx
);
...
@@ -52,4 +55,4 @@ void tMergeTreePrint(const SMultiwayMergeTreeInfo *pTree);
...
@@ -52,4 +55,4 @@ void tMergeTreePrint(const SMultiwayMergeTreeInfo *pTree);
}
}
#endif
#endif
#endif
/*_TD_UTIL_LOSERTREE_H
*/
#endif
/*_TD_UTIL_LOSERTREE_H_
*/
include/util/tmacro.h
浏览文件 @
a2829971
...
@@ -24,7 +24,7 @@ extern "C" {
...
@@ -24,7 +24,7 @@ extern "C" {
// Module init/clear MACRO definitions
// Module init/clear MACRO definitions
#define TD_MOD_UNINITIALIZED 0
#define TD_MOD_UNINITIALIZED 0
#define TD_MOD_INITIALIZED 1
#define TD_MOD_INITIALIZED
1
typedef
int8_t
td_mode_flag_t
;
typedef
int8_t
td_mode_flag_t
;
...
...
source/util/src/tlosertree.c
浏览文件 @
a2829971
...
@@ -13,12 +13,10 @@
...
@@ -13,12 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "os.h"
#define _DEFAULT_SOURCE
#include "tlog.h"
#include "tlosertree.h"
#include "tlosertree.h"
#include "taoserror.h"
#include "taoserror.h"
#include "tlog.h"
// Set the initial value of the multiway merge tree.
// Set the initial value of the multiway merge tree.
static
void
tMergeTreeInit
(
SMultiwayMergeTreeInfo
*
pTree
)
{
static
void
tMergeTreeInit
(
SMultiwayMergeTreeInfo
*
pTree
)
{
...
@@ -33,10 +31,12 @@ static void tMergeTreeInit(SMultiwayMergeTreeInfo* pTree) {
...
@@ -33,10 +31,12 @@ static void tMergeTreeInit(SMultiwayMergeTreeInfo* pTree) {
}
}
}
}
int32_t
tMergeTreeCreate
(
SMultiwayMergeTreeInfo
**
pTree
,
uint32_t
numOfSources
,
void
*
param
,
__merge_compare_fn_t
compareFn
)
{
int32_t
tMergeTreeCreate
(
SMultiwayMergeTreeInfo
**
pTree
,
uint32_t
numOfSources
,
void
*
param
,
__merge_compare_fn_t
compareFn
)
{
int32_t
totalEntries
=
numOfSources
<<
1u
;
int32_t
totalEntries
=
numOfSources
<<
1u
;
SMultiwayMergeTreeInfo
*
pTreeInfo
=
(
SMultiwayMergeTreeInfo
*
)
calloc
(
1
,
sizeof
(
SMultiwayMergeTreeInfo
)
+
sizeof
(
STreeNode
)
*
totalEntries
);
SMultiwayMergeTreeInfo
*
pTreeInfo
=
(
SMultiwayMergeTreeInfo
*
)
calloc
(
1
,
sizeof
(
SMultiwayMergeTreeInfo
)
+
sizeof
(
STreeNode
)
*
totalEntries
);
if
(
pTreeInfo
==
NULL
)
{
if
(
pTreeInfo
==
NULL
)
{
uError
(
"allocate memory for loser-tree failed. reason:%s"
,
strerror
(
errno
));
uError
(
"allocate memory for loser-tree failed. reason:%s"
,
strerror
(
errno
));
return
TAOS_SYSTEM_ERROR
(
errno
);
return
TAOS_SYSTEM_ERROR
(
errno
);
...
@@ -88,7 +88,7 @@ void tMergeTreeAdjust(SMultiwayMergeTreeInfo* pTree, int32_t idx) {
...
@@ -88,7 +88,7 @@ void tMergeTreeAdjust(SMultiwayMergeTreeInfo* pTree, int32_t idx) {
return
;
return
;
}
}
int32_t
parentId
=
idx
>>
1
;
int32_t
parentId
=
idx
>>
1
;
STreeNode
kLeaf
=
pTree
->
pNode
[
idx
];
STreeNode
kLeaf
=
pTree
->
pNode
[
idx
];
while
(
parentId
>
0
)
{
while
(
parentId
>
0
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录