Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_rand_tree.H
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
31
48# ifndef TPL_RAND_TREE_H
49# define TPL_RAND_TREE_H
50
51# include <ctime>
52# include <climits>
53# include <type_traits>
54# include <utility>
55# include <ah-random.H>
56# include <ahUtils.H>
57# include <ahFunction.H>
58# include <tpl_randNode.H>
59# include <tpl_binTreeOps.H>
60# include <ah-errors.H>
61# include <ah-concepts.H>
62
63using namespace Aleph;
64
65namespace Aleph
66{
159 template <template <typename> class NodeType, typename Key, class Compare>
160 requires StrictWeakOrder<Compare, Key>
162 {
163 public:
164 using Node = NodeType<Key>;
165
166 private:
169 Compare cmp;
170
171 // The insertions and the removal compare on the way down, the split of
172 // an insertion at the root included, and link or count on the way
173 // back, so a comparison that throws leaves the tree as it was
175 noexcept(nothrow_compare_copy_v<Compare, Key>)
176 {
177 if (root == Node::NullPtr)
178 return p;
179
180 // Prefetch children to reduce memory latency
181 __builtin_prefetch(LLINK(root));
182 __builtin_prefetch(RLINK(root));
183
184 const size_t n = COUNT(root); // a long has 32 bits on Windows
185 if (const size_t rn = r.uniform_int_ne(n + 1); rn == n) [[unlikely]]
187
188 Node *result;
189 const Key & pk = KEY(p);
190 const Key & rk = KEY(root);
191 if (cmp(pk, rk)) // KEY(p) < KEY(root)
192 {
193 result = random_insert(LLINK(root), p);
194 if (result != Node::NullPtr) // p was inserted
195 {
196 LLINK(root) = result;
197 ++COUNT(root);
198 return root;
199 }
200 }
201 else if (cmp(rk, pk)) // KEY(p) > KEY(root)
202 {
203 result = random_insert(RLINK(root), p);
204 if (result != Node::NullPtr) // p was inserted
205 {
206 RLINK(root) = result;
207 ++COUNT(root);
208 return root;
209 }
210 }
211
212 return Node::NullPtr; // duplicated key ==> no insertion
213 }
214
216 noexcept(nothrow_compare_copy_v<Compare, Key>)
217 {
218 if (root == Node::NullPtr)
219 return p;
220
221 // Prefetch children to reduce memory latency
222 __builtin_prefetch(LLINK(root));
223 __builtin_prefetch(RLINK(root));
224
225 const size_t n = COUNT(root); // a long has 32 bits on Windows
226 if (const size_t rn = r.uniform_int_ne(n + 1); rn == n) [[unlikely]]
228
229 const Key & pk = KEY(p);
230 const Key & rk = KEY(root);
231 if (cmp(pk, rk)) // KEY(p) < KEY(root)
233 else
235
236 ++COUNT(root);
237
238 return root;
239 }
240
242 noexcept(nothrow_compare_copy_v<Compare, Key>)
243 {
244 if (root == Node::NullPtr)
245 return root = p;
246
247 // Prefetch children to reduce memory latency
248 if (LLINK(root) != Node::NullPtr)
249 __builtin_prefetch(LLINK(root));
250 if (RLINK(root) != Node::NullPtr)
251 __builtin_prefetch(RLINK(root));
252
253 const size_t n = COUNT(root); // a long has 32 bits on Windows
254 if (const size_t rn = r.uniform_int_ne(n + 1); rn == n) [[unlikely]]
255 {
256 if (BinTreeXt_Operation<Node, Compare>(cmp).insert_root(root, p) != Node::NullPtr)
257 return p;
258
259 return searchInBinTree<Node, Compare>(root, KEY(p), cmp);
260 }
261
262 const Key & pk = KEY(p);
263 const Key & rk = KEY(root);
264 if (cmp(pk, rk))
265 {
267 if (ret == p)
268 ++COUNT(root);
269
270 return ret;
271 }
272 if (cmp(rk, pk))
273 {
275 if (ret == p)
276 ++COUNT(root);
277
278 return ret;
279 }
280
281 return root; // key == root: found existing
282 }
283
284 public:
285 Gen_Rand_Tree(const Gen_Rand_Tree &) = delete;
286
288
289 private:
290 // The seed of the generator, modulo 2^32 - 1, as it was taken for GSL
291 static unsigned long generator_seed(const unsigned long seed) noexcept
292 {
293 return seed % static_cast<unsigned long>(Gsl_Compatible_Rng::max());
294 }
295
296 public:
298 Compare &key_comp() noexcept { return cmp; }
299
301 const Compare &key_comp() const noexcept { return cmp; }
302
304 Compare &get_compare() noexcept { return key_comp(); }
305
307 const Compare &get_compare() const noexcept { return cmp; }
308
311 [[nodiscard]] Random_Source & random_source() noexcept { return r; }
312
315 [[nodiscard]] const Random_Source & random_source() const noexcept { return r; }
316
326 [[deprecated("it makes a Mersenne Twister in a tree that has none: "
327 "use random_source(); it goes in 8.0.0")]]
328 [[nodiscard]] Gsl_Compatible_Rng & rng() { return r.mersenne_twister(); }
329
330# if ALEPH_WITH_GSL
339 [[deprecated("the generator is no longer of GSL: use random_source(); it goes in 8.0.0")]]
340 gsl_rng * gsl_rng_object() { return r.gsl(); }
341# endif
342
352 void set_seed(const unsigned long seed)
353 {
355 }
356
366 Gen_Rand_Tree(const unsigned int seed, const Compare & __cmp = Compare())
367 : tree_root(Node::NullPtr),
368 r(Random_Source::Engine::Mersenne_Twister, generator_seed(seed)), cmp(__cmp)
369 {
370 // empty
371 }
372
387 noexcept(std::is_nothrow_default_constructible_v<Compare> and
388 std::is_nothrow_copy_constructible_v<Compare>)
389 : Gen_Rand_Tree(Compare())
390 {
391 // empty
392 }
393
402 Gen_Rand_Tree(const Compare & cmp)
403 noexcept(std::is_nothrow_copy_constructible_v<Compare>)
404 : tree_root(Node::NullPtr), cmp(cmp)
405 {
406 // empty
407 }
408
416 void swap(Gen_Rand_Tree & tree) noexcept(std::is_nothrow_swappable_v<Compare>)
417 {
418 // the swap that the specification evaluates: that of Compare found by
419 // its arguments, else std::swap(); first, since it may throw
420 using std::swap;
421 swap(cmp, tree.cmp);
422 std::swap(tree_root, tree.tree_root);
423 r.swap(tree.r);
424 }
425
435 noexcept(std::is_nothrow_copy_constructible_v<Compare>)
436 : Gen_Rand_Tree(other.cmp)
437 {
438 // the comparison criterion is already a copy of that of other, which
439 // keeps its own: exchanging it again would need its move assignment
440 std::swap(tree_root, other.tree_root);
441 r.swap(other.r);
442 }
443
456 Gen_Rand_Tree &operator =(Gen_Rand_Tree && other) noexcept(noexcept(swap(other)))
457 {
458 swap(other);
459 return *this;
460 }
461
462 virtual ~Gen_Rand_Tree() noexcept
463 {
464 // Note: nodes are NOT freed here. DynSetTree::empty() handles node deletion.
465 // The underlying tree only manages the tree structure, not node memory.
466 }
467
480 Node * insert(Node *p) noexcept(nothrow_compare_copy_v<Compare, Key>)
481 {
482 assert(p != Node::NullPtr);
483 assert((LLINK(p) == Node::NullPtr) and (RLINK(p) == Node::NullPtr));
484 assert(COUNT(p) == 1);
485
486 Node *result = random_insert(tree_root, p);
487 if (result == Node::NullPtr)
488 return nullptr;
489
490 tree_root = result; // the new root, which is p only now and then
491
492 return p;
493 }
494
508 Node * insert_dup(Node *p) noexcept(nothrow_compare_copy_v<Compare, Key>)
509 {
510 assert(p != Node::NullPtr);
511 assert((LLINK(p) == Node::NullPtr) and (RLINK(p) == Node::NullPtr));
512 assert(COUNT(p) == 1);
513
515
516 return p;
517 }
518
519 private:
520 Node * random_join_exclusive(Node *tl, Node *tr) noexcept
521 {
522 if (tl == Node::NullPtr)
523 return tr;
524
525 if (tr == Node::NullPtr)
526 return tl;
527
528 const size_t & m = COUNT(tl);
529 const size_t & n = COUNT(tr);
530 if (const size_t rn = 1 + r.uniform_int_ne(m + n); rn <= m)
531 { // left subtree wins
532 COUNT(tl) += COUNT(tr);
533 RLINK(tl) = random_join_exclusive(RLINK(tl), tr);
534 return tl;
535 }
536 COUNT(tr) += COUNT(tl);
537 LLINK(tr) = random_join_exclusive(tl, LLINK(tr));
538 return tr;
539 }
540
541 Node * random_remove(Node *& root, const Key & key)
542 noexcept(nothrow_compare_v<Compare, Key>)
543 {
544 if (root == Node::NullPtr)
545 return Node::NullPtr;
546
547 Node *ret_val;
548 const Key & rk = KEY(root);
549 if (cmp(key, rk))
550 {
551 ret_val = random_remove(LLINK(root), key);
552 if (ret_val != Node::NullPtr)
553 --COUNT(root);
554
555 return ret_val;
556 }
557 if (cmp(rk, key))
558 {
559 ret_val = random_remove(RLINK(root), key);
560 if (ret_val != Node::NullPtr)
561 --COUNT(root);
562
563 return ret_val;
564 }
565
566 // key was found
567 ret_val = root;
569 ret_val->reset();
570
571 return ret_val;
572 }
573
574 public:
585 Node * remove(const Key & key) noexcept(nothrow_compare_v<Compare, Key>)
586 {
587 Node *ret_val = random_remove(tree_root, key);
588
589 return ret_val != Node::NullPtr ? ret_val : nullptr;
590 }
591
602 Node * search(const Key & key) const noexcept(nothrow_compare_v<Compare, Key>)
603 {
604 Node *retVal = searchInBinTree<Node, Compare>(tree_root, key, cmp);
605 return retVal == Node::NullPtr ? nullptr : retVal;
606 }
607
627 noexcept(nothrow_compare_copy_v<Compare, Key>)
628 {
629 assert(p != Node::NullPtr);
630 assert(COUNT(p) == 1);
631
633 }
634
636 [[nodiscard]] bool verify() const
637 {
639 }
640
642 Node *&getRoot() noexcept { return tree_root; }
643
651 Node * select(const size_t i) const
652 {
653 return Aleph::select(tree_root, i);
654 }
655
657 [[nodiscard]] size_t size() const noexcept { return COUNT(tree_root); }
658
660 [[nodiscard]] bool is_empty() const noexcept { return tree_root == Node::NullPtr; }
661
675 std::pair<long, Node *> position(const Key & key) const
676 noexcept(nothrow_compare_copy_v<Compare, Key>)
677 {
678 std::pair<long, Node *> ret_val;
680 inorder_position(tree_root, key, ret_val.second);
681
682 return ret_val;
683 }
684
715 std::pair<long, Node *> find_position(const Key & key) const
716 noexcept(nothrow_compare_copy_v<Compare, Key>)
717 {
718 std::pair<long, Node *> r(-2, nullptr);
719
721 find_position(tree_root, key, r.second);
722
723 return r;
724 }
725
726 private:
727 Node * remove_pos(Node *& root, const size_t pos) noexcept
728 {
729 if (pos == COUNT(LLINK(root)))
730 {
731 Node *ret_val = root;
732 root = random_join_exclusive(LLINK(ret_val), RLINK(ret_val));
733 return ret_val;
734 }
735
736 --COUNT(root);
737 if (pos < COUNT(LLINK(root)))
738 return remove_pos(LLINK(root), pos);
739 else
740 return remove_pos(RLINK(root), pos - COUNT(LLINK(root)) - 1);
741 }
742
743 public:
751 Node * remove_pos(const size_t i)
752 {
753 ah_out_of_range_error_if(i >= COUNT(tree_root)) << "infix position out of range";
754
755 return remove_pos(tree_root, i);
756 }
757
772 bool split_key(const Key & key, Gen_Rand_Tree & t1, Gen_Rand_Tree & t2)
773 noexcept(nothrow_compare_v<Compare, Key>)
774 {
775 return split_key_rec_xt(tree_root, key, t1.getRoot(), t2.getRoot(), cmp);
776 }
777
793 void split_key_dup(const Key & key, Gen_Rand_Tree & t1, Gen_Rand_Tree & t2)
794 noexcept(nothrow_compare_v<Compare, Key>)
795 {
796 split_key_dup_rec_xt(tree_root, key, t1.getRoot(), t2.getRoot(), cmp);
797 }
798
814 void split_pos(size_t pos, Gen_Rand_Tree & t1, Gen_Rand_Tree & t2)
815 {
816 split_pos_rec(tree_root, pos, t1.getRoot(), t2.getRoot());
817 }
818
819 private:
820 Node * random_join(Node *t1, Node *t2, Node *& dup)
821 {
822 if (t1 == Node::NullPtr)
823 return t2;
824
825 if (t2 == Node::NullPtr)
826 return t1;
827
828 Node *ret = Node::NullPtr;
829 const size_t m = COUNT(t1);
830 const size_t n = COUNT(t2);
831 if (const size_t rn = 1 + r.uniform_int_ne(m + n); rn <= m)
832 { // root of t1 wins
833 Node *l = LLINK(t1), *r = RLINK(t1);
834 t1->reset();
835 t1_wins:
836 ret = insert_root_xt(t2, t1, cmp);
837 if (ret != Node::NullPtr)
838 {
839 LLINK(ret) = random_join(LLINK(ret), l, dup);
840 RLINK(ret) = random_join(RLINK(ret), r, dup);
841 COUNT(ret) = COUNT(LLINK(ret)) + 1 + COUNT(RLINK(ret));
842 }
843 else
844 {
845 dup = random_insert_dup(dup, random_remove(t2, KEY(t1)));
846 goto t1_wins;
847 }
848 }
849 else
850 { // root of t2 wins
851 Node *l = LLINK(t2), *r = RLINK(t2);
852 t2->reset();
853 t2_wins:
854 ret = insert_root_xt(t1, t2, cmp);
855 if (ret != Node::NullPtr)
856 {
857 LLINK(ret) = random_join(l, LLINK(ret), dup);
858 RLINK(ret) = random_join(r, RLINK(ret), dup);
859 COUNT(ret) = COUNT(LLINK(ret)) + 1 + COUNT(RLINK(ret));
860 }
861 else
862 {
863 dup = random_insert_dup(dup, random_remove(t1, KEY(t2)));
864 goto t2_wins;
865 }
866 }
867
868 return ret;
869 }
870
872 {
873 if (t1 == Node::NullPtr)
874 return t2;
875
876 if (t2 == Node::NullPtr)
877 return t1;
878
879 Node *ret = Node::NullPtr;
880 const size_t & m = COUNT(t1);
881 const size_t & n = COUNT(t2);
882 const size_t total = m + n;
883 if (const size_t rn = 1 + r.uniform_int_ne(total); rn <= m)
884 { // root of t1 wins
885 Node *l = LLINK(t1), *r = RLINK(t1);
886 t1->reset();
887 ret = insert_dup_root_xt(t2, t1, cmp);
888 LLINK(ret) = random_join(LLINK(ret), l);
889 RLINK(ret) = random_join(RLINK(ret), r);
890 }
891 else
892 { // root of t2 wins
893 Node *l = LLINK(t2), *r = RLINK(t2);
894 t2->reset();
895 ret = insert_dup_root_xt(t1, t2, cmp);
896 LLINK(ret) = random_join(l, LLINK(ret));
897 RLINK(ret) = random_join(r, RLINK(ret));
898 }
899
900 COUNT(ret) = total;
901 return ret;
902 }
903
904 public:
922 void join(Gen_Rand_Tree & t, Gen_Rand_Tree & dup) noexcept
923 {
924 tree_root = random_join(tree_root, t.tree_root, dup.tree_root);
925 t.tree_root = Node::NullPtr;
926 }
927
942 void join_dup(Gen_Rand_Tree & t) noexcept
943 {
944 tree_root = random_join(tree_root, t.tree_root);
945 t.tree_root = Node::NullPtr;
946 }
947
959 void join_exclusive(Gen_Rand_Tree & t) noexcept
960 {
962 t.tree_root = Node::NullPtr;
963 }
964
971 struct Iterator : public BinNodeInfixIterator<Node>
972 {
974 };
975 };
976
1012 template <typename Key, class Compare = Aleph::less<Key>>
1013 requires StrictWeakOrder<Compare, Key>
1014 struct Rand_Tree : public Gen_Rand_Tree<RandNode, Key, Compare>
1015 {
1017 using Base::Base;
1018 };
1019
1020
1051 template <typename Key, class Compare = Aleph::less<Key>>
1053 struct Rand_Tree_Vtl : public Gen_Rand_Tree<RandNodeVtl, Key, Compare>
1054 {
1056 using Base::Base;
1057 };
1058} // end namespace Aleph
1059
1060# endif // TPL_RAND_TREE_H
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
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:727
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
Standard functor implementations and comparison objects.
General utility functions and helpers.
@ KEY
Definition btreepic.C:169
Inorder iterator on the nodes of a binary tree.
Functor encompassing basic operation for extended binary search trees.
Node * insert_dup_root(Node *&root, Node *p) noexcept(nothrow_compare_v< Cmp, Key >)
Insert a node as root of an extended binary search tree.
Randomized binary search tree with rank support.
bool is_empty() const noexcept
Return true if the tree is empty.
Gen_Rand_Tree(const unsigned int seed, const Compare &__cmp=Compare())
Builds an empty random tree whose positions are those of GSL for seed: it draws them from a Mersenne ...
Node * remove(const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
Remove a key from the tree.
bool verify() const
Return true if this is a consistent randomized tree.
Node * insert_dup(Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >)
Insert a node in the tree.
const Compare & key_comp() const noexcept
Gsl_Compatible_Rng & rng()
The Mersenne Twister of the tree, which a tree that was given no seed makes here, and draws from it f...
void split_key_dup(const Key &key, Gen_Rand_Tree &t1, Gen_Rand_Tree &t2) noexcept(nothrow_compare_v< Compare, Key >)
Split the tree according to a key that could be in the tree.
const Random_Source & random_source() const noexcept
The source of random numbers, to look at it: its engine, or whether it is equal to another one.
Node * search_or_insert(Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >)
Search or insert a key.
NodeType< Key > Node
Node * random_insert_dup(Node *root, Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >)
Compare & key_comp() noexcept
return the comparison criteria
virtual ~Gen_Rand_Tree() noexcept
bool split_key(const Key &key, Gen_Rand_Tree &t1, Gen_Rand_Tree &t2) noexcept(nothrow_compare_v< Compare, Key >)
Split the tree according to a key.
Compare & get_compare() noexcept
See key_comp().
Gen_Rand_Tree(Gen_Rand_Tree &&other) noexcept(std::is_nothrow_copy_constructible_v< Compare >)
Take the nodes, the generator and the comparison criterion of another tree, which is left empty,...
Random_Source & random_source() noexcept
The source of random numbers, which draws the positions of the nodes.
Gen_Rand_Tree(const Compare &cmp) noexcept(std::is_nothrow_copy_constructible_v< Compare >)
Builds an empty random tree with the comparison criteria cmp, which draws its positions from a SplitM...
void join_exclusive(Gen_Rand_Tree &t) noexcept
Join exclusive of this with t
size_t size() const noexcept
Return the number of nodes that have the tree.
Node * select(const size_t i) const
Return the i-th node in inorder sense.
void swap(Gen_Rand_Tree &tree) noexcept(std::is_nothrow_swappable_v< Compare >)
Swap in constant time all the nodes of this with tree.
Node * remove_pos(const size_t i)
Remove the key at inorder position i
Gen_Rand_Tree(const Gen_Rand_Tree &)=delete
std::pair< long, Node * > find_position(const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >)
Find the inorder position of a key in the tree.
const Compare & get_compare() const noexcept
void join_dup(Gen_Rand_Tree &t) noexcept
Join this with t independently of the presence of duplicated keys.
Node * random_insert(Node *root, Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >)
Node * random_remove(Node *&root, const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
Node * random_join(Node *t1, Node *t2)
Node *& getRoot() noexcept
Return the tree's root.
void join(Gen_Rand_Tree &t, Gen_Rand_Tree &dup) noexcept
Join this with t filtering the duplicated keys.
void set_seed(const unsigned long seed)
Seeds the Mersenne Twister of the tree, modulo 2^32 - 1: the positions are from then on those of GSL ...
Node * search(const Key &key) const noexcept(nothrow_compare_v< Compare, Key >)
Search a key.
Node * random_join(Node *t1, Node *t2, Node *&dup)
void split_pos(size_t pos, Gen_Rand_Tree &t1, Gen_Rand_Tree &t2)
Split a extended binary tree according to a position.
Node * random_join_exclusive(Node *tl, Node *tr) noexcept
Node * insert(Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >)
Insert a node in the tree.
Node * remove_pos(Node *&root, const size_t pos) noexcept
static unsigned long generator_seed(const unsigned long seed) noexcept
Gen_Rand_Tree() noexcept(std::is_nothrow_default_constructible_v< Compare > and std::is_nothrow_copy_constructible_v< Compare >)
Builds an empty random tree with a comparison criteria built by default, which draws its positions fr...
Node * random_search_or_insert(Node *&root, Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >)
Node * tree_root
The type of node.
Gen_Rand_Tree & operator=(const Gen_Rand_Tree &)=delete
A random number generator with the sequences of GSL's gsl_rng_mt19937.
Definition ah-random.H:147
static constexpr result_type max() noexcept
The greatest number of operator()(): 2^32 - 1.
Definition ah-random.H:259
The source of random numbers of a randomized structure, which draws from one of two generators.
Definition ah-random.H:883
@ Mersenne_Twister
A Gsl_Compatible_Rng, in dynamic memory.
Gsl_Compatible_Rng & mersenne_twister()
The Mersenne Twister of the source, which is its engine from now on.
Definition ah-random.H:1087
void seed(const std::uint64_t s) noexcept
Draws from now on from the SplitMix64 of a seed.
Definition ah-random.H:1040
void swap(Random_Source &o) noexcept
Swaps the generators, with their states.
Definition ah-random.H:1021
std::uint64_t uniform_int_ne(const std::uint64_t n) noexcept
An integer in [0, n), each with the same probability, without checking n.
Definition ah-random.H:1147
Strict weak ordering constraint for BST comparators.
__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:4138
std::pair< long, Node * > position(const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >)
Compute the inorder position of a key.
Node * insert_dup_root_xt(Node *&root, Node *p, Compare &cmp) noexcept
Insert a node as root of an extended binary search tree.
bool split_key_rec_xt(Node *&root, const typename Node::key_type &key, Node *&l, Node *&r, Compare &cmp) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
Split an extended binary search tree according to a key.
bool check_rank_tree(Node *root) noexcept
Return true if root is a valid extended binary tree.
void split_pos_rec(Node *&r, const size_t i, Node *&ts, Node *&tg)
Split a extended binary tree according to a position.
bool check_bst(Node *p, const Compare &cmp=Compare())
Return true if p is a binary search tree.
auto & COUNT(Node *p) noexcept
Return the number of nodes of the tree fron p is root.
void split_key_dup_rec_xt(Node *&root, const typename Node::key_type &key, Node *&l, Node *&r, Compare &cmp) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
Split an extended binary search tree according to a key which can be in the tree.
Node * insert_root_xt(Node *&root, Node *p, Compare &cmp) noexcept
Insert a node p as root of an extended binary search tree.
long inorder_position(Node *r, const typename Node::key_type &key, Node *&p, Compare &cmp) noexcept(nothrow_compare_v< Compare, typename Node::key_type >)
Compute the inorder position of a key.
Node * insert_root(Node *&root, Node *p) noexcept(nothrow_compare_v< Cmp, Key >)
Insert a node p as root of an extended binary search tree.
Node * select(Node *r, const size_t pos)
Iterative selection of a node according to inorder position.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
STL namespace.
Iterator on nodes of the tree.
Randomized binary search tree.
Randomized binary search tree.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
#define RLINK(i, n)
#define LLINK(i, n)
ValueArg< size_t > seed
Definition testHash.C:53
Binary tree operations (split, join, rotate).
Randomized tree node.
DynList< int > l