From a282997149c1f8ea6387ae3d5804c13ca5292aa0 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Feb 2022 14:07:19 +0800 Subject: [PATCH] losertree --- include/util/tlosertree.h | 17 ++++++++++------- include/util/tmacro.h | 2 +- source/util/src/tlosertree.c | 14 +++++++------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/include/util/tlosertree.h b/include/util/tlosertree.h index 241647ba1e..51906443f5 100644 --- a/include/util/tlosertree.h +++ b/include/util/tlosertree.h @@ -13,14 +13,16 @@ * along with this program. If not, see . */ -#ifndef _TD_UTIL_LOSERTREE_H -#define _TD_UTIL_LOSERTREE_H +#ifndef _TD_UTIL_LOSERTREE_H_ +#define _TD_UTIL_LOSERTREE_H_ + +#include "os.h" #ifdef __cplusplus extern "C" { #endif -typedef int (*__merge_compare_fn_t)(const void *, const void *, void *param); +typedef int32_t (*__merge_compare_fn_t)(const void *, const void *, void *param); typedef struct STreeNode { int32_t index; @@ -31,16 +33,17 @@ typedef struct SMultiwayMergeTreeInfo { int32_t numOfSources; int32_t totalSources; __merge_compare_fn_t comparFn; - void * param; + void *param; struct STreeNode *pNode; } SMultiwayMergeTreeInfo; #define tMergeTreeGetChosenIndex(t_) ((t_)->pNode[0].index) #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); @@ -52,4 +55,4 @@ void tMergeTreePrint(const SMultiwayMergeTreeInfo *pTree); } #endif -#endif /*_TD_UTIL_LOSERTREE_H*/ +#endif /*_TD_UTIL_LOSERTREE_H_*/ diff --git a/include/util/tmacro.h b/include/util/tmacro.h index 297c37d62a..07c6e6509e 100644 --- a/include/util/tmacro.h +++ b/include/util/tmacro.h @@ -24,7 +24,7 @@ extern "C" { // Module init/clear MACRO definitions #define TD_MOD_UNINITIALIZED 0 -#define TD_MOD_INITIALIZED 1 +#define TD_MOD_INITIALIZED 1 typedef int8_t td_mode_flag_t; diff --git a/source/util/src/tlosertree.c b/source/util/src/tlosertree.c index 8b7f55809b..6349ab170c 100644 --- a/source/util/src/tlosertree.c +++ b/source/util/src/tlosertree.c @@ -13,12 +13,10 @@ * along with this program. If not, see . */ -#include "os.h" -#include "tlog.h" +#define _DEFAULT_SOURCE #include "tlosertree.h" #include "taoserror.h" - - +#include "tlog.h" // Set the initial value of the multiway merge tree. 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; - SMultiwayMergeTreeInfo* pTreeInfo = (SMultiwayMergeTreeInfo*)calloc(1, sizeof(SMultiwayMergeTreeInfo) + sizeof(STreeNode) * totalEntries); + SMultiwayMergeTreeInfo* pTreeInfo = + (SMultiwayMergeTreeInfo*)calloc(1, sizeof(SMultiwayMergeTreeInfo) + sizeof(STreeNode) * totalEntries); if (pTreeInfo == NULL) { uError("allocate memory for loser-tree failed. reason:%s", strerror(errno)); return TAOS_SYSTEM_ERROR(errno); @@ -88,7 +88,7 @@ void tMergeTreeAdjust(SMultiwayMergeTreeInfo* pTree, int32_t idx) { return; } - int32_t parentId = idx >> 1; + int32_t parentId = idx >> 1; STreeNode kLeaf = pTree->pNode[idx]; while (parentId > 0) { -- GitLab