diff options
author | babenko <babenko@yandex-team.ru> | 2022-02-10 16:49:19 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:19 +0300 |
commit | cec37806d8847aa3db53bafc9e251d4aaf325c12 (patch) | |
tree | 4a61c191e93e31d9ab423e258c71ab43550ee3d2 /library/cpp/yt/coding/zig_zag-inl.h | |
parent | 58cd0b86ed99a72df22479e26a20bc1c1e57e65e (diff) | |
download | ydb-cec37806d8847aa3db53bafc9e251d4aaf325c12.tar.gz |
Restoring authorship annotation for <babenko@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yt/coding/zig_zag-inl.h')
-rw-r--r-- | library/cpp/yt/coding/zig_zag-inl.h | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/library/cpp/yt/coding/zig_zag-inl.h b/library/cpp/yt/coding/zig_zag-inl.h index c611f7e1d4..67ad1f98b0 100644 --- a/library/cpp/yt/coding/zig_zag-inl.h +++ b/library/cpp/yt/coding/zig_zag-inl.h @@ -1,40 +1,40 @@ -#ifndef ZIG_ZAG_INL_H_ -#error "Direct inclusion of this file is not allowed, include zig_zag.h" -// For the sake of sane code completion. -#include "zig_zag.h" -#endif -#undef ZIG_ZAG_INL_H_ - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// - -inline ui32 ZigZagEncode32(i32 n) -{ - // Note: the right-shift must be arithmetic. - // Note: left shift must be unsigned because of overflow. - return (static_cast<ui32>(n) << 1) ^ static_cast<ui32>(n >> 31); -} - -inline i32 ZigZagDecode32(ui32 n) -{ - // Note: using unsigned types prevent undefined behavior. - return static_cast<i32>((n >> 1) ^ (~(n & 1) + 1)); -} - -inline ui64 ZigZagEncode64(i64 n) -{ - // Note: the right-shift must be arithmetic. - // Note: left shift must be unsigned because of overflow. - return (static_cast<ui64>(n) << 1) ^ static_cast<ui64>(n >> 63); -} - -inline i64 ZigZagDecode64(ui64 n) -{ - // Note: using unsigned types prevent undefined behavior. - return static_cast<i64>((n >> 1) ^ (~(n & 1) + 1)); -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT +#ifndef ZIG_ZAG_INL_H_ +#error "Direct inclusion of this file is not allowed, include zig_zag.h" +// For the sake of sane code completion. +#include "zig_zag.h" +#endif +#undef ZIG_ZAG_INL_H_ + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +inline ui32 ZigZagEncode32(i32 n) +{ + // Note: the right-shift must be arithmetic. + // Note: left shift must be unsigned because of overflow. + return (static_cast<ui32>(n) << 1) ^ static_cast<ui32>(n >> 31); +} + +inline i32 ZigZagDecode32(ui32 n) +{ + // Note: using unsigned types prevent undefined behavior. + return static_cast<i32>((n >> 1) ^ (~(n & 1) + 1)); +} + +inline ui64 ZigZagEncode64(i64 n) +{ + // Note: the right-shift must be arithmetic. + // Note: left shift must be unsigned because of overflow. + return (static_cast<ui64>(n) << 1) ^ static_cast<ui64>(n >> 63); +} + +inline i64 ZigZagDecode64(ui64 n) +{ + // Note: using unsigned types prevent undefined behavior. + return static_cast<i64>((n >> 1) ^ (~(n & 1) + 1)); +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT |