qPercentile.h 2.2 KB
Newer Older
H
hjxilinx 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

H
hjxilinx 已提交
16 17
#ifndef TDENGINE_QPERCENTILE_H
#define TDENGINE_QPERCENTILE_H
H
hjxilinx 已提交
18

H
Haojun Liao 已提交
19 20 21 22
#ifdef __cplusplus
extern "C" {
#endif

H
Haojun Liao 已提交
23
#include "qExtbuffer.h"
H
Haojun Liao 已提交
24 25
#include "qResultbuf.h"
#include "qTsbuf.h"
H
hjxilinx 已提交
26 27 28

typedef struct MinMaxEntry {
  union {
H
Haojun Liao 已提交
29 30 31
    double   dMinVal;
    int64_t  i64MinVal;
    uint64_t u64MinVal;
H
hjxilinx 已提交
32 33 34 35
  };
  union {
    double  dMaxVal;
    int64_t i64MaxVal;
H
Haojun Liao 已提交
36
    int64_t u64MaxVal;
H
hjxilinx 已提交
37 38 39
  };
} MinMaxEntry;

H
Haojun Liao 已提交
40
typedef struct {
H
Haojun Liao 已提交
41 42
  int32_t    size;
  int32_t    pageId;
H
Haojun Liao 已提交
43 44 45 46
  tFilePage *data;
} SSlotInfo;

typedef struct tMemBucketSlot {
H
Haojun Liao 已提交
47 48
  SSlotInfo   info;
  MinMaxEntry range;
H
Haojun Liao 已提交
49 50 51 52
} tMemBucketSlot;

struct tMemBucket;
typedef int32_t (*__perc_hash_func_t)(struct tMemBucket *pBucket, const void *value);
H
hjxilinx 已提交
53 54

typedef struct tMemBucket {
H
Haojun Liao 已提交
55 56 57 58
  int16_t       numOfSlots;
  int16_t       type;
  int16_t       bytes;
  int32_t       total;
H
Haojun Liao 已提交
59 60 61 62 63
  int32_t       elemPerPage;  // number of elements for each object
  int32_t       maxCapacity;  // maximum allowed number of elements that can be sort directly to get the result
  int32_t       bufPageSize;  // disk page size
  MinMaxEntry   range;        // value range
  int32_t       times;        // count that has been checked for deciding the correct data value buckets.
H
Haojun Liao 已提交
64 65
  __compar_fn_t comparFn;

H
Haojun Liao 已提交
66
  tMemBucketSlot *     pSlots;
H
Haojun Liao 已提交
67
  SDiskbasedResultBuf *pBuffer;
H
Haojun Liao 已提交
68
  __perc_hash_func_t   hashFunc;
H
hjxilinx 已提交
69 70
} tMemBucket;

H
Haojun Liao 已提交
71
tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval, double maxval);
H
hjxilinx 已提交
72 73 74

void tMemBucketDestroy(tMemBucket *pBucket);

H
Haojun Liao 已提交
75
int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size);
H
hjxilinx 已提交
76 77 78

double getPercentile(tMemBucket *pMemBucket, double percent);

H
hjxilinx 已提交
79
#endif  // TDENGINE_QPERCENTILE_H
H
Haojun Liao 已提交
80 81 82 83

#ifdef __cplusplus
}
#endif