49#include <gtest/gtest.h>
54using namespace testing;
64 std::vector<Node *> allocated;
66 Node *
make(
const typename Node::key_type & key)
69 allocated.push_back(p);
75 for (
auto & q : allocated)
85 for (
Node * p : allocated)
94 std::vector<typename Node::key_type>
keys;
95 if (
root ==
nullptr ||
root == Node::NullPtr)
99 keys.insert(
keys.end(), left.begin(), left.end());
102 keys.insert(
keys.end(), right.begin(), right.end());
108 template <
class Node>
111 if (
root ==
nullptr ||
root == Node::NullPtr)
117 template <
class Node>
120 if (p ==
nullptr || p == Node::NullPtr)
133 template <
class Node>
136 if (p ==
nullptr || p == Node::NullPtr)
149 template <
class Tree>
152 auto root = tree.getRoot();
153 if (
root ==
nullptr ||
root == Tree::Node::NullPtr)
206 tree.
insert(pool.make(10));
210 tree.
insert(pool.make(5));
211 tree.
insert(pool.make(15));
217 insert_values({50, 25, 75, 10, 30, 60, 90});
230 insert_values({50, 25, 75});
244 insert_values({50, 25, 75});
257 tree.
insert(pool.make(50));
263 insert_values({50, 25, 75, 10, 30, 60, 90, 5, 15, 27, 35});
269 for (
int i = 1; i <= 20; ++i)
270 tree.
insert(pool.make(i));
278 for (
int i = 20; i >= 1; --i)
279 tree.
insert(pool.make(i));
287 insert_values({50, 25, 75, 10, 30, 60, 90});
303 insert_values({50, 25, 75, 10, 30, 60, 90});
313 insert_values({50, 25, 75, 10, 30, 60, 90});
327 tree.
insert(pool.make(50));
328 tree.
insert(pool.make(25));
329 tree.
insert(pool.make(75));
338 insert_values({50, 25, 75, 10, 30, 60, 90, 5, 15, 27, 35});
352 tree1.set_seed(12345);
355 for (
int v : {50, 25, 75, 10, 30})
363 tree2.set_seed(12345);
366 for (
int v : {50, 25, 75, 10, 30})
384 std::mt19937
rng(42);
385 std::uniform_int_distribution<int> dist(1, 10000);
386 std::set<int> inserted;
388 for (
int i = 0; i < 1000; ++i)
390 int value = dist(
rng);
391 if (inserted.insert(value).second)
392 tree.
insert(pool.make(value));
401 std::mt19937
rng(123);
402 std::uniform_int_distribution<int> dist(1, 1000);
403 std::vector<int> values;
406 for (
int i = 0; i < 500; ++i)
408 int value = dist(
rng);
409 values.push_back(value);
410 tree.
insert(pool.make(value));
416 std::shuffle(values.begin(), values.end(),
rng);
417 for (
size_t i = 0; i < values.size() / 2; ++i)
436 for (
int i = 1; i <= 10000; ++i)
437 tree.
insert(pool.make(i));
WeightedDigraph::Node Node
void set_seed(const unsigned long seed) noexcept
Set the random number generator seed.
Node *& getRoot() noexcept
Return the tree's root.
Node * insert(Node *root, Node *p) noexcept
Node for QuadTree spatial data structure.
QuadTree - Hierarchical spatial index for 2D points.
void remove(const Point &p)
Remove a point from the tree.
Point * search(const Point &p) noexcept
Search for a point in the tree.
Point * insert(Node *&r, const Point &p)
Recursive insert helper.
void insert_values(std::initializer_list< int > values)
__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)
unsigned long & PRIO(Node *p) noexcept
Access the priority of a treap node.
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)
Treap: randomized BST combining tree and heap properties.
TEST_F(TreapTest, EmptyTreeIsEmpty)