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
};

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

wmmhello's avatar
wmmhello 已提交
37
typedef struct SSortSource {
38
  SMultiMergeSource src;
wmmhello's avatar
wmmhello 已提交
39 40 41 42 43 44 45
  union{
    struct{
      SArray*           pageIdList;
      int32_t           pageIndex;
    };
    void             *param;
  };
46

wmmhello's avatar
wmmhello 已提交
47
} SSortSource;
48

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

wmmhello's avatar
wmmhello 已提交
55 56 57 58 59
struct STupleHandle {
  SSDataBlock* pBlock;
  int32_t      rowIndex;
};

60 61 62 63 64 65 66 67 68 69 70
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 已提交
71
SSortHandle* tsortCreateSortHandle(SArray* pOrderInfo, int32_t type, int32_t pageSize, int32_t numOfPages, SSDataBlock* pBlock, const char* idstr);
72 73 74 75 76

/**
 *
 * @param pSortHandle
 */
H
Haojun Liao 已提交
77
void tsortDestroySortHandle(SSortHandle* pSortHandle);
78 79 80 81 82 83

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

/**
 *
 * @param pHandle
 * @return
 */
H
Haojun Liao 已提交
91
int32_t tsortClose(SSortHandle* pHandle);
92 93 94 95 96

/**
 *
 * @return
 */
H
Haojun Liao 已提交
97
int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fp);
98 99 100 101 102 103 104

/**
 *
 * @param pHandle
 * @param fp
 * @return
 */
H
Haojun Liao 已提交
105
int32_t tsortSetComparFp(SSortHandle* pHandle, _sort_merge_compar_fn_t fp);
106 107 108 109 110 111 112

/**
 *
 * @param pHandle
 * @param pSource
 * @return success or failed
 */
H
Haojun Liao 已提交
113
int32_t tsortAddSource(SSortHandle* pSortHandle, void* pSource);
114 115 116 117 118 119

/**
 *
 * @param pHandle
 * @return
 */
H
Haojun Liao 已提交
120
STupleHandle* tsortNextTuple(SSortHandle* pHandle);
121 122 123 124 125 126 127

/**
 *
 * @param pHandle
 * @param colIndex
 * @return
 */
H
Haojun Liao 已提交
128
bool tsortIsNullVal(STupleHandle* pVHandle, int32_t colIndex);
129 130 131 132 133 134 135

/**
 *
 * @param pHandle
 * @param colIndex
 * @return
 */
H
Haojun Liao 已提交
136
void* tsortGetValue(STupleHandle* pVHandle, int32_t colIndex);
137 138 139 140 141 142

#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_TSORT_H