diff options
author | akhropov <akhropov@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
commit | 00afc96e9c0298054b7386fa7fb9e3cc3d67b974 (patch) | |
tree | cb7a9f4a92c0d4cc5a86eeed49ad71e810953c1f /library/cpp/packedtypes | |
parent | 83a8efcf3af051e3dd59c00d1d5dafc96412ec1e (diff) | |
download | ydb-00afc96e9c0298054b7386fa7fb9e3cc3d67b974.tar.gz |
Restoring authorship annotation for <akhropov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/packedtypes')
-rw-r--r-- | library/cpp/packedtypes/packed.h | 62 | ||||
-rw-r--r-- | library/cpp/packedtypes/packed_ut.cpp | 102 | ||||
-rw-r--r-- | library/cpp/packedtypes/packedfloat.h | 16 |
3 files changed, 90 insertions, 90 deletions
diff --git a/library/cpp/packedtypes/packed.h b/library/cpp/packedtypes/packed.h index 88cff26ae2..044e53be34 100644 --- a/library/cpp/packedtypes/packed.h +++ b/library/cpp/packedtypes/packed.h @@ -1,10 +1,10 @@ #pragma once - + #include <library/cpp/streams/zc_memory_input/zc_memory_input.h> - + #include <util/stream/output.h> -#include <util/ysaveload.h> - +#include <util/ysaveload.h> + #include "longs.h" struct Stream_traits { @@ -38,57 +38,57 @@ struct Stream_traits { static int is_good(IOutputStream& /*out*/) { return 1; } -}; - +}; + struct TZCMemoryInput_traits { template <typename T> static T get(TZCMemoryInput& in) { T x; - in.ReadPOD(x); + in.ReadPOD(x); return x; - } - + } + static ui8 Y_FORCE_INLINE get_8(TZCMemoryInput& in) { return get<ui8>(in); - } - + } + static ui16 Y_FORCE_INLINE get_16(TZCMemoryInput& in) { return get<ui16>(in); - } - + } + static ui32 Y_FORCE_INLINE get_32(TZCMemoryInput& in) { return get<ui32>(in); } static int Y_FORCE_INLINE is_good(TZCMemoryInput&) { - return 1; - } -}; - + return 1; + } +}; + void Y_FORCE_INLINE PackUI32(IOutputStream& out, ui32 v) { - char buf[sizeof(ui32)]; - char* bufPtr = buf; - size_t size; + char buf[sizeof(ui32)]; + char* bufPtr = buf; + size_t size; PACK_28(v, bufPtr, mem_traits, size); - out.Write(buf, size); -} - + out.Write(buf, size); +} + template <class TStream> struct TInputStream2Traits { - typedef Stream_traits TTraits; -}; - + typedef Stream_traits TTraits; +}; + template <> struct TInputStream2Traits<TZCMemoryInput> { - typedef TZCMemoryInput_traits TTraits; -}; - + typedef TZCMemoryInput_traits TTraits; +}; + template <class TStream> void Y_FORCE_INLINE UnPackUI32(TStream& in, ui32& v) { - size_t size; + size_t size; UNPACK_28(v, in, TInputStream2Traits<TStream>::TTraits, size); (void)size; -} +} template <class TStream> ui32 Y_FORCE_INLINE UnPackUI32(TStream& in) { diff --git a/library/cpp/packedtypes/packed_ut.cpp b/library/cpp/packedtypes/packed_ut.cpp index 70a22cf9c3..2be6f6f77f 100644 --- a/library/cpp/packedtypes/packed_ut.cpp +++ b/library/cpp/packedtypes/packed_ut.cpp @@ -1,13 +1,13 @@ #include "packed.h" #include <library/cpp/testing/unittest/registar.h> - + #include <util/system/defaults.h> #include <util/generic/ylimits.h> #include <util/generic/buffer.h> -#include <util/stream/mem.h> +#include <util/stream/mem.h> #include <util/stream/buffer.h> - + namespace NPrivate { #if 0 static ui64 gSeed = 42; @@ -26,67 +26,67 @@ static T PseudoRandom(T max = Max<T>()) { Y_UNIT_TEST_SUITE(TPackedTest) { void TestPackUi32Sub(ui32 v, const TVector<char>& p) { - TBufferOutput out; - PackUI32(out, v); - const TBuffer& buf = out.Buffer(); + TBufferOutput out; + PackUI32(out, v); + const TBuffer& buf = out.Buffer(); UNIT_ASSERT_VALUES_EQUAL(buf.Size(), p.size()); - UNIT_ASSERT(!memcmp(buf.Data(), &p[0], buf.Size())); + UNIT_ASSERT(!memcmp(buf.Data(), &p[0], buf.Size())); - { - TBufferInput in(buf); - ui32 v2; - UnPackUI32(in, v2); + { + TBufferInput in(buf); + ui32 v2; + UnPackUI32(in, v2); UNIT_ASSERT_VALUES_EQUAL(v, v2); - } - + } + { - TZCMemoryInput in(buf.Data(), buf.Size()); - ui32 v2; - UnPackUI32(in, v2); + TZCMemoryInput in(buf.Data(), buf.Size()); + ui32 v2; + UnPackUI32(in, v2); UNIT_ASSERT_VALUES_EQUAL(v, v2); - } - } + } + } Y_UNIT_TEST(TestPackUi32) { - ui32 v; + ui32 v; TVector<char> pv; - - v = 0; - pv.resize(1); - pv[0] = 0x0; + + v = 0; + pv.resize(1); + pv[0] = 0x0; TestPackUi32Sub(v, pv); - - v = 0x1600; - pv.resize(2); - pv[0] = 0x96; - pv[1] = 0x00; + + v = 0x1600; + pv.resize(2); + pv[0] = 0x96; + pv[1] = 0x00; TestPackUi32Sub(v, pv); - - v = 0xEF98; - pv.resize(3); - pv[0] = 0xC0; + + v = 0xEF98; + pv.resize(3); + pv[0] = 0xC0; #if defined(_big_endian_) - pv[1] = 0xEF; - pv[2] = 0x98; -#elif defined(_little_endian_) - pv[1] = 0x98; - pv[2] = 0xEF; -#endif + pv[1] = 0xEF; + pv[2] = 0x98; +#elif defined(_little_endian_) + pv[1] = 0x98; + pv[2] = 0xEF; +#endif TestPackUi32Sub(v, pv); - - v = 0xF567FE4; - pv.resize(4); - pv[0] = 0xEF; - pv[1] = 0x56; + + v = 0xF567FE4; + pv.resize(4); + pv[0] = 0xEF; + pv[1] = 0x56; #if defined(_big_endian_) - pv[2] = 0x7F; - pv[3] = 0xE4; -#elif defined(_little_endian_) - pv[2] = 0xE4; - pv[3] = 0x7F; -#endif + pv[2] = 0x7F; + pv[3] = 0xE4; +#elif defined(_little_endian_) + pv[2] = 0xE4; + pv[3] = 0x7F; +#endif TestPackUi32Sub(v, pv); - } + } #if 0 Y_UNIT_TEST(ReadWrite32) { @@ -127,4 +127,4 @@ Y_UNIT_TEST_SUITE(TPackedTest) { } } #endif -}; +}; diff --git a/library/cpp/packedtypes/packedfloat.h b/library/cpp/packedtypes/packedfloat.h index f178912ed3..334072f211 100644 --- a/library/cpp/packedtypes/packedfloat.h +++ b/library/cpp/packedtypes/packedfloat.h @@ -157,27 +157,27 @@ using uf8 = NPackedFloat::float8<0>; using f8d = NPackedFloat::float8<1, 1>; using uf8d = NPackedFloat::float8<0, 1>; -// [0,1) value in 1/255s. +// [0,1) value in 1/255s. using frac8 = ui8; - + using frac16 = ui16; template <class T> inline constexpr T Float2Frac(float fac) { return T(fac * float(Max<T>())); -} - +} + template <class T> inline constexpr T Float2FracR(float fac) { float v = fac * float(Max<T>()); - return T(v + 0.5f); -} - + return T(v + 0.5f); +} + template <class T> inline constexpr float Frac2Float(T pf) { constexpr float multiplier = float(1.0 / Max<T>()); return pf * multiplier; -} +} class TUi82FloatMapping { private: |