#pragma once #include "traits.h" namespace NYsonPull { namespace NDetail { namespace NZigZag { //! Functions that provide coding of integers with property: 0 <= f(x) <= 2 * |x| template inline NTraits::to_unsigned encode(TSigned x) { using TUnsigned = NTraits::to_unsigned; constexpr auto rshift = sizeof(TSigned) * 8 - 1; return (static_cast(x) << 1) ^ static_cast(x >> rshift); } template inline NTraits::to_signed decode(TUnsigned x) { using TSigned = NTraits::to_signed; return static_cast(x >> 1) ^ -static_cast(x & 1); } } } // namespace NDetail }