43#include <gtest/gtest.h>
48using namespace testing;
57 std::vector<Node *> allocated;
59 Node *
make(
const typename Node::key_type & key)
62 allocated.push_back(p);
68 for (
auto & q : allocated)
78 for (
Node * p : allocated)
86 std::vector<typename Node::key_type>
keys;
97 const std::vector<int>
input{5, 3, 7, 2, 4, 6, 8};
104 auto * found = t.
search(4);
122 auto * a = pool.make(5);
123 auto * b = pool.make(5);
128 auto * c = pool.make(5);
162 auto * dup = pool.make(25);
207 for (
int k : {50, 25, 75, 12, 37, 62, 87, 6, 18, 31, 43})
221 for (
int k : {31, 37, 25, 50})
247 for (
int k : {1, 2, 3})
258 for (
int k : {3, 1, 4, 2})
279 std::mt19937
rng(12345);
280 std::uniform_int_distribution<int> dist(0, 500);
284 for (
int i = 0; i < 300; ++i)
287 auto * p = pool.make(
k);
300 for (
int i = 0; i < 200; ++i)
362 std::mt19937
rng(123456);
363 std::uniform_int_distribution<int> dist(0, 2000);
364 std::bernoulli_distribution do_insert(0.6);
368 for (
int i = 0; i < 1500; ++i)
373 auto * p = pool.make(
k);
405 bool operator()(
int a,
int b)
const noexcept {
return a > b; }
411 for (
int k : {1, 2, 3, 4, 5})
416 const std::vector<int>
expected{5, 4, 3, 2, 1};
448 auto * dup = pool.make(30);
459 std::mt19937
rng(77777);
460 std::uniform_int_distribution<int>
n_dist(1, 50);
469 for (
int i = 1; i <= n; ++i)
493 for (
int i = 0; i < n; ++i)
495 ASSERT_NE(t.
insert(pool.make(i)),
nullptr) <<
"Insert failed at i=" << i;
500 for (
int i = 0; i < n; ++i)
512 for (
int i = n - 1; i >= 0; --i)
518 for (
int i = 0; i < n; ++i)
531 for (
int i = 0; i < n / 2; ++i)
539 for (
int i = 0; i < n; ++i)
549 std::mt19937
rng(99999);
550 std::uniform_int_distribution<int>
key_dist(0, 50000);
551 std::uniform_int_distribution<int>
op_dist(0, 2);
557 for (
int i = 0; i <
num_ops; ++i)
566 auto * p = pool.make(key);
599 auto * found = t.
search(key);
626 std::vector<int>
keys(n);
627 std::iota(
keys.begin(),
keys.end(), 0);
629 std::mt19937
rng(12345);
689 std::mt19937
rng(54321);
690 std::uniform_int_distribution<int> dist(0, 10000);
694 for (
int i = 0; i < n; ++i)
700 auto * p = pool.make(
k);
701 if (t.
insert(p) ==
nullptr)
735 std::mt19937
rng(11111);
736 std::uniform_int_distribution<int>
len_dist(1, 30);
737 std::uniform_int_distribution<int>
char_dist(
'a',
'z');
743 for (
int i = 0; i < len; ++i)
748 std::set<std::string>
oracle;
752 for (
int i = 0; i < n; ++i)
755 auto * p = pool.make(s);
756 if (t.
insert(p) !=
nullptr)
768 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.
__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)
Main namespace for Aleph-w library functions.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
std::vector< int > inorder_keys(NodeT *root)
AVL binary search tree with nodes without virtual destructor.
ValueArg< size_t > num_keys
AVL tree implementation (height-balanced BST).