diff options
author | lucius <lucius@yandex-team.ru> | 2022-02-10 16:50:14 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:14 +0300 |
commit | fcc260ce89e9b359b47474d8dfa6dfcb6aae3fe9 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 | |
parent | 95ad0bd7bde5cd56bd6395ad6b7c47f0e73e4c99 (diff) | |
download | ydb-fcc260ce89e9b359b47474d8dfa6dfcb6aae3fe9.tar.gz |
Restoring authorship annotation for <lucius@yandex-team.ru>. Commit 2 of 2.
-rw-r--r-- | library/cpp/archive/yarchive.cpp | 30 | ||||
-rw-r--r-- | library/cpp/cache/cache.h | 232 | ||||
-rw-r--r-- | library/cpp/cache/ut/cache_ut.cpp | 24 | ||||
-rw-r--r-- | library/cpp/digest/md5/md5.cpp | 6 | ||||
-rw-r--r-- | tools/archiver/main.cpp | 112 | ||||
-rw-r--r-- | util/draft/ip.h | 2 | ||||
-rw-r--r-- | util/generic/ut/ya.make | 18 |
7 files changed, 212 insertions, 212 deletions
diff --git a/library/cpp/archive/yarchive.cpp b/library/cpp/archive/yarchive.cpp index f34c8bf680..1becc3e5da 100644 --- a/library/cpp/archive/yarchive.cpp +++ b/library/cpp/archive/yarchive.cpp @@ -32,7 +32,7 @@ static inline T ESLoad(IInputStream* in) { T t = T(); if (in->Load(&t, sizeof(t)) != sizeof(t)) { - ythrow TSerializeException() << "malformed archive"; + ythrow TSerializeException() << "malformed archive"; } return LittleToHost(t); @@ -49,7 +49,7 @@ inline TString ESLoad<TString>(IInputStream* in) { const size_t readed = in->Read(tmp.Data(), toread); if (!readed) { - ythrow TSerializeException() << "malformed archive"; + ythrow TSerializeException() << "malformed archive"; } ret.append(tmp.Data(), readed); @@ -190,7 +190,7 @@ private: }; TArchiveWriter::TArchiveWriter(IOutputStream* out, bool compress) - : Impl_(new TImpl(*out, compress)) + : Impl_(new TImpl(*out, compress)) { } @@ -283,7 +283,7 @@ public: for (size_t i = 0; i < count; ++i) { TArchiveRecordDescriptorRef descr(new TArchiveRecordDescriptor(&d)); - + Recs_.push_back(descr); Dict_[descr->Name()] = descr; } @@ -314,7 +314,7 @@ public: inline bool Has(const TStringBuf key) const { return Dict_.contains(key); } - + inline TAutoPtr<IInputStream> ObjectByKey(const TStringBuf key) const { TBlob subBlob = BlobByKey(key); @@ -322,9 +322,9 @@ public: return new TArchiveInputStream(subBlob); } else { return new TMemoryInput(subBlob.Data(), subBlob.Length()); - } + } } - + inline TBlob ObjectBlobByKey(const TStringBuf key) const { TBlob subBlob = BlobByKey(key); @@ -354,7 +354,7 @@ public: inline bool Compressed() const { return UseDecompression; } - + private: TBlob Blob_; TVector<TArchiveRecordDescriptorRef> Recs_; @@ -384,15 +384,15 @@ bool TArchiveReader::Has(const TStringBuf key) const { TAutoPtr<IInputStream> TArchiveReader::ObjectByKey(const TStringBuf key) const { return Impl_->ObjectByKey(key); } - + TBlob TArchiveReader::ObjectBlobByKey(const TStringBuf key) const { return Impl_->ObjectBlobByKey(key); } TBlob TArchiveReader::BlobByKey(const TStringBuf key) const { - return Impl_->BlobByKey(key); -} - -bool TArchiveReader::Compressed() const { - return Impl_->Compressed(); -} + return Impl_->BlobByKey(key); +} + +bool TArchiveReader::Compressed() const { + return Impl_->Compressed(); +} diff --git a/library/cpp/cache/cache.h b/library/cpp/cache/cache.h index cc9005d2b0..6dc997076d 100644 --- a/library/cpp/cache/cache.h +++ b/library/cpp/cache/cache.h @@ -1,6 +1,6 @@ #pragma once -#include <util/generic/algorithm.h> +#include <util/generic/algorithm.h> #include <util/generic/ptr.h> #include <util/generic/intrlist.h> #include <util/generic/hash_set.h> @@ -229,60 +229,60 @@ private: size_t MaxSize; }; -// Least Weighted list -// discards the least weighted items first -// doesn't support promotion -template <typename TKey, typename TValue, typename TWeight, typename TWeighter> -class TLWList { -public: - TLWList(size_t maxSize) - : Size(0) - , MaxSize(maxSize) - { - } - - struct TItem { - TItem(const TKey& key, const TValue& value = TValue()) - : Key(key) - , Value(value) - , Weight(TWeighter::Weight(value)) - { - } - - TItem(const TItem& rhs) - : Key(rhs.Key) - , Value(rhs.Value) - , Weight(rhs.Weight) - { - } - +// Least Weighted list +// discards the least weighted items first +// doesn't support promotion +template <typename TKey, typename TValue, typename TWeight, typename TWeighter> +class TLWList { +public: + TLWList(size_t maxSize) + : Size(0) + , MaxSize(maxSize) + { + } + + struct TItem { + TItem(const TKey& key, const TValue& value = TValue()) + : Key(key) + , Value(value) + , Weight(TWeighter::Weight(value)) + { + } + + TItem(const TItem& rhs) + : Key(rhs.Key) + , Value(rhs.Value) + , Weight(rhs.Weight) + { + } + bool operator<(const TItem& rhs) const { - return Key < rhs.Key; - } - + return Key < rhs.Key; + } + bool operator==(const TItem& rhs) const { - return Key == rhs.Key; - } - - TKey Key; - TValue Value; - TWeight Weight; - - struct THash { + return Key == rhs.Key; + } + + TKey Key; + TValue Value; + TWeight Weight; + + struct THash { size_t operator()(const TItem& item) const { - return ::THash<TKey>()(item.Key); - } - }; - }; - - struct THeapComparator { - bool operator()(TItem* const item1, TItem* const item2) const { - return item1->Weight > item2->Weight; - } - }; - -public: - TItem* Insert(TItem* item) { + return ::THash<TKey>()(item.Key); + } + }; + }; + + struct THeapComparator { + bool operator()(TItem* const item1, TItem* const item2) const { + return item1->Weight > item2->Weight; + } + }; + +public: + TItem* Insert(TItem* item) { FixHeap(); if (Size >= MaxSize && item->Weight < GetLightest()->Weight) { @@ -298,41 +298,41 @@ public: TItem* RemoveIfOverflown() { if (Size <= MaxSize) { - return nullptr; - } + return nullptr; + } auto lightest = GetLightest(); Erase(lightest); PopHeap(Heap.begin(), Heap.end(), THeapComparator()); return lightest; - } - - TItem* GetLightest() { + } + + TItem* GetLightest() { FixHeap(); Y_ASSERT(!Heap.empty()); - return Heap.front(); - } - - // This method doesn't remove items from the heap. - // Erased items are stored in Removed set - // and will be deleted on-access (using FixHeap method) - void Erase(TItem* item) { + return Heap.front(); + } + + // This method doesn't remove items from the heap. + // Erased items are stored in Removed set + // and will be deleted on-access (using FixHeap method) + void Erase(TItem* item) { Y_ASSERT(Size > 0); - --Size; + --Size; Removed.insert(item); - } - - void Promote(TItem*) { - // do nothing - } - + } + + void Promote(TItem*) { + // do nothing + } + [[nodiscard]] size_t GetSize() const { - return Size; - } - + return Size; + } + size_t GetMaxSize() const { return MaxSize; } @@ -343,18 +343,18 @@ public: MaxSize = newSize; } - void Clear() { - Heap.clear(); - Removed.clear(); - Size = 0; - } - + void Clear() { + Heap.clear(); + Removed.clear(); + Size = 0; + } + private: - // Physically remove erased elements from the heap - void FixHeap() { + // Physically remove erased elements from the heap + void FixHeap() { if (Removed.empty()) { return; - } + } Heap.erase(std::remove_if(Heap.begin(), Heap.end(), [this](TItem* item) { return this->Removed.contains(item); @@ -363,16 +363,16 @@ private: MakeHeap(Heap.begin(), Heap.end(), THeapComparator()); Removed.clear(); Size = Heap.size(); - } - -private: + } + +private: TVector<TItem*> Heap; THashSet<TItem*> Removed; - - size_t Size; - size_t MaxSize; -}; - + + size_t Size; + size_t MaxSize; +}; + template <typename TKey, typename TValue, typename TListType, typename TDeleter> class TCache { typedef typename TListType::TItem TItem; @@ -481,11 +481,11 @@ public: return false; TIndexIterator it = Index.insert(tmpItem); - TItem* insertedItem = const_cast<TItem*>(&*it); + TItem* insertedItem = const_cast<TItem*>(&*it); auto removedItem = List.Insert(insertedItem); auto insertedWasRemoved = removedItem == insertedItem; - if (removedItem) { - EraseFromIndex(removedItem); + if (removedItem) { + EraseFromIndex(removedItem); while ((removedItem = List.RemoveIfOverflown())) { insertedWasRemoved = insertedWasRemoved || insertedItem == removedItem; EraseFromIndex(removedItem); @@ -622,28 +622,28 @@ public: return TBase::Empty() ? TBase::End() : this->FindByItem(TBase::List.GetLeastFrequentlyUsed()); } }; - -// Least Weighted cache -// discards the least weighted items first -// doesn't support promotion -template <typename TKey, typename TValue, typename TWeight, typename TWeighter, typename TDeleter = TNoopDelete> + +// Least Weighted cache +// discards the least weighted items first +// doesn't support promotion +template <typename TKey, typename TValue, typename TWeight, typename TWeighter, typename TDeleter = TNoopDelete> class TLWCache: public TCache<TKey, TValue, TLWList<TKey, TValue, TWeight, TWeighter>, TDeleter> { - typedef TCache<TKey, TValue, TLWList<TKey, TValue, TWeight, TWeighter>, TDeleter> TBase; + typedef TCache<TKey, TValue, TLWList<TKey, TValue, TWeight, TWeighter>, TDeleter> TBase; using TListType = TLWList<TKey, TValue, TWeight, TWeighter>; - -public: - typedef typename TBase::TIterator TIterator; - - TLWCache(size_t maxSize, bool multiValue = false) + +public: + typedef typename TBase::TIterator TIterator; + + TLWCache(size_t maxSize, bool multiValue = false) : TBase(TListType(maxSize), multiValue) - { - } - - TValue& GetLightest() { - return TBase::List.GetLightest()->Value; - } - - TIterator FindLightest() { - return TBase::Empty() ? TBase::End() : this->FindByItem(TBase::List.GetLightest()); - } -}; + { + } + + TValue& GetLightest() { + return TBase::List.GetLightest()->Value; + } + + TIterator FindLightest() { + return TBase::Empty() ? TBase::End() : this->FindByItem(TBase::List.GetLightest()); + } +}; diff --git a/library/cpp/cache/ut/cache_ut.cpp b/library/cpp/cache/ut/cache_ut.cpp index cf2ea3eeab..329872cfde 100644 --- a/library/cpp/cache/ut/cache_ut.cpp +++ b/library/cpp/cache/ut/cache_ut.cpp @@ -2,12 +2,12 @@ #include <library/cpp/cache/thread_safe_cache.h> #include <library/cpp/testing/unittest/registar.h> -struct TStrokaWeighter { +struct TStrokaWeighter { static size_t Weight(const TString& s) { - return s.size(); - } -}; - + return s.size(); + } +}; + Y_UNIT_TEST_SUITE(TCacheTest) { Y_UNIT_TEST(LRUListTest) { typedef TLRUList<int, TString> TListType; @@ -88,32 +88,32 @@ Y_UNIT_TEST_SUITE(TCacheTest) { Y_UNIT_TEST(LWListTest) { typedef TLWList<int, TString, size_t, TStrokaWeighter> TListType; TListType list(2); - + TListType::TItem x1(1, "tt"); list.Insert(&x1); UNIT_ASSERT_EQUAL(list.GetLightest()->Key, 1); UNIT_ASSERT_EQUAL(list.GetSize(), 1); - + TListType::TItem x2(2, "yyyy"); list.Insert(&x2); UNIT_ASSERT_EQUAL(list.GetLightest()->Key, 1); UNIT_ASSERT_EQUAL(list.GetSize(), 2); - + TListType::TItem x3(3, "z"); list.Insert(&x3); UNIT_ASSERT_EQUAL(list.GetLightest()->Key, 1); UNIT_ASSERT_EQUAL(list.GetSize(), 2); - + TListType::TItem x4(4, "xxxxxx"); list.Insert(&x4); UNIT_ASSERT_EQUAL(list.GetLightest()->Key, 2); UNIT_ASSERT_EQUAL(list.GetSize(), 2); - + list.Erase(&x2); UNIT_ASSERT_EQUAL(list.GetLightest()->Key, 4); UNIT_ASSERT_EQUAL(list.GetSize(), 1); - } - + } + Y_UNIT_TEST(SimpleTest) { typedef TLRUCache<int, TString> TCache; TCache s(2); // size 2 diff --git a/library/cpp/digest/md5/md5.cpp b/library/cpp/digest/md5/md5.cpp index 07909bba13..24a5b69eef 100644 --- a/library/cpp/digest/md5/md5.cpp +++ b/library/cpp/digest/md5/md5.cpp @@ -83,11 +83,11 @@ char* MD5::Stream(IInputStream* in, char* buf) { MD5& MD5::Update(IInputStream* in) { TMd5Stream md5(this); - TransferData(in, &md5); + TransferData(in, &md5); return *this; -} - +} + static const ui8 PADDING[MD5_BLOCK_LENGTH] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, diff --git a/tools/archiver/main.cpp b/tools/archiver/main.cpp index 2f630bc0b8..6cda54c1ea 100644 --- a/tools/archiver/main.cpp +++ b/tools/archiver/main.cpp @@ -5,7 +5,7 @@ #include <util/folder/dirut.h> #include <util/folder/filelist.h> -#include <util/folder/path.h> +#include <util/folder/path.h> #include <util/generic/vector.h> #include <util/generic/yexception.h> #include <util/memory/blob.h> @@ -332,7 +332,7 @@ static inline void Append(IOutputStream& w, const TString& fname, const TString& TMappedFileInput in(fname); if (!Quiet) { - Cerr << "--> " << rname << Endl; + Cerr << "--> " << rname << Endl; } TransferData((IInputStream*)&in, &w); @@ -341,20 +341,20 @@ static inline void Append(IOutputStream& w, const TString& fname, const TString& static inline void Append(TDuplicatesMap& w, const TString& fname, const TString& rname) { w.Add(fname, rname); } - + static inline void Append(TDeduplicationArchiveWriter& w, const TString& fname, const TString& rname) { if (!Quiet) { - Cerr << "--> " << rname << Endl; + Cerr << "--> " << rname << Endl; } - + if (const TString* rootRecordName = w.DuplicatesMap.Synonyms.FindPtr(rname)) { w.Writer.AddSynonym(*rootRecordName, rname); } else { TMappedFileInput in(fname); w.Writer.Add(rname, &in); } -} - +} + namespace { struct TRec { bool Recursive = false; @@ -376,7 +376,7 @@ namespace { } else { Append(w, Path, Key.size() ? Key : Prefix + "/" + GetFile(Path)); } - } + } template <typename T> inline void DoRecurse(T& w, const TString& off) const { @@ -415,13 +415,13 @@ namespace { } static TString CutFirstSlash(const TString& fileName) { - if (fileName[0] == '/') { - return fileName.substr(1); - } else { - return fileName; - } -} - + if (fileName[0] == '/') { + return fileName.substr(1); + } else { + return fileName; + } +} + struct TMappingReader { TMemoryMap Map; TBlob Blob; @@ -438,51 +438,51 @@ struct TMappingReader { static void UnpackArchive(const TString& archive, const TFsPath& dir = TFsPath()) { TMappingReader mappingReader(archive); const TArchiveReader& reader = mappingReader.Reader; - const size_t count = reader.Count(); - for (size_t i = 0; i < count; ++i) { + const size_t count = reader.Count(); + for (size_t i = 0; i < count; ++i) { const TString key = reader.KeyByIndex(i); const TString fileName = CutFirstSlash(key); if (!Quiet) { - Cerr << archive << " --> " << fileName << Endl; + Cerr << archive << " --> " << fileName << Endl; } const TFsPath path(dir / fileName); - path.Parent().MkDirs(); + path.Parent().MkDirs(); TAutoPtr<IInputStream> in = reader.ObjectByKey(key); TFixedBufferFileOutput out(path); - TransferData(in.Get(), &out); - out.Finish(); - } -} - + TransferData(in.Get(), &out); + out.Finish(); + } +} + static void ListArchive(const TString& archive, bool cutSlash) { TMappingReader mappingReader(archive); const TArchiveReader& reader = mappingReader.Reader; - const size_t count = reader.Count(); - for (size_t i = 0; i < count; ++i) { + const size_t count = reader.Count(); + for (size_t i = 0; i < count; ++i) { const TString key = reader.KeyByIndex(i); TString fileName = key; if (cutSlash) { fileName = CutFirstSlash(key); } - Cout << fileName << Endl; - } -} - + Cout << fileName << Endl; + } +} + static void ListArchiveMd5(const TString& archive, bool cutSlash) { TMappingReader mappingReader(archive); const TArchiveReader& reader = mappingReader.Reader; - const size_t count = reader.Count(); - for (size_t i = 0; i < count; ++i) { + const size_t count = reader.Count(); + for (size_t i = 0; i < count; ++i) { const TString key = reader.KeyByIndex(i); TString fileName = key; if (cutSlash) { fileName = CutFirstSlash(key); } - char md5buf[33]; - Cout << fileName << '\t' << MD5::Stream(reader.ObjectByKey(key).Get(), md5buf) << Endl; - } -} - + char md5buf[33]; + Cout << fileName << '\t' << MD5::Stream(reader.ObjectByKey(key).Get(), md5buf) << Endl; + } +} + int main(int argc, char** argv) { NLastGetopt::TOpts opts; opts.AddHelpOption('?'); @@ -633,27 +633,27 @@ int main(int argc, char** argv) { } try { - if (listMd5) { + if (listMd5) { for (const auto& rec: recs) { ListArchiveMd5(rec.Path, cutSlash); - } - } else if (list) { + } + } else if (list) { for (const auto& rec: recs) { ListArchive(rec.Path, cutSlash); - } - } else if (unpack) { - const TFsPath dir(unpackDir); + } + } else if (unpack) { + const TFsPath dir(unpackDir); for (const auto& rec: recs) { UnpackArchive(rec.Path, dir); - } - } else { + } + } else { TAutoPtr<IOutputStream> outf(OpenOutput(outputf)); IOutputStream* out = outf.Get(); THolder<IOutputStream> hexout; - if (hexdump) { - hexout.Reset(new THexOutput(out)); - out = hexout.Get(); + if (hexdump) { + hexout.Reset(new THexOutput(out)); + out = hexout.Get(); } else if (stride) { hexout.Reset(new TStringArrayOutput(out, stride)); out = hexout.Get(); @@ -663,29 +663,29 @@ int main(int argc, char** argv) { } else if (cppBase) { hexout.Reset(new TCStringOutput(out, cppBase)); out = hexout.Get(); - } + } outf->Write(prepend.data(), prepend.size()); - if (cat) { + if (cat) { for (const auto& rec: recs) { rec.Recurse(*out); - } - } else { + } + } else { TDuplicatesMap duplicatesMap; if (deduplicate) { for (const auto& rec: recs) { rec.Recurse(duplicatesMap); } - } + } duplicatesMap.Finish(); TDeduplicationArchiveWriter w(duplicatesMap, out, !doNotZip); for (const auto& rec: recs) { rec.Recurse(w); } - w.Finish(); - } - + w.Finish(); + } + try { out->Finish(); } catch (...) { diff --git a/util/draft/ip.h b/util/draft/ip.h index 755019e57f..eb947cd2cd 100644 --- a/util/draft/ip.h +++ b/util/draft/ip.h @@ -6,7 +6,7 @@ #include <util/str_stl.h> #include <util/generic/maybe.h> -#include <util/generic/variant.h> +#include <util/generic/variant.h> #ifdef _unix_ #include <sys/types.h> diff --git a/util/generic/ut/ya.make b/util/generic/ut/ya.make index daf9b46d0e..6eaf24cc5f 100644 --- a/util/generic/ut/ya.make +++ b/util/generic/ut/ya.make @@ -7,7 +7,7 @@ FORK_TESTS() SRCS( generic/adaptor_ut.cpp - generic/algorithm_ut.cpp + generic/algorithm_ut.cpp generic/array_ref_ut.cpp generic/array_size_ut.cpp generic/bitmap_ut.cpp @@ -19,36 +19,36 @@ SRCS( generic/flags_ut.cpp generic/function_ut.cpp generic/guid_ut.cpp - generic/hash_primes_ut.cpp + generic/hash_primes_ut.cpp generic/hash_ut.cpp generic/intrlist_ut.cpp generic/is_in_ut.cpp generic/iterator_ut.cpp generic/iterator_range_ut.cpp - generic/lazy_value_ut.cpp + generic/lazy_value_ut.cpp generic/list_ut.cpp generic/map_ut.cpp generic/mapfindptr_ut.cpp generic/maybe_ut.cpp - generic/mem_copy_ut.cpp + generic/mem_copy_ut.cpp generic/objects_counter_ut.cpp generic/overloaded_ut.cpp generic/ptr_ut.cpp generic/queue_ut.cpp generic/serialized_enum_ut.cpp generic/set_ut.cpp - generic/singleton_ut.cpp + generic/singleton_ut.cpp generic/size_literals_ut.cpp - generic/stack_ut.cpp + generic/stack_ut.cpp generic/store_policy_ut.cpp generic/strbuf_ut.cpp generic/string_ut.cpp - generic/typelist_ut.cpp + generic/typelist_ut.cpp generic/typetraits_ut.cpp generic/utility_ut.cpp - generic/va_args_ut.cpp + generic/va_args_ut.cpp generic/vector_ut.cpp - generic/xrange_ut.cpp + generic/xrange_ut.cpp generic/yexception_ut.c generic/yexception_ut.cpp generic/ylimits_ut.cpp |