diff options
author | Ruslan Kovalev <ruslan.a.kovalev@gmail.com> | 2022-02-10 16:46:45 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:45 +0300 |
commit | 9123176b341b6f2658cff5132482b8237c1416c8 (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/bit_io/bitinput.h | |
parent | 59e19371de37995fcb36beb16cd6ec030af960bc (diff) | |
download | ydb-9123176b341b6f2658cff5132482b8237c1416c8.tar.gz |
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/bit_io/bitinput.h')
-rw-r--r-- | library/cpp/bit_io/bitinput.h | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/library/cpp/bit_io/bitinput.h b/library/cpp/bit_io/bitinput.h index 397b311783..85711eb7f9 100644 --- a/library/cpp/bit_io/bitinput.h +++ b/library/cpp/bit_io/bitinput.h @@ -1,16 +1,16 @@ #pragma once -#include "bitinput_impl.h" - +#include "bitinput_impl.h" + #include <util/system/yassert.h> -#include <util/generic/vector.h> -#include <util/generic/yexception.h> +#include <util/generic/vector.h> +#include <util/generic/yexception.h> #include <iterator> -namespace NBitIO { +namespace NBitIO { // Based on junk/solar/codecs/bitstream.h - + class TBitInput: protected TBitInputImpl { public: template <typename TVec> @@ -18,27 +18,27 @@ namespace NBitIO { : TBitInputImpl(std::begin(vec), std::end(vec)) { } - + TBitInput(const char* start, const char* end) : TBitInputImpl(start, end) { } - + bool Eof() const { return EofImpl(); } - + ui64 GetOffset() const { ui64 bo = BitOffset(); return bo / 8 + !!(bo % 8); } - - using TBitInputImpl::GetBitLength; - + + using TBitInputImpl::GetBitLength; + ui64 GetBitOffset() const { return BitOffset() % 8; } - + public: // Read with static number of bits. // Preserves what's in result. @@ -49,7 +49,7 @@ namespace NBitIO { CopyToResultK<bits>(result, r64, skipbits); return ret; } - + // Read with static number of bits. // Zeroes other bits in result. template <ui64 bits, typename T> @@ -59,42 +59,42 @@ namespace NBitIO { result = r; return res; } - + // Shortcut to impl. template <ui64 bits> Y_FORCE_INLINE bool ReadK(ui64& result) { if (bits <= 56) return ReadKImpl<bits>(result); - + ui64 r1 = 0ULL; ui64 r2 = 0ULL; - + bool ret1 = ReadKImpl<56ULL>(r1); bool ret2 = ReadKImpl<(bits > 56ULL ? bits - 56ULL : 0) /*or else we get negative param in template*/>(r2); - + result = (r2 << 56ULL) | r1; - + return ret1 & ret2; } - + // It's safe to read up to 64 bits. // Zeroes other bits in result. template <typename T> Y_FORCE_INLINE bool ReadSafe(T& result, ui64 bits) { if (bits <= 56ULL) return Read(result, bits); - + ui64 r1 = 0ULL; ui64 r2 = 0ULL; - + bool ret1 = ReadKImpl<56ULL>(r1); bool ret2 = ReadImpl(r2, bits - 56ULL); - + result = (r2 << 56ULL) | r1; - + return ret1 & ret2; } - + // It's safe to read up to 64 bits. // Preserves what's in result. template <typename T> @@ -104,7 +104,7 @@ namespace NBitIO { CopyToResult(result, r64, bits, skipbits); return ret; } - + // Do not try to read more than 56 bits at once. Split in two reads or use ReadSafe. // Zeroes other bits in result. template <typename T> @@ -114,7 +114,7 @@ namespace NBitIO { result = r64; return ret; } - + // Shortcut to impl. Y_FORCE_INLINE bool Read(ui64& result, ui64 bits) { return ReadImpl(result, bits); @@ -129,7 +129,7 @@ namespace NBitIO { CopyToResult(result, r64, bits, skipbits); return ret; } - + // Unsigned wordwise read. Underlying data is splitted in "words" of "bits(data) + 1(flag)" bits. // Like this: (unsigned char)0x2E<3> (0010 1110) <=> 1110 0101 // fddd fddd @@ -142,13 +142,13 @@ namespace NBitIO { return retCode; } - + // Shortcut to impl. template <ui64 bits> Y_FORCE_INLINE bool ReadWords(ui64& result) { return ReadWordsImpl<bits>(result); } - + Y_FORCE_INLINE bool Back(int bits) { return Seek(BitOffset() - bits); } @@ -168,4 +168,4 @@ namespace NBitIO { return ret; } }; -} +} |