diff options
author | pkalinnikov <pkalinnikov@yandex-team.ru> | 2022-02-10 16:50:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:15 +0300 |
commit | 9e33e026829d561d6fd46d72b88c367952e08075 (patch) | |
tree | 2af190fca83ac522e9a7e29de1daae32582064b4 /library/cpp/packedtypes/zigzag.h | |
parent | ba5325cc01aabb81effc91ff1bdbb461313cbd00 (diff) | |
download | ydb-9e33e026829d561d6fd46d72b88c367952e08075.tar.gz |
Restoring authorship annotation for <pkalinnikov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/packedtypes/zigzag.h')
-rw-r--r-- | library/cpp/packedtypes/zigzag.h | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/library/cpp/packedtypes/zigzag.h b/library/cpp/packedtypes/zigzag.h index 548403f838..2adc715902 100644 --- a/library/cpp/packedtypes/zigzag.h +++ b/library/cpp/packedtypes/zigzag.h @@ -1,21 +1,21 @@ -#pragma once - -#include <util/generic/typetraits.h> - +#pragma once + +#include <util/generic/typetraits.h> + #include <limits.h> -//! Convert signed values to unsigned. Convenient for further varint encoding. -//! See https://developers.google.com/protocol-buffers/docs/encoding#types for details. - -template <typename TSignedInt> +//! Convert signed values to unsigned. Convenient for further varint encoding. +//! See https://developers.google.com/protocol-buffers/docs/encoding#types for details. + +template <typename TSignedInt> inline auto ZigZagEncode(TSignedInt n) -> std::make_unsigned_t<TSignedInt> { static_assert(std::is_signed<TSignedInt>::value && std::is_integral<TSignedInt>::value, "Expected signed integral type."); auto un = static_cast<std::make_unsigned_t<TSignedInt>>(n); return (un << 1) ^ (n >> (CHAR_BIT * sizeof(TSignedInt) - 1)); -} - -template <typename TUnsignedInt> +} + +template <typename TUnsignedInt> inline auto ZigZagDecode(TUnsignedInt n) -> std::make_signed_t<TUnsignedInt> { static_assert(std::is_unsigned<TUnsignedInt>::value, "Expected unsigned integral type."); return (n >> 1) ^ -static_cast<std::make_signed_t<TUnsignedInt>>(n & 1); -} +} |