diff options
author | ironpeter <ironpeter@yandex-team.ru> | 2022-02-10 16:49:52 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:52 +0300 |
commit | edee5b99e1eec042f46725b89dcd81ea7e41d663 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/compproto | |
parent | ff97837ecc5972a00cb395483d8856566738375c (diff) | |
download | ydb-edee5b99e1eec042f46725b89dcd81ea7e41d663.tar.gz |
Restoring authorship annotation for <ironpeter@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/compproto')
-rw-r--r-- | library/cpp/compproto/bit.h | 64 | ||||
-rw-r--r-- | library/cpp/compproto/compproto_ut.cpp | 142 | ||||
-rw-r--r-- | library/cpp/compproto/compressor.h | 20 | ||||
-rw-r--r-- | library/cpp/compproto/huff.h | 136 | ||||
-rw-r--r-- | library/cpp/compproto/metainfo.h | 76 | ||||
-rw-r--r-- | library/cpp/compproto/ya.make | 16 |
6 files changed, 227 insertions, 227 deletions
diff --git a/library/cpp/compproto/bit.h b/library/cpp/compproto/bit.h index 15022bd374..6a421b65f7 100644 --- a/library/cpp/compproto/bit.h +++ b/library/cpp/compproto/bit.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include <util/generic/array_ref.h> #include <util/generic/vector.h> @@ -6,9 +6,9 @@ #include <util/stream/input.h> #include "huff.h" -#include "compressor.h" +#include "compressor.h" #include "metainfo.h" - + namespace NCompProto { struct TBitBuffer { TVector<ui8> Out; @@ -29,13 +29,13 @@ namespace NCompProto { ui64 Read(ui64 position, size_t size) { return Read(&Out[0], position, size); } - + void Code(ui64 value, size_t size) { if (++Counter == 0) { Junk(257 * 64); } Position = Code(value, size, Position); - } + } ui64 Code(ui64 value, size_t size, ui64 position) { ui8* dst = &Out[size_t(position >> 3)]; ui64& outCode = *(ui64*)dst; @@ -43,7 +43,7 @@ namespace NCompProto { ui64 mask = ((1ULL << size) - 1) << shift; outCode = ((value << shift) & mask) | (outCode & ~mask); return position + size; - } + } void Junk(size_t junk = 1024) { size_t need = size_t(Position >> 3); if (Out.size() * 8 < Position + junk) { @@ -55,16 +55,16 @@ namespace NCompProto { ui64 newVal = Read(position, 56); position = Code(value, size, position); value = newVal; - + while (position < Position + 64) { newVal = Read(position + 56 - size, 56); position = Code(value, 56, position); value = newVal; } - + Position += size; - } - + } + size_t ByteLength() const { return (Position + 7) / 8; } @@ -116,7 +116,7 @@ namespace NCompProto { } } } - + void Save(IOutputStream& stream, TString offset) { TString step = " "; for (size_t i = 0; i < Coder.Entries.size(); ++i) { @@ -126,13 +126,13 @@ namespace NCompProto { stream << (ui32)Coder.Entries[i].PrefixBits << " "; stream << (ui32)Coder.Entries[i].AllBits << " "; stream << Endl; - } + } stream << offset << "end" << Endl; - } - + } + void BeginElement(TBitBuffer& out) { Position = out.Position; - } + } void Add(ui32 value, TBitBuffer& out) { size_t val = 0; ui64 code = Coder.Code(value, val); @@ -148,12 +148,12 @@ namespace NCompProto { out.Junk(); } }; - + struct THist { TAccum Accum; THist() { - } - + } + void Load(IInputStream& stream) { TString name; while (1) { @@ -168,14 +168,14 @@ namespace NCompProto { void Add(ui32 value, TEmpty& /*empty*/) { Accum.Add(value); - } + } void AddDelayed(ui32 value, TEmpty& /*empty*/) { Accum.Add(value); } void BeginElement(TEmpty& /*empty*/) { } }; - + struct THistToHuff { static THistToHuff Instance() { return THistToHuff(); @@ -188,7 +188,7 @@ namespace NCompProto { info.Coder.Normalize(); } }; - + struct IDecompressor { // sequentially decompresses whole structure according to metainfo, starts at position offset virtual void Decompress(const TMetaInfo<TTable>* table, const ui8* codes, ui64& offset) = 0; @@ -196,14 +196,14 @@ namespace NCompProto { virtual void DecompressOne(const TMetaInfo<TTable>* table, const ui8* codes, ui64& offset, ui32 prevIndex = -1) = 0; virtual ~IDecompressor() = default; }; - + template <class X> struct TMetaIterator: public IDecompressor { X Self; TMetaIterator() { Self.Parent = this; } - + private: inline void DecompressSingle(ui32 repeatedIndex, const TMetaInfo<TTable>* table, const ui8* codes, ui64& offset) { Self.BeginElement(repeatedIndex); @@ -227,7 +227,7 @@ namespace NCompProto { } Self.EndElement(); } - + inline void DecompressSingleScalarsOnly(ui32 repeatedIndex, const TMetaInfo<TTable>* table, const ui8* codes, ui64& offset) { Self.BeginElement(repeatedIndex); ui32 mask = table->Mask.Decompress(codes, offset); @@ -236,7 +236,7 @@ namespace NCompProto { while (scalarMask) { if (mask & 1) { ui32 val = table->Scalar[index].Decompress(codes, offset); - Self.SetScalar(index, val); + Self.SetScalar(index, val); } else if (table->Default[index].Type == TScalarDefaultValue::Fixed) { Self.SetScalar(index, table->Default[index].Value); } @@ -275,7 +275,7 @@ namespace NCompProto { void DecompressOne(const TMetaInfo<TTable>* table, const ui8* codes, ui64& offset, ui32 prevIndex = -1) override { table->Index.Decompress(codes, offset); DecompressSingle(prevIndex, table, codes, offset); - } + } ui32 DecompressCount(const TMetaInfo<TTable>* table, const ui8* codes, ui64& offset) { return table->Count.Decompress(codes, offset); @@ -290,7 +290,7 @@ namespace NCompProto { { } }; - + struct TEmptyDecompressor: public TParentHold<TEmptyDecompressor> { void BeginSelf(ui32 /*count*/, ui32 /*id*/) { } @@ -307,12 +307,12 @@ namespace NCompProto { return *Parent; } }; - + inline TMetaIterator<TEmptyDecompressor>& GetEmptyDecompressor() { static TMetaIterator<TEmptyDecompressor> empty; return empty; - } - + } + struct THuffToTable { static THuffToTable Instance() { return THuffToTable(); @@ -330,13 +330,13 @@ namespace NCompProto { } } }; - + struct THuffToTableWithDecompressor: private THuffToTable { TSimpleSharedPtr<IDecompressor> Decompressor; THuffToTableWithDecompressor(TSimpleSharedPtr<IDecompressor> decompressor) : Decompressor(decompressor) { - } + } TSimpleSharedPtr<IDecompressor> Build() const { return Decompressor; } diff --git a/library/cpp/compproto/compproto_ut.cpp b/library/cpp/compproto/compproto_ut.cpp index b93eb7d99a..9393be967a 100644 --- a/library/cpp/compproto/compproto_ut.cpp +++ b/library/cpp/compproto/compproto_ut.cpp @@ -66,7 +66,7 @@ void TestWithParams(const TString& metainfo, const ECompMode mode, const TTestPa ui64 codedSize = buffer.Position; - TMetaInfo<TTable> decompressor(*meta, THuffToTable::Instance()); + TMetaInfo<TTable> decompressor(*meta, THuffToTable::Instance()); // verify that no memory read beyond buffer occurs const size_t byteSize = buffer.ByteLength(); @@ -87,7 +87,7 @@ void TestWithParams(const TString& metainfo, const ECompMode mode, const TTestPa memcpy(dataStart, buffer.Out.data(), byteSize); ui64 position = 0; - TMetaIterator<TDecompressor> instance; + TMetaIterator<TDecompressor> instance; // we should not read beyond dataEnd here instance.Decompress(&decompressor, dataStart, position); const ui64 decodedSize = position; @@ -177,70 +177,70 @@ Y_UNIT_TEST_SUITE(CompProtoTestBasic) { struct TRegClicks: public TParentHold<TRegClicks> { const TData* Data; const TRegInfo* Elem; - TRegClicks() + TRegClicks() : Data(nullptr) , Elem(nullptr) - { - } + { + } void BeginSelf(ui32 /*count*/, ui32 /*id*/) { - } - void EndSelf() { - } - void BeginElement(ui32 element) { + } + void EndSelf() { + } + void BeginElement(ui32 element) { TMap<ui32, TRegInfo>::const_iterator it = Data->RegClicks.find(element); - if (it == Data->RegClicks.end()) { - UNIT_ASSERT(0); - } - Elem = &it->second; - } - void EndElement() { - } - void SetScalar(size_t index, ui32 val) { - if (index == 0) - UNIT_ASSERT_EQUAL(val, Elem->Clicks); - if (index == 1) - UNIT_ASSERT_EQUAL(val, Elem->Shows); - } + if (it == Data->RegClicks.end()) { + UNIT_ASSERT(0); + } + Elem = &it->second; + } + void EndElement() { + } + void SetScalar(size_t index, ui32 val) { + if (index == 0) + UNIT_ASSERT_EQUAL(val, Elem->Clicks); + if (index == 1) + UNIT_ASSERT_EQUAL(val, Elem->Shows); + } IDecompressor& GetDecompressor(size_t) { - UNIT_ASSERT(0); - return GetEmptyDecompressor(); - } - }; - + UNIT_ASSERT(0); + return GetEmptyDecompressor(); + } + }; + const TData* Elem; - TMetaIterator<TRegClicks> RegClicks; + TMetaIterator<TRegClicks> RegClicks; void BeginSelf(ui32 /*count*/, ui32 /*id*/) { - } - void EndSelf() { - } - void BeginElement(ui32 element) { - UNIT_ASSERT(element < data.size()); - Elem = &data[element]; - } - void EndElement() { - } - void SetScalar(size_t index, ui32 val) { - if (index == 0) - UNIT_ASSERT_EQUAL(val, Elem->Clicks); - if (index == 1) - UNIT_ASSERT_EQUAL(val, Elem->Shows); + } + void EndSelf() { + } + void BeginElement(ui32 element) { + UNIT_ASSERT(element < data.size()); + Elem = &data[element]; + } + void EndElement() { + } + void SetScalar(size_t index, ui32 val) { + if (index == 0) + UNIT_ASSERT_EQUAL(val, Elem->Clicks); + if (index == 1) + UNIT_ASSERT_EQUAL(val, Elem->Shows); if (index == 31) UNIT_ASSERT_EQUAL(val, Elem->Extra); - } + } IDecompressor& GetDecompressor(size_t index) { - if (index == 2) { - RegClicks.Self.Data = Elem; - return RegClicks; - } - UNIT_ASSERT(0); - return GetEmptyDecompressor(); - } - TMultiDecompressor() + if (index == 2) { + RegClicks.Self.Data = Elem; + return RegClicks; + } + UNIT_ASSERT(0); + return GetEmptyDecompressor(); + } + TMultiDecompressor() : Elem(nullptr) - { - } - }; - + { + } + }; + struct TVerifyingDecompressor: public TParentHold<TVerifyingDecompressor> { enum EState { Startstop, @@ -255,14 +255,14 @@ Y_UNIT_TEST_SUITE(CompProtoTestBasic) { TMetaIterator<TVerifyingDecompressor>& GetDecompressor(size_t index) { Y_UNUSED(index); - return *Parent; - } - + return *Parent; + } + TVerifyingDecompressor() : State(Startstop) , DataInd(0) - { - } + { + } void BeginSelf(ui32 /*count*/, ui32 id) { switch (State) { case Startstop: @@ -361,14 +361,14 @@ Y_UNIT_TEST_SUITE(CompProtoTestBasic) { Y_UNIT_TEST(VerifyHistDecompression) { Test<TVerifyingDecompressor, TSerialize>(metainfo, CM_TWOPASS); } - + Y_UNIT_TEST(VerifyDecompressionMulti) { - Test<TMultiDecompressor, TSerialize>(metainfo, CM_SINGLEPASS); - } - + Test<TMultiDecompressor, TSerialize>(metainfo, CM_SINGLEPASS); + } + Y_UNIT_TEST(VerifyHistDecompressionMulti) { - Test<TMultiDecompressor, TSerialize>(metainfo, CM_TWOPASS); - } + Test<TMultiDecompressor, TSerialize>(metainfo, CM_TWOPASS); + } } Y_UNIT_TEST_SUITE(CompProtoTestExtended) { @@ -443,14 +443,14 @@ Y_UNIT_TEST_SUITE(CompProtoTestExtended) { : State(Startstop) , DataInd(0) , ArrayInd(0) - { - } + { + } TMetaIterator<TVerifyingDecompressor>& GetDecompressor(size_t index) { Y_UNUSED(index); - return *Parent; - } - + return *Parent; + } + void BeginSelf(ui32 /*count*/, ui32 id) { switch (State) { case Startstop: diff --git a/library/cpp/compproto/compressor.h b/library/cpp/compproto/compressor.h index 1fb678e04e..14b335e13c 100644 --- a/library/cpp/compproto/compressor.h +++ b/library/cpp/compproto/compressor.h @@ -1,5 +1,5 @@ -#pragma once - +#pragma once + #include <util/system/defaults.h> namespace NCompProto { @@ -15,7 +15,7 @@ namespace NCompProto { PrefLength[i] = 0; Id[i] = 0; } - } + } ui32 CodeBase[64]; ui32 CodeMask[64]; ui8 Length[64]; @@ -23,15 +23,15 @@ namespace NCompProto { ui8 Id[64]; enum { PAGE_BOUND = 4096, -#ifdef WITH_VALGRIND +#ifdef WITH_VALGRIND SAFE_MODE = 1, -#else +#else #if defined(__has_feature) #if __has_feature(address_sanitizer) SAFE_MODE = 1, #else SAFE_MODE = 0, -#endif +#endif #else SAFE_MODE = 0, #endif @@ -44,7 +44,7 @@ namespace NCompProto { if (pageOff > PAGE_BOUND - 8 || SAFE_MODE) { size_t off = 8; ui64 res = codes[0]; - ++codes; + ++codes; ui64 indexCur = ((res + 0x0000) >> readOff) & 63; ui64 indexAlt = ((res + 0xff00) >> readOff) & 63; if (Id[indexCur] != Id[indexAlt]) { @@ -63,12 +63,12 @@ namespace NCompProto { offset += length; ui64 code = res >> readOff; return (((ui32)(code >> PrefLength[index])) & CodeMask[index]) + CodeBase[index]; - } + } ui64 code = ((const ui64*)(codes))[0] >> readOff; ui64 index = code & 63; offset += Length[index]; - return (((ui32)(code >> PrefLength[index])) & CodeMask[index]) + CodeBase[index]; - } + return (((ui32)(code >> PrefLength[index])) & CodeMask[index]) + CodeBase[index]; + } }; } diff --git a/library/cpp/compproto/huff.h b/library/cpp/compproto/huff.h index da2b8ca4f6..fa5c139189 100644 --- a/library/cpp/compproto/huff.h +++ b/library/cpp/compproto/huff.h @@ -1,5 +1,5 @@ -#pragma once - +#pragma once + #include <util/system/defaults.h> #include <util/generic/yexception.h> #include <util/generic/ptr.h> @@ -9,8 +9,8 @@ #include <queue> -#include "compressor.h" - +#include "compressor.h" + namespace NCompProto { template <size_t CacheSize, typename TEntry> struct TCache { @@ -47,17 +47,17 @@ namespace NCompProto { , Start(start) , Bits(bits) { - } - + } + bool operator<(const TCode& code) const { return Probability < code.Probability; } - + bool operator>(const TCode& code) const { return Probability > code.Probability; } }; - + struct TAccum { struct TTable { TAutoPtr<TTable> Tables[16]; @@ -74,25 +74,25 @@ namespace NCompProto { for (auto& count : Counts) count = 0; } - + i64 GetCellCount(size_t i) { i64 count = Counts[i]; if (Tables[i].Get()) { for (size_t j = 0; j < 16; ++j) { count += Tables[i]->GetCellCount(j); } - } + } return count; - } - + } + i64 GetCount() { i64 count = 0; - for (size_t j = 0; j < 16; ++j) { + for (size_t j = 0; j < 16; ++j) { count += GetCellCount(j); - } + } return count; - } - + } + void GenerateFreqs(TVector<std::pair<i64, TCode>>& codes, int depth, int termDepth, ui32 code, i64 cnt) { if (depth == termDepth) { for (size_t i = 0; i < 16; ++i) { @@ -101,7 +101,7 @@ namespace NCompProto { Counts[i] = iCount; Tables[i].Reset(nullptr); } - + if (iCount > cnt || (termDepth == 0 && iCount > 0)) { std::pair<i64, TCode> codep; codep.first = iCount; @@ -113,32 +113,32 @@ namespace NCompProto { } } } - for (size_t i = 0; i < 16; ++i) { + for (size_t i = 0; i < 16; ++i) { if (Tables[i].Get()) { Tables[i]->GenerateFreqs(codes, depth + 4, termDepth, code + (i << (28 - depth)), cnt); - } - } - } + } + } + } }; - + TTable Root; int TableCount; i64 Total; ui64 Max; - + TAccum() { TableCount = 0; Total = 0; Max = 0; } - + void GenerateFreqs(TVector<std::pair<i64, TCode>>& codes, int mul) const { TTable root(Root); - + for (int i = 28; i > 0; i -= 4) { root.GenerateFreqs(codes, 0, i, 0, Total / mul); } - + i64 iCount = root.GetCount(); if (iCount == 0) return; @@ -154,10 +154,10 @@ namespace NCompProto { } codep.second.Bits = bits; codes.push_back(codep); - } - + } + TCache<256, i64*> Cache; - + void AddMap(ui32 value, i64 weight = 1) { ui32 index = Cache.Hash(value); if (Cache.CacheKey[index] == value) { @@ -177,22 +177,22 @@ namespace NCompProto { root->Counts[index2] += weight; return; } - } + } root = root->Tables[index2].Get(); - } + } Cache.CacheKey[index] = value; Cache.CacheVal[index] = &root->Counts[value & 0xf]; root->Counts[value & 0xf] += weight; - } - + } + void Add(ui32 value, i64 weight = 1) { Max = ::Max(Max, (ui64)value); Total += weight; AddMap(value, weight); }; - }; - + }; + struct THuffNode { i64 Weight; i64 Priority; @@ -206,7 +206,7 @@ namespace NCompProto { Nodes[0] = nullptr; Nodes[1] = nullptr; } - + void BuildPrefixes(ui32 depth, ui32 prefix) { if (Code) { Code->Prefix = prefix; @@ -216,44 +216,44 @@ namespace NCompProto { Nodes[0]->BuildPrefixes(depth + 1, prefix + (0UL << depth)); Nodes[1]->BuildPrefixes(depth + 1, prefix + (1UL << depth)); } - + i64 Iterate(size_t depth) const { if (Code) { return (depth + Code->Bits) * Code->Probability; } return Nodes[0]->Iterate(depth + 1) + Nodes[1]->Iterate(depth + 1); - } - + } + size_t Depth() const { if (Code) { return 0; } return Max(Nodes[0]->Depth(), Nodes[1]->Depth()) + 1; - } + } }; - + struct THLess { bool operator()(const THuffNode* a, const THuffNode* b) { if (a->Weight > b->Weight) return 1; if (a->Weight == b->Weight && a->Priority > b->Priority) return 1; - return 0; - } + return 0; + } }; - + inline i64 BuildHuff(TVector<TCode>& codes) { TVector<TSimpleSharedPtr<THuffNode>> hold; std::priority_queue<THuffNode*, TVector<THuffNode*>, THLess> nodes; i64 ret = 0; - + int priority = 0; for (size_t i = 0; i < codes.size(); ++i) { TSimpleSharedPtr<THuffNode> node(new THuffNode(codes[i].Probability, priority++, &codes[i])); hold.push_back(node); nodes.push(node.Get()); } - + while (nodes.size() > 1) { THuffNode* nodea = nodes.top(); nodes.pop(); @@ -265,27 +265,27 @@ namespace NCompProto { hold.push_back(node); nodes.push(node.Get()); } - + if (nodes.size()) { THuffNode* node = nodes.top(); node->BuildPrefixes(0, 0); ret = node->Iterate(0); } - + return ret; }; - + struct TCoderEntry { ui32 MinValue; ui16 Prefix; ui8 PrefixBits; ui8 AllBits; - + ui64 MaxValue() const { return MinValue + (1ULL << (AllBits - PrefixBits)); } }; - + inline i64 Analyze(const TAccum& acc, TVector<TCoderEntry>& retCodes) { i64 ret; for (int k = 256; k > 0; --k) { @@ -296,9 +296,9 @@ namespace NCompProto { for (size_t i = 0; i < pairs.size(); ++i) { codes.push_back(pairs[i].second); } - + StableSort(codes.begin(), codes.end(), std::greater<TCode>()); - + ret = BuildHuff(codes); bool valid = true; for (size_t i = 0; i < codes.size(); ++i) { @@ -313,17 +313,17 @@ namespace NCompProto { } if (valid) return ret; - } - + } + return ret; } - + struct TComparer { bool operator()(const TCoderEntry& e0, const TCoderEntry& e1) const { return e0.AllBits < e1.AllBits; - } + } }; - + struct TCoder { TVector<TCoderEntry> Entries; void Normalize() { @@ -355,14 +355,14 @@ namespace NCompProto { } }; } - + TCache<1024, TCoderEntry> Cache; - + ui64 RealCode(ui32 value, const TCoderEntry& entry, size_t& length) { length = entry.AllBits; return (ui64(value - entry.MinValue) << entry.PrefixBits) + entry.Prefix; } - + bool Empty() const { return Entries.empty(); } @@ -374,17 +374,17 @@ namespace NCompProto { id = ui8(i); return entry; } - } + } ythrow yexception() << "bad entry"; return Entries[0]; - } - + } + ui64 Code(ui32 entry, size_t& length) { ui32 index = Cache.Hash(entry); if (Cache.CacheKey[index] == entry) { ++Cache.Hits; - return RealCode(entry, Cache.CacheVal[index], length); - } + return RealCode(entry, Cache.CacheVal[index], length); + } ++Cache.Misses; for (size_t i = 0; i < Entries.size(); ++i) { if (entry >= Entries[i].MinValue && entry < Entries[i].MaxValue()) { @@ -396,7 +396,7 @@ namespace NCompProto { ythrow yexception() << "bad huff tree"; return 0; - } + } }; - + } diff --git a/library/cpp/compproto/metainfo.h b/library/cpp/compproto/metainfo.h index 05d328a766..6e68f86e12 100644 --- a/library/cpp/compproto/metainfo.h +++ b/library/cpp/compproto/metainfo.h @@ -1,5 +1,5 @@ -#pragma once - +#pragma once + #include <util/system/defaults.h> #include <util/generic/yexception.h> #include <util/generic/ptr.h> @@ -7,8 +7,8 @@ #include <util/stream/input.h> #include <util/stream/str.h> -#include "compressor.h" - +#include "compressor.h" + namespace NCompProto { const size_t MAX_ELEMENTS = 32; @@ -25,7 +25,7 @@ namespace NCompProto { EType Type; ui32 Value; }; - + template <class X> struct TMetaInfo { X Index; @@ -42,7 +42,7 @@ namespace NCompProto { TString ChildName[MAX_ELEMENTS]; size_t Id; TMetaInfo* Parent; - + struct TCheck { ui32 Count; ui32 Mask; @@ -74,7 +74,7 @@ namespace NCompProto { ClearAll(); } }; - + TCheck Serializer; void SetDefaults(TMetaInfo* parent) { @@ -108,12 +108,12 @@ namespace NCompProto { info->Parent = this; Repeated[i].Reset(info.Release()); } - } - } + } + } TMetaInfo(TMetaInfo* parent) { SetDefaults(parent); - } + } template <class T> TMetaInfo& BeginRepeated(size_t id, T& functor) { @@ -121,13 +121,13 @@ namespace NCompProto { TMetaInfo& res = *Repeated[id].Get(); res.Count.BeginElement(functor); return res; - } + } template <class T> void BeginSelf(T& functor) { Serializer.ClearAll(); Count.BeginElement(functor); - } + } template <class T> void EndRepeated(T& functor) { @@ -135,7 +135,7 @@ namespace NCompProto { Serializer.ClearCount(); Serializer.ClearIndex(); Y_ENSURE(Serializer.Mask == 0, "Serializer.Mask != 0"); - } + } template <class T> void BeginElement(ui32 index, T& functor) { @@ -147,7 +147,7 @@ namespace NCompProto { Serializer.LastIndex = index; ++Serializer.Count; } - + template <class TFunctor> void Iterate(TFunctor& functor) { Cout << Name << " " @@ -157,7 +157,7 @@ namespace NCompProto { functor.Process(Count); Cout << "Mask" << Endl; functor.Process(Mask); - + for (size_t i = 0; i < Size; ++i) { ui32 index = (1UL << i); if (ScalarMask & index) { @@ -170,15 +170,15 @@ namespace NCompProto { << " " << i << Endl; Repeated[i]->Iterate(functor); } - } - } - + } + } + template <class T> void EndElement(T& functor) { Mask.AddDelayed(Serializer.Mask, functor); Serializer.ClearMask(); } - + template <class T> void SetScalar(size_t id, ui32 value, T& functor) { if (Default[id].Type != TScalarDefaultValue::Fixed || value != Default[id].Value) { @@ -186,32 +186,32 @@ namespace NCompProto { Scalar[id].Add(value, functor); } } - + ui32 Check(size_t id) { Y_ENSURE(id < MAX_ELEMENTS, "id >= MAX_ELEMENTS"); - + ui32 mask = 1UL << id; if (ScalarMask & mask) { ythrow yexception() << "ScalarMask & mask"; - } + } if (RepeatedMask & mask) { ythrow yexception() << "RepeatedMask & mask"; - } + } Size = Max(id + 1, Size); return mask; - } - + } + TMetaInfo(IInputStream& stream) { SetDefaults(nullptr); Load(stream); - } - + } + TMetaInfo(const TString& str) { SetDefaults(nullptr); TStringInput stream(str); Load(stream); - } - + } + void Save(IOutputStream& stream, const TString& offset = TString()) { stream << offset << "repeated " << Name << " id " << Id << Endl; TString step = " "; @@ -221,7 +221,7 @@ namespace NCompProto { Count.Save(stream, step + offset); stream << step << offset << "mask" << Endl; Mask.Save(stream, step + offset); - + for (size_t i = 0; i < MAX_ELEMENTS; ++i) { ui32 mask = 1UL << i; if (mask & RepeatedMask) { @@ -237,13 +237,13 @@ namespace NCompProto { << "id " << i << Endl; Scalar[i].Save(stream, step + offset); } - } + } stream << offset << "end" << Endl; - } - + } + void Load(IInputStream& stream) { TString name; - stream >> name; + stream >> name; if (name == "repeated") { stream >> name; } @@ -251,9 +251,9 @@ namespace NCompProto { stream >> name; Y_ENSURE(name == "id", "Name mismatch: " << name.Quote() << " != id. "); stream >> Id; - + while (1) { - stream >> name; + stream >> name; if (name == "index") { Index.Load(stream); } else if (name == "count") { @@ -297,8 +297,8 @@ namespace NCompProto { } else if (name == "end" /* || stream.IsEOF()*/) { return; } - } - } + } + } }; } diff --git a/library/cpp/compproto/ya.make b/library/cpp/compproto/ya.make index 9957cd23b5..60d5cfa08d 100644 --- a/library/cpp/compproto/ya.make +++ b/library/cpp/compproto/ya.make @@ -1,13 +1,13 @@ -LIBRARY() - +LIBRARY() + OWNER(ironpeter) -SRCS( - bit.h - compressor.h - huff.h - metainfo.h +SRCS( + bit.h + compressor.h + huff.h + metainfo.h lib.cpp ) -END() +END() |