TDengine/include/util/tlosertree.h

59 lines
1.7 KiB
C
Raw Normal View History

2019-07-11 08:36:16 +00:00
/*
* 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/>.
*/
2022-02-28 06:07:19 +00:00
#ifndef _TD_UTIL_LOSERTREE_H_
#define _TD_UTIL_LOSERTREE_H_
#include "os.h"
2019-07-11 08:36:16 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2022-02-28 06:07:19 +00:00
typedef int32_t (*__merge_compare_fn_t)(const void *, const void *, void *param);
2019-07-11 08:36:16 +00:00
2022-02-09 05:44:16 +00:00
typedef struct STreeNode {
int32_t index;
void *pData; // TODO remove it?
} STreeNode;
typedef struct SMultiwayMergeTreeInfo {
int32_t numOfSources;
int32_t totalSources;
__merge_compare_fn_t comparFn;
2022-02-28 06:07:19 +00:00
void *param;
struct STreeNode *pNode;
} SMultiwayMergeTreeInfo;
2019-07-11 08:36:16 +00:00
2022-02-09 05:44:16 +00:00
#define tMergeTreeGetChosenIndex(t_) ((t_)->pNode[0].index)
#define tMergeTreeGetAdjustIndex(t_) (tMergeTreeGetChosenIndex(t_) + (t_)->numOfSources)
2022-02-28 06:07:19 +00:00
int32_t tMergeTreeCreate(SMultiwayMergeTreeInfo **pTree, uint32_t numOfEntries, void *param,
__merge_compare_fn_t compareFn);
2019-07-11 08:36:16 +00:00
2023-06-26 10:43:00 +00:00
void tMergeTreeDestroy(SMultiwayMergeTreeInfo **pTree);
2022-02-08 10:01:21 +00:00
void tMergeTreeAdjust(SMultiwayMergeTreeInfo *pTree, int32_t idx);
2019-07-11 08:36:16 +00:00
void tMergeTreeRebuild(SMultiwayMergeTreeInfo *pTree);
2019-07-11 08:36:16 +00:00
void tMergeTreePrint(const SMultiwayMergeTreeInfo *pTree);
2019-07-11 08:36:16 +00:00
#ifdef __cplusplus
}
#endif
2022-02-28 06:07:19 +00:00
#endif /*_TD_UTIL_LOSERTREE_H_*/