diff options
author | hindsight <hindsight@yandex-team.ru> | 2022-02-10 16:50:06 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:06 +0300 |
commit | a76f5e1efe665e1bb125f05ae275b2a6226517d9 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library | |
parent | fe0f94e19a639b45108b1229c889c445edc7adef (diff) | |
download | ydb-a76f5e1efe665e1bb125f05ae275b2a6226517d9.tar.gz |
Restoring authorship annotation for <hindsight@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/containers/intrusive_avl_tree/avltree.h | 214 | ||||
-rw-r--r-- | library/cpp/containers/intrusive_avl_tree/ut/avltree_ut.cpp | 76 | ||||
-rw-r--r-- | library/cpp/coroutine/listener/listen.cpp | 6 | ||||
-rw-r--r-- | library/cpp/coroutine/listener/listen.h | 14 |
4 files changed, 155 insertions, 155 deletions
diff --git a/library/cpp/containers/intrusive_avl_tree/avltree.h b/library/cpp/containers/intrusive_avl_tree/avltree.h index 9970592f06..a58c63b07c 100644 --- a/library/cpp/containers/intrusive_avl_tree/avltree.h +++ b/library/cpp/containers/intrusive_avl_tree/avltree.h @@ -10,103 +10,103 @@ class TAvlTree: public TNonCopyable { using TTreeItem = TAvlTreeItem<T, C>; friend struct TAvlTreeItem<T, C>; - static inline const T* AsT(const TTreeItem* item) noexcept { - return (const T*)item; - } - - static inline T* AsT(TTreeItem* item) noexcept { + static inline const T* AsT(const TTreeItem* item) noexcept { + return (const T*)item; + } + + static inline T* AsT(TTreeItem* item) noexcept { return (T*)item; } - template <class TTreeItem, class TValue> - class TIteratorBase { + template <class TTreeItem, class TValue> + class TIteratorBase { public: - inline TIteratorBase(TTreeItem* p, const TAvlTree* t) noexcept + inline TIteratorBase(TTreeItem* p, const TAvlTree* t) noexcept : Ptr_(p) , Tree_(t) { } - inline bool IsEnd() const noexcept { + inline bool IsEnd() const noexcept { return Ptr_ == nullptr; } - inline bool IsBegin() const noexcept { + inline bool IsBegin() const noexcept { return Ptr_ == nullptr; } - inline bool IsFirst() const noexcept { + inline bool IsFirst() const noexcept { return Ptr_ && Ptr_ == Tree_->Head_; } - inline bool IsLast() const noexcept { + inline bool IsLast() const noexcept { return Ptr_ && Ptr_ == Tree_->Tail_; } - inline TValue& operator*() const noexcept { + inline TValue& operator*() const noexcept { return *AsT(Ptr_); } - inline TValue* operator->() const noexcept { + inline TValue* operator->() const noexcept { return AsT(Ptr_); } - inline TTreeItem* Inc() noexcept { + inline TTreeItem* Inc() noexcept { return Ptr_ = FindNext(Ptr_); } - inline TTreeItem* Dec() noexcept { + inline TTreeItem* Dec() noexcept { return Ptr_ = FindPrev(Ptr_); } - inline TIteratorBase& operator++() noexcept { + inline TIteratorBase& operator++() noexcept { Inc(); return *this; } - inline TIteratorBase operator++(int) noexcept { - TIteratorBase ret(*this); + inline TIteratorBase operator++(int) noexcept { + TIteratorBase ret(*this); Inc(); return ret; } - inline TIteratorBase& operator--() noexcept { + inline TIteratorBase& operator--() noexcept { Dec(); return *this; } - inline TIteratorBase operator--(int) noexcept { - TIteratorBase ret(*this); + inline TIteratorBase operator--(int) noexcept { + TIteratorBase ret(*this); Dec(); return ret; } - inline TIteratorBase Next() const noexcept { + inline TIteratorBase Next() const noexcept { return ConstructNext(*this); } - inline TIteratorBase Prev() const noexcept { + inline TIteratorBase Prev() const noexcept { return ConstructPrev(*this); } - inline bool operator==(const TIteratorBase& r) const noexcept { + inline bool operator==(const TIteratorBase& r) const noexcept { return Ptr_ == r.Ptr_; } - inline bool operator!=(const TIteratorBase& r) const noexcept { + inline bool operator!=(const TIteratorBase& r) const noexcept { return Ptr_ != r.Ptr_; } private: - inline static TIteratorBase ConstructNext(const TIteratorBase& i) noexcept { + inline static TIteratorBase ConstructNext(const TIteratorBase& i) noexcept { return TIterator(FindNext(i.Ptr_), i.Tree_); } - inline static TIteratorBase ConstructPrev(const TIteratorBase& i) noexcept { + inline static TIteratorBase ConstructPrev(const TIteratorBase& i) noexcept { return TIterator(FindPrev(i.Ptr_), i.Tree_); } - inline static TIteratorBase FindPrev(TTreeItem* el) noexcept { + inline static TIteratorBase FindPrev(TTreeItem* el) noexcept { if (el->Left_ != nullptr) { el = el->Left_; @@ -153,22 +153,22 @@ class TAvlTree: public TNonCopyable { const TAvlTree* Tree_; }; - using TConstIterator = TIteratorBase<const TTreeItem, const T>; - using TIterator = TIteratorBase<TTreeItem, T>; - - static inline TConstIterator ConstructFirstConst(const TAvlTree* t) noexcept { - return TConstIterator(t->Head_, t); - } - - static inline TIterator ConstructFirst(const TAvlTree* t) noexcept { + using TConstIterator = TIteratorBase<const TTreeItem, const T>; + using TIterator = TIteratorBase<TTreeItem, T>; + + static inline TConstIterator ConstructFirstConst(const TAvlTree* t) noexcept { + return TConstIterator(t->Head_, t); + } + + static inline TIterator ConstructFirst(const TAvlTree* t) noexcept { return TIterator(t->Head_, t); } - static inline TConstIterator ConstructLastConst(const TAvlTree* t) noexcept { - return TConstIterator(t->Tail_, t); - } - - static inline TIterator ConstructLast(const TAvlTree* t) noexcept { + static inline TConstIterator ConstructLastConst(const TAvlTree* t) noexcept { + return TConstIterator(t->Tail_, t); + } + + static inline TIterator ConstructLast(const TAvlTree* t) noexcept { return TIterator(t->Tail_, t); } @@ -177,17 +177,17 @@ class TAvlTree: public TNonCopyable { } public: - using const_iterator = TConstIterator; + using const_iterator = TConstIterator; using iterator = TIterator; - inline TAvlTree() noexcept + inline TAvlTree() noexcept : Root_(nullptr) , Head_(nullptr) , Tail_(nullptr) { } - inline ~TAvlTree() noexcept { + inline ~TAvlTree() noexcept { Clear(); } @@ -197,7 +197,7 @@ public: } } - inline T* Insert(TTreeItem* el, TTreeItem** lastFound = nullptr) noexcept { + inline T* Insert(TTreeItem* el, TTreeItem** lastFound = nullptr) noexcept { el->Unlink(); el->Tree_ = this; @@ -232,7 +232,7 @@ public: } } - inline T* Find(const TTreeItem* el) const noexcept { + inline T* Find(const TTreeItem* el) const noexcept { TTreeItem* curEl = Root_; while (curEl) { @@ -248,7 +248,7 @@ public: return nullptr; } - inline T* LowerBound(const TTreeItem* el) const noexcept { + inline T* LowerBound(const TTreeItem* el) const noexcept { TTreeItem* curEl = Root_; TTreeItem* lowerBound = nullptr; @@ -266,7 +266,7 @@ public: return AsT(lowerBound); } - inline T* Erase(TTreeItem* el) noexcept { + inline T* Erase(TTreeItem* el) noexcept { if (el->Tree_ == this) { return this->EraseImpl(el); } @@ -274,7 +274,7 @@ public: return nullptr; } - inline T* EraseImpl(TTreeItem* el) noexcept { + inline T* EraseImpl(TTreeItem* el) noexcept { el->Tree_ = nullptr; TTreeItem* replacement; @@ -377,67 +377,67 @@ public: return AsT(el); } - inline const_iterator First() const noexcept { - return ConstructFirstConst(this); - } - - inline const_iterator Last() const noexcept { - return ConstructLastConst(this); - } - - inline const_iterator Begin() const noexcept { - return First(); - } - - inline const_iterator End() const noexcept { - return const_iterator(nullptr, this); - } - - inline const_iterator begin() const noexcept { - return Begin(); - } - - inline const_iterator end() const noexcept { - return End(); - } - - inline const_iterator cbegin() const noexcept { - return Begin(); - } - - inline const_iterator cend() const noexcept { - return End(); - } - - inline iterator First() noexcept { + inline const_iterator First() const noexcept { + return ConstructFirstConst(this); + } + + inline const_iterator Last() const noexcept { + return ConstructLastConst(this); + } + + inline const_iterator Begin() const noexcept { + return First(); + } + + inline const_iterator End() const noexcept { + return const_iterator(nullptr, this); + } + + inline const_iterator begin() const noexcept { + return Begin(); + } + + inline const_iterator end() const noexcept { + return End(); + } + + inline const_iterator cbegin() const noexcept { + return Begin(); + } + + inline const_iterator cend() const noexcept { + return End(); + } + + inline iterator First() noexcept { return ConstructFirst(this); } - inline iterator Last() noexcept { + inline iterator Last() noexcept { return ConstructLast(this); } - inline iterator Begin() noexcept { + inline iterator Begin() noexcept { return First(); } - inline iterator End() noexcept { + inline iterator End() noexcept { return iterator(nullptr, this); } - inline iterator begin() noexcept { - return Begin(); - } - - inline iterator end() noexcept { - return End(); - } - - inline bool Empty() const noexcept { + inline iterator begin() noexcept { + return Begin(); + } + + inline iterator end() noexcept { + return End(); + } + + inline bool Empty() const noexcept { return const_cast<TAvlTree*>(this)->Begin() == const_cast<TAvlTree*>(this)->End(); } - inline explicit operator bool() const noexcept { + inline explicit operator bool() const noexcept { return !this->Empty(); } @@ -454,7 +454,7 @@ public: } private: - inline TTreeItem* Rebalance(TTreeItem* n) noexcept { + inline TTreeItem* Rebalance(TTreeItem* n) noexcept { long lheight, rheight; TTreeItem* a; @@ -561,7 +561,7 @@ private: return ggp; } - inline void RecalcHeights(TTreeItem* el) noexcept { + inline void RecalcHeights(TTreeItem* el) noexcept { long lheight, rheight, new_height; while (el) { @@ -580,7 +580,7 @@ private: } } - inline TTreeItem* FindFirstUnbalGP(TTreeItem* el) noexcept { + inline TTreeItem* FindFirstUnbalGP(TTreeItem* el) noexcept { long lheight, rheight, balanceProp; TTreeItem* gp; @@ -606,7 +606,7 @@ private: return nullptr; } - inline TTreeItem* FindFirstUnbalEl(TTreeItem* el) noexcept { + inline TTreeItem* FindFirstUnbalEl(TTreeItem* el) noexcept { if (el == nullptr) { return nullptr; } @@ -626,7 +626,7 @@ private: return nullptr; } - inline void ReplaceEl(TTreeItem* el, TTreeItem* replacement) noexcept { + inline void ReplaceEl(TTreeItem* el, TTreeItem* replacement) noexcept { TTreeItem* parent = el->Parent_; TTreeItem* left = el->Left_; TTreeItem* right = el->Right_; @@ -658,7 +658,7 @@ private: replacement->Height_ = el->Height_; } - inline void RemoveEl(TTreeItem* el, TTreeItem* filler) noexcept { + inline void RemoveEl(TTreeItem* el, TTreeItem* filler) noexcept { TTreeItem* parent = el->Parent_; if (parent) { @@ -723,10 +723,10 @@ struct TAvlTreeItem: public TNonCopyable { public: using TTree = TAvlTree<T, C>; friend class TAvlTree<T, C>; - friend typename TAvlTree<T, C>::TConstIterator; - friend typename TAvlTree<T, C>::TIterator; + friend typename TAvlTree<T, C>::TConstIterator; + friend typename TAvlTree<T, C>::TIterator; - inline TAvlTreeItem() noexcept + inline TAvlTreeItem() noexcept : Left_(nullptr) , Right_(nullptr) , Parent_(nullptr) @@ -735,11 +735,11 @@ public: { } - inline ~TAvlTreeItem() noexcept { + inline ~TAvlTreeItem() noexcept { Unlink(); } - inline void Unlink() noexcept { + inline void Unlink() noexcept { if (Tree_) { Tree_->EraseImpl(this); } diff --git a/library/cpp/containers/intrusive_avl_tree/ut/avltree_ut.cpp b/library/cpp/containers/intrusive_avl_tree/ut/avltree_ut.cpp index fca5501324..cab2365cce 100644 --- a/library/cpp/containers/intrusive_avl_tree/ut/avltree_ut.cpp +++ b/library/cpp/containers/intrusive_avl_tree/ut/avltree_ut.cpp @@ -5,12 +5,12 @@ class TAvlTreeTest: public TTestBase { UNIT_TEST_SUITE(TAvlTreeTest); UNIT_TEST(TestLowerBound); - UNIT_TEST(TestIterator); + UNIT_TEST(TestIterator); UNIT_TEST_SUITE_END(); private: void TestLowerBound(); - void TestIterator(); + void TestIterator(); class TIt; struct TItCompare { @@ -61,43 +61,43 @@ void TAvlTreeTest::TestLowerBound() { UNIT_ASSERT_EQUAL(its.LowerBound(&it_zero), &it5); UNIT_ASSERT_EQUAL(its.LowerBound(&it_large), nullptr); } - -void TAvlTreeTest::TestIterator() { - TIts its; - TIt it1(1); - TIt it2(2); - TIt it3(3); - TIt it4(4); - TIt it5(5); - TIt it6(6); - TIt it7(7); - - its.Insert(&it3); - its.Insert(&it1); - its.Insert(&it7); - its.Insert(&it5); - its.Insert(&it4); - its.Insert(&it6); - its.Insert(&it2); - + +void TAvlTreeTest::TestIterator() { + TIts its; + TIt it1(1); + TIt it2(2); + TIt it3(3); + TIt it4(4); + TIt it5(5); + TIt it6(6); + TIt it7(7); + + its.Insert(&it3); + its.Insert(&it1); + its.Insert(&it7); + its.Insert(&it5); + its.Insert(&it4); + its.Insert(&it6); + its.Insert(&it2); + TVector<int> res; for (const TIt& i : its) { - res.push_back(i.Val); - } - + res.push_back(i.Val); + } + TVector<int> expected{1, 2, 3, 4, 5, 6, 7}; - UNIT_ASSERT_EQUAL(res, expected); - - res.clear(); + UNIT_ASSERT_EQUAL(res, expected); + + res.clear(); for (TIt& i : its) { - res.push_back(i.Val); - } - UNIT_ASSERT_EQUAL(res, expected); - - res.clear(); - const TIts* constIts = &its; - for (TIts::const_iterator i = constIts->begin(); i != constIts->end(); ++i) { - res.push_back(i->Val); - } - UNIT_ASSERT_EQUAL(res, expected); -} + res.push_back(i.Val); + } + UNIT_ASSERT_EQUAL(res, expected); + + res.clear(); + const TIts* constIts = &its; + for (TIts::const_iterator i = constIts->begin(); i != constIts->end(); ++i) { + res.push_back(i->Val); + } + UNIT_ASSERT_EQUAL(res, expected); +} diff --git a/library/cpp/coroutine/listener/listen.cpp b/library/cpp/coroutine/listener/listen.cpp index 45dfe96509..3d4e711d1d 100644 --- a/library/cpp/coroutine/listener/listen.cpp +++ b/library/cpp/coroutine/listener/listen.cpp @@ -73,9 +73,9 @@ private: if (opts.RecvBufSize) { SetInputBuffer(ListenSocket_, opts.RecvBufSize); } - if (opts.ReusePort) { - SetReusePort(ListenSocket_, opts.ReusePort); - } + if (opts.ReusePort) { + SetReusePort(ListenSocket_, opts.ReusePort); + } SetNonBlock(ListenSocket_); diff --git a/library/cpp/coroutine/listener/listen.h b/library/cpp/coroutine/listener/listen.h index ae86839b20..3a89cd3ecc 100644 --- a/library/cpp/coroutine/listener/listen.h +++ b/library/cpp/coroutine/listener/listen.h @@ -20,7 +20,7 @@ public: , SendBufSize(0) , RecvBufSize(0) , EnableDeferAccept(false) - , ReusePort(false) + , ReusePort(false) { } @@ -49,16 +49,16 @@ public: } inline TOptions& SetReusePort(bool reusePort) noexcept { - ReusePort = reusePort; - - return *this; - } - + ReusePort = reusePort; + + return *this; + } + size_t ListenQueue; unsigned SendBufSize; unsigned RecvBufSize; bool EnableDeferAccept; - bool ReusePort; + bool ReusePort; }; class ICallBack { |