Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_treapRk.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
50# ifndef TPL_TREAPRK_H
51# define TPL_TREAPRK_H
52
53# include <gsl/gsl_rng.h>
54# include <ahFunction.H>
55# include <tpl_binTreeOps.H>
56# include <ran_array.h>
57# include <treapNode.H>
58# include <ah-errors.H>
59# include <ah-concepts.H>
60
61using namespace Aleph;
62
63namespace Aleph {
64
66{
67 unsigned long priority;
68
69 unsigned long count;
70
71public:
72
74 {
75 /* empty */
76 }
77
82
83 unsigned long & getPriority() noexcept { return priority; }
84
85 unsigned long & getCount() noexcept { return count; }
86
87 void reset() noexcept { count = 1; }
88};
89
91
180 template <template <class> class NodeType, class Key, class Compare>
183{
184public:
185
187
188private:
189
194 Compare cmp;
195
196 void init(unsigned int seed)
197 {
200
201 ah_bad_alloc_if(r == nullptr);
202
204 }
205
206public:
207
209 void set_seed(const unsigned long seed) noexcept { gsl_rng_set(r, seed); }
210
212 Compare & key_comp() noexcept { return cmp; }
213
215 Compare & get_compare() noexcept { return key_comp(); }
216
219 Gen_Treap_Rk(const unsigned long seed, Compare __cmp = Compare())
221 {
222 init(seed);
223 }
224
226 {
227 // empty
228 }
229
231 {
232 if (r != nullptr)
234 }
235
237 void swap(Gen_Treap_Rk & tree) noexcept
238 {
239 std::swap(tree_root, tree.tree_root);
240 std::swap(cmp, tree.cmp);
241 std::swap(r, tree.r);
242 }
243
246
248
255 Node * search(const Key & key) const noexcept
256 {
258 return ret_val == Node::NullPtr ? nullptr : ret_val;
259 }
260
261private:
262
263 bool insert(Node *& root, Node * p) noexcept
264 {
265 if (root == Node::NullPtr)
266 {
267 root = p;
268 return true;
269 }
270
271 const Key & pk = KEY(p);
272 const Key & rk = KEY(root);
273 if (cmp(pk, rk))
274 {
275 if (insert(LLINK(root), p))
276 {
277 ++COUNT(root);
278 if (PRIO(LLINK(root)) < PRIO(root) )
280
281 return true;
282 }
283 }
284 else if (cmp(rk, pk))
285 {
286 if (insert(RLINK(root), p))
287 {
288 ++COUNT(root);
289 if (PRIO(RLINK(root)) < PRIO(root) )
291
292 return true;
293 }
294 }
295
296 return false;
297 }
298
299 // Search or insert p. Return p if KEY(p) is not in the tree;
300 // otherwise, it returns a pointer to a node containing KEY(p)
301 Node * search_or_insert(Node *& root, Node * p) noexcept
302 {
303 if (root == Node::NullPtr)
304 return root = p;
305
306 const Key & pk = KEY(p);
307 const Key & rk = KEY(root);
308 if (cmp(pk, rk))
309 {
311 if (ret == p) // insertion done?
312 { // yes ==> increase counter and perhaps rotate
313 ++COUNT(root);
314 if (PRIO(LLINK(root)) < PRIO(root))
316
318 PRIO(root) <= PRIO(LLINK(root)));
319 }
320
321 return ret;
322 }
323 if (cmp(rk, pk))
324 {
326 if (ret == p) // insertion done?
327 { // yes ==> increase counter and perhaps rotate
328 ++COUNT(root);
329 if (PRIO(RLINK(root)) < PRIO(root))
331
333 PRIO(root) <= PRIO(LLINK(root)));
334 }
335
336 return ret;
337 }
338
340
341 return root;
342 }
343
344 // Return p; root could be modified
345 Node * insert_dup(Node *& root, Node * p) noexcept
346 {
347 if (root == Node::NullPtr)
348 return root = p;
349
350 const Key & pk = KEY(p);
351 const Key & rk = KEY(root);
352 if (cmp(pk, rk))
353 {
354 insert_dup(LLINK(root), p);
355 ++COUNT(root);
356 if (PRIO(LLINK(root)) < PRIO(root))
358 }
359 else
360 {
361 insert_dup(RLINK(root), p);
362 ++COUNT(root);
363 if (PRIO(RLINK(root)) < PRIO(root))
365 }
366
367 return p;
368 }
369
370public:
371
381 Node * insert(Node * p) noexcept
382 {
383 assert(p != Node::NullPtr);
384
385 PRIO(p) = gsl_rng_get(r);
386
387 return insert(tree_root, p) ? p : nullptr;
388 }
389
397 Node * insert_dup(Node * p) noexcept
398 {
399 assert(p != Node::NullPtr);
400
401 PRIO(p) = gsl_rng_get(r);
402
403 return insert_dup(tree_root, p);
404 }
405
418 Node * search_or_insert(Node * p) noexcept
419 {
420 assert(p != Node::NullPtr);
421
422 PRIO(p) = gsl_rng_get(r);
423
424 return search_or_insert(tree_root, p);
425 }
426
428 bool verify() const { return is_treap(tree_root); }
429
430private:
431
432 static Node * join_exclusive(Node * t1, Node * t2) noexcept
433 {
434 if (t1 == Node::NullPtr)
435 return t2;
436
437 if (t2 == Node::NullPtr)
438 return t1;
439
440 if (PRIO(t1) < PRIO(t2))
441 {
442 COUNT(t1) += COUNT(t2);
444 return t1;
445 }
446 COUNT(t2) += COUNT(t1);
448 return t2;
449 }
450
451 Node * remove(Node *& root, const Key & key) noexcept
452 {
453 if (root == Node::NullPtr)
454 return Node::NullPtr;
455
456 Node * ret_val;
457 const Key & rk = KEY(root);
458 if (cmp(key, rk))
459 ret_val = remove(LLINK(root), key);
460 else if (cmp(rk, key))
461 ret_val = remove(RLINK(root), key);
462 else
463 {
464 ret_val = root;
466
467 return ret_val;
468 }
469
470 if (ret_val == Node::NullPtr)
471 return Node::NullPtr;
472
473 --COUNT(root);
474
475 return ret_val;
476 }
477
478public:
479
486 Node * remove(const Key & key) noexcept
487 {
488 Node * ret_val = remove(tree_root, key);
489 if (ret_val == Node::NullPtr)
490 return nullptr;
491
492 ret_val->reset();
493
494 return ret_val;
495 }
496
505 Node * remove(const size_t beg, const size_t end)
506 {
507 ah_range_error_if(beg > end or end > COUNT(tree_root)) << "remove of TreapRk out of range";
508
509 Node * before_beg, * after_end, * aux;
510
512
513 split_pos_rec(ret_val, end + 1, aux, after_end);
515
517
518 return ret_val;
519 }
520
521private:
522
523 static Node * remove_pos(Node *& root, const size_t pos) noexcept
524 {
525 if (pos == COUNT(LLINK(root)))
526 {
527 Node * ret_val = root;
529 return ret_val;
530 }
531
532 --COUNT(root);
533 if (pos < COUNT(LLINK(root)))
534 return remove_pos(LLINK(root), pos);
535 return remove_pos(RLINK(root), pos - COUNT(LLINK(root)) - 1);
536 }
537
538public:
539
547 Node * remove_pos(const size_t pos)
548 {
549 ah_out_of_range_error_if(pos >= COUNT(tree_root)) << "infix position out of range";
550
551 return remove_pos(tree_root, pos);
552 }
553
561 Node * select(const size_t i) const
562 {
563 return Aleph::select(tree_root, i);
564 }
565
567 size_t size() const noexcept { return COUNT(tree_root); }
568
570 bool is_empty() const noexcept { return tree_root == Node::NullPtr; }
571
580 std::pair<int, Node*> position(const Key & key) const noexcept
581 {
582 std::pair<int, Node*> ret_val;
583
585 inorder_position(tree_root, key, ret_val.second);
586
587 return ret_val;
588 }
589
616 std::pair<int, Node*> find_position(const Key & key) const noexcept
617 {
618 std::pair<int, Node*> r(-2, nullptr);
619
621 find_position(tree_root, key, r.second);
622
623 return r;
624 }
625
634 bool split_key(const Key & key, Gen_Treap_Rk & t1, Gen_Treap_Rk & t2) noexcept
635 {
636 return split_key_rec_xt(tree_root, key, t1.getRoot(), t2.getRoot());
637 }
638
649 void
650 split_key_dup(const Key & key, Gen_Treap_Rk & t1, Gen_Treap_Rk & t2) noexcept
651 {
652 split_key_dup_rec_xt(tree_root, key, t1.getRoot(), t2.getRoot());
653 }
654
661 void split_pos(size_t pos, Gen_Treap_Rk & t1, Gen_Treap_Rk & t2)
662 {
663 split_pos_rec(tree_root, pos, t1.getRoot(), t2.getRoot());
664 }
665
666private:
667
668 void join_dup(Node *& t1, Node * t2) noexcept
669 {
670 if (t2 == Node::NullPtr)
671 return;
672
673 Node * l = LLINK(t2), * r = RLINK(t2);
674 t2->reset();
675 insert_dup(t1, t2); // insert_dup modifies t1 by reference
676 join_dup(t1, l);
677 join_dup(t1, r);
678 }
679
680 void join(Node *& t1, Node * t2, Node *& dup) noexcept
681 {
682 if (t2 == Node::NullPtr)
683 return;
684
685 Node * l = LLINK(t2), * r = RLINK(t2);
686 t2->reset();
687 ins:
688 const bool inserted = insert(t1, t2);
689 if (not inserted)
690 {
691 Node * removed = remove(t1, KEY(t2));
692 removed->reset();
693 insert_dup(dup, removed);
694 goto ins;
695 }
696 join(t1, l, dup);
697 join(t1, r, dup);
698 }
699
700public:
701
714 void join(Gen_Treap_Rk & t, Gen_Treap_Rk & dup) noexcept
715 {
716 join(tree_root, t.tree_root, dup.tree_root);
717 t.tree_root = Node::NullPtr;
718 }
719
728 void join_dup(Gen_Treap_Rk & t) noexcept
729 {
730 join_dup(tree_root, t.tree_root);
731 t.tree_root = Node::NullPtr;
732 }
733
745 void join_exclusive(Gen_Treap_Rk & t) noexcept
746 {
747 tree_root = join_exclusive(tree_root, t.tree_root);
748 t.tree_root = Node::NullPtr;
749 }
750
758 {
759 protected:
760
762 mutable Node * curr;
763 mutable int curr_pos;
764
765 static constexpr int Pos_Not_Current = -1;
766 static constexpr int Pos_Empty_Container = -2;
767 static constexpr int Pos_Not_Updated = -3;
768
769 private:
770
772 {
773 return COUNT(tree_ptr->getRoot()) == 0;
774 }
775
777 {
778 return curr_pos != Pos_Not_Updated;
779 }
780
782 {
783 return curr != nullptr;
784 }
785
787 {
788 return pos_updated() and curr_updated();
789 }
790
798
809
810 public:
811
813 : tree_ptr(nullptr), curr(nullptr), curr_pos(Pos_Not_Current)
814 {
815 /* empty */
816 }
817
820 : tree_ptr(&const_cast<Gen_Treap_Rk&>(__tree)), curr(nullptr)
821 {
823 }
824
827 : tree_ptr(&const_cast<Gen_Treap_Rk&>(__tree)),
829 {
830 // empty
831 }
832
834 Iterator(const Gen_Treap_Rk & __tree, const size_t pos) noexcept
835 : tree_ptr(&const_cast<Gen_Treap_Rk&>(__tree)),
836 curr(nullptr), curr_pos(pos)
837 {
838 // empty
839 }
840
842 : tree_ptr(itor.tree_ptr), curr(itor.curr), curr_pos(itor.curr_pos)
843 {
844 // Empty
845 }
846
847 Iterator & operator = (const Iterator & itor) noexcept
848 {
849 if (this == &itor)
850 return *this;
851
852 tree_ptr = itor.tree_ptr;
853 curr = itor.curr;
854 curr_pos = itor.curr_pos;
855
856 return *this;
857 }
858
861 {
862 curr = nullptr;
864 }
865
868 {
869 curr = nullptr;
871 COUNT(tree_ptr->getRoot()) - 1);
872 }
873
876 {
877 put_itor_at_the_end(*this);
878 }
879
887 void reset_to_key(const Key & key) noexcept
888 {
889 std::pair<int, Node*> p = tree_ptr->find_position(key);
890 curr_pos = p.first;
891 }
892
898 void reset_to_node(Node * node) noexcept
899 {
900 curr = node;
901 curr_pos = -2;
902 }
903
905 void reset_to_pos(const size_t pos) noexcept
906 {
907 curr = nullptr;
908 curr_pos = pos;
909 }
910
913 {
914 if (not curr_updated())
915 update_curr();
916
917 return curr;
918 }
919
922 {
923 return get_curr_ne();
924 }
925
934 size_t get_current_position() const
935 {
936 if (not pos_updated())
937 update_pos();
938
939 ah_range_error_if(curr_pos < -1) << "TreapRk iterator has not current";
940
941 ah_range_error_if(curr_pos > COUNT(tree_ptr->getRoot())) << "TreapRk iterator has not current";
942
943 return curr_pos;
944 }
945
947 size_t get_pos() const { return get_current_position(); }
948
951 {
952 if (not pos_updated())
953 update_pos();
954
955 return curr_pos >= 0 and curr_pos < COUNT(tree_ptr->getRoot());
956 }
957
960 void prev()
961 {
962 ah_underflow_error_if(not has_curr()) << "TreapRk iterator has not current";
963
964 --curr_pos;
965 curr = nullptr;
966 }
967
969 {
970 ++curr_pos;
971 curr = nullptr;
972 }
973
976 void next()
977 {
978 ah_underflow_error_if(not has_curr()) << "TreapRk iterator has not current";
979 next_ne();
980 }
981
984 {
985 ah_underflow_error_if(not has_curr()) << "TreapRk iterator has not current";
986
987 if (not curr_updated())
988 update_curr();
989
991
992 curr = nullptr;
993
994 return ret_val;
995 }
996
998 bool operator == (const Iterator & itor) const noexcept
999 {
1000 if (is_container_empty() and itor.is_container_empty())
1001 return true;
1002
1003 if (pos_updated() and itor.pos_updated())
1004 return curr_pos == itor.curr_pos;
1005
1006 if (curr_updated() and itor.curr_updated())
1007 return curr == itor.curr;
1008
1009 if (not pos_updated())
1010 {
1011 update_pos();
1012 return curr_pos == itor.curr_pos;
1013 }
1014
1015 itor.update_pos();
1016
1017 return curr_pos == itor.curr_pos;
1018 }
1019
1021 bool operator != (const Iterator & itor) const
1022 {
1023 return not (*this == itor);
1024 }
1025
1026 bool verify(Gen_Treap_Rk * r) const noexcept
1027 {
1028 return tree_ptr->getRoot() == r->getRoot();
1029 }
1030
1031 bool verify(const Iterator & it) const noexcept
1032 {
1033 return tree_ptr->getRoot() == it.tree_ptr->getRoot();
1034 }
1035 }; // end class Iterator
1036};
1037
1077 template <typename Key, class Compare = Aleph::less<Key>>
1079struct Treap_Rk : public Gen_Treap_Rk<Treap_Rk_Node, Key, Compare>
1080{
1082 using Base::Base;
1083};
1084
1124 template <typename Key, class Compare = Aleph::less<Key>>
1126struct Treap_Rk_Vtl : public Gen_Treap_Rk<Treap_Rk_NodeVtl, Key, Compare>
1127{
1129 using Base::Base;
1130};
1131
1132
1133} // end namespace Aleph
1134
1135# endif // TPL_TREAPRK_H
C++20 concepts for constraining comparison functors.
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
Definition ah-errors.H:579
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
Definition ah-errors.H:368
#define ah_bad_alloc_if(C)
Throws std::bad_alloc if condition holds.
Definition ah-errors.H:429
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
Definition ah-errors.H:207
SentinelCtor
Tag type for sentinel node construction.
Definition ahDefs.H:81
Standard functor implementations and comparison objects.
void put_itor_at_the_end(Itor &it) noexcept
Definition aleph.H:54
@ KEY
Definition btreepic.C:169
Iterator on nodes of the tree.
bool operator==(const Iterator &itor) const noexcept
Return true if this is equal to itor
bool has_curr() const noexcept
Return true if iterator has current node.
static constexpr int Pos_Not_Updated
void update_curr() const noexcept
Node * del()
Remove the current node and move the iterator one position forward.
void reset_to_key(const Key &key) noexcept
Put the iterator to a node according to specific key.
Node * get_curr() const noexcept
void reset_first() noexcept
Reset the iterator to the first position.
Iterator & operator=(const Iterator &itor) noexcept
Iterator(const Gen_Treap_Rk &__tree, const size_t pos) noexcept
Initialize an iterator starting from the iorder position pos
bool curr_updated() const noexcept
bool verify(const Iterator &it) const noexcept
static constexpr int Pos_Empty_Container
bool operator!=(const Iterator &itor) const
Return true if this is not equal to itor
Node * get_curr_ne() const noexcept
Return the current node.
void prev()
Move the iterator one position backward.
void update_pos() const noexcept
Iterator(const Gen_Treap_Rk &__tree) noexcept
Initialize an iterator on __tree
void reset_last() noexcept
Reset the iterator to the last position.
void reset_to_pos(const size_t pos) noexcept
Put the current to the position pos.
bool verify(Gen_Treap_Rk *r) const noexcept
void next()
Move the iterator one position forward.
bool is_container_empty() const noexcept
static constexpr int Pos_Not_Current
void reset_to_node(Node *node) noexcept
Put the current node to a specific node.
Iterator(const Iterator &itor) noexcept
Iterator(const Gen_Treap_Rk &__tree, Node *__curr) noexcept
Initialize an iterator starting from node __curr
size_t get_current_position() const
return the position of current node
bool pos_updated() const noexcept
void end() noexcept
Put the iterator in the end state.
bool is_updated() const noexcept
Extended Treap with rank support for O(log n) indexed access.
Gen_Treap_Rk(Compare __cmp=Compare())
Gen_Treap_Rk(const unsigned long seed, Compare __cmp=Compare())
Initialize a treap with random seed and comparison criteria __cmp
Node head
The type of node.
Node * remove(const Key &key) noexcept
Remove a key from the tree.
void set_seed(const unsigned long seed) noexcept
Set the random number generator seed.
bool split_key(const Key &key, Gen_Treap_Rk &t1, Gen_Treap_Rk &t2) noexcept
Split the tree according to a key.
Node *& getRoot() noexcept
Return the tree's root.
static Node * remove_pos(Node *&root, const size_t pos) noexcept
bool verify() const
Return true if the treap is consistent.
Compare & get_compare() noexcept
Node * insert_dup(Node *&root, Node *p) noexcept
Node * select(const size_t i) const
Return the i-th node in order sense.
Node * insert(Node *p) noexcept
Insert a node in a treap.
void join_exclusive(Gen_Treap_Rk &t) noexcept
Join exclusive of this with t
size_t size() const noexcept
Return the number of nodes contained in the tree.
NodeType< Key > Node
static Node * join_exclusive(Node *t1, Node *t2) noexcept
void join_dup(Node *&t1, Node *t2) noexcept
Node * insert_dup(Node *p) noexcept
Insert a node in the tree.
void split_pos(size_t pos, Gen_Treap_Rk &t1, Gen_Treap_Rk &t2)
Split the tree at the inorder position pos.
Node * remove(const size_t beg, const size_t end)
Remove from the treap all the keys between inorder position beg and end.
Node * search_or_insert(Node *&root, Node *p) noexcept
Node * search(const Key &key) const noexcept
Search a key in a treap.
Node * search_or_insert(Node *p) noexcept
Search or insert a key.
void join(Node *&t1, Node *t2, Node *&dup) noexcept
void init(unsigned int seed)
Node * remove_pos(const size_t pos)
Remove the node at the inorder position pos.
std::pair< int, Node * > find_position(const Key &key) const noexcept
Find the inorder position of a key in the tree.
Node * remove(Node *&root, const Key &key) noexcept
Node * getRoot() const noexcept
Compare & key_comp() noexcept
return the comparison criteria
void swap(Gen_Treap_Rk &tree) noexcept
Swap in constant time all the nodes of this with tree
void join_dup(Gen_Treap_Rk &t) noexcept
Join this with t independently of the presence of duplicated keys.
void join(Gen_Treap_Rk &t, Gen_Treap_Rk &dup) noexcept
Join this with t filtering the duplicated keys.
bool is_empty() const noexcept
Return true if tree is empty.
bool insert(Node *&root, Node *p) noexcept
void split_key_dup(const Key &key, Gen_Treap_Rk &t1, Gen_Treap_Rk &t2) noexcept
Split the tree according to a key that could be in the tree.
void reset() noexcept
Definition tpl_treapRk.H:87
TreapRkNode_Data() noexcept
Definition tpl_treapRk.H:73
unsigned long priority
Definition tpl_treapRk.H:67
unsigned long & getPriority() noexcept
Definition tpl_treapRk.H:83
unsigned long & getCount() noexcept
Definition tpl_treapRk.H:85
TreapRkNode_Data(SentinelCtor) noexcept
Definition tpl_treapRk.H:78
Strict weak ordering constraint for BST comparators.
Definition ah-concepts.H:84
__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)
Definition gmpfrxx.h:4060
long inorder_position(Node *r, const typename Node::key_type &key, Node *&p, Compare &cmp) noexcept
Compute the inorder position of a key.
void split_pos_rec(Node *&r, const size_t i, Node *&ts, Node *&tg)
Split a extended binary tree according to a position.
std::pair< int, Node * > position(const Key &key) const noexcept
Compute the inorder position of a key.
#define DECLARE_BINNODE_SENTINEL(Name, height, Control_Data)
Specify tree node for a binary tree.
auto & COUNT(Node *p) noexcept
Return the number of nodes of the tree fron p is root.
Node * rotate_to_left_xt(Node *p) noexcept
Rotate to left the extended binary tree with root p.
bool split_key_rec_xt(Node *&root, const typename Node::key_type &key, Node *&l, Node *&r, Compare &cmp) noexcept
Split an extended binary search tree according to a key.
Node * select(Node *r, const size_t pos)
Iterative selection of a node according to inorder position.
Node * searchInBinTree(Node *root, const typename Node::key_type &key, const Compare &cmp=Compare()) noexcept
Search a key in a binary search tree.
unsigned long & PRIO(Node *p) noexcept
Access the priority of a treap node.
Definition treapNode.H:120
Node * rotate_to_right_xt(Node *p) noexcept
Rotate to right the extended bianry tree with root p
void split_key_dup_rec_xt(Node *&root, const typename Node::key_type &key, Node *&l, Node *&r, Compare &cmp) noexcept
Split an extended binary search tree according to a key which can be in the tree.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
and
Check uniqueness with explicit hash + equality functors.
bool is_treap(Node *root) noexcept
Validate that a tree satisfies treap (heap) property.
Definition treapNode.H:144
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.
const long Max_Priority
Maximum priority value (used for sentinel/leaves)
Definition treapNode.H:75
const long Min_Priority
Minimum priority value.
Definition treapNode.H:78
static std::atomic< bool > init
Definition hash-fct.C:53
Extended treap (a special type of randomized binary search tree) which manages selection and splittin...
Extended treap (a special type of randomized binary search tree) which manages selection and splittin...
#define RLINK(i, n)
#define LLINK(i, n)
ValueArg< size_t > seed
Definition testHash.C:48
Binary tree operations (split, join, rotate).
Treap node definition with BST key and heap priority.
DynList< int > l