aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/codecs
diff options
context:
space:
mode:
authoraprudaev <aprudaev@yandex-team.ru>2022-02-10 16:49:58 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:58 +0300
commit042dfdfd1388209ce3aa06dca56bd52ec63d40b2 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/codecs
parent29e66fe2ab37743577f88e6ab770defc4e6c1002 (diff)
downloadydb-042dfdfd1388209ce3aa06dca56bd52ec63d40b2.tar.gz
Restoring authorship annotation for <aprudaev@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/codecs')
-rw-r--r--library/cpp/codecs/huffman_codec.cpp22
-rw-r--r--library/cpp/codecs/huffman_codec.h2
-rw-r--r--library/cpp/codecs/ut/codecs_ut.cpp66
3 files changed, 45 insertions, 45 deletions
diff --git a/library/cpp/codecs/huffman_codec.cpp b/library/cpp/codecs/huffman_codec.cpp
index 8882615aaf..650fe7cdfd 100644
--- a/library/cpp/codecs/huffman_codec.cpp
+++ b/library/cpp/codecs/huffman_codec.cpp
@@ -58,15 +58,15 @@ namespace NCodecs {
tree.back().Char = i;
tree.back().Freq = freqs[i];
}
-
+
StableSort(tree.begin(), tree.end(), TTreeEntry::ByFreq);
- }
-
+ }
+
void InitTree(TCodeTree& tree, ISequenceReader* in) {
using namespace NPrivate;
ui64 freqs[256];
Zero(freqs);
-
+
TStringBuf r;
while (in->NextRegion(r)) {
for (ui64 i = 0; i < r.size(); ++i)
@@ -466,24 +466,24 @@ namespace NCodecs {
ui64 freqsArray[256];
Zero(freqsArray);
-
+
for (const auto& freq : freqs)
freqsArray[static_cast<ui8>(freq.first)] += freq.second;
-
+
InitTreeByFreqs(tree, freqsArray);
CalculateCodeLengths(tree);
-
+
Y_ENSURE(!tree.empty(), " ");
-
+
GenerateEncoder(tree);
BuildDecoder();
}
-
+
void Save(IOutputStream* out) {
::Save(out, Invalid.CodeLength);
Encoder.Save(out);
}
-
+
void Load(IInputStream* in) {
::Load(in, Invalid.CodeLength);
Encoder.Load(in);
@@ -589,4 +589,4 @@ namespace NCodecs {
Trained = true;
}
-}
+}
diff --git a/library/cpp/codecs/huffman_codec.h b/library/cpp/codecs/huffman_codec.h
index 59d18cb7b1..559545b90d 100644
--- a/library/cpp/codecs/huffman_codec.h
+++ b/library/cpp/codecs/huffman_codec.h
@@ -29,7 +29,7 @@ namespace NCodecs {
void Decode(TStringBuf in, TBuffer& bbb) const override;
void LearnByFreqs(const TArrayRef<std::pair<char, ui64>>& freqs);
-
+
protected:
void DoLearn(ISequenceReader& in) override;
void Save(IOutputStream* out) const override;
diff --git a/library/cpp/codecs/ut/codecs_ut.cpp b/library/cpp/codecs/ut/codecs_ut.cpp
index ea9490b9a6..caf6089aef 100644
--- a/library/cpp/codecs/ut/codecs_ut.cpp
+++ b/library/cpp/codecs/ut/codecs_ut.cpp
@@ -864,7 +864,7 @@ class TCodecsTest: public TTestBase {
UNIT_TEST(TestHuffman)
UNIT_TEST(TestZStdDict)
UNIT_TEST(TestCompTable)
- UNIT_TEST(TestHuffmanLearnByFreqs)
+ UNIT_TEST(TestHuffmanLearnByFreqs)
UNIT_TEST(TestSolar)
UNIT_TEST(TestPFor)
UNIT_TEST(TestRegistry)
@@ -1194,60 +1194,60 @@ private:
DoTestSimpleCodec<NCodecs::TCompTableCodec>();
}
- void TestHuffmanLearnByFreqs() {
- using namespace NCodecs;
-
+ void TestHuffmanLearnByFreqs() {
+ using namespace NCodecs;
+
TVector<TBuffer> data;
-
+
for (auto& textValue : TextValues) {
data.emplace_back(textValue, strlen(textValue));
- }
-
+ }
+
TVector<TBuffer> outLearn;
-
- {
- THuffmanCodec codec;
- static_cast<ICodec&>(codec).Learn(data.begin(), data.end());
-
- for (ui32 i = 0; i < data.size(); ++i) {
+
+ {
+ THuffmanCodec codec;
+ static_cast<ICodec&>(codec).Learn(data.begin(), data.end());
+
+ for (ui32 i = 0; i < data.size(); ++i) {
outLearn.emplace_back();
codec.Encode(AsStrBuf(data[i]), outLearn[i]);
- }
- }
-
+ }
+ }
+
TVector<TBuffer> outLearnByFreqs;
-
- {
- THuffmanCodec codec;
+
+ {
+ THuffmanCodec codec;
std::pair<char, ui64> freqs[256];
-
+
for (size_t i = 0; i < Y_ARRAY_SIZE(freqs); ++i) {
- freqs[i].first = (char)i;
- freqs[i].second = 0;
- }
-
+ freqs[i].first = (char)i;
+ freqs[i].second = 0;
+ }
+
for (auto& textValue : TextValues) {
size_t len = strlen(textValue);
for (size_t j = 0; j < len; ++j) {
++freqs[(ui32)(0xFF & textValue[j])].second;
}
- }
-
+ }
+
codec.LearnByFreqs(TArrayRef<std::pair<char, ui64>>(freqs, Y_ARRAY_SIZE(freqs)));
-
- for (ui32 i = 0; i < data.size(); ++i) {
+
+ for (ui32 i = 0; i < data.size(); ++i) {
outLearnByFreqs.emplace_back();
codec.Encode(AsStrBuf(data[i]), outLearnByFreqs[i]);
- }
- }
-
+ }
+ }
+
UNIT_ASSERT_EQUAL(outLearn.size(), outLearnByFreqs.size());
const size_t sz = outLearn.size();
for (size_t n = 0; n < sz; ++n) {
UNIT_ASSERT_EQUAL(AsStrBuf(outLearn[n]), AsStrBuf(outLearnByFreqs[n]));
}
- }
-
+ }
+
void TestSolar() {
using namespace NCodecs;
{