summaryrefslogtreecommitdiffstats
path: root/library/cpp/packedtypes
diff options
context:
space:
mode:
authorAnton Samokhvalov <[email protected]>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/packedtypes
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
Restoring authorship annotation for Anton Samokhvalov <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/packedtypes')
-rw-r--r--library/cpp/packedtypes/fixed_point.h108
-rw-r--r--library/cpp/packedtypes/longs.cpp2
-rw-r--r--library/cpp/packedtypes/longs.h392
-rw-r--r--library/cpp/packedtypes/longs_ut.cpp16
-rw-r--r--library/cpp/packedtypes/packed.h40
-rw-r--r--library/cpp/packedtypes/packed_ut.cpp24
-rw-r--r--library/cpp/packedtypes/packedfloat.cpp12
-rw-r--r--library/cpp/packedtypes/packedfloat.h204
-rw-r--r--library/cpp/packedtypes/packedfloat_ut.cpp36
-rw-r--r--library/cpp/packedtypes/ya.make2
-rw-r--r--library/cpp/packedtypes/zigzag.h4
11 files changed, 420 insertions, 420 deletions
diff --git a/library/cpp/packedtypes/fixed_point.h b/library/cpp/packedtypes/fixed_point.h
index b36b80876e1..63b45a73c57 100644
--- a/library/cpp/packedtypes/fixed_point.h
+++ b/library/cpp/packedtypes/fixed_point.h
@@ -1,71 +1,71 @@
#pragma once
namespace NFixedPoint {
- template <ui64 FracMult>
- class TFixedPoint {
- typedef TFixedPoint<FracMult> TSelf;
- ui64 Rep;
+ template <ui64 FracMult>
+ class TFixedPoint {
+ typedef TFixedPoint<FracMult> TSelf;
+ ui64 Rep;
- public:
- TFixedPoint()
- : Rep()
- {
- }
+ public:
+ TFixedPoint()
+ : Rep()
+ {
+ }
- template <typename T>
- explicit TFixedPoint(T t)
- : Rep(ui64(t * FracMult))
- {
- }
+ template <typename T>
+ explicit TFixedPoint(T t)
+ : Rep(ui64(t * FracMult))
+ {
+ }
- explicit TFixedPoint(ui64 i, ui64 f)
- : Rep(i * FracMult + f % FracMult)
- {
- }
+ explicit TFixedPoint(ui64 i, ui64 f)
+ : Rep(i * FracMult + f % FracMult)
+ {
+ }
- template <typename T>
- TSelf& operator=(T t) {
- Rep = t * FracMult;
- return *this;
- }
+ template <typename T>
+ TSelf& operator=(T t) {
+ Rep = t * FracMult;
+ return *this;
+ }
- operator double() const {
- return Int() + double(Frac()) / FracMult;
- }
+ operator double() const {
+ return Int() + double(Frac()) / FracMult;
+ }
- operator ui64() const {
- return Int();
- }
+ operator ui64() const {
+ return Int();
+ }
- template <typename T>
- TSelf& operator/=(T t) {
- Rep = ui64(Rep / t);
- return *this;
- }
+ template <typename T>
+ TSelf& operator/=(T t) {
+ Rep = ui64(Rep / t);
+ return *this;
+ }
- template <typename T>
- TSelf operator/(T t) const {
- TSelf r = *this;
- return r /= t;
- }
+ template <typename T>
+ TSelf operator/(T t) const {
+ TSelf r = *this;
+ return r /= t;
+ }
- ui64 Frac() const {
- return Rep % FracMult;
- }
+ ui64 Frac() const {
+ return Rep % FracMult;
+ }
- ui64 Int() const {
- return Rep / FracMult;
- }
+ ui64 Int() const {
+ return Rep / FracMult;
+ }
- static ui64 Mult() {
- return FracMult;
- }
+ static ui64 Mult() {
+ return FracMult;
+ }
- static TSelf Make(ui64 rep) {
- TFixedPoint<FracMult> fp;
- fp.Rep = rep;
- return fp;
- }
- };
+ static TSelf Make(ui64 rep) {
+ TFixedPoint<FracMult> fp;
+ fp.Rep = rep;
+ return fp;
+ }
+ };
}
diff --git a/library/cpp/packedtypes/longs.cpp b/library/cpp/packedtypes/longs.cpp
index 4cb6f4963ba..162322af449 100644
--- a/library/cpp/packedtypes/longs.cpp
+++ b/library/cpp/packedtypes/longs.cpp
@@ -1 +1 @@
-#include "longs.h"
+#include "longs.h"
diff --git a/library/cpp/packedtypes/longs.h b/library/cpp/packedtypes/longs.h
index 084098d705e..ddf2a9d3ca9 100644
--- a/library/cpp/packedtypes/longs.h
+++ b/library/cpp/packedtypes/longs.h
@@ -1,45 +1,45 @@
#pragma once
-#include <util/system/defaults.h> // _BIDSCLASS _EXPCLASS
+#include <util/system/defaults.h> // _BIDSCLASS _EXPCLASS
#include <util/system/yassert.h>
#include <util/system/unaligned_mem.h>
+
+#define PUT_8(x, buf, shift) WriteUnaligned<ui8>((buf)++, (x) >> (shift))
+#define GET_8_OR(x, buf, type, shift) (x) |= (type) * (buf)++ << (shift)
-#define PUT_8(x, buf, shift) WriteUnaligned<ui8>((buf)++, (x) >> (shift))
-#define GET_8_OR(x, buf, type, shift) (x) |= (type) * (buf)++ << (shift)
-
-#if defined(_big_endian_)
+#if defined(_big_endian_)
#define LO_SHIFT 1
#define HI_SHIFT 0
-#elif defined(_little_endian_)
+#elif defined(_little_endian_)
#define LO_SHIFT 0
#define HI_SHIFT 1
#endif
-#if !defined(_must_align2_)
-#define PUT_16(x, buf, shift) WriteUnaligned<ui16>(buf, (x) >> (shift)), (buf) += 2
-#define GET_16_OR(x, buf, type, shift) (x) |= (type)ReadUnaligned<ui16>(buf) << (shift), (buf) += 2
+#if !defined(_must_align2_)
+#define PUT_16(x, buf, shift) WriteUnaligned<ui16>(buf, (x) >> (shift)), (buf) += 2
+#define GET_16_OR(x, buf, type, shift) (x) |= (type)ReadUnaligned<ui16>(buf) << (shift), (buf) += 2
#else
-#define PUT_16(x, buf, shift) PUT_8(x, buf, shift + 8 * LO_SHIFT), PUT_8(x, buf, shift + 8 * HI_SHIFT)
-#define GET_16_OR(x, buf, type, shift) GET_8_OR(x, buf, type, shift + 8 * LO_SHIFT), GET_8_OR(x, buf, type, shift + 8 * HI_SHIFT)
+#define PUT_16(x, buf, shift) PUT_8(x, buf, shift + 8 * LO_SHIFT), PUT_8(x, buf, shift + 8 * HI_SHIFT)
+#define GET_16_OR(x, buf, type, shift) GET_8_OR(x, buf, type, shift + 8 * LO_SHIFT), GET_8_OR(x, buf, type, shift + 8 * HI_SHIFT)
#endif
-#if !defined(_must_align4_)
-#define PUT_32(x, buf, shift) WriteUnaligned<ui32>(buf, (x) >> (shift)), (buf) += 4
-#define GET_32_OR(x, buf, type, shift) (x) |= (type)ReadUnaligned<ui32>(buf) << (shift), (buf) += 4
+#if !defined(_must_align4_)
+#define PUT_32(x, buf, shift) WriteUnaligned<ui32>(buf, (x) >> (shift)), (buf) += 4
+#define GET_32_OR(x, buf, type, shift) (x) |= (type)ReadUnaligned<ui32>(buf) << (shift), (buf) += 4
#else
-#define PUT_32(x, buf, shift) PUT_16(x, buf, shift + 16 * LO_SHIFT), PUT_16(x, buf, shift + 16 * HI_SHIFT)
-#define GET_32_OR(x, buf, type, shift) GET_16_OR(x, buf, type, shift + 16 * LO_SHIFT), GET_16_OR(x, buf, type, shift + 16 * HI_SHIFT)
+#define PUT_32(x, buf, shift) PUT_16(x, buf, shift + 16 * LO_SHIFT), PUT_16(x, buf, shift + 16 * HI_SHIFT)
+#define GET_32_OR(x, buf, type, shift) GET_16_OR(x, buf, type, shift + 16 * LO_SHIFT), GET_16_OR(x, buf, type, shift + 16 * HI_SHIFT)
#endif
-#if !defined(_must_align8_)
-#define PUT_64(x, buf, shift) WriteUnaligned<ui64>(buf, (x) >> (shift)), (buf) += 8
-#define GET_64_OR(x, buf, type, shift) (x) |= (type)ReadUnaligned<ui64>(buf) << (shift), (buf) += 8
+#if !defined(_must_align8_)
+#define PUT_64(x, buf, shift) WriteUnaligned<ui64>(buf, (x) >> (shift)), (buf) += 8
+#define GET_64_OR(x, buf, type, shift) (x) |= (type)ReadUnaligned<ui64>(buf) << (shift), (buf) += 8
#else
-#define PUT_64(x, buf, shift) PUT_32(x, buf, shift + 32 * LO_SHIFT), PUT_32(x, buf, shift + 32 * HI_SHIFT)
-#define GET_64_OR(x, buf, type, shift) GET_32_OR(x, buf, type, shift + 32 * LO_SHIFT), GET_32_OR(x, buf, type, shift + 32 * HI_SHIFT)
+#define PUT_64(x, buf, shift) PUT_32(x, buf, shift + 32 * LO_SHIFT), PUT_32(x, buf, shift + 32 * HI_SHIFT)
+#define GET_64_OR(x, buf, type, shift) GET_32_OR(x, buf, type, shift + 32 * LO_SHIFT), GET_32_OR(x, buf, type, shift + 32 * HI_SHIFT)
#endif
-struct mem_traits {
+struct mem_traits {
static ui8 get_8(const char*& mem) {
ui8 x = 0;
GET_8_OR(x, mem, ui8, 0);
@@ -64,7 +64,7 @@ struct mem_traits {
static void put_32(ui32 x, char*& mem) {
PUT_32(x, mem, 0);
}
- static int is_good(char*&) {
+ static int is_good(char*&) {
return 1;
}
};
@@ -93,216 +93,216 @@ struct mem_traits {
#define MY_28(x) ((ui32)(x) < PACK2LIM ? MY_14(x) : ((ui32)(x) < PACK3LIM ? 3 : 4))
#define MY_32(x) ((ui32)(x) < PACK4LIM ? MY_28(x) : 5)
-#define MY_64(x) ((ui64)(x) < PACK4LIM ? MY_28(x) : ((ui64)(x) < PACK6LIM ? ((ui64)(x) < PACK5LIM ? 5 : 6) : ((ui64)(x) < PACK7LIM ? 7 : ((ui64)(x) < PACK8LIM ? 8 : 9))))
+#define MY_64(x) ((ui64)(x) < PACK4LIM ? MY_28(x) : ((ui64)(x) < PACK6LIM ? ((ui64)(x) < PACK5LIM ? 5 : 6) : ((ui64)(x) < PACK7LIM ? 7 : ((ui64)(x) < PACK8LIM ? 8 : 9))))
-#if !defined(MACRO_BEGIN)
-#define MACRO_BEGIN do {
-#define MACRO_END \
- } \
- while (0)
+#if !defined(MACRO_BEGIN)
+#define MACRO_BEGIN do {
+#define MACRO_END \
+ } \
+ while (0)
#endif
-#define PACK_14(x, buf, how, ret) \
- MACRO_BEGIN \
- if ((ui16)(x) < PACK1LIM) { \
- how::put_8((ui8)(x), (buf)); \
- (ret) = 1; \
- } else { \
- how::put_8((ui8)(0x80 | (x) >> 8), (buf)); \
- how::put_8((ui8)(x), (buf)); \
- (ret) = 2; \
- } \
- MACRO_END
+#define PACK_14(x, buf, how, ret) \
+ MACRO_BEGIN \
+ if ((ui16)(x) < PACK1LIM) { \
+ how::put_8((ui8)(x), (buf)); \
+ (ret) = 1; \
+ } else { \
+ how::put_8((ui8)(0x80 | (x) >> 8), (buf)); \
+ how::put_8((ui8)(x), (buf)); \
+ (ret) = 2; \
+ } \
+ MACRO_END
-#define PACK_28(x, buf, how, ret) \
- MACRO_BEGIN \
- if ((ui32)(x) < PACK2LIM) { \
- PACK_14(x, buf, how, ret); \
- } else { \
- if ((ui32)(x) < PACK3LIM) { \
- how::put_8((ui8)(0xC0 | (x) >> 16), buf); \
- (ret) = 3; \
- } else { \
- how::put_8((ui8)(0xE0 | (x) >> 24), buf); \
- how::put_8((ui8)((x) >> 16), buf); \
- (ret) = 4; \
- } \
- how::put_16((ui16)(x), (buf)); \
- } \
- MACRO_END
+#define PACK_28(x, buf, how, ret) \
+ MACRO_BEGIN \
+ if ((ui32)(x) < PACK2LIM) { \
+ PACK_14(x, buf, how, ret); \
+ } else { \
+ if ((ui32)(x) < PACK3LIM) { \
+ how::put_8((ui8)(0xC0 | (x) >> 16), buf); \
+ (ret) = 3; \
+ } else { \
+ how::put_8((ui8)(0xE0 | (x) >> 24), buf); \
+ how::put_8((ui8)((x) >> 16), buf); \
+ (ret) = 4; \
+ } \
+ how::put_16((ui16)(x), (buf)); \
+ } \
+ MACRO_END
-#define PACK_32(x, buf, how, ret) \
- MACRO_BEGIN \
- if ((ui32)(x) < PACK4LIM) { \
- PACK_28(x, buf, how, ret); \
- } else { \
- how::put_8((ui8)(0xF0), buf); \
- how::put_32((ui32)(x), buf); \
- (ret) = 5; \
- } \
- MACRO_END
+#define PACK_32(x, buf, how, ret) \
+ MACRO_BEGIN \
+ if ((ui32)(x) < PACK4LIM) { \
+ PACK_28(x, buf, how, ret); \
+ } else { \
+ how::put_8((ui8)(0xF0), buf); \
+ how::put_32((ui32)(x), buf); \
+ (ret) = 5; \
+ } \
+ MACRO_END
-#define PACK_64(x, buf, how, ret) \
- MACRO_BEGIN \
- if ((ui64)(x) < PACK4LIM) { \
- PACK_28((ui32)(x), buf, how, ret); \
- } else { \
- if ((ui64)(x) < PACK6LIM) { \
- if ((ui64)(x) < PACK5LIM) { \
- how::put_8((ui8)(0xF0 | (x) >> 32), buf); \
- (ret) = 5; \
- } else { \
- how::put_8((ui8)(0xF8 | (x) >> 40), buf); \
- how::put_8((ui8)((x) >> 32), buf); \
- (ret) = 6; \
- } \
- } else { \
- if ((ui64)(x) < PACK7LIM) { \
- how::put_8((ui8)(0xFC | (x) >> 48), buf); \
- (ret) = 7; \
- } else { \
- if ((ui64)(x) < PACK8LIM) { \
- how::put_8((ui8)(0xFE | (x) >> 56), buf); \
- how::put_8((ui8)((x) >> 48), buf); \
- (ret) = 8; \
- } else { \
- how::put_8((ui8)(0xFF), buf); \
- how::put_16((ui16)((x) >> 48), buf); \
- (ret) = 9; \
- } \
- } \
- how::put_16((ui16)((x) >> 32), buf); \
- } \
- how::put_32((ui32)(x), buf); \
- } \
- MACRO_END
+#define PACK_64(x, buf, how, ret) \
+ MACRO_BEGIN \
+ if ((ui64)(x) < PACK4LIM) { \
+ PACK_28((ui32)(x), buf, how, ret); \
+ } else { \
+ if ((ui64)(x) < PACK6LIM) { \
+ if ((ui64)(x) < PACK5LIM) { \
+ how::put_8((ui8)(0xF0 | (x) >> 32), buf); \
+ (ret) = 5; \
+ } else { \
+ how::put_8((ui8)(0xF8 | (x) >> 40), buf); \
+ how::put_8((ui8)((x) >> 32), buf); \
+ (ret) = 6; \
+ } \
+ } else { \
+ if ((ui64)(x) < PACK7LIM) { \
+ how::put_8((ui8)(0xFC | (x) >> 48), buf); \
+ (ret) = 7; \
+ } else { \
+ if ((ui64)(x) < PACK8LIM) { \
+ how::put_8((ui8)(0xFE | (x) >> 56), buf); \
+ how::put_8((ui8)((x) >> 48), buf); \
+ (ret) = 8; \
+ } else { \
+ how::put_8((ui8)(0xFF), buf); \
+ how::put_16((ui16)((x) >> 48), buf); \
+ (ret) = 9; \
+ } \
+ } \
+ how::put_16((ui16)((x) >> 32), buf); \
+ } \
+ how::put_32((ui32)(x), buf); \
+ } \
+ MACRO_END
-#define DO_UNPACK_14(firstByte, x, buf, how, ret) \
- MACRO_BEGIN \
- if (firstByte < 0x80) { \
- (x) = (firstByte); \
- (ret) = 1; \
- } else { \
- (x) = (firstByte & 0x7F) << 8; \
- (x) |= how::get_8(buf); \
- (ret) = 2; \
- } \
- MACRO_END
+#define DO_UNPACK_14(firstByte, x, buf, how, ret) \
+ MACRO_BEGIN \
+ if (firstByte < 0x80) { \
+ (x) = (firstByte); \
+ (ret) = 1; \
+ } else { \
+ (x) = (firstByte & 0x7F) << 8; \
+ (x) |= how::get_8(buf); \
+ (ret) = 2; \
+ } \
+ MACRO_END
-#define UNPACK_14(x, buf, how, ret) \
- MACRO_BEGIN \
- ui8 firstByte = how::get_8(buf); \
- DO_UNPACK_14(firstByte, x, buf, how, ret); \
- MACRO_END
+#define UNPACK_14(x, buf, how, ret) \
+ MACRO_BEGIN \
+ ui8 firstByte = how::get_8(buf); \
+ DO_UNPACK_14(firstByte, x, buf, how, ret); \
+ MACRO_END
-#define DO_UNPACK_28(firstByte, x, buf, how, ret) \
- MACRO_BEGIN \
- if (firstByte < 0xC0) { \
- DO_UNPACK_14(firstByte, x, buf, how, ret); \
- } else { \
- if (firstByte < 0xE0) { \
- (x) = (firstByte & 0x3F) << 16; \
- (ret) = 3; \
- } else { \
- (x) = (firstByte & 0x1F) << 24; \
- (x) |= how::get_8(buf) << 16; \
- (ret) = 4; \
- } \
- (x) |= how::get_16(buf); \
- } \
- MACRO_END
+#define DO_UNPACK_28(firstByte, x, buf, how, ret) \
+ MACRO_BEGIN \
+ if (firstByte < 0xC0) { \
+ DO_UNPACK_14(firstByte, x, buf, how, ret); \
+ } else { \
+ if (firstByte < 0xE0) { \
+ (x) = (firstByte & 0x3F) << 16; \
+ (ret) = 3; \
+ } else { \
+ (x) = (firstByte & 0x1F) << 24; \
+ (x) |= how::get_8(buf) << 16; \
+ (ret) = 4; \
+ } \
+ (x) |= how::get_16(buf); \
+ } \
+ MACRO_END
-#define UNPACK_28(x, buf, how, ret) \
- MACRO_BEGIN \
- ui8 firstByte = how::get_8(buf); \
- DO_UNPACK_28(firstByte, x, buf, how, ret); \
- MACRO_END
+#define UNPACK_28(x, buf, how, ret) \
+ MACRO_BEGIN \
+ ui8 firstByte = how::get_8(buf); \
+ DO_UNPACK_28(firstByte, x, buf, how, ret); \
+ MACRO_END
-#define DO_UNPACK_32(firstByte, x, buf, how, ret) \
- MACRO_BEGIN \
- if (firstByte < 0xF0) { \
- DO_UNPACK_28(firstByte, x, buf, how, ret); \
- } else { \
- (x) = how::get_32(buf); \
- (ret) = 5; \
- } \
- MACRO_END
+#define DO_UNPACK_32(firstByte, x, buf, how, ret) \
+ MACRO_BEGIN \
+ if (firstByte < 0xF0) { \
+ DO_UNPACK_28(firstByte, x, buf, how, ret); \
+ } else { \
+ (x) = how::get_32(buf); \
+ (ret) = 5; \
+ } \
+ MACRO_END
-#define UNPACK_32(x, buf, how, ret) \
- MACRO_BEGIN \
- ui8 firstByte = how::get_8(buf); \
- DO_UNPACK_32(firstByte, x, buf, how, ret); \
- MACRO_END
+#define UNPACK_32(x, buf, how, ret) \
+ MACRO_BEGIN \
+ ui8 firstByte = how::get_8(buf); \
+ DO_UNPACK_32(firstByte, x, buf, how, ret); \
+ MACRO_END
-#define DO_UNPACK_64(firstByte, x, buf, how, ret) \
- MACRO_BEGIN \
- if (firstByte < 0xF0) { \
- DO_UNPACK_28(firstByte, x, buf, how, ret); \
- } else { \
- if (firstByte < 0xFC) { \
- if (firstByte < 0xF8) { \
- (x) = (ui64)(firstByte & 0x0F) << 32; \
- (ret) = 5; \
- } else { \
- (x) = (ui64)(firstByte & 0x07) << 40; \
- (x) |= (ui64)how::get_8(buf) << 32; \
- (ret) = 6; \
- } \
- } else { \
- if (firstByte < 0xFE) { \
- (x) = (ui64)(firstByte & 0x03) << 48; \
- (ret) = 7; \
- } else { \
- if (firstByte < 0xFF) { \
- (x) = (ui64)(firstByte & 0x01) << 56; \
- (x) |= (ui64)how::get_8(buf) << 48; \
- (ret) = 8; \
- } else { \
- (x) = (ui64)how::get_16(buf) << 48; \
- (ret) = 9; \
- } \
- } \
- (x) |= (ui64)how::get_16(buf) << 32; \
- } \
- (x) |= how::get_32(buf); \
- } \
- MACRO_END
+#define DO_UNPACK_64(firstByte, x, buf, how, ret) \
+ MACRO_BEGIN \
+ if (firstByte < 0xF0) { \
+ DO_UNPACK_28(firstByte, x, buf, how, ret); \
+ } else { \
+ if (firstByte < 0xFC) { \
+ if (firstByte < 0xF8) { \
+ (x) = (ui64)(firstByte & 0x0F) << 32; \
+ (ret) = 5; \
+ } else { \
+ (x) = (ui64)(firstByte & 0x07) << 40; \
+ (x) |= (ui64)how::get_8(buf) << 32; \
+ (ret) = 6; \
+ } \
+ } else { \
+ if (firstByte < 0xFE) { \
+ (x) = (ui64)(firstByte & 0x03) << 48; \
+ (ret) = 7; \
+ } else { \
+ if (firstByte < 0xFF) { \
+ (x) = (ui64)(firstByte & 0x01) << 56; \
+ (x) |= (ui64)how::get_8(buf) << 48; \
+ (ret) = 8; \
+ } else { \
+ (x) = (ui64)how::get_16(buf) << 48; \
+ (ret) = 9; \
+ } \
+ } \
+ (x) |= (ui64)how::get_16(buf) << 32; \
+ } \
+ (x) |= how::get_32(buf); \
+ } \
+ MACRO_END
-#define UNPACK_64(x, buf, how, ret) \
- MACRO_BEGIN \
- ui8 firstByte = how::get_8(buf); \
- DO_UNPACK_64(firstByte, x, buf, how, ret); \
- MACRO_END
+#define UNPACK_64(x, buf, how, ret) \
+ MACRO_BEGIN \
+ ui8 firstByte = how::get_8(buf); \
+ DO_UNPACK_64(firstByte, x, buf, how, ret); \
+ MACRO_END
-inline int in_long(i64& longVal, const char* ptrBuf) {
+inline int in_long(i64& longVal, const char* ptrBuf) {
int ret;
UNPACK_64(longVal, ptrBuf, mem_traits, ret);
return ret;
}
-inline int out_long(const i64& longVal, char* ptrBuf) {
+inline int out_long(const i64& longVal, char* ptrBuf) {
int ret;
- PACK_64(longVal, ptrBuf, mem_traits, ret); /*7*/
+ PACK_64(longVal, ptrBuf, mem_traits, ret); /*7*/
return ret;
}
-inline int len_long(const i64& longVal) {
+inline int len_long(const i64& longVal) {
return MY_64(longVal);
}
-inline int in_long(i32& longVal, const char* ptrBuf) {
+inline int in_long(i32& longVal, const char* ptrBuf) {
int ret;
UNPACK_32(longVal, ptrBuf, mem_traits, ret);
return ret;
}
-inline int out_long(const i32& longVal, char* ptrBuf) {
+inline int out_long(const i32& longVal, char* ptrBuf) {
int ret;
PACK_32(longVal, ptrBuf, mem_traits, ret);
return ret;
}
-inline int len_long(const i32& longVal) {
+inline int len_long(const i32& longVal) {
return MY_32(longVal);
}
diff --git a/library/cpp/packedtypes/longs_ut.cpp b/library/cpp/packedtypes/longs_ut.cpp
index 8b06c934d2f..e09c03d8ac6 100644
--- a/library/cpp/packedtypes/longs_ut.cpp
+++ b/library/cpp/packedtypes/longs_ut.cpp
@@ -1,9 +1,9 @@
-#include "longs.h"
-
+#include "longs.h"
+
#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/digest/old_crc/crc.h>
-#include <util/string/util.h>
+#include <util/string/util.h>
#include <util/stream/output.h>
#include <util/system/hi_lo.h>
@@ -19,7 +19,7 @@ Y_UNIT_TEST_SUITE(TLongsTest) {
char buf[100];
memset(buf, 0, 100);
- char* p = buf;
+ char* p = buf;
int l = out_long(x64, buf);
s += Sprintf("x64=0x%" PRIi64 "\n", x64);
s += Sprintf("LO_32(x64)=0x%" PRIu32 " HI_32(x64)=0x%" PRIu32 "\n", (ui32)Lo32(x64), (ui32)Hi32(x64));
@@ -28,7 +28,7 @@ Y_UNIT_TEST_SUITE(TLongsTest) {
s += Sprintf("0x%02x ", buf[i]);
}
s += Sprintf("\n");
-
+
p = buf;
in_long(y64, p);
s += Sprintf("x=0x%" PRIi64 " y=0x%" PRIi64 "\n", x64, y64);
@@ -37,7 +37,7 @@ Y_UNIT_TEST_SUITE(TLongsTest) {
} else {
s += Sprintf("OK\n");
}
-
+
UNIT_ASSERT_EQUAL(Crc<ui64>(s.data(), s.size()), 7251624297500315779ULL); // WTF?
}
@@ -58,9 +58,9 @@ Y_UNIT_TEST_SUITE(TLongsTest) {
TestOneValue<TSignedInt>((TSignedInt)(1ull << i));
TestOneValue<TSignedInt>((TSignedInt)((1ull << i) - 1));
TestOneValue<TSignedInt>((TSignedInt)((1ull << i) + 1));
- }
+ }
}
-
+
Y_UNIT_TEST(TestCornerCases) {
TestCornerCasesImpl<i32>(31);
TestCornerCasesImpl<i64>(63);
diff --git a/library/cpp/packedtypes/packed.h b/library/cpp/packedtypes/packed.h
index 88cff26ae2a..340fd994726 100644
--- a/library/cpp/packedtypes/packed.h
+++ b/library/cpp/packedtypes/packed.h
@@ -7,8 +7,8 @@
#include "longs.h"
-struct Stream_traits {
- template <typename T>
+struct Stream_traits {
+ template <typename T>
static T get(IInputStream& in) {
T x;
::Load(&in, x);
@@ -32,23 +32,23 @@ struct Stream_traits {
static void put_32(ui32 x, IOutputStream& out) {
::Save(&out, x);
}
- static int is_good(IInputStream& /*in*/) {
- return 1;
- }
- static int is_good(IOutputStream& /*out*/) {
- return 1;
- }
+ static int is_good(IInputStream& /*in*/) {
+ return 1;
+ }
+ static int is_good(IOutputStream& /*out*/) {
+ return 1;
+ }
};
-struct TZCMemoryInput_traits {
- template <typename T>
+struct TZCMemoryInput_traits {
+ template <typename T>
static T get(TZCMemoryInput& in) {
T x;
in.ReadPOD(x);
return x;
}
- static ui8 Y_FORCE_INLINE get_8(TZCMemoryInput& in) {
+ static ui8 Y_FORCE_INLINE get_8(TZCMemoryInput& in) {
return get<ui8>(in);
}
@@ -73,25 +73,25 @@ void Y_FORCE_INLINE PackUI32(IOutputStream& out, ui32 v) {
out.Write(buf, size);
}
-template <class TStream>
-struct TInputStream2Traits {
+template <class TStream>
+struct TInputStream2Traits {
typedef Stream_traits TTraits;
};
-template <>
-struct TInputStream2Traits<TZCMemoryInput> {
+template <>
+struct TInputStream2Traits<TZCMemoryInput> {
typedef TZCMemoryInput_traits TTraits;
};
-template <class TStream>
-void Y_FORCE_INLINE UnPackUI32(TStream& in, ui32& v) {
+template <class TStream>
+void Y_FORCE_INLINE UnPackUI32(TStream& in, ui32& v) {
size_t size;
UNPACK_28(v, in, TInputStream2Traits<TStream>::TTraits, size);
- (void)size;
+ (void)size;
}
-template <class TStream>
-ui32 Y_FORCE_INLINE UnPackUI32(TStream& in) {
+template <class TStream>
+ui32 Y_FORCE_INLINE UnPackUI32(TStream& in) {
ui32 res;
UnPackUI32(in, res);
return res;
diff --git a/library/cpp/packedtypes/packed_ut.cpp b/library/cpp/packedtypes/packed_ut.cpp
index 70a22cf9c31..4f7bd4a9cac 100644
--- a/library/cpp/packedtypes/packed_ut.cpp
+++ b/library/cpp/packedtypes/packed_ut.cpp
@@ -1,15 +1,15 @@
-#include "packed.h"
-
+#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/buffer.h>
+#include <util/stream/buffer.h>
namespace NPrivate {
-#if 0
+#if 0
static ui64 gSeed = 42;
template<typename T>
@@ -21,8 +21,8 @@ static T PseudoRandom(T max = Max<T>()) {
gSeed = gSeed ^ (ui64(max) << 17u);
return gSeed % max;
};
-#endif
-}
+#endif
+}
Y_UNIT_TEST_SUITE(TPackedTest) {
void TestPackUi32Sub(ui32 v, const TVector<char>& p) {
@@ -54,38 +54,38 @@ Y_UNIT_TEST_SUITE(TPackedTest) {
v = 0;
pv.resize(1);
pv[0] = 0x0;
- TestPackUi32Sub(v, pv);
+ TestPackUi32Sub(v, pv);
v = 0x1600;
pv.resize(2);
pv[0] = 0x96;
pv[1] = 0x00;
- TestPackUi32Sub(v, pv);
+ TestPackUi32Sub(v, pv);
v = 0xEF98;
pv.resize(3);
pv[0] = 0xC0;
-#if defined(_big_endian_)
+#if defined(_big_endian_)
pv[1] = 0xEF;
pv[2] = 0x98;
#elif defined(_little_endian_)
pv[1] = 0x98;
pv[2] = 0xEF;
#endif
- TestPackUi32Sub(v, pv);
+ TestPackUi32Sub(v, pv);
v = 0xF567FE4;
pv.resize(4);
pv[0] = 0xEF;
pv[1] = 0x56;
-#if defined(_big_endian_)
+#if defined(_big_endian_)
pv[2] = 0x7F;
pv[3] = 0xE4;
#elif defined(_little_endian_)
pv[2] = 0xE4;
pv[3] = 0x7F;
#endif
- TestPackUi32Sub(v, pv);
+ TestPackUi32Sub(v, pv);
}
#if 0
diff --git a/library/cpp/packedtypes/packedfloat.cpp b/library/cpp/packedtypes/packedfloat.cpp
index 6039d78969e..3f6d7379a48 100644
--- a/library/cpp/packedtypes/packedfloat.cpp
+++ b/library/cpp/packedtypes/packedfloat.cpp
@@ -2,10 +2,10 @@
#include <util/stream/output.h>
-#define OUT_IMPL(T) \
- template <> \
- void Out<T>(IOutputStream & os, TTypeTraits<T>::TFuncParam val) { \
- os << (float)val; \
+#define OUT_IMPL(T) \
+ template <> \
+ void Out<T>(IOutputStream & os, TTypeTraits<T>::TFuncParam val) { \
+ os << (float)val; \
}
OUT_IMPL(f16)
@@ -14,5 +14,5 @@ OUT_IMPL(f8)
OUT_IMPL(uf8)
OUT_IMPL(f8d)
OUT_IMPL(uf8d)
-
-#undef OUT_IMPL
+
+#undef OUT_IMPL
diff --git a/library/cpp/packedtypes/packedfloat.h b/library/cpp/packedtypes/packedfloat.h
index f178912ed33..2f66d111301 100644
--- a/library/cpp/packedtypes/packedfloat.h
+++ b/library/cpp/packedtypes/packedfloat.h
@@ -1,86 +1,86 @@
#pragma once
#include <util/generic/cast.h>
-#include <util/generic/ylimits.h>
+#include <util/generic/ylimits.h>
#include <util/system/hi_lo.h>
-
+
#include <cmath>
#include <cfloat>
-#include <limits>
+#include <limits>
#include <algorithm>
#include <cassert>
namespace NPackedFloat {
- /*
+ /*
Exponent Mantissa zero Mantissa non-zero Equation
0x00 zero denormal (-1)^sign * 2^-126 * 0.mantissa
0x01–0xfe normalized value (-1)^sign * 2^(exponent - 127) * 1.mantissa
0xff infinity NaN
* */
- //fast 16 bit floats by melkov
- template <ui8 SIGNED>
- struct float16 {
- private:
- typedef float16<SIGNED> self;
+ //fast 16 bit floats by melkov
+ template <ui8 SIGNED>
+ struct float16 {
+ private:
+ typedef float16<SIGNED> self;
- public:
- ui16 val;
+ public:
+ ui16 val;
- explicit float16(ui16 v = 0)
- : val(v)
- {
- }
+ explicit float16(ui16 v = 0)
+ : val(v)
+ {
+ }
- self& operator=(float t) {
- assert(SIGNED == 1 || SIGNED == 0 && t >= 0.);
+ self& operator=(float t) {
+ assert(SIGNED == 1 || SIGNED == 0 && t >= 0.);
val = BitCast<ui32>(t) >> (15 + SIGNED);
- return *this;
- }
+ return *this;
+ }
- operator float() const {
+ operator float() const {
return BitCast<float>((ui32)val << (15 + SIGNED));
- }
+ }
- static self New(float v) {
- self f;
- return f = v;
- }
+ static self New(float v) {
+ self f;
+ return f = v;
+ }
- static self denorm_min() {
- return self(0x0001);
- }
+ static self denorm_min() {
+ return self(0x0001);
+ }
- static self min() {
- return self(SIGNED ? 0x0080 : 0x0100);
- }
+ static self min() {
+ return self(SIGNED ? 0x0080 : 0x0100);
+ }
- static self max() {
- return self(SIGNED ? 0x7f7f : 0xfeff);
- }
+ static self max() {
+ return self(SIGNED ? 0x7f7f : 0xfeff);
+ }
};
- //fast 8 bit floats
- template <ui8 SIGNED, ui8 DENORM = 0>
- struct float8 {
- private:
- typedef float8<SIGNED, DENORM> self;
- enum {
- FMinExp = SIGNED ? 0x7c : 0x78,
- FMaxExp = SIGNED ? 0x83 : 0x87,
- MaxExp = SIGNED ? 0x70 : 0xf0,
- };
+ //fast 8 bit floats
+ template <ui8 SIGNED, ui8 DENORM = 0>
+ struct float8 {
+ private:
+ typedef float8<SIGNED, DENORM> self;
+ enum {
+ FMinExp = SIGNED ? 0x7c : 0x78,
+ FMaxExp = SIGNED ? 0x83 : 0x87,
+ MaxExp = SIGNED ? 0x70 : 0xf0,
+ };
- public:
- ui8 val;
+ public:
+ ui8 val;
- explicit float8(ui8 v = 0)
- : val(v)
- {
- }
+ explicit float8(ui8 v = 0)
+ : val(v)
+ {
+ }
- self& operator=(float t) {
- assert(SIGNED == 1 || SIGNED == 0 && t >= 0.);
+ self& operator=(float t) {
+ assert(SIGNED == 1 || SIGNED == 0 && t >= 0.);
ui16 hi16 = Hi16(t);
ui8 sign = SIGNED ? Hi8(hi16) & 0x80 : 0;
@@ -88,68 +88,68 @@ namespace NPackedFloat {
hi16 <<= 1;
ui8 fexp = Hi8(hi16);
- ui8 exp;
+ ui8 exp;
ui8 frac = (Lo8(hi16) & 0xf0) >> 4;
-
- if (fexp <= FMinExp) {
- exp = 0;
- frac = DENORM ? ((ui8)(0x10 | frac) >> std::min<int>((FMinExp - fexp + 1), 8)) : 0;
- } else if (fexp > FMaxExp) {
- exp = MaxExp;
- frac = 0x0f;
- } else {
- exp = (fexp - FMinExp) << 4;
- }
-
- val = sign | exp | frac;
- return *this;
+
+ if (fexp <= FMinExp) {
+ exp = 0;
+ frac = DENORM ? ((ui8)(0x10 | frac) >> std::min<int>((FMinExp - fexp + 1), 8)) : 0;
+ } else if (fexp > FMaxExp) {
+ exp = MaxExp;
+ frac = 0x0f;
+ } else {
+ exp = (fexp - FMinExp) << 4;
+ }
+
+ val = sign | exp | frac;
+ return *this;
}
- operator float() const {
+ operator float() const {
ui32 v = 0;
v |= SIGNED ? (val & 0x80) << 24 : 0;
- ui8 frac = val & 0x0f;
- ui8 exp = val & MaxExp;
+ ui8 frac = val & 0x0f;
+ ui8 exp = val & MaxExp;
- if (exp) {
+ if (exp) {
v |= ((exp >> 4) + FMinExp) << 23 | frac << 19;
- } else if (DENORM && val & 0x0f) {
- while (!(frac & 0x10)) {
- frac <<= 1;
- ++exp;
- }
+ } else if (DENORM && val & 0x0f) {
+ while (!(frac & 0x10)) {
+ frac <<= 1;
+ ++exp;
+ }
v |= (FMinExp - exp + 1) << 23 | (frac & 0x0f) << 19;
- } else
+ } else
v |= 0;
return BitCast<float>(v);
- }
+ }
- static self New(float v) {
- self f;
- return f = v;
- }
+ static self New(float v) {
+ self f;
+ return f = v;
+ }
- static self denorm_min() {
- return self(0x01);
- }
+ static self denorm_min() {
+ return self(0x01);
+ }
- static self min() {
- return self(0x10);
- }
+ static self min() {
+ return self(0x10);
+ }
- static self max() {
- return self(SIGNED ? 0x7f : 0xff);
- }
- };
+ static self max() {
+ return self(SIGNED ? 0x7f : 0xff);
+ }
+ };
}
using f64 = double;
using f32 = float;
-static_assert(sizeof(f32) == 4, "expect sizeof(f32) == 4");
-static_assert(sizeof(f64) == 8, "expect sizeof(f64) == 8");
+static_assert(sizeof(f32) == 4, "expect sizeof(f32) == 4");
+static_assert(sizeof(f64) == 8, "expect sizeof(f64) == 8");
using f16 = NPackedFloat::float16<1>;
using uf16 = NPackedFloat::float16<0>;
using f8 = NPackedFloat::float8<1>;
@@ -162,18 +162,18 @@ using frac8 = ui8;
using frac16 = ui16;
-template <class T>
+template <class T>
inline constexpr T Float2Frac(float fac) {
- return T(fac * float(Max<T>()));
+ return T(fac * float(Max<T>()));
}
-template <class T>
+template <class T>
inline constexpr T Float2FracR(float fac) {
- float v = fac * float(Max<T>());
+ float v = fac * float(Max<T>());
return T(v + 0.5f);
}
-template <class T>
+template <class T>
inline constexpr float Frac2Float(T pf) {
constexpr float multiplier = float(1.0 / Max<T>());
return pf * multiplier;
@@ -206,12 +206,12 @@ inline float Frac2Float(ui8 pf) {
template <>
inline float Frac2Float(ui32 pf) = delete;
-template <class T>
-inline float FracOrFloatToFloat(T t) {
+template <class T>
+inline float FracOrFloatToFloat(T t) {
return Frac2Float(t);
}
-template <>
-inline float FracOrFloatToFloat<float>(float t) {
+template <>
+inline float FracOrFloatToFloat<float>(float t) {
return t;
}
diff --git a/library/cpp/packedtypes/packedfloat_ut.cpp b/library/cpp/packedtypes/packedfloat_ut.cpp
index f61e49014cc..9f161c031c3 100644
--- a/library/cpp/packedtypes/packedfloat_ut.cpp
+++ b/library/cpp/packedtypes/packedfloat_ut.cpp
@@ -1,21 +1,21 @@
-#include "packedfloat.h"
-
+#include "packedfloat.h"
+
#include <library/cpp/testing/unittest/registar.h>
-#include <util/generic/ylimits.h>
-
+#include <util/generic/ylimits.h>
+
class TPackedFloatTest: public TTestBase {
- UNIT_TEST_SUITE(TPackedFloatTest);
- UNIT_TEST(F16Test);
- UNIT_TEST(Uf16Test);
- UNIT_TEST(F8dTest);
- UNIT_TEST(F8Test);
- UNIT_TEST(Uf8dTest);
- UNIT_TEST(Uf8Test);
- UNIT_TEST_SUITE_END();
-
+ UNIT_TEST_SUITE(TPackedFloatTest);
+ UNIT_TEST(F16Test);
+ UNIT_TEST(Uf16Test);
+ UNIT_TEST(F8dTest);
+ UNIT_TEST(F8Test);
+ UNIT_TEST(Uf8dTest);
+ UNIT_TEST(Uf8Test);
+ UNIT_TEST_SUITE_END();
+
private:
- template <typename F>
+ template <typename F>
void TestF(float f, float rf) {
UNIT_ASSERT(F::New(f) == rf);
}
@@ -34,7 +34,7 @@ private:
TestF16(2.0f * f16::max(), std::numeric_limits<float>::infinity());
TestF16(0.5 * f16::min(), 0.5 * f16::min());
TestF16(0.5 * f16::denorm_min(), 0);
- TestF16(-0.5 * f16::denorm_min(), 0);
+ TestF16(-0.5 * f16::denorm_min(), 0);
TestF16(FLT_MIN, FLT_MIN);
TestF16(FLT_MAX, f16::max());
TestF16(f16::min(), FLT_MIN);
@@ -125,6 +125,6 @@ private:
TestUf8(uf8::min(), uf8::min());
TestUf8(2.0 * uf8::max(), uf8::max());
TestUf8(0.5 * uf8::min(), 0);
- }
-};
-UNIT_TEST_SUITE_REGISTRATION(TPackedFloatTest);
+ }
+};
+UNIT_TEST_SUITE_REGISTRATION(TPackedFloatTest);
diff --git a/library/cpp/packedtypes/ya.make b/library/cpp/packedtypes/ya.make
index 4c2c9506195..b91af5624c9 100644
--- a/library/cpp/packedtypes/ya.make
+++ b/library/cpp/packedtypes/ya.make
@@ -11,7 +11,7 @@ PEERDIR(
SRCS(
fixed_point.h
- longs.cpp
+ longs.cpp
packed.h
packedfloat.cpp
packedfloat.h
diff --git a/library/cpp/packedtypes/zigzag.h b/library/cpp/packedtypes/zigzag.h
index 548403f8384..0f982199ad1 100644
--- a/library/cpp/packedtypes/zigzag.h
+++ b/library/cpp/packedtypes/zigzag.h
@@ -2,8 +2,8 @@
#include <util/generic/typetraits.h>
-#include <limits.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.