41#include <gtest/gtest.h>
50 size_t count_nodes(
Node *
root)
noexcept
52 if (
root == Node::NullPtr)
60 std::vector<typename Node::key_type>
keys;
61 if (
root == Node::NullPtr)
65 keys.insert(
keys.end(), left.begin(), left.end());
68 keys.insert(
keys.end(), right.begin(), right.end());
75 ASSERT_TRUE(tree.verify()) <<
"BST invariant violated";
82 std::vector<Node *> allocated;
86 auto * p =
new Node(
k);
87 allocated.push_back(p);
93 for (
auto & q : allocated)
103 for (
auto * p : allocated)
110 bool use_abs =
false;
112 StatefulLess() =
default;
113 explicit StatefulLess(
bool b) : use_abs(b) {}
115 bool operator()(
int a,
int b)
const
145 auto * p = pool.make(7);
160 auto * p1 = pool.make(10);
163 auto * p2 = pool.make(10);
178 for (
int i = 0; i < 5; ++i)
179 ASSERT_NE(tree.insert_dup(pool.make(42)),
nullptr);
195 for (
int k : {5, 3, 7, 1, 4, 6, 8})
198 auto * found = tree.
search(4);
213 for (
int k : {1, 3, 5})
217 ASSERT_NE(tree.getRoot(), Tree::Node::NullPtr);
221 ASSERT_NE(tree.getRoot(), Tree::Node::NullPtr);
235 auto * p1 = pool.make(10);
236 EXPECT_EQ(tree.search_or_insert(p1), p1);
238 auto * p2 = pool.make(10);
239 auto *
ret2 = tree.search_or_insert(p2);
254 for (
int k : {1, 2, 3, 4, 5})
281 for (
int k : {1, 2, 3, 4, 5})
289 ASSERT_NE(tree.getRoot(), Node::NullPtr);
299 Tree tree(StatefulLess(
true));
302 auto * p = pool.make(1);
WeightedDigraph::Node Node
Node *& getRoot() noexcept
Get the top-down splay tree's root.
Node * remove(const Key &key) noexcept
Remove a key from a top down splay tree.
Node * search(const Key &key) noexcept
Searches a key in a top-down splay tree.
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.
__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)
Top-down splay tree implementation (without rank support).