diff options
author | Ruslan Kovalev <ruslan.a.kovalev@gmail.com> | 2022-02-10 16:46:44 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:44 +0300 |
commit | 59e19371de37995fcb36beb16cd6ec030af960bc (patch) | |
tree | fa68e36093ebff8b805462e9e6d331fe9d348214 /library/cpp/bit_io/bitoutput.h | |
parent | 89db6fe2fe2c32d2a832ddfeb04e8d078e301084 (diff) | |
download | ydb-59e19371de37995fcb36beb16cd6ec030af960bc.tar.gz |
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/bit_io/bitoutput.h')
-rw-r--r-- | library/cpp/bit_io/bitoutput.h | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/library/cpp/bit_io/bitoutput.h b/library/cpp/bit_io/bitoutput.h index 2b886c1f02..c54a9a7835 100644 --- a/library/cpp/bit_io/bitoutput.h +++ b/library/cpp/bit_io/bitoutput.h @@ -1,19 +1,19 @@ #pragma once #include <library/cpp/deprecated/accessors/accessors.h> - + #include <util/stream/output.h> #include <util/system/yassert.h> #include <util/generic/bitops.h> -#include <util/generic/vector.h> -#include <util/generic/yexception.h> +#include <util/generic/vector.h> +#include <util/generic/yexception.h> -namespace NBitIO { +namespace NBitIO { // Based on junk/solar/codecs/bitstream.h - + // Almost all code is hard tuned for sequential write performance. // Use tools/bursttrie/benchmarks/bitstreams_benchmark to check your changes. - + inline constexpr ui64 BytesUp(ui64 bits) { return (bits + 7ULL) >> 3ULL; } @@ -25,7 +25,7 @@ namespace NBitIO { ui64 FreeBits; ui64 Active; ui64 Offset; - + public: TBitOutputBase(TStorage* storage) : Storage(storage) @@ -38,15 +38,15 @@ namespace NBitIO { ui64 GetOffset() const { return Offset + BytesUp(64ULL - FreeBits); } - + ui64 GetBitOffset() const { return (64ULL - FreeBits) & 7ULL; } - + ui64 GetByteReminder() const { return FreeBits & 7ULL; } - + public: // interface @@ -58,14 +58,14 @@ namespace NBitIO { Active |= (data & MaskLowerBits(FreeBits)) << (64ULL - FreeBits); data >>= FreeBits; - + FreeBits = 0ULL; } Flush(); } - Active |= bits ? ((data & MaskLowerBits(bits)) << (64ULL - FreeBits)) : 0; + Active |= bits ? ((data & MaskLowerBits(bits)) << (64ULL - FreeBits)) : 0; FreeBits -= bits; } @@ -73,7 +73,7 @@ namespace NBitIO { Y_FORCE_INLINE void Write(ui64 data, ui64 bits, ui64 skipbits) { Write(data >> skipbits, bits); } - + // Unsigned wordwise write. Underlying data is splitted in "words" of "bits(data) + 1(flag)" bits. // Like this: (unsigned char)0x2E<3> (0000 0010 1110) <=> 1110 0101 // fddd fddd @@ -81,32 +81,32 @@ namespace NBitIO { Y_FORCE_INLINE void WriteWords(ui64 data) { do { ui64 part = data; - + data >>= bits; part |= FastZeroIfFalse(data, NthBit64(bits)); Write(part, bits + 1ULL); } while (data); } - + Y_FORCE_INLINE ui64 /* padded bits */ Flush() { const ui64 ubytes = 8ULL - (FreeBits >> 3ULL); - + if (ubytes) { Active <<= FreeBits; Active >>= FreeBits; - + Storage->WriteData((const char*)&Active, (const char*)&Active + ubytes); Offset += ubytes; } - + const ui64 padded = FreeBits & 7; FreeBits = 64ULL; Active = 0ULL; - + return padded; } - + virtual ~TBitOutputBase() { Flush(); } @@ -116,22 +116,22 @@ namespace NBitIO { return -i64(cond) & iftrue; } }; - + template <typename TVec> class TBitOutputVectorImpl { TVec* Data; - + public: void WriteData(const char* begin, const char* end) { NAccessors::Append(*Data, begin, end); } - + TBitOutputVectorImpl(TVec* data) : Data(data) { } }; - + template <typename TVec> struct TBitOutputVector: public TBitOutputVectorImpl<TVec>, public TBitOutputBase<TBitOutputVectorImpl<TVec>> { inline TBitOutputVector(TVec* data) @@ -144,7 +144,7 @@ namespace NBitIO { class TBitOutputArrayImpl { char* Data; size_t Left; - + public: void WriteData(const char* begin, const char* end) { size_t sz = end - begin; @@ -153,14 +153,14 @@ namespace NBitIO { Data += sz; Left -= sz; } - + TBitOutputArrayImpl(char* begin, size_t len) : Data(begin) , Left(len) { } }; - + struct TBitOutputArray: public TBitOutputArrayImpl, public TBitOutputBase<TBitOutputArrayImpl> { inline TBitOutputArray(char* begin, size_t len) : TBitOutputArrayImpl(begin, len) @@ -170,15 +170,15 @@ namespace NBitIO { }; using TBitOutputYVector = TBitOutputVector<TVector<char>>; - + class TBitOutputStreamImpl { IOutputStream* Out; - + public: void WriteData(const char* begin, const char* end) { Out->Write(begin, end - begin); } - + TBitOutputStreamImpl(IOutputStream* out) : Out(out) { @@ -192,4 +192,4 @@ namespace NBitIO { { } }; -} +} |