tsort.h 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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/>.
 */

#ifndef TDENGINE_TSORT_H
#define TDENGINE_TSORT_H

#ifdef __cplusplus
extern "C" {
#endif

S
common  
Shengliang Guan 已提交
23
#include "tcommon.h"
24 25 26
#include "os.h"

enum {
H
Haojun Liao 已提交
27 28
  SORT_MULTISOURCE_MERGE = 0x1,
  SORT_SINGLESOURCE_SORT = 0x2,
29 30 31 32 33 34 35 36 37 38 39 40 41 42
};

typedef struct SMultiMergeSource {
  int32_t      type;
  int32_t      rowIndex;
  SSDataBlock *pBlock;
} SMultiMergeSource;

typedef struct SExternalMemSource {
  SMultiMergeSource src;
  SArray*           pageIdList;
  int32_t           pageIndex;
} SExternalMemSource;

H
Haojun Liao 已提交
43
typedef struct SGenericSource {
44
  SMultiMergeSource src;
H
Haojun Liao 已提交
45 46
  void             *param;
} SGenericSource;
47

48 49 50 51 52 53 54
typedef struct SMsortComparParam {
  void        **pSources;
  int32_t       numOfSources;
  SArray       *orderInfo;   // SArray<SBlockOrderInfo>
  bool          nullFirst;
} SMsortComparParam;

55 56 57 58 59 60 61 62 63 64 65
typedef struct SSortHandle SSortHandle;
typedef struct STupleHandle STupleHandle;

typedef SSDataBlock* (*_sort_fetch_block_fn_t)(void* param);
typedef int32_t (*_sort_merge_compar_fn_t)(const void* p1, const void* p2, void* param);

/**
 *
 * @param type
 * @return
 */
H
Haojun Liao 已提交
66
SSortHandle* tsortCreateSortHandle(SArray* pOrderInfo, int32_t type, int32_t pageSize, int32_t numOfPages, SSDataBlock* pBlock, const char* idstr);
67 68 69 70 71

/**
 *
 * @param pSortHandle
 */
H
Haojun Liao 已提交
72
void tsortDestroySortHandle(SSortHandle* pSortHandle);
73 74 75 76 77 78

/**
 *
 * @param pHandle
 * @return
 */
H
Haojun Liao 已提交
79
int32_t tsortOpen(SSortHandle* pHandle);
80 81 82 83 84 85

/**
 *
 * @param pHandle
 * @return
 */
H
Haojun Liao 已提交
86
int32_t tsortClose(SSortHandle* pHandle);
87 88 89 90 91

/**
 *
 * @return
 */
H
Haojun Liao 已提交
92
int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fp);
93 94 95 96 97 98 99

/**
 *
 * @param pHandle
 * @param fp
 * @return
 */
H
Haojun Liao 已提交
100
int32_t tsortSetComparFp(SSortHandle* pHandle, _sort_merge_compar_fn_t fp);
101 102 103 104 105 106 107

/**
 *
 * @param pHandle
 * @param pSource
 * @return success or failed
 */
H
Haojun Liao 已提交
108
int32_t tsortAddSource(SSortHandle* pSortHandle, void* pSource);
109 110 111 112 113 114

/**
 *
 * @param pHandle
 * @return
 */
H
Haojun Liao 已提交
115
STupleHandle* tsortNextTuple(SSortHandle* pHandle);
116 117 118 119 120 121 122

/**
 *
 * @param pHandle
 * @param colIndex
 * @return
 */
H
Haojun Liao 已提交
123
bool tsortIsNullVal(STupleHandle* pVHandle, int32_t colIndex);
124 125 126 127 128 129 130

/**
 *
 * @param pHandle
 * @param colIndex
 * @return
 */
H
Haojun Liao 已提交
131
void* tsortGetValue(STupleHandle* pVHandle, int32_t colIndex);
132 133 134 135 136 137

#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_TSORT_H