tpercentile.h 2.3 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_TPERCENTILE_H
#define TDENGINE_TPERCENTILE_H

#ifdef __cplusplus
extern "C" {
#endif

H
Haojun Liao 已提交
23
#include "tpagedbuf.h"
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include "ttszip.h"

typedef struct MinMaxEntry {
  union {
    double   dMinVal;
    int64_t  i64MinVal;
    uint64_t u64MinVal;
  };
  union {
    double  dMaxVal;
    int64_t i64MaxVal;
    int64_t u64MaxVal;
  };
} MinMaxEntry;

typedef struct {
  int32_t    size;
  int32_t    pageId;
H
Haojun Liao 已提交
42
  SFilePage *data;
43 44 45 46 47 48 49 50 51 52 53
} SSlotInfo;

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

struct tMemBucket;
typedef int32_t (*__perc_hash_func_t)(struct tMemBucket *pBucket, const void *value);

typedef struct tMemBucket {
54 55 56 57 58 59 60 61 62 63
  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;
H
Hongze Cheng 已提交
64 65
  tMemBucketSlot    *pSlots;
  SDiskbasedBuf     *pBuffer;
66
  __perc_hash_func_t hashFunc;
H
Hongze Cheng 已提交
67
  SHashObj          *groupPagesMap;  // disk page map for different groups;
68 69 70 71 72 73 74 75
} tMemBucket;

tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval, double maxval);

void tMemBucketDestroy(tMemBucket *pBucket);

int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size);

G
Ganlin Zhao 已提交
76
int32_t getPercentile(tMemBucket *pMemBucket, double percent, double *result);
77 78 79 80 81

#endif  // TDENGINE_TPERCENTILE_H

#ifdef __cplusplus
}
G
Ganlin Zhao 已提交
82
#endif