TDengine/include/util/tcompression.h

148 lines
7.4 KiB
C
Raw Normal View History

2019-07-11 08:36:16 +00:00
/*
* 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/>.
*/
2022-02-28 02:47:44 +00:00
#ifndef _TD_UTIL_COMPRESSION_H_
#define _TD_UTIL_COMPRESSION_H_
#include "os.h"
#include "taos.h"
#include "tutil.h"
2019-07-11 08:36:16 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2020-04-27 09:40:57 +00:00
#define COMP_OVERFLOW_BYTES 2
2022-02-28 02:47:44 +00:00
#define BITS_PER_BYTE 8
2019-07-11 08:36:16 +00:00
// Masks
2020-09-30 03:02:52 +00:00
#define INT64MASK(_x) ((((uint64_t)1) << _x) - 1)
2019-07-11 08:36:16 +00:00
#define INT32MASK(_x) (((uint32_t)1 << _x) - 1)
2022-02-28 02:47:44 +00:00
#define INT8MASK(_x) (((uint8_t)1 << _x) - 1)
2019-07-11 08:36:16 +00:00
// Compression algorithm
#define NO_COMPRESSION 0
#define ONE_STAGE_COMP 1
#define TWO_STAGE_COMP 2
2021-07-02 02:08:31 +00:00
//
// compressed data first byte foramt
// ------ 7 bit ---- | ---- 1 bit ----
// algorithm mode
//
// compression data mode save first byte lower 1 bit
2022-02-28 02:47:44 +00:00
#define MODE_NOCOMPRESS 0 // original data
#define MODE_COMPRESS 1 // compatible old compress
2021-07-02 02:08:31 +00:00
// compression algorithm save first byte higher 7 bit
2022-02-28 02:47:44 +00:00
#define ALGO_SZ_LOSSY 1 // SZ compress
#define HEAD_MODE(x) x % 2
#define HEAD_ALGO(x) x / 2
2021-07-19 12:22:34 +00:00
#ifdef TD_TSZ
2021-07-07 12:39:49 +00:00
extern bool lossyFloat;
extern bool lossyDouble;
2023-09-23 03:59:30 +00:00
int32_t tsCompressInit(char* lossyColumns, float fPrecision, double dPrecision, uint32_t maxIntervals, uint32_t intervals,
2023-09-19 04:57:18 +00:00
int32_t ifAdtFse, const char* compressor);
void tsCompressExit();
2020-04-30 07:07:51 +00:00
2023-09-15 06:30:23 +00:00
int32_t tsCompressFloatLossyImp(const char *const input, const int32_t nelements, char *const output);
int32_t tsDecompressFloatLossyImp(const char *const input, int32_t compressedSize, const int32_t nelements, char *const output);
int32_t tsCompressDoubleLossyImp(const char *const input, const int32_t nelements, char *const output);
int32_t tsDecompressDoubleLossyImp(const char *const input, int32_t compressedSize, const int32_t nelements, char *const output);
2022-02-28 02:47:44 +00:00
static FORCE_INLINE int32_t tsCompressFloatLossy(const char *const input, int32_t inputSize, const int32_t nelements,
char *const output, int32_t outputSize, char algorithm,
char *const buffer, int32_t bufferSize) {
2021-06-28 09:51:57 +00:00
return tsCompressFloatLossyImp(input, nelements, output);
}
2021-06-24 11:58:45 +00:00
2022-02-28 02:47:44 +00:00
static FORCE_INLINE int32_t tsDecompressFloatLossy(const char *const input, int32_t compressedSize,
const int32_t nelements, char *const output, int32_t outputSize,
char algorithm, char *const buffer, int32_t bufferSize) {
2021-06-28 09:51:57 +00:00
return tsDecompressFloatLossyImp(input, compressedSize, nelements, output);
}
2021-06-24 11:58:45 +00:00
2022-02-28 02:47:44 +00:00
static FORCE_INLINE int32_t tsCompressDoubleLossy(const char *const input, int32_t inputSize, const int32_t nelements,
char *const output, int32_t outputSize, char algorithm,
char *const buffer, int32_t bufferSize) {
2021-06-28 09:51:57 +00:00
return tsCompressDoubleLossyImp(input, nelements, output);
}
2021-06-24 11:58:45 +00:00
2022-02-28 02:47:44 +00:00
static FORCE_INLINE int32_t tsDecompressDoubleLossy(const char *const input, int32_t compressedSize,
const int32_t nelements, char *const output, int32_t outputSize,
char algorithm, char *const buffer, int32_t bufferSize) {
2021-06-28 09:51:57 +00:00
return tsDecompressDoubleLossyImp(input, compressedSize, nelements, output);
}
2021-06-24 11:58:45 +00:00
#endif
2021-06-24 11:58:45 +00:00
2022-09-20 05:39:32 +00:00
/*************************************************************************
* REGULAR COMPRESSION
*************************************************************************/
2022-09-20 03:08:46 +00:00
int32_t tsCompressTimestamp(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsDecompressTimestamp(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg,
void *pBuf, int32_t nBuf);
int32_t tsCompressFloat(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsDecompressFloat(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsCompressDouble(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsDecompressDouble(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsCompressString(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsDecompressString(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsCompressBool(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsDecompressBool(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsCompressTinyint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsDecompressTinyint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsCompressSmallint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsDecompressSmallint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg,
void *pBuf, int32_t nBuf);
int32_t tsCompressInt(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsDecompressInt(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsCompressBigint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
int32_t tsDecompressBigint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
int32_t nBuf);
2019-07-11 08:36:16 +00:00
2022-09-20 05:39:32 +00:00
/*************************************************************************
* STREAM COMPRESSION
*************************************************************************/
typedef struct SCompressor SCompressor;
int32_t tCompressorCreate(SCompressor **ppCmprsor);
int32_t tCompressorDestroy(SCompressor *pCmprsor);
2022-09-26 02:47:24 +00:00
int32_t tCompressStart(SCompressor *pCmprsor, int8_t type, int8_t cmprAlg);
2022-09-27 09:36:02 +00:00
int32_t tCompressEnd(SCompressor *pCmprsor, const uint8_t **ppOut, int32_t *nOut, int32_t *nOrigin);
2022-09-20 05:39:32 +00:00
int32_t tCompress(SCompressor *pCmprsor, const void *pData, int64_t nData);
2019-07-11 08:36:16 +00:00
#ifdef __cplusplus
}
#endif
2022-02-28 02:47:44 +00:00
#endif /*_TD_UTIL_COMPRESSION_H_*/