aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/codecs/float_huffman.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/codecs/float_huffman.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/codecs/float_huffman.h')
-rw-r--r--library/cpp/codecs/float_huffman.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/library/cpp/codecs/float_huffman.h b/library/cpp/codecs/float_huffman.h
new file mode 100644
index 0000000000..786a8eae1d
--- /dev/null
+++ b/library/cpp/codecs/float_huffman.h
@@ -0,0 +1,50 @@
+#pragma once
+
+#include <util/generic/array_ref.h>
+#include <util/generic/vector.h>
+#include <util/generic/strbuf.h>
+
+#include <array>
+
+namespace NCodecs::NFloatHuff {
+ TString Encode(TArrayRef<const float> factors);
+
+ class TDecoder {
+ public:
+ explicit TDecoder(TStringBuf data);
+
+ TVector<float> DecodeAll(size_t sizeHint = 0);
+
+ // Returns number of decoded floats. May be fewer than requested if the EOS is found.
+ size_t Decode(TArrayRef<float> dest);
+
+ // Returns the number of skipped values.
+ size_t Skip(size_t count);
+
+ bool HasMore() const;
+
+ private:
+ struct TState {
+ ui64 Workspace = 0;
+ int WorkspaceSize = 0;
+ ui64 Position = 0;
+ TStringBuf Data;
+
+ ui64 NextBitsUnmasked(int count); // The upper 64 - count bits may be arbitrary
+ ui64 PeekBits(int count);
+ void SkipBits(int count);
+ };
+
+ void FillDecodeBuffer();
+
+ TState State;
+ std::array<float, 128> DecodeBuffer;
+ // The range of already decompressed numbers inside the DecodeBuffer.
+ // Always kept non-empty until the EOS is encountered.
+ float* Begin;
+ float* End;
+ bool HitEos = false;
+ };
+
+ TVector<float> Decode(TStringBuf data, size_t sizeHint = 0);
+}