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 /library/cpp | |
parent | 95ad0bd7bde5cd56bd6395ad6b7c47f0e73e4c99 (diff) | |
download | ydb-fcc260ce89e9b359b47474d8dfa6dfcb6aae3fe9.tar.gz |
Restoring authorship annotation for <lucius@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp')
-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 |
4 files changed, 146 insertions, 146 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, |