40# include <gtest/gtest.h>
55template <
typename Tree>
62 static constexpr size_t N = 1000;
108 for (
size_t i = 0; i <
N; ++i)
110 auto p = tree.select(i);
112 EXPECT_EQ(p->get_key(),
static_cast<int>(i));
121 for (
size_t i = 0; i <
N; ++i)
123 auto [pos, node] = tree.position(
static_cast<int>(i));
126 EXPECT_EQ(node->get_key(),
static_cast<int>(i));
135 auto [pos, node] = tree.position(
static_cast<int>(
N + 100));
145 for (
size_t i = 0; i <
N / 2; ++i)
147 auto p = tree.remove(
keys[i]);
163 auto p = tree.remove(
k);
170 for (
size_t i = 0; i <
N / 2; ++i)
172 auto p = tree.select(i);
174 EXPECT_EQ(p->get_key(),
static_cast<int>(2 * i + 1));
193 for (
size_t i = 0; i <
N; ++i)
195 auto p = tree.select(i);
197 EXPECT_EQ(p->get_key(),
static_cast<int>(i));
206 for (
size_t i = 0; i <
N; ++i)
208 auto [pos, node] = tree.position(
static_cast<int>(i));
211 EXPECT_EQ(node->get_key(),
static_cast<int>(i));
220 auto [pos, node] = tree.position(
static_cast<int>(
N + 100));
230 for (
size_t i = 0; i <
N / 2; ++i)
232 auto p = tree.remove(
keys[i]);
248 auto p = tree.remove(
k);
255 for (
size_t i = 0; i <
N / 2; ++i)
257 auto p = tree.select(i);
259 EXPECT_EQ(p->get_key(),
static_cast<int>(2 * i + 1));
269 const size_t N = 5000;
272 for (
size_t i = 0; i <
N; ++i)
274 auto p =
new Node(
static_cast<int>(i));
283 for (
int i = 0; i < 100; ++i)
285 size_t pos = dist(
rng);
286 auto p = tree.
select(pos);
287 EXPECT_EQ(p->get_key(),
static_cast<int>(pos));
291 for (
int i = 0; i < 100; ++i)
293 int key =
static_cast<int>(dist(
rng));
294 auto [pos, node] = tree.
position(key);
314 const size_t N = 5000;
317 for (
size_t i = 0; i <
N; ++i)
319 auto p =
new Node(
static_cast<int>(i));
328 for (
int i = 0; i < 100; ++i)
330 size_t pos = dist(
rng);
331 auto p = tree.
select(pos);
332 EXPECT_EQ(p->get_key(),
static_cast<int>(pos));
336 for (
int i = 0; i < 100; ++i)
338 int key =
static_cast<int>(dist(
rng));
339 auto [pos, node] = tree.
position(key);
366 auto [pos, node] = tree.
position(42);
379 auto [pos, node] = tree.
position(42);
390 auto p =
new Node(42);
396 auto selected = tree.
select(0);
399 auto [pos, node] = tree.
position(42);
412 auto p =
new Node(42);
418 auto selected = tree.
select(0);
421 auto [pos, node] = tree.
position(42);
436 auto p1 =
new Node(42);
441 auto p2 =
new Node(42);
455 auto p1 =
new Node(42);
460 auto p2 =
new Node(42);
476 for (
int i = 0; i < 10; ++i)
478 auto p =
new Node(42);
486 for (
size_t i = 0; i < 10; ++i)
498 for (
int i = 0; i < 10; ++i)
500 auto p =
new Node(42);
508 for (
size_t i = 0; i < 10; ++i)
520template <
typename Tree>
523 while (
not tree.is_empty())
524 delete tree.
remove(tree.getRoot()->get_key());
535 for (
int i = 0; i < 50; ++i)
537 for (
int i = 50; i < 100; ++i)
545 t1.join_exclusive(
t2);
552 for (
int i = 0; i < 100; ++i)
554 auto p =
t1.select(i);
566 for (
int i = 0; i < 50; ++i)
583 for (
int i = 0; i < 50; ++i)
600 for (
int i = 0; i < 100; ++i)
615 for (
int i = 0; i < 50; ++i)
619 for (
int i = 0; i < 49; ++i)
633 for (
int i = 0; i < 100; i += 2)
658 for (
int i = 0; i < 100; ++i)
671 for (
int i = 0; i < 30; ++i)
675 for (
int i = 0; i < 70; ++i)
687 for (
int i = 0; i < 50; ++i)
705 for (
int i = 0; i < 50; ++i)
723 for (
int i = 0; i < 50; ++i)
725 for (
int i = 50; i < 100; ++i)
751 for (
int i = 0; i < 50; ++i)
753 for (
int i = 50; i < 100; ++i)
761 t1.join_exclusive(
t2);
767 for (
int i = 0; i < 100; ++i)
769 auto p =
t1.select(i);
781 for (
int i = 0; i < 50; ++i)
798 for (
int i = 0; i < 50; ++i)
815 for (
int i = 0; i < 100; ++i)
829 for (
int i = 0; i < 50; ++i)
832 for (
int i = 0; i < 49; ++i)
845 for (
int i = 0; i < 100; i += 2)
867 for (
int i = 0; i < 100; ++i)
879 for (
int i = 0; i < 30; ++i)
882 for (
int i = 0; i < 70; ++i)
894 for (
int i = 0; i < 50; ++i)
912 for (
int i = 0; i < 50; ++i)
930 for (
int i = 0; i < 50; ++i)
932 for (
int i = 50; i < 100; ++i)
959 for (
int i = 0; i <
N / 2; ++i)
961 for (
int i =
N / 2; i <
N; ++i)
974 t3.join_exclusive(
t4);
987 for (
int i = 0; i <
N / 2; ++i)
989 for (
int i =
N / 2; i <
N; ++i)
1002 t3.join_exclusive(
t4);
1017 for (
int i = 0; i < 50; ++i)
1019 for (
int i = 0; i < 10; ++i)
1021 for (
int i = 51; i < 100; ++i)
1046 for (
int i = 0; i < 50; ++i)
1048 for (
int i = 0; i < 10; ++i)
1050 for (
int i = 51; i < 100; ++i)
1071 ::testing::InitGoogleTest(&
argc,
argv);
TEST_F(AvlRkTest, InsertAndVerify)
void destroy_tree(Tree &tree)
WeightedDigraph::Node Node
Node * insert(Node *p) noexcept
Insert the node pointed by p in the tree.
constexpr Node *& getRoot() noexcept
Return a modifiable reference to tree's root.
Node * select(const size_t i) const
Return the i-th node in order sense.
Node * search_or_insert(Node *p) noexcept
Search or insert a key.
Node * remove(const Key &key) noexcept
Remove from tree the node containing key.
size_t size() const noexcept
Return the number of nodes in the tree.
void join_exclusive(Gen_Avl_Tree_Rk &t) noexcept
Join this tree exclusively with another tree.
constexpr bool is_empty() const noexcept
Return true if tree is empty.
Node * insert_dup(Node *p) noexcept
Insert the node p without testing for key duplicity.
void split_key_dup(const Key &key, Gen_Avl_Tree_Rk &t1, Gen_Avl_Tree_Rk &t2) noexcept
Split tree by key including duplicates.
Node * split_key(const Key &key, Gen_Avl_Tree_Rk &t1, Gen_Avl_Tree_Rk &t2) noexcept
Split tree by key.
void split_pos(const size_t pos, Gen_Avl_Tree_Rk &t1, Gen_Avl_Tree_Rk &t2) noexcept
Split tree by inorder position.
bool verify() const noexcept
Return true if the tree is a valid AVL tree with correct counters.
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...
std::pair< long, Node * > position(const Key &key) const noexcept
Compute the inorder position of a key.
Node * split_key(const Key &key, Gen_Rb_Tree_Rk &t1, Gen_Rb_Tree_Rk &t2) noexcept
Split tree by key.
size_t size() const noexcept
void join_exclusive(Gen_Rb_Tree_Rk &t) noexcept
Join this tree exclusively with another tree.
Node * select(const size_t i) const
Return the i-th node in order sense.
Node * insert_dup(Node *p)
bool is_empty() const noexcept
Node * search(const Key &key)
void split_pos(size_t pos, Gen_Rb_Tree_Rk &t1, Gen_Rb_Tree_Rk &t2) noexcept
Split tree by inorder position.
Node * search_or_insert(Node *p)
void split_key_dup(const Key &key, Gen_Rb_Tree_Rk &t1, Gen_Rb_Tree_Rk &t2) noexcept
Split tree by key including duplicates.
Node *& getRoot() noexcept
Node * remove(const Key &key)
std::pair< long, Node * > position(const Key &key) const noexcept
Compute the inorder position of a key.
QuadTree - Hierarchical spatial index for 2D points.
void remove(const Point &p)
Remove a point from the tree.
Point * insert(Node *&r, const Point &p)
Recursive insert helper.
static constexpr size_t N
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.
void iota(C &container, typename C::Item_Type start)
Fill all elements of a container with unit-step sequential values.
auto shuffle(const C< T > &c)
Randomly shuffle a sequence.
Ranked AVL tree with nodes without a virtual destructor.
Red-Black binary search tree with nodes without virtual destructor and with subtree counters for sele...
AVL tree with rank (order statistics).
Red-Black tree with rank (order statistics).