diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/comptable/comptable.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/comptable/comptable.h')
-rw-r--r-- | library/cpp/comptable/comptable.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/library/cpp/comptable/comptable.h b/library/cpp/comptable/comptable.h new file mode 100644 index 0000000000..d225fed7a0 --- /dev/null +++ b/library/cpp/comptable/comptable.h @@ -0,0 +1,75 @@ +#pragma once + +#include <util/generic/vector.h> +#include <util/memory/blob.h> +#include <util/ysaveload.h> + +#include <library/cpp/compproto/huff.h> + +namespace NCompTable { + struct TCompressorTable { + ui32 Table[65536]; + ui32 HashMul; + NCompProto::TCoderEntry HuffCodes[10]; + ui8 HuffIndices[256]; + + void GetHuffCode(const NCompProto::TCoderEntry& entry, ui32 value, ui64& bitCode, ui8& bitLength) const; + void GetLastHuffCode(ui32 value, ui64& bitCode, ui8& bitLength) const; + void GetHuffCode(ui32 value, ui64& bitCode, ui8& bitLength) const; + ui8 GetHuffIndex(ui8 prefix); + void BuildHuffCodes(i64 totalFreq, i64 freqs[65536]); + bool BuildHuffCodes(i64 totalFreq, i64 freqs[65536], i64 add); + }; + + struct TDataSampler { + enum { + Size = 1 << 18, + }; + ui32 EntryVal[Size]; + i64 EntryHit[Size]; + i64 Counter; + + public: + TDataSampler(); + void BuildTable(TCompressorTable& table) const; + void AddStat(ui32 val); + void AddStat(const TStringBuf& stringBuf); + }; + + class TDataCompressor; + class TDataDecompressor; + + class TChunkCompressor { + public: + TChunkCompressor(bool highQuality, const TCompressorTable& table); + void Compress(TStringBuf data, TVector<char>* result) const; + ~TChunkCompressor(); + + private: + bool HighQuality; + THolder<TDataCompressor> Compressor; + }; + + class TChunkDecompressor { + public: + TChunkDecompressor(bool highQuality, const TCompressorTable& table); + void Decompress(TStringBuf data, TVector<char>* result) const; + ~TChunkDecompressor(); + + private: + bool HighQuality; + THolder<TDataDecompressor> Decompressor; + }; + +} + +template <> +class TSerializer<NCompTable::TCompressorTable> { +public: + static inline void Save(IOutputStream* out, const NCompTable::TCompressorTable& entry) { + SavePodType(out, entry); + } + static inline void Load(IInputStream* in, NCompTable::TCompressorTable& entry) { + LoadPodType(in, entry); + } +}; |