aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/packers
diff options
context:
space:
mode:
authorRuslan Kovalev <ruslan.a.kovalev@gmail.com>2022-02-10 16:46:45 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:45 +0300
commit9123176b341b6f2658cff5132482b8237c1416c8 (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/packers
parent59e19371de37995fcb36beb16cd6ec030af960bc (diff)
downloadydb-9123176b341b6f2658cff5132482b8237c1416c8.tar.gz
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/packers')
-rw-r--r--library/cpp/packers/packers.cpp38
-rw-r--r--library/cpp/packers/packers.h128
-rw-r--r--library/cpp/packers/region_packer.h16
-rw-r--r--library/cpp/packers/ut/packers_ut.cpp36
-rw-r--r--library/cpp/packers/ut/ya.make16
-rw-r--r--library/cpp/packers/ya.make16
6 files changed, 125 insertions, 125 deletions
diff --git a/library/cpp/packers/packers.cpp b/library/cpp/packers/packers.cpp
index 5b2e938573..54615a9e7f 100644
--- a/library/cpp/packers/packers.cpp
+++ b/library/cpp/packers/packers.cpp
@@ -1,20 +1,20 @@
-#include "packers.h"
-#include "region_packer.h"
-
-namespace NPackers {
-#define _X_4(X) X, X, X, X
-#define _X_8(X) _X_4(X), _X_4(X)
-#define _X_16(X) _X_8(X), _X_8(X)
-#define _X_32(X) _X_16(X), _X_16(X)
-#define _X_64(X) _X_32(X), _X_32(X)
-#define _X_128(X) _X_64(X), _X_64(X)
-
+#include "packers.h"
+#include "region_packer.h"
+
+namespace NPackers {
+#define _X_4(X) X, X, X, X
+#define _X_8(X) _X_4(X), _X_4(X)
+#define _X_16(X) _X_8(X), _X_8(X)
+#define _X_32(X) _X_16(X), _X_16(X)
+#define _X_64(X) _X_32(X), _X_32(X)
+#define _X_128(X) _X_64(X), _X_64(X)
+
const ui8 SkipTable[256] = {_X_128(1), _X_64(2), _X_32(3), _X_16(4), _X_8(5), _X_4(6), 7, 7, 8, 9};
-
-#undef _X_4
-#undef _X_8
-#undef _X_16
-#undef _X_32
-#undef _X_64
-#undef _X_128
-}
+
+#undef _X_4
+#undef _X_8
+#undef _X_16
+#undef _X_32
+#undef _X_64
+#undef _X_128
+}
diff --git a/library/cpp/packers/packers.h b/library/cpp/packers/packers.h
index fe3fd633c4..1bde1b59aa 100644
--- a/library/cpp/packers/packers.h
+++ b/library/cpp/packers/packers.h
@@ -1,7 +1,7 @@
-#pragma once
+#pragma once
#include <util/generic/string.h>
-#include <util/generic/strbuf.h>
+#include <util/generic/strbuf.h>
#include <util/generic/set.h>
#include <util/generic/list.h>
#include <util/generic/vector.h>
@@ -51,7 +51,7 @@ public:
// Implementation
-namespace NPackers {
+namespace NPackers {
template <class T>
inline ui64 ConvertIntegral(const T& data);
@@ -131,19 +131,19 @@ namespace NPackers {
buffer[0] = (char)(lenmask | value);
}
- extern const ui8 SkipTable[];
+ extern const ui8 SkipTable[];
- template <>
- inline void TIntegralPacker<ui64>::UnpackLeaf(const char* p, ui64& result) const {
- unsigned char ch = *(p++);
- size_t taillen = SkipTable[ch] - 1;
+ template <>
+ inline void TIntegralPacker<ui64>::UnpackLeaf(const char* p, ui64& result) const {
+ unsigned char ch = *(p++);
+ size_t taillen = SkipTable[ch] - 1;
+
+ result = (ch & (0x7F >> taillen));
- result = (ch & (0x7F >> taillen));
+ while (taillen--)
+ result = ((result << 8) | (*(p++) & 0xFF));
+ }
- while (taillen--)
- result = ((result << 8) | (*(p++) & 0xFF));
- }
-
template <>
inline size_t TIntegralPacker<ui64>::SkipLeaf(const char* p) const {
return SkipTable[(ui8)*p];
@@ -197,58 +197,58 @@ namespace NPackers {
}
//-------------------------------------------
- // TFPPacker --- for float/double
- namespace NImpl {
- template <class TFloat, class TUInt>
- class TFPPackerBase {
- protected:
- typedef TIntegralPacker<TUInt> TPacker;
-
- union THelper {
- TFloat F;
- TUInt U;
- };
-
- TFloat FromUInt(TUInt u) const {
- THelper h;
+ // TFPPacker --- for float/double
+ namespace NImpl {
+ template <class TFloat, class TUInt>
+ class TFPPackerBase {
+ protected:
+ typedef TIntegralPacker<TUInt> TPacker;
+
+ union THelper {
+ TFloat F;
+ TUInt U;
+ };
+
+ TFloat FromUInt(TUInt u) const {
+ THelper h;
h.U = ReverseBytes(u);
- return h.F;
- }
-
- TUInt ToUInt(TFloat f) const {
- THelper h;
- h.F = f;
+ return h.F;
+ }
+
+ TUInt ToUInt(TFloat f) const {
+ THelper h;
+ h.F = f;
return ReverseBytes(h.U);
- }
-
- public:
- void UnpackLeaf(const char* c, TFloat& t) const {
- TUInt u = 0;
- TPacker().UnpackLeaf(c, u);
- t = FromUInt(u);
- }
-
- void PackLeaf(char* c, const TFloat& t, size_t sz) const {
- TPacker().PackLeaf(c, ToUInt(t), sz);
- }
-
- size_t MeasureLeaf(const TFloat& t) const {
- return TPacker().MeasureLeaf(ToUInt(t));
- }
-
- size_t SkipLeaf(const char* c) const {
- return TPacker().SkipLeaf(c);
- }
- };
- }
-
+ }
+
+ public:
+ void UnpackLeaf(const char* c, TFloat& t) const {
+ TUInt u = 0;
+ TPacker().UnpackLeaf(c, u);
+ t = FromUInt(u);
+ }
+
+ void PackLeaf(char* c, const TFloat& t, size_t sz) const {
+ TPacker().PackLeaf(c, ToUInt(t), sz);
+ }
+
+ size_t MeasureLeaf(const TFloat& t) const {
+ return TPacker().MeasureLeaf(ToUInt(t));
+ }
+
+ size_t SkipLeaf(const char* c) const {
+ return TPacker().SkipLeaf(c);
+ }
+ };
+ }
+
class TFloatPacker: public NImpl::TFPPackerBase<float, ui32> {
- };
-
+ };
+
class TDoublePacker: public NImpl::TFPPackerBase<double, ui64> {
- };
-
- //-------------------------------------------
+ };
+
+ //-------------------------------------------
// TStringPacker --- for TString/TUtf16String and TStringBuf.
template <class TStringType>
@@ -480,7 +480,7 @@ namespace NPackers {
}
template <class T1, class T2, class TPacker1, class TPacker2>
- inline size_t TPairPacker<T1, T2, TPacker1, TPacker2>::SkipLeaf(const char* buffer) const {
+ inline size_t TPairPacker<T1, T2, TPacker1, TPacker2>::SkipLeaf(const char* buffer) const {
size_t size1 = TPacker1().SkipLeaf(buffer);
size_t size2 = TPacker2().SkipLeaf(buffer + size1);
return size1 + size2;
@@ -539,10 +539,10 @@ namespace NPackers {
//------------------------------------
// TPacker --- the generic packer.
-
+
template <class T, bool IsIntegral>
class TPackerImpl;
-
+
template <class T>
class TPackerImpl<T, true>: public TIntegralPacker<T> {
};
diff --git a/library/cpp/packers/region_packer.h b/library/cpp/packers/region_packer.h
index 35ec9f3359..2c661cb5bc 100644
--- a/library/cpp/packers/region_packer.h
+++ b/library/cpp/packers/region_packer.h
@@ -1,7 +1,7 @@
#pragma once
-#include "packers.h"
-
+#include "packers.h"
+
#include <util/generic/array_ref.h>
// Stores an array of PODs in the trie (copying them with memcpy).
@@ -14,8 +14,8 @@ public:
void UnpackLeaf(const char* p, TRecords& result) const {
size_t len;
- NPackers::TIntegralPacker<size_t>().UnpackLeaf(p, len);
- size_t start = NPackers::TIntegralPacker<size_t>().SkipLeaf(p);
+ NPackers::TIntegralPacker<size_t>().UnpackLeaf(p, len);
+ size_t start = NPackers::TIntegralPacker<size_t>().SkipLeaf(p);
result = TRecords((TRecord*)(p + start), len);
}
@@ -23,19 +23,19 @@ public:
size_t len = data.size();
size_t lenChar = len * sizeof(TRecord);
size_t start = computedSize - lenChar;
- NPackers::TIntegralPacker<size_t>().PackLeaf(buf, len, NPackers::TIntegralPacker<size_t>().MeasureLeaf(len));
+ NPackers::TIntegralPacker<size_t>().PackLeaf(buf, len, NPackers::TIntegralPacker<size_t>().MeasureLeaf(len));
memcpy(buf + start, data.data(), lenChar);
}
size_t MeasureLeaf(const TRecords& data) const {
size_t len = data.size();
- return NPackers::TIntegralPacker<size_t>().MeasureLeaf(len) + len * sizeof(TRecord);
+ return NPackers::TIntegralPacker<size_t>().MeasureLeaf(len) + len * sizeof(TRecord);
}
size_t SkipLeaf(const char* p) const {
- size_t result = NPackers::TIntegralPacker<size_t>().SkipLeaf(p);
+ size_t result = NPackers::TIntegralPacker<size_t>().SkipLeaf(p);
size_t len;
- NPackers::TIntegralPacker<size_t>().UnpackLeaf(p, len);
+ NPackers::TIntegralPacker<size_t>().UnpackLeaf(p, len);
result += len * sizeof(TRecord);
return result;
}
diff --git a/library/cpp/packers/ut/packers_ut.cpp b/library/cpp/packers/ut/packers_ut.cpp
index 331ff7f995..18ce2150d1 100644
--- a/library/cpp/packers/ut/packers_ut.cpp
+++ b/library/cpp/packers/ut/packers_ut.cpp
@@ -17,14 +17,14 @@
#include <util/string/hex.h>
-#include "packers.h"
+#include "packers.h"
#include <array>
#include <iterator>
class TPackersTest: public TTestBase {
private:
- UNIT_TEST_SUITE(TPackersTest);
+ UNIT_TEST_SUITE(TPackersTest);
UNIT_TEST(TestPackers);
UNIT_TEST_SUITE_END();
@@ -38,10 +38,10 @@ public:
void TestPackers();
};
-UNIT_TEST_SUITE_REGISTRATION(TPackersTest);
+UNIT_TEST_SUITE_REGISTRATION(TPackersTest);
template <class TData, class TPacker>
-void TPackersTest::TestPacker(const TData& data) {
+void TPackersTest::TestPacker(const TData& data) {
size_t len = TPacker().MeasureLeaf(data);
size_t bufLen = len * 3;
@@ -58,13 +58,13 @@ void TPackersTest::TestPacker(const TData& data) {
}
template <class TData, class TPacker>
-void TPackersTest::TestPacker(const TData* test, size_t size) {
+void TPackersTest::TestPacker(const TData* test, size_t size) {
for (size_t i = 0; i < size; ++i) {
TestPacker<TData, TPacker>(test[i]);
}
}
-void TPackersTest::TestPackers() {
+void TPackersTest::TestPackers() {
{
const TString test[] = {"",
"a", "b", "c", "d",
@@ -91,20 +91,20 @@ void TPackersTest::TestPackers() {
TestPacker<int, NPackers::TPacker<int>>(test, Y_ARRAY_SIZE(test));
}
- {
- const float test[] = {
- 2.f, 3.f, 4.f, 0.f, -0.f, 1.f, -1.f, 1.1f, -1.1f,
+ {
+ const float test[] = {
+ 2.f, 3.f, 4.f, 0.f, -0.f, 1.f, -1.f, 1.1f, -1.1f,
std::numeric_limits<float>::min(), -std::numeric_limits<float>::min(),
std::numeric_limits<float>::max(), -std::numeric_limits<float>::max()};
-
- TestPacker<float, NPackers::TFloatPacker>(test, Y_ARRAY_SIZE(test));
- }
- {
- const double test[] = {
- 0., -0., 1., -1., 1.1, -1.1,
+
+ TestPacker<float, NPackers::TFloatPacker>(test, Y_ARRAY_SIZE(test));
+ }
+ {
+ const double test[] = {
+ 0., -0., 1., -1., 1.1, -1.1,
std::numeric_limits<double>::min(), -std::numeric_limits<double>::min(),
std::numeric_limits<double>::max(), -std::numeric_limits<double>::max()};
-
- TestPacker<double, NPackers::TDoublePacker>(test, Y_ARRAY_SIZE(test));
- }
+
+ TestPacker<double, NPackers::TDoublePacker>(test, Y_ARRAY_SIZE(test));
+ }
}
diff --git a/library/cpp/packers/ut/ya.make b/library/cpp/packers/ut/ya.make
index 7767faff47..1c024ffd94 100644
--- a/library/cpp/packers/ut/ya.make
+++ b/library/cpp/packers/ut/ya.make
@@ -1,12 +1,12 @@
UNITTEST_FOR(library/cpp/packers)
-
+
OWNER(velavokr)
-
-SRCS(
- packers_ut.cpp
+
+SRCS(
+ packers_ut.cpp
proto_packer_ut.cpp
- region_packer_ut.cpp
+ region_packer_ut.cpp
test.proto
-)
-
-END()
+)
+
+END()
diff --git a/library/cpp/packers/ya.make b/library/cpp/packers/ya.make
index e2f08f922f..e1ec4972ed 100644
--- a/library/cpp/packers/ya.make
+++ b/library/cpp/packers/ya.make
@@ -1,11 +1,11 @@
-LIBRARY()
-
+LIBRARY()
+
OWNER(velavokr)
-
-SRCS(
- packers.cpp
+
+SRCS(
+ packers.cpp
proto_packer.cpp
region_packer.cpp
-)
-
-END()
+)
+
+END()