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 | d507a9366b2ab84411afe63fea9fba5498891e1b (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/packedtypes/zigzag.h | |
parent | 9e33e026829d561d6fd46d72b88c367952e08075 (diff) | |
download | ydb-d507a9366b2ab84411afe63fea9fba5498891e1b.tar.gz |
Restoring authorship annotation for <pkalinnikov@yandex-team.ru>. Commit 2 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 2adc715902..548403f838 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); -} +} |