diff --git a/include/util/tlosertree.h b/include/util/tlosertree.h index 241647ba1eff40c2860368923008432768f92485..51906443f5ab874a2e7b16a11304ed6890f90437 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 297c37d62a99763462a7a61222ababf706a62b43..07c6e6509e4d5eedd7c14a830922b8347111f6e8 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 8b7f55809baa1eabbd10be49d22b4f44d2db8c90..6349ab170c3df30abd94f8b978f16aa598bc22da 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) {