aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/containers
diff options
context:
space:
mode:
authormikari <mikari@yandex-team.ru>2022-02-10 16:48:47 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:47 +0300
commitf821ddfc9200113ec259d8d35b7cf3833372abc9 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/containers
parent2e0ed5ad2d70bf924ccd3cbbfab508784ab36325 (diff)
downloadydb-f821ddfc9200113ec259d8d35b7cf3833372abc9.tar.gz
Restoring authorship annotation for <mikari@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/containers')
-rw-r--r--library/cpp/containers/intrusive_rb_tree/fuzz/rb_tree_fuzzing.cpp114
-rw-r--r--library/cpp/containers/intrusive_rb_tree/fuzz/ya.make28
-rw-r--r--library/cpp/containers/intrusive_rb_tree/rb_tree.h50
-rw-r--r--library/cpp/containers/intrusive_rb_tree/rb_tree_ut.cpp142
4 files changed, 167 insertions, 167 deletions
diff --git a/library/cpp/containers/intrusive_rb_tree/fuzz/rb_tree_fuzzing.cpp b/library/cpp/containers/intrusive_rb_tree/fuzz/rb_tree_fuzzing.cpp
index 8c386a59e51..92370760b59 100644
--- a/library/cpp/containers/intrusive_rb_tree/fuzz/rb_tree_fuzzing.cpp
+++ b/library/cpp/containers/intrusive_rb_tree/fuzz/rb_tree_fuzzing.cpp
@@ -1,65 +1,65 @@
#include <library/cpp/containers/intrusive_rb_tree/rb_tree.h>
-
-#include <util/generic/deque.h>
-#include <stdint.h>
-#include <stddef.h>
-
-struct TCmp {
- template <class T>
- static inline bool Compare(const T& l, const T& r) {
- return l.N < r.N;
- }
-
- template <class T>
+
+#include <util/generic/deque.h>
+#include <stdint.h>
+#include <stddef.h>
+
+struct TCmp {
+ template <class T>
+ static inline bool Compare(const T& l, const T& r) {
+ return l.N < r.N;
+ }
+
+ template <class T>
static inline bool Compare(const T& l, ui8 r) {
- return l.N < r;
- }
-
- template <class T>
+ return l.N < r;
+ }
+
+ template <class T>
static inline bool Compare(ui8 l, const T& r) {
- return l < r.N;
- }
-};
-
-class TNode: public TRbTreeItem<TNode, TCmp> {
-public:
+ return l < r.N;
+ }
+};
+
+class TNode: public TRbTreeItem<TNode, TCmp> {
+public:
inline TNode(ui8 n) noexcept
- : N(n)
- {
- }
-
+ : N(n)
+ {
+ }
+
ui8 N;
-};
-
-using TTree = TRbTree<TNode, TCmp>;
-
+};
+
+using TTree = TRbTree<TNode, TCmp>;
+
extern "C" int LLVMFuzzerTestOneInput(const ui8* data, size_t size) {
TDeque<TNode> records;
const ui8 half = 128u;
- TTree tree;
- for (size_t i = 0; i < size; ++i) {
- if (data[i] / half == 0) {
- records.emplace_back(data[i] % half);
- tree.Insert(&records.back());
- } else {
- auto* ptr = tree.Find(data[i] % half);
- if (ptr != nullptr) {
- tree.Erase(ptr);
- }
- }
- auto check = [](const TNode& node) {
- size_t childrens = 1;
- if (node.Left_) {
- Y_ENSURE(static_cast<const TNode*>(node.Left_)->N <= node.N);
- childrens += node.Left_->Children_;
- }
- if (node.Right_) {
- Y_ENSURE(node.N <= static_cast<const TNode*>(node.Right_)->N);
- childrens += node.Right_->Children_;
- }
- Y_ENSURE(childrens == node.Children_);
- };
- tree.ForEach(check);
- }
- return 0;
-}
+ TTree tree;
+ for (size_t i = 0; i < size; ++i) {
+ if (data[i] / half == 0) {
+ records.emplace_back(data[i] % half);
+ tree.Insert(&records.back());
+ } else {
+ auto* ptr = tree.Find(data[i] % half);
+ if (ptr != nullptr) {
+ tree.Erase(ptr);
+ }
+ }
+ auto check = [](const TNode& node) {
+ size_t childrens = 1;
+ if (node.Left_) {
+ Y_ENSURE(static_cast<const TNode*>(node.Left_)->N <= node.N);
+ childrens += node.Left_->Children_;
+ }
+ if (node.Right_) {
+ Y_ENSURE(node.N <= static_cast<const TNode*>(node.Right_)->N);
+ childrens += node.Right_->Children_;
+ }
+ Y_ENSURE(childrens == node.Children_);
+ };
+ tree.ForEach(check);
+ }
+ return 0;
+}
diff --git a/library/cpp/containers/intrusive_rb_tree/fuzz/ya.make b/library/cpp/containers/intrusive_rb_tree/fuzz/ya.make
index 90c55bc9b86..61be9919e6d 100644
--- a/library/cpp/containers/intrusive_rb_tree/fuzz/ya.make
+++ b/library/cpp/containers/intrusive_rb_tree/fuzz/ya.make
@@ -1,20 +1,20 @@
-FUZZ()
-
+FUZZ()
+
OWNER(
g:util
mikari
)
-
-SIZE(LARGE)
-TAG(ya:fat)
-
-PEERDIR(
+SIZE(LARGE)
+
+TAG(ya:fat)
+
+PEERDIR(
library/cpp/containers/intrusive_rb_tree
-)
-
-SRCS(
- rb_tree_fuzzing.cpp
-)
-
-END()
+)
+
+SRCS(
+ rb_tree_fuzzing.cpp
+)
+
+END()
diff --git a/library/cpp/containers/intrusive_rb_tree/rb_tree.h b/library/cpp/containers/intrusive_rb_tree/rb_tree.h
index 4118d01a254..0259452a145 100644
--- a/library/cpp/containers/intrusive_rb_tree/rb_tree.h
+++ b/library/cpp/containers/intrusive_rb_tree/rb_tree.h
@@ -67,8 +67,8 @@ public:
static void Rebalance(TBasePtr x, TBasePtr& root);
static TBasePtr RebalanceForErase(TBasePtr z, TBasePtr& root, TBasePtr& leftmost, TBasePtr& rightmost);
- static void DecrementChildrenUntilRoot(TBasePtr x, TBasePtr root);
- static void RecalcChildren(TBasePtr x);
+ static void DecrementChildrenUntilRoot(TBasePtr x, TBasePtr root);
+ static void RecalcChildren(TBasePtr x);
static TBasePtr IncrementNode(TBasePtr);
static TBasePtr DecrementNode(TBasePtr);
@@ -610,21 +610,21 @@ void TRbGlobal<TDummy>::Rebalance(TRbTreeNodeBase* x, TRbTreeNodeBase*& root) {
}
template <class TDummy>
-void TRbGlobal<TDummy>::RecalcChildren(TRbTreeNodeBase* x) {
- x->Children_ = ((x->Left_) ? x->Left_->Children_ : 0) + ((x->Right_) ? x->Right_->Children_ : 0) + 1;
-}
-
-template <class TDummy>
-void TRbGlobal<TDummy>::DecrementChildrenUntilRoot(TRbTreeNodeBase* x, TRbTreeNodeBase* root) {
- auto* ptr = x;
- --ptr->Children_;
- while (ptr != root) {
- ptr = ptr->Parent_;
- --ptr->Children_;
- }
-}
-
-template <class TDummy>
+void TRbGlobal<TDummy>::RecalcChildren(TRbTreeNodeBase* x) {
+ x->Children_ = ((x->Left_) ? x->Left_->Children_ : 0) + ((x->Right_) ? x->Right_->Children_ : 0) + 1;
+}
+
+template <class TDummy>
+void TRbGlobal<TDummy>::DecrementChildrenUntilRoot(TRbTreeNodeBase* x, TRbTreeNodeBase* root) {
+ auto* ptr = x;
+ --ptr->Children_;
+ while (ptr != root) {
+ ptr = ptr->Parent_;
+ --ptr->Children_;
+ }
+}
+
+template <class TDummy>
TRbTreeNodeBase* TRbGlobal<TDummy>::RebalanceForErase(TRbTreeNodeBase* z,
TRbTreeNodeBase*& root,
TRbTreeNodeBase*& leftmost,
@@ -665,14 +665,14 @@ TRbTreeNodeBase* TRbGlobal<TDummy>::RebalanceForErase(TRbTreeNodeBase* z,
z->Parent_->Right_ = y;
y->Parent_ = z->Parent_;
DoSwap(y->Color_, z->Color_);
-
- RecalcChildren(y);
- if (x_parent != y) {
- --x_parent->Children_;
- }
- if (x_parent != root) {
- DecrementChildrenUntilRoot(x_parent->Parent_, root);
- }
+
+ RecalcChildren(y);
+ if (x_parent != y) {
+ --x_parent->Children_;
+ }
+ if (x_parent != root) {
+ DecrementChildrenUntilRoot(x_parent->Parent_, root);
+ }
y = z;
// y now points to node to be actually deleted
} else {
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 095cf76b470..c34ed1fd9b4 100644
--- a/library/cpp/containers/intrusive_rb_tree/rb_tree_ut.cpp
+++ b/library/cpp/containers/intrusive_rb_tree/rb_tree_ut.cpp
@@ -43,8 +43,8 @@ class TRedBlackTreeTest: public TTestBase {
UNIT_TEST(TestFind)
UNIT_TEST(TestStress)
UNIT_TEST(TestGettingIndexWithDifferentValues)
- UNIT_TEST(TestCheckChildrenAfterErase)
- UNIT_TEST(TestGettingIndexWithDifferentValuesAfterErase)
+ UNIT_TEST(TestCheckChildrenAfterErase)
+ UNIT_TEST(TestGettingIndexWithDifferentValuesAfterErase)
UNIT_TEST(TestGettingIndexWithEqualValues)
UNIT_TEST(TestLessCountOnEmptyTree)
UNIT_TEST_SUITE_END();
@@ -104,77 +104,77 @@ private:
}
}
- inline void TestCheckChildrenAfterErase() {
+ inline void TestCheckChildrenAfterErase() {
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());
- }
- auto checker = [](const TTree& tree) {
- for (auto node = tree.Begin(); node != tree.End(); ++node) {
- size_t childrens = 1;
- if (node->Left_) {
- childrens += node->Left_->Children_;
- }
- if (node->Right_) {
- childrens += node->Right_->Children_;
- }
- UNIT_ASSERT_VALUES_EQUAL(childrens, node->Children_);
- }
- };
-
- for (auto node : nodes) {
- tree.Erase(node.Get());
- checker(tree);
- }
- }
-
- inline void TestGettingIndexWithDifferentValuesAfterErase() {
+ 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());
+ }
+ auto checker = [](const TTree& tree) {
+ for (auto node = tree.Begin(); node != tree.End(); ++node) {
+ size_t childrens = 1;
+ if (node->Left_) {
+ childrens += node->Left_->Children_;
+ }
+ if (node->Right_) {
+ childrens += node->Right_->Children_;
+ }
+ UNIT_ASSERT_VALUES_EQUAL(childrens, node->Children_);
+ }
+ };
+
+ for (auto node : nodes) {
+ tree.Erase(node.Get());
+ checker(tree);
+ }
+ }
+
+ inline void TestGettingIndexWithDifferentValuesAfterErase() {
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());
- }
- {
- size_t index = 0;
- for (auto node = tree.Begin(); node != tree.End(); ++node, ++index) {
- UNIT_ASSERT_VALUES_EQUAL(tree.GetIndex(&*node), index);
- UNIT_ASSERT_VALUES_EQUAL(tree.ByIndex(index)->N, node->N);
- UNIT_ASSERT_VALUES_EQUAL(node->N, index);
- }
- }
-
- for (size_t i = 1; i < N; i += 2) {
- auto* node = tree.Find(i);
- UNIT_ASSERT_VALUES_EQUAL(node->N, i);
- tree.Erase(node);
- }
- {
- size_t index = 0;
- for (auto node = tree.Begin(); node != tree.End(); ++node, ++index) {
- UNIT_ASSERT_VALUES_EQUAL(tree.GetIndex(&*node), index);
- UNIT_ASSERT_VALUES_EQUAL(tree.ByIndex(index)->N, node->N);
- UNIT_ASSERT_VALUES_EQUAL(node->N, 2 * index);
- }
- }
- }
-
+ 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());
+ }
+ {
+ size_t index = 0;
+ for (auto node = tree.Begin(); node != tree.End(); ++node, ++index) {
+ UNIT_ASSERT_VALUES_EQUAL(tree.GetIndex(&*node), index);
+ UNIT_ASSERT_VALUES_EQUAL(tree.ByIndex(index)->N, node->N);
+ UNIT_ASSERT_VALUES_EQUAL(node->N, index);
+ }
+ }
+
+ for (size_t i = 1; i < N; i += 2) {
+ auto* node = tree.Find(i);
+ UNIT_ASSERT_VALUES_EQUAL(node->N, i);
+ tree.Erase(node);
+ }
+ {
+ size_t index = 0;
+ for (auto node = tree.Begin(); node != tree.End(); ++node, ++index) {
+ UNIT_ASSERT_VALUES_EQUAL(tree.GetIndex(&*node), index);
+ UNIT_ASSERT_VALUES_EQUAL(tree.ByIndex(index)->N, node->N);
+ UNIT_ASSERT_VALUES_EQUAL(node->N, 2 * index);
+ }
+ }
+ }
+
inline void TestGettingIndexWithEqualValues() {
TVector<TSimpleSharedPtr<TNode>> nodes;
size_t N = 1000;