diff options
author | mikari <mikari@yandex-team.ru> | 2022-02-10 16:48:47 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:47 +0300 |
commit | 2e0ed5ad2d70bf924ccd3cbbfab508784ab36325 (patch) | |
tree | c407f44de8fd4579bf0ceffc822d243ff76cfd26 /library/cpp/containers/intrusive_rb_tree/fuzz/rb_tree_fuzzing.cpp | |
parent | ab32245a89d56835833808c7e644b3da277d7085 (diff) | |
download | ydb-2e0ed5ad2d70bf924ccd3cbbfab508784ab36325.tar.gz |
Restoring authorship annotation for <mikari@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/containers/intrusive_rb_tree/fuzz/rb_tree_fuzzing.cpp')
-rw-r--r-- | library/cpp/containers/intrusive_rb_tree/fuzz/rb_tree_fuzzing.cpp | 114 |
1 files changed, 57 insertions, 57 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 92370760b5..8c386a59e5 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; +} |