43#include <gtest/gtest.h>
49using namespace testing;
58 std::vector<Node *> allocated;
60 Node *
make(
const typename Node::key_type & key)
63 allocated.push_back(p);
69 for (
auto & q : allocated)
79 for (
Node * p : allocated)
87 std::vector<typename Node::key_type>
keys;
98 const std::vector<int>
input{5, 3, 7, 2, 4, 6, 8};
105 auto * found = t.
search(4);
123 auto * a = pool.make(5);
124 auto * b = pool.make(5);
129 auto * c = pool.make(5);
163 auto * dup = pool.make(25);
208 for (
int k : {50, 25, 75, 12, 37, 62, 87, 6, 18, 31, 43})
222 for (
int k : {31, 37, 25, 50})
248 for (
int k : {1, 2, 3})
259 for (
int k : {3, 1, 4, 2})
280 std::mt19937
rng(12345);
281 std::uniform_int_distribution<int> dist(0, 500);
285 for (
int i = 0; i < 300; ++i)
288 auto * p = pool.make(
k);
301 for (
int i = 0; i < 200; ++i)
363 std::mt19937
rng(123456);
364 std::uniform_int_distribution<int> dist(0, 2000);
365 std::bernoulli_distribution do_insert(0.6);
369 for (
int i = 0; i < 1500; ++i)
374 auto * p = pool.make(
k);
406 bool operator()(
int a,
int b)
const noexcept {
return a > b; }
412 for (
int k : {1, 2, 3, 4, 5})
417 const std::vector<int>
expected{5, 4, 3, 2, 1};
449 auto * dup = pool.make(30);
460 std::mt19937
rng(77777);
461 std::uniform_int_distribution<int>
n_dist(1, 50);
470 for (
int i = 1; i <= n; ++i)
494 for (
int i = 0; i < n; ++i)
496 ASSERT_NE(t.
insert(pool.make(i)),
nullptr) <<
"Insert failed at i=" << i;
501 for (
int i = 0; i < n; ++i)
513 for (
int i = n - 1; i >= 0; --i)
519 for (
int i = 0; i < n; ++i)
532 for (
int i = 0; i < n / 2; ++i)
540 for (
int i = 0; i < n; ++i)
550 std::mt19937
rng(99999);
551 std::uniform_int_distribution<int>
key_dist(0, 50000);
552 std::uniform_int_distribution<int>
op_dist(0, 2);
558 for (
int i = 0; i <
num_ops; ++i)
567 auto * p = pool.make(key);
600 auto * found = t.
search(key);
627 std::vector<int>
keys(n);
628 std::iota(
keys.begin(),
keys.end(), 0);
630 std::mt19937
rng(12345);
690 std::mt19937
rng(54321);
691 std::uniform_int_distribution<int> dist(0, 10000);
695 for (
int i = 0; i < n; ++i)
701 auto * p = pool.make(
k);
702 if (t.
insert(p) ==
nullptr)
736 std::mt19937
rng(11111);
737 std::uniform_int_distribution<int>
len_dist(1, 30);
738 std::uniform_int_distribution<int>
char_dist(
'a',
'z');
744 for (
int i = 0; i < len; ++i)
749 std::set<std::string>
oracle;
753 for (
int i = 0; i < n; ++i)
756 auto * p = pool.make(s);
757 if (t.
insert(p) !=
nullptr)
769 for (
const auto & s :
oracle)
static string random_string(std::mt19937 &rng, size_t len)
bool is_avl(Node *p)
Validate that a tree satisfies AVL properties.
#define DIFF(p)
Access the balance factor of node p.
WeightedDigraph::Node Node
Node * search(const Key &key) const noexcept
Search a node containing key; if found, then a pointer to the node containing it is returned; otherwi...
Node * search_or_insert(Node *p) noexcept
Search or insert a key.
Node * insert_dup(Node *p) noexcept
Insert the node p without testing for key duplicity.
constexpr Node *& getRoot() noexcept
Return a modifiable reference to tree's root.
Node * insert(Node *p) noexcept
Insert the node pointed by p in the tree.
bool verify() const noexcept
Node * remove(const Key &key) noexcept
Remove from an AVL tree the node containing key key.
Minimal std::expected-style result type for C++20.
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
std::vector< int > inorder_keys(NodeT *root)
AVL binary search tree with nodes without a virtual destructor.
ValueArg< size_t > num_keys
AVL tree implementation (height-balanced BST).