diff options
author | shutovich <shutovich@yandex-team.ru> | 2022-02-10 16:50:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:39 +0300 |
commit | 351478f45647e95dd78ef336009c498001b6917f (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp | |
parent | 8fd697e2f8595853b13873e99b318d89e4635795 (diff) | |
download | ydb-351478f45647e95dd78ef336009c498001b6917f.tar.gz |
Restoring authorship annotation for <shutovich@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/containers/comptrie/comptrie_ut.cpp | 244 | ||||
-rw-r--r-- | library/cpp/packers/packers.h | 230 |
2 files changed, 237 insertions, 237 deletions
diff --git a/library/cpp/containers/comptrie/comptrie_ut.cpp b/library/cpp/containers/comptrie/comptrie_ut.cpp index 026a4390eb..74bee09b5d 100644 --- a/library/cpp/containers/comptrie/comptrie_ut.cpp +++ b/library/cpp/containers/comptrie/comptrie_ut.cpp @@ -78,21 +78,21 @@ private: UNIT_TEST(TestTrieForVectorInt64); UNIT_TEST(TestTrieForListInt64); UNIT_TEST(TestTrieForSetInt64); - + UNIT_TEST(TestTrieForVectorStroka); UNIT_TEST(TestTrieForListStroka); UNIT_TEST(TestTrieForSetStroka); - + UNIT_TEST(TestTrieForVectorWtroka); UNIT_TEST(TestTrieForVectorFloat); UNIT_TEST(TestTrieForVectorDouble); - + UNIT_TEST(TestTrieForListVectorInt64); UNIT_TEST(TestTrieForPairWtrokaVectorInt64); - + UNIT_TEST(TestEmptyValueOutOfOrder); UNIT_TEST(TestFindLongestPrefixWithEmptyValue); - + UNIT_TEST(TestSearchIterChar); UNIT_TEST(TestSearchIterWchar); UNIT_TEST(TestSearchIterWchar32) @@ -143,15 +143,15 @@ private: void TestUniqueImpl(bool isPrefixGrouped); TVector<TUtf16String> GetSampleKeys(size_t nKeys) const; - template <class TContainer> + template <class TContainer> TVector<TContainer> GetSampleVectorData(size_t nValues); - template <class TContainer> + template <class TContainer> TVector<TContainer> GetSampleTextVectorData(size_t nValues); template <class T> - void CheckEquality(const T& value1, const T& value2) const; - template <class TContainer> + void CheckEquality(const T& value1, const T& value2) const; + template <class TContainer> void TestTrieWithContainers(const TVector<TUtf16String>& keys, const TVector<TContainer>& sampleData, TString methodName); - + template <typename TChar> void TestSearchIterImpl(); @@ -211,22 +211,22 @@ public: void TestIterateEmptyKey(); void TestTrieSet(); - - void TestTrieForVectorInt64(); - void TestTrieForListInt64(); - void TestTrieForSetInt64(); - - void TestTrieForVectorStroka(); - void TestTrieForListStroka(); - void TestTrieForSetStroka(); - - void TestTrieForVectorWtroka(); - void TestTrieForVectorFloat(); - void TestTrieForVectorDouble(); - - void TestTrieForListVectorInt64(); - void TestTrieForPairWtrokaVectorInt64(); - + + void TestTrieForVectorInt64(); + void TestTrieForListInt64(); + void TestTrieForSetInt64(); + + void TestTrieForVectorStroka(); + void TestTrieForListStroka(); + void TestTrieForSetStroka(); + + void TestTrieForVectorWtroka(); + void TestTrieForVectorFloat(); + void TestTrieForVectorDouble(); + + void TestTrieForListVectorInt64(); + void TestTrieForPairWtrokaVectorInt64(); + void TestEmptyValueOutOfOrder(); void TestFindLongestPrefixWithEmptyValue(); @@ -1102,156 +1102,156 @@ void TCompactTrieTest::TestTrieSet() { UNIT_ASSERT(empty.Has("")); // contains only empty string } -// Tests for trie with vector (list, set) values - +// Tests for trie with vector (list, set) values + TVector<TUtf16String> TCompactTrieTest::GetSampleKeys(size_t nKeys) const { Y_ASSERT(nKeys <= 10); TString sampleKeys[] = {"a", "b", "ac", "bd", "abe", "bcf", "deg", "ah", "xy", "abc"}; TVector<TUtf16String> result; - for (size_t i = 0; i < nKeys; i++) + for (size_t i = 0; i < nKeys; i++) result.push_back(ASCIIToWide(sampleKeys[i])); - return result; -} - -template <class TContainer> + return result; +} + +template <class TContainer> TVector<TContainer> TCompactTrieTest::GetSampleVectorData(size_t nValues) { TVector<TContainer> data; - for (size_t i = 0; i < nValues; i++) { - data.push_back(TContainer()); - for (size_t j = 0; j < i; j++) + for (size_t i = 0; i < nValues; i++) { + data.push_back(TContainer()); + for (size_t j = 0; j < i; j++) data[i].insert(data[i].end(), (typename TContainer::value_type)((j == 3) ? 0 : (1 << (j * 5)))); - } - return data; -} - -template <class TContainer> + } + return data; +} + +template <class TContainer> TVector<TContainer> TCompactTrieTest::GetSampleTextVectorData(size_t nValues) { TVector<TContainer> data; - for (size_t i = 0; i < nValues; i++) { - data.push_back(TContainer()); - for (size_t j = 0; j < i; j++) + for (size_t i = 0; i < nValues; i++) { + data.push_back(TContainer()); + for (size_t j = 0; j < i; j++) data[i].insert(data[i].end(), TString("abc") + ToString<size_t>(j)); - } - return data; -} - + } + return data; +} + template <class T> -void TCompactTrieTest::CheckEquality(const T& value1, const T& value2) const { - UNIT_ASSERT_VALUES_EQUAL(value1, value2); -} - +void TCompactTrieTest::CheckEquality(const T& value1, const T& value2) const { + UNIT_ASSERT_VALUES_EQUAL(value1, value2); +} + template <> void TCompactTrieTest::CheckEquality<TVector<i64>>(const TVector<i64>& value1, const TVector<i64>& value2) const { UNIT_ASSERT_VALUES_EQUAL(value1.size(), value2.size()); for (size_t i = 0; i < value1.size(); i++) UNIT_ASSERT_VALUES_EQUAL(value1[i], value2[i]); -} - -template <class TContainer> +} + +template <class TContainer> void TCompactTrieTest::TestTrieWithContainers(const TVector<TUtf16String>& keys, const TVector<TContainer>& sampleData, TString methodName) { TString fileName = GetSystemTempDir() + "/TCompactTrieTest-TestTrieWithContainers-" + methodName; - - TCompactTrieBuilder<wchar16, TContainer> b; - for (size_t i = 0; i < keys.size(); i++) { - b.Add(keys[i], sampleData[i]); - } + + TCompactTrieBuilder<wchar16, TContainer> b; + for (size_t i = 0; i < keys.size(); i++) { + b.Add(keys[i], sampleData[i]); + } TUnbufferedFileOutput out(fileName); - b.Save(out); - - TCompactTrie<wchar16, TContainer> trie(TBlob::FromFileSingleThreaded(fileName)); - for (size_t i = 0; i < keys.size(); i++) { - TContainer value = trie.Get(keys[i]); - UNIT_ASSERT_VALUES_EQUAL(value.size(), sampleData[i].size()); - typename TContainer::const_iterator p = value.begin(); - typename TContainer::const_iterator p1 = sampleData[i].begin(); - for (; p != value.end(); p++, p1++) - CheckEquality<typename TContainer::value_type>(*p, *p1); - } + b.Save(out); + + TCompactTrie<wchar16, TContainer> trie(TBlob::FromFileSingleThreaded(fileName)); + for (size_t i = 0; i < keys.size(); i++) { + TContainer value = trie.Get(keys[i]); + UNIT_ASSERT_VALUES_EQUAL(value.size(), sampleData[i].size()); + typename TContainer::const_iterator p = value.begin(); + typename TContainer::const_iterator p1 = sampleData[i].begin(); + for (; p != value.end(); p++, p1++) + CheckEquality<typename TContainer::value_type>(*p, *p1); + } unlink(fileName.data()); -} - +} + template <> void TCompactTrieTest::TestTrieWithContainers<std::pair<TUtf16String, TVector<i64>>>(const TVector<TUtf16String>& keys, const TVector<std::pair<TUtf16String, TVector<i64>>>& sampleData, TString methodName) { typedef std::pair<TUtf16String, TVector<i64>> TContainer; TString fileName = GetSystemTempDir() + "/TCompactTrieTest-TestTrieWithContainers-" + methodName; - - TCompactTrieBuilder<wchar16, TContainer> b; - for (size_t i = 0; i < keys.size(); i++) { - b.Add(keys[i], sampleData[i]); - } + + TCompactTrieBuilder<wchar16, TContainer> b; + for (size_t i = 0; i < keys.size(); i++) { + b.Add(keys[i], sampleData[i]); + } TUnbufferedFileOutput out(fileName); - b.Save(out); - - TCompactTrie<wchar16, TContainer> trie(TBlob::FromFileSingleThreaded(fileName)); - for (size_t i = 0; i < keys.size(); i++) { - TContainer value = trie.Get(keys[i]); + b.Save(out); + + TCompactTrie<wchar16, TContainer> trie(TBlob::FromFileSingleThreaded(fileName)); + for (size_t i = 0; i < keys.size(); i++) { + TContainer value = trie.Get(keys[i]); CheckEquality<TContainer::first_type>(value.first, sampleData[i].first); CheckEquality<TContainer::second_type>(value.second, sampleData[i].second); - } + } unlink(fileName.data()); -} - -void TCompactTrieTest::TestTrieForVectorInt64() { +} + +void TCompactTrieTest::TestTrieForVectorInt64() { TestTrieWithContainers<TVector<i64>>(GetSampleKeys(10), GetSampleVectorData<TVector<i64>>(10), "v-i64"); -} - -void TCompactTrieTest::TestTrieForListInt64() { +} + +void TCompactTrieTest::TestTrieForListInt64() { TestTrieWithContainers<TList<i64>>(GetSampleKeys(10), GetSampleVectorData<TList<i64>>(10), "l-i64"); -} - -void TCompactTrieTest::TestTrieForSetInt64() { +} + +void TCompactTrieTest::TestTrieForSetInt64() { TestTrieWithContainers<TSet<i64>>(GetSampleKeys(10), GetSampleVectorData<TSet<i64>>(10), "s-i64"); -} - -void TCompactTrieTest::TestTrieForVectorStroka() { +} + +void TCompactTrieTest::TestTrieForVectorStroka() { TestTrieWithContainers<TVector<TString>>(GetSampleKeys(10), GetSampleTextVectorData<TVector<TString>>(10), "v-str"); -} - -void TCompactTrieTest::TestTrieForListStroka() { +} + +void TCompactTrieTest::TestTrieForListStroka() { TestTrieWithContainers<TList<TString>>(GetSampleKeys(10), GetSampleTextVectorData<TList<TString>>(10), "l-str"); -} - -void TCompactTrieTest::TestTrieForSetStroka() { +} + +void TCompactTrieTest::TestTrieForSetStroka() { TestTrieWithContainers<TSet<TString>>(GetSampleKeys(10), GetSampleTextVectorData<TSet<TString>>(10), "s-str"); -} - -void TCompactTrieTest::TestTrieForVectorWtroka() { +} + +void TCompactTrieTest::TestTrieForVectorWtroka() { TVector<TVector<TString>> data = GetSampleTextVectorData<TVector<TString>>(10); TVector<TVector<TUtf16String>> wData; - for (size_t i = 0; i < data.size(); i++) { + for (size_t i = 0; i < data.size(); i++) { wData.push_back(TVector<TUtf16String>()); - for (size_t j = 0; j < data[i].size(); j++) + for (size_t j = 0; j < data[i].size(); j++) wData[i].push_back(UTF8ToWide(data[i][j])); - } + } TestTrieWithContainers<TVector<TUtf16String>>(GetSampleKeys(10), wData, "v-wtr"); -} - -void TCompactTrieTest::TestTrieForVectorFloat() { +} + +void TCompactTrieTest::TestTrieForVectorFloat() { TestTrieWithContainers<TVector<float>>(GetSampleKeys(10), GetSampleVectorData<TVector<float>>(10), "v-float"); -} - -void TCompactTrieTest::TestTrieForVectorDouble() { +} + +void TCompactTrieTest::TestTrieForVectorDouble() { TestTrieWithContainers<TVector<double>>(GetSampleKeys(10), GetSampleVectorData<TVector<double>>(10), "v-double"); -} - -void TCompactTrieTest::TestTrieForListVectorInt64() { +} + +void TCompactTrieTest::TestTrieForListVectorInt64() { TVector<i64> tmp; tmp.push_back(0); TList<TVector<i64>> dataElement(5, tmp); TVector<TList<TVector<i64>>> data(10, dataElement); TestTrieWithContainers<TList<TVector<i64>>>(GetSampleKeys(10), data, "l-v-i64"); -} - -void TCompactTrieTest::TestTrieForPairWtrokaVectorInt64() { +} + +void TCompactTrieTest::TestTrieForPairWtrokaVectorInt64() { TVector<TUtf16String> keys = GetSampleKeys(10); TVector<TVector<i64>> values = GetSampleVectorData<TVector<i64>>(10); TVector<std::pair<TUtf16String, TVector<i64>>> data; - for (size_t i = 0; i < 10; i++) + for (size_t i = 0; i < 10; i++) data.push_back(std::pair<TUtf16String, TVector<i64>>(keys[i] + u"_v", values[i])); TestTrieWithContainers<std::pair<TUtf16String, TVector<i64>>>(keys, data, "pair-str-v-i64"); -} +} void TCompactTrieTest::TestEmptyValueOutOfOrder() { TBufferOutput buffer; diff --git a/library/cpp/packers/packers.h b/library/cpp/packers/packers.h index 26506fabe2..1bde1b59aa 100644 --- a/library/cpp/packers/packers.h +++ b/library/cpp/packers/packers.h @@ -2,9 +2,9 @@ #include <util/generic/string.h> #include <util/generic/strbuf.h> -#include <util/generic/set.h> -#include <util/generic/list.h> -#include <util/generic/vector.h> +#include <util/generic/set.h> +#include <util/generic/list.h> +#include <util/generic/vector.h> #include <util/generic/bitops.h> #include <array> @@ -295,19 +295,19 @@ namespace NPackers { } template <class T> - class TPacker; - - // TContainerPacker --- for any container - // Requirements to class C: - // - has method size() (returns size_t) - // - has subclass C::value_type - // - has subclass C::const_iterator - // - has methods begin() and end() (return C::const_iterator) - // - has method insert(C::const_iterator, const C::value_type&) + class TPacker; + + // TContainerPacker --- for any container + // Requirements to class C: + // - has method size() (returns size_t) + // - has subclass C::value_type + // - has subclass C::const_iterator + // - has methods begin() and end() (return C::const_iterator) + // - has method insert(C::const_iterator, const C::value_type&) // Examples: TVector, TList, TSet - // Requirements to class EP: has methods as in any packer (UnpackLeaf, PackLeaf, MeasureLeaf, SkipLeaf) that - // are applicable to C::value_type - + // Requirements to class EP: has methods as in any packer (UnpackLeaf, PackLeaf, MeasureLeaf, SkipLeaf) that + // are applicable to C::value_type + template <typename T> struct TContainerInfo { enum { @@ -353,139 +353,139 @@ namespace NPackers { template <class C, class EP = TPacker<typename C::value_type>> class TContainerPacker { - private: - typedef C TContainer; - typedef EP TElementPacker; - typedef typename TContainer::const_iterator TElementIterator; + private: + typedef C TContainer; + typedef EP TElementPacker; + typedef typename TContainer::const_iterator TElementIterator; void UnpackLeafSimple(const char* buffer, TContainer& c) const; void UnpackLeafVector(const char* buffer, TContainer& c) const; friend class TContainerPackerHelper<TContainerInfo<C>::IsVector>; - public: + public: void UnpackLeaf(const char* buffer, TContainer& c) const { TContainerPackerHelper<TContainerInfo<C>::IsVector>::UnpackLeaf(*this, buffer, c); } - void PackLeaf(char* buffer, const TContainer& data, size_t size) const; - size_t MeasureLeaf(const TContainer& data) const; - size_t SkipLeaf(const char* buffer) const; - }; - + void PackLeaf(char* buffer, const TContainer& data, size_t size) const; + size_t MeasureLeaf(const TContainer& data) const; + size_t SkipLeaf(const char* buffer) const; + }; + template <class C, class EP> inline void TContainerPacker<C, EP>::UnpackLeafSimple(const char* buffer, C& result) const { - size_t offset = TIntegralPacker<size_t>().SkipLeaf(buffer); // first value is the total size (not needed here) + size_t offset = TIntegralPacker<size_t>().SkipLeaf(buffer); // first value is the total size (not needed here) size_t len; - TIntegralPacker<size_t>().UnpackLeaf(buffer + offset, len); - offset += TIntegralPacker<size_t>().SkipLeaf(buffer + offset); - + TIntegralPacker<size_t>().UnpackLeaf(buffer + offset, len); + offset += TIntegralPacker<size_t>().SkipLeaf(buffer + offset); + result.clear(); typename C::value_type value; - for (size_t i = 0; i < len; i++) { - TElementPacker().UnpackLeaf(buffer + offset, value); + for (size_t i = 0; i < len; i++) { + TElementPacker().UnpackLeaf(buffer + offset, value); result.insert(result.end(), value); - offset += TElementPacker().SkipLeaf(buffer + offset); - } - } - + offset += TElementPacker().SkipLeaf(buffer + offset); + } + } + template <class C, class EP> inline void TContainerPacker<C, EP>::UnpackLeafVector(const char* buffer, C& result) const { - size_t offset = TIntegralPacker<size_t>().SkipLeaf(buffer); // first value is the total size (not needed here) + size_t offset = TIntegralPacker<size_t>().SkipLeaf(buffer); // first value is the total size (not needed here) size_t len; - TIntegralPacker<size_t>().UnpackLeaf(buffer + offset, len); - offset += TIntegralPacker<size_t>().SkipLeaf(buffer + offset); + TIntegralPacker<size_t>().UnpackLeaf(buffer + offset, len); + offset += TIntegralPacker<size_t>().SkipLeaf(buffer + offset); result.resize(len); - + for (size_t i = 0; i < len; i++) { - TElementPacker().UnpackLeaf(buffer + offset, result[i]); - offset += TElementPacker().SkipLeaf(buffer + offset); + TElementPacker().UnpackLeaf(buffer + offset, result[i]); + offset += TElementPacker().SkipLeaf(buffer + offset); } } template <class C, class EP> - inline void TContainerPacker<C, EP>::PackLeaf(char* buffer, const C& data, size_t size) const { - size_t sizeOfSize = TIntegralPacker<size_t>().MeasureLeaf(size); - TIntegralPacker<size_t>().PackLeaf(buffer, size, sizeOfSize); - size_t len = data.size(); - size_t curSize = TIntegralPacker<size_t>().MeasureLeaf(len); - TIntegralPacker<size_t>().PackLeaf(buffer + sizeOfSize, len, curSize); - curSize += sizeOfSize; - for (TElementIterator p = data.begin(); p != data.end(); p++) { - size_t sizeChange = TElementPacker().MeasureLeaf(*p); - TElementPacker().PackLeaf(buffer + curSize, *p, sizeChange); - curSize += sizeChange; - } + inline void TContainerPacker<C, EP>::PackLeaf(char* buffer, const C& data, size_t size) const { + size_t sizeOfSize = TIntegralPacker<size_t>().MeasureLeaf(size); + TIntegralPacker<size_t>().PackLeaf(buffer, size, sizeOfSize); + size_t len = data.size(); + size_t curSize = TIntegralPacker<size_t>().MeasureLeaf(len); + TIntegralPacker<size_t>().PackLeaf(buffer + sizeOfSize, len, curSize); + curSize += sizeOfSize; + for (TElementIterator p = data.begin(); p != data.end(); p++) { + size_t sizeChange = TElementPacker().MeasureLeaf(*p); + TElementPacker().PackLeaf(buffer + curSize, *p, sizeChange); + curSize += sizeChange; + } Y_ASSERT(curSize == size); - } - + } + template <class C, class EP> - inline size_t TContainerPacker<C, EP>::MeasureLeaf(const C& data) const { - size_t curSize = TIntegralPacker<size_t>().MeasureLeaf(data.size()); - for (TElementIterator p = data.begin(); p != data.end(); p++) - curSize += TElementPacker().MeasureLeaf(*p); - size_t extraSize = TIntegralPacker<size_t>().MeasureLeaf(curSize); - - // Double measurement protects against sudden increases in extraSize, - // e.g. when curSize is 127 and stays in one byte, but curSize + 1 requires two bytes. - - extraSize = TIntegralPacker<size_t>().MeasureLeaf(curSize + extraSize); + inline size_t TContainerPacker<C, EP>::MeasureLeaf(const C& data) const { + size_t curSize = TIntegralPacker<size_t>().MeasureLeaf(data.size()); + for (TElementIterator p = data.begin(); p != data.end(); p++) + curSize += TElementPacker().MeasureLeaf(*p); + size_t extraSize = TIntegralPacker<size_t>().MeasureLeaf(curSize); + + // Double measurement protects against sudden increases in extraSize, + // e.g. when curSize is 127 and stays in one byte, but curSize + 1 requires two bytes. + + extraSize = TIntegralPacker<size_t>().MeasureLeaf(curSize + extraSize); Y_ASSERT(extraSize == TIntegralPacker<size_t>().MeasureLeaf(curSize + extraSize)); - return curSize + extraSize; - } - + return curSize + extraSize; + } + template <class C, class EP> - inline size_t TContainerPacker<C, EP>::SkipLeaf(const char* buffer) const { - size_t value; - TIntegralPacker<size_t>().UnpackLeaf(buffer, value); - return value; - } - + inline size_t TContainerPacker<C, EP>::SkipLeaf(const char* buffer) const { + size_t value; + TIntegralPacker<size_t>().UnpackLeaf(buffer, value); + return value; + } + // TPairPacker --- for std::pair<T1, T2> (any two types; can be nested) - // TPacker<T1> and TPacker<T2> should be valid classes - + // TPacker<T1> and TPacker<T2> should be valid classes + template <class T1, class T2, class TPacker1 = TPacker<T1>, class TPacker2 = TPacker<T2>> class TPairPacker { - private: + private: typedef std::pair<T1, T2> TMyPair; - public: + public: void UnpackLeaf(const char* buffer, TMyPair& pair) const; - void PackLeaf(char* buffer, const TMyPair& data, size_t size) const; - size_t MeasureLeaf(const TMyPair& data) const; - size_t SkipLeaf(const char* buffer) const; - }; - + void PackLeaf(char* buffer, const TMyPair& data, size_t size) const; + size_t MeasureLeaf(const TMyPair& data) const; + size_t SkipLeaf(const char* buffer) const; + }; + template <class T1, class T2, class TPacker1, class TPacker2> inline void TPairPacker<T1, T2, TPacker1, TPacker2>::UnpackLeaf(const char* buffer, std::pair<T1, T2>& pair) const { TPacker1().UnpackLeaf(buffer, pair.first); - size_t size = TPacker1().SkipLeaf(buffer); + size_t size = TPacker1().SkipLeaf(buffer); TPacker2().UnpackLeaf(buffer + size, pair.second); - } - + } + template <class T1, class T2, class TPacker1, class TPacker2> inline void TPairPacker<T1, T2, TPacker1, TPacker2>::PackLeaf(char* buffer, const std::pair<T1, T2>& data, size_t size) const { - size_t size1 = TPacker1().MeasureLeaf(data.first); - TPacker1().PackLeaf(buffer, data.first, size1); - size_t size2 = TPacker2().MeasureLeaf(data.second); - TPacker2().PackLeaf(buffer + size1, data.second, size2); + size_t size1 = TPacker1().MeasureLeaf(data.first); + TPacker1().PackLeaf(buffer, data.first, size1); + size_t size2 = TPacker2().MeasureLeaf(data.second); + TPacker2().PackLeaf(buffer + size1, data.second, size2); Y_ASSERT(size == size1 + size2); - } - + } + template <class T1, class T2, class TPacker1, class TPacker2> inline size_t TPairPacker<T1, T2, TPacker1, TPacker2>::MeasureLeaf(const std::pair<T1, T2>& data) const { - size_t size1 = TPacker1().MeasureLeaf(data.first); - size_t size2 = TPacker2().MeasureLeaf(data.second); - return size1 + size2; - } - + size_t size1 = TPacker1().MeasureLeaf(data.first); + size_t size2 = TPacker2().MeasureLeaf(data.second); + return size1 + size2; + } + template <class T1, class T2, class TPacker1, class TPacker2> 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; - } - + size_t size1 = TPacker1().SkipLeaf(buffer); + size_t size2 = TPacker2().SkipLeaf(buffer + size1); + return size1 + size2; + } + //------------------------------------------------------------------------------------------ // Packer for fixed-size arrays, i.e. for std::array. // Saves memory by not storing anything about their size. @@ -575,37 +575,37 @@ namespace NPackers { template <> class TPacker<TWtringBuf>: public TStringPacker<TWtringBuf> { }; - - template <class T> + + template <class T> class TPacker<std::vector<T>>: public TContainerPacker<std::vector<T>> { }; template <class T> class TPacker<TVector<T>>: public TContainerPacker<TVector<T>> { - }; - - template <class T> + }; + + template <class T> class TPacker<std::list<T>>: public TContainerPacker<std::list<T>> { }; template <class T> class TPacker<TList<T>>: public TContainerPacker<TList<T>> { - }; - - template <class T> + }; + + template <class T> class TPacker<std::set<T>>: public TContainerPacker<std::set<T>> { }; template <class T> class TPacker<TSet<T>>: public TContainerPacker<TSet<T>> { - }; - + }; + template <class T1, class T2> class TPacker<std::pair<T1, T2>>: public TPairPacker<T1, T2> { - }; - + }; + template <class T, size_t N> class TPacker<std::array<T, N>>: public TArrayPacker<std::array<T, N>> { }; - + } |