aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorvavbrs <vavbrs@yandex-team.ru>2022-02-10 16:50:37 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:37 +0300
commitf5adc48f207b2a0e660881efd443f304cc1536ff (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library
parente457c00835fa6b453dda3392d911fa8a25fd4f37 (diff)
downloadydb-f5adc48f207b2a0e660881efd443f304cc1536ff.tar.gz
Restoring authorship annotation for <vavbrs@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library')
-rw-r--r--library/cpp/containers/intrusive_rb_tree/rb_tree.h98
-rw-r--r--library/cpp/containers/intrusive_rb_tree/rb_tree_ut.cpp110
2 files changed, 104 insertions, 104 deletions
diff --git a/library/cpp/containers/intrusive_rb_tree/rb_tree.h b/library/cpp/containers/intrusive_rb_tree/rb_tree.h
index 805f7959ee..0259452a14 100644
--- a/library/cpp/containers/intrusive_rb_tree/rb_tree.h
+++ b/library/cpp/containers/intrusive_rb_tree/rb_tree.h
@@ -350,26 +350,26 @@ public:
return static_cast<TValue*>(y);
}
- size_t GetIndex(TBasePtr x) const {
- size_t index = 0;
-
- if (x->Left_ != nullptr) {
- index += x->Left_->Children_;
- }
-
- while (x != nullptr && x->Parent_ != nullptr && x->Parent_ != const_cast<TBasePtr>(&this->Data_)) {
- if (x->Parent_->Right_ == x && x->Parent_->Left_ != nullptr) {
- index += x->Parent_->Left_->Children_;
- }
- if (x->Parent_->Right_ == x) {
- index += 1;
- }
- x = x->Parent_;
- }
-
- return index;
- }
-
+ size_t GetIndex(TBasePtr x) const {
+ size_t index = 0;
+
+ if (x->Left_ != nullptr) {
+ index += x->Left_->Children_;
+ }
+
+ while (x != nullptr && x->Parent_ != nullptr && x->Parent_ != const_cast<TBasePtr>(&this->Data_)) {
+ if (x->Parent_->Right_ == x && x->Parent_->Left_ != nullptr) {
+ index += x->Parent_->Left_->Children_;
+ }
+ if (x->Parent_->Right_ == x) {
+ index += 1;
+ }
+ x = x->Parent_;
+ }
+
+ return index;
+ }
+
template <class T1>
inline TBasePtr LowerBound(const T1& k) const {
TBasePtr y = const_cast<TBasePtr>(&this->Data_); /* Last node which is not less than k. */
@@ -398,40 +398,40 @@ public:
return y;
}
- template <class T1>
- inline size_t LessCount(const T1& k) const {
- auto x = LowerBound(k);
- if (x == const_cast<TBasePtr>(&this->Data_)) {
+ template <class T1>
+ inline size_t LessCount(const T1& k) const {
+ auto x = LowerBound(k);
+ if (x == const_cast<TBasePtr>(&this->Data_)) {
if (const auto root = Root()) {
return root->Children_;
} else {
return 0;
}
- } else {
- return GetIndex(x);
- }
- }
-
- template <class T1>
- inline size_t NotLessCount(const T1& k) const {
- return Root()->Children_ - LessCount<T1>(k);
- }
-
- template <class T1>
- inline size_t GreaterCount(const T1& k) const {
- auto x = UpperBound(k);
- if (x == const_cast<TBasePtr>(&this->Data_)) {
- return 0;
- } else {
- return Root()->Children_ - GetIndex(x);
- }
- }
-
- template <class T1>
- inline size_t NotGreaterCount(const T1& k) const {
- return Root()->Children_ - GreaterCount<T1>(k);
- }
-
+ } else {
+ return GetIndex(x);
+ }
+ }
+
+ template <class T1>
+ inline size_t NotLessCount(const T1& k) const {
+ return Root()->Children_ - LessCount<T1>(k);
+ }
+
+ template <class T1>
+ inline size_t GreaterCount(const T1& k) const {
+ auto x = UpperBound(k);
+ if (x == const_cast<TBasePtr>(&this->Data_)) {
+ return 0;
+ } else {
+ return Root()->Children_ - GetIndex(x);
+ }
+ }
+
+ template <class T1>
+ inline size_t NotGreaterCount(const T1& k) const {
+ return Root()->Children_ - GreaterCount<T1>(k);
+ }
+
TValue* ByIndex(size_t index) {
return static_cast<TValue*>(TRbTreeNodeBase::ByIndex(Root(), index));
}
diff --git a/library/cpp/containers/intrusive_rb_tree/rb_tree_ut.cpp b/library/cpp/containers/intrusive_rb_tree/rb_tree_ut.cpp
index 2fab91405a..c34ed1fd9b 100644
--- a/library/cpp/containers/intrusive_rb_tree/rb_tree_ut.cpp
+++ b/library/cpp/containers/intrusive_rb_tree/rb_tree_ut.cpp
@@ -4,7 +4,7 @@
#include <util/random/fast.h>
#include <util/random/easy.h>
-#include <util/random/shuffle.h>
+#include <util/random/shuffle.h>
class TRedBlackTreeTest: public TTestBase {
struct TCmp {
@@ -42,10 +42,10 @@ class TRedBlackTreeTest: public TTestBase {
UNIT_TEST(TestErase)
UNIT_TEST(TestFind)
UNIT_TEST(TestStress)
- UNIT_TEST(TestGettingIndexWithDifferentValues)
+ UNIT_TEST(TestGettingIndexWithDifferentValues)
UNIT_TEST(TestCheckChildrenAfterErase)
UNIT_TEST(TestGettingIndexWithDifferentValuesAfterErase)
- UNIT_TEST(TestGettingIndexWithEqualValues)
+ UNIT_TEST(TestGettingIndexWithEqualValues)
UNIT_TEST(TestLessCountOnEmptyTree)
UNIT_TEST_SUITE_END();
@@ -77,33 +77,33 @@ private:
}
}
- inline void TestGettingIndexWithDifferentValues() {
+ inline void TestGettingIndexWithDifferentValues() {
TVector<TSimpleSharedPtr<TNode>> nodes;
- size_t N = 1000;
-
- for (size_t i = 0; i < N; ++i) {
- nodes.push_back(new TNode(int(i)));
- }
-
- TTree tree;
- Shuffle(nodes.begin(), nodes.end());
-
- for (size_t i = 0; i < N; ++i) {
- tree.Insert(nodes[i].Get());
- }
-
- for (size_t i = 0; i < N; ++i) {
- UNIT_ASSERT_EQUAL(tree.LessCount(i), i);
- UNIT_ASSERT_EQUAL(tree.NotGreaterCount(i), i + 1);
- UNIT_ASSERT_EQUAL(tree.GreaterCount(i), N - i - 1);
- UNIT_ASSERT_EQUAL(tree.NotLessCount(i), N - i);
-
- auto nodePtr = tree.Find(i);
- UNIT_ASSERT_EQUAL(tree.GetIndex(nodePtr), i);
- UNIT_ASSERT_EQUAL(tree.GetIndex(nodes[i].Get()), static_cast<size_t>(nodes[i]->N));
- }
- }
-
+ size_t N = 1000;
+
+ for (size_t i = 0; i < N; ++i) {
+ nodes.push_back(new TNode(int(i)));
+ }
+
+ TTree tree;
+ Shuffle(nodes.begin(), nodes.end());
+
+ for (size_t i = 0; i < N; ++i) {
+ tree.Insert(nodes[i].Get());
+ }
+
+ for (size_t i = 0; i < N; ++i) {
+ UNIT_ASSERT_EQUAL(tree.LessCount(i), i);
+ UNIT_ASSERT_EQUAL(tree.NotGreaterCount(i), i + 1);
+ UNIT_ASSERT_EQUAL(tree.GreaterCount(i), N - i - 1);
+ UNIT_ASSERT_EQUAL(tree.NotLessCount(i), N - i);
+
+ auto nodePtr = tree.Find(i);
+ UNIT_ASSERT_EQUAL(tree.GetIndex(nodePtr), i);
+ UNIT_ASSERT_EQUAL(tree.GetIndex(nodes[i].Get()), static_cast<size_t>(nodes[i]->N));
+ }
+ }
+
inline void TestCheckChildrenAfterErase() {
TVector<TSimpleSharedPtr<TNode>> nodes;
size_t N = 1000;
@@ -175,33 +175,33 @@ private:
}
}
- inline void TestGettingIndexWithEqualValues() {
+ inline void TestGettingIndexWithEqualValues() {
TVector<TSimpleSharedPtr<TNode>> nodes;
- size_t N = 1000;
-
- for (size_t i = 0; i < N; ++i) {
- nodes.push_back(new TNode(0));
- }
-
- TTree tree;
-
- for (size_t i = 0; i < N; ++i) {
- tree.Insert(nodes[i].Get());
- }
-
- for (size_t i = 0; i < N; ++i) {
- UNIT_ASSERT_EQUAL(tree.LessCount(nodes[i]->N), 0);
- UNIT_ASSERT_EQUAL(tree.NotGreaterCount(nodes[i]->N), N);
- UNIT_ASSERT_EQUAL(tree.GreaterCount(nodes[i]->N), 0);
- UNIT_ASSERT_EQUAL(tree.NotLessCount(nodes[i]->N), N);
-
- UNIT_ASSERT_EQUAL(tree.LessCount(*nodes[i].Get()), 0);
- UNIT_ASSERT_EQUAL(tree.NotGreaterCount(*nodes[i].Get()), N);
- UNIT_ASSERT_EQUAL(tree.GreaterCount(*nodes[i].Get()), 0);
- UNIT_ASSERT_EQUAL(tree.NotLessCount(*nodes[i].Get()), N);
- }
- }
-
+ size_t N = 1000;
+
+ for (size_t i = 0; i < N; ++i) {
+ nodes.push_back(new TNode(0));
+ }
+
+ TTree tree;
+
+ for (size_t i = 0; i < N; ++i) {
+ tree.Insert(nodes[i].Get());
+ }
+
+ for (size_t i = 0; i < N; ++i) {
+ UNIT_ASSERT_EQUAL(tree.LessCount(nodes[i]->N), 0);
+ UNIT_ASSERT_EQUAL(tree.NotGreaterCount(nodes[i]->N), N);
+ UNIT_ASSERT_EQUAL(tree.GreaterCount(nodes[i]->N), 0);
+ UNIT_ASSERT_EQUAL(tree.NotLessCount(nodes[i]->N), N);
+
+ UNIT_ASSERT_EQUAL(tree.LessCount(*nodes[i].Get()), 0);
+ UNIT_ASSERT_EQUAL(tree.NotGreaterCount(*nodes[i].Get()), N);
+ UNIT_ASSERT_EQUAL(tree.GreaterCount(*nodes[i].Get()), 0);
+ UNIT_ASSERT_EQUAL(tree.NotLessCount(*nodes[i].Get()), N);
+ }
+ }
+
inline void TestFind() {
TTree tree;