qPercentile.h 2.1 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
#include "qExtbuffer.h"
H
Haojun Liao 已提交
20 21
#include "qResultbuf.h"
#include "qTsbuf.h"
H
hjxilinx 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35

typedef struct MinMaxEntry {
  union {
    double  dMinVal;
    int32_t iMinVal;
    int64_t i64MinVal;
  };
  union {
    double  dMaxVal;
    int32_t iMaxVal;
    int64_t i64MaxVal;
  };
} MinMaxEntry;

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

typedef struct tMemBucketSlot {
  SSlotInfo      info;
  MinMaxEntry    range;
} tMemBucketSlot;

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

typedef struct tMemBucket {
H
Haojun Liao 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64
  int16_t       numOfSlots;
  int16_t       type;
  int16_t       bytes;
  int32_t       total;
  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.
  __compar_fn_t comparFn;

  tMemBucketSlot *pSlots;
  SDiskbasedResultBuf *pBuffer;
  __perc_hash_func_t hashFunc;
H
hjxilinx 已提交
65 66
} tMemBucket;

H
Haojun Liao 已提交
67
tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType);
H
hjxilinx 已提交
68 69 70

void tMemBucketDestroy(tMemBucket *pBucket);

H
Haojun Liao 已提交
71
void tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size);
H
hjxilinx 已提交
72 73 74

double getPercentile(tMemBucket *pMemBucket, double percent);

H
hjxilinx 已提交
75
#endif  // TDENGINE_QPERCENTILE_H