Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_dynSkipList.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
68# ifndef TPL_DYNSKIPLIST_H
69# define TPL_DYNSKIPLIST_H
70
71# include <climits>
72# include <ctime>
73# include <type_traits>
74# include <utility>
75# include <initializer_list>
76# include <ah-random.H>
77# include <ah-errors.H>
78# include <ah-args-ctor.H>
79# include <ahDry.H>
80# include <ahFunctional.H>
81# include <ahIterator.H>
82# include <ah-iterator.H>
83# include <ah-dry.H>
84
85namespace Aleph {
86
121template <typename Key, class Compare = std::less<Key>>
123 : public GenericTraverse<DynSkipList<Key, Compare>>,
124 public SpecialCtors<DynSkipList<Key, Compare>, Key>,
125 public LocateFunctions<DynSkipList<Key, Compare>, Key>,
126 public FunctionalMethods<DynSkipList<Key, Compare>, Key>,
127 public GenericItems<DynSkipList<Key, Compare>, Key>,
128 public StlAlephIterator<DynSkipList<Key, Compare>>
129{
130public:
131
134
136 using Item_Type = Key;
137
139 using Key_Type = Key;
140
142 static constexpr int maxLevel = 32;
143
145 static constexpr double defaultProbability = 0.5;
146
147private:
148
150 struct Node
151 {
152 Key key;
153 int level;
155
156 Node(const Key & k, int lvl) : key(k), level(lvl)
157 {
158 forward = new Node*[lvl];
159 for (int i = 0; i < lvl; ++i)
160 forward[i] = nullptr;
161 }
162
163 Node(Key && k, int lvl) : key(std::move(k)), level(lvl)
164 {
165 forward = new Node*[lvl];
166 for (int i = 0; i < lvl; ++i)
167 forward[i] = nullptr;
168 }
169
170 // Dummy header node constructor
171 explicit Node(int lvl) : level(lvl)
172 {
173 forward = new Node*[lvl];
174 for (int i = 0; i < lvl; ++i)
175 forward[i] = nullptr;
176 }
177
179 {
180 delete[] forward;
181 }
182 };
183
185 mutable Random_Source r; // random number generator, drawn from by const members
186 size_t num_nodes = 0;
189 Compare cmp;
190
191 // The seed of the generator, modulo 2^32 - 1, as it was taken for GSL
192 static unsigned long generator_seed(const unsigned long seed) noexcept
193 {
194 return seed % static_cast<unsigned long>(Gsl_Compatible_Rng::max());
195 }
196
197 int random_level() const noexcept
198 {
199 int lvl = 1;
200 while (r.uniform() < probability and lvl < maxLevel)
201 ++lvl;
202 return lvl;
203 }
204
205 // Check if two keys are equal using the comparator
206 bool keys_equal(const Key & k1, const Key & k2) const noexcept
207 {
208 return not cmp(k1, k2) and not cmp(k2, k1);
209 }
210
211 // An empty list of probability p, whose comparison is a copy of c: the
212 // one that a move builds, without a copy assignment of the comparison.
213 // Its generator is not seeded
214 DynSkipList(const double p, const Compare & c)
215 : probability(p), cmp(c)
216 {
217 header = new Node(maxLevel);
218 }
219
220 // The same, with c moved: for a comparison that cannot be copied
221 DynSkipList(const double p, Compare && c)
222 : probability(p), cmp(std::move(c))
223 {
224 header = new Node(maxLevel);
225 }
226
227 // What a move takes of the comparison c: c to copy, if it can be copied,
228 // so that the source keeps its own; else c to move
229 static decltype(auto) comparison_to_take(Compare & c) noexcept
230 {
231 if constexpr (std::is_copy_constructible_v<Compare>)
232 return static_cast<const Compare &>(c);
233 else
234 return std::move(c);
235 }
236
237 // Exchanges with other all but the comparison
238 void swap_but_comparison(DynSkipList & other) noexcept
239 {
240 std::swap(header, other.header);
241 r.swap(other.r);
242 std::swap(num_nodes, other.num_nodes);
243 std::swap(current_level, other.current_level);
244 std::swap(probability, other.probability);
245 }
246
247public:
248
258 void set_seed(unsigned long seed)
259 {
261 }
262
264 [[nodiscard]] Random_Source & random_source() noexcept { return r; }
265
268 [[nodiscard]] const Random_Source & random_source() const noexcept { return r; }
269
279 [[deprecated("it makes a Mersenne Twister in a list that has none: "
280 "use random_source(); it goes in 8.0.0")]]
281 [[nodiscard]] Gsl_Compatible_Rng & rng() { return r.mersenne_twister(); }
282
283# if ALEPH_WITH_GSL
292 [[deprecated("the generator is no longer of GSL: use random_source(); it goes in 8.0.0")]]
293 gsl_rng * gsl_rng_object() { return r.gsl(); }
294# endif
295
308 DynSkipList(unsigned long seed, double p = defaultProbability)
309 : r(Random_Source::Engine::Mersenne_Twister, generator_seed(seed)), probability(p)
310 {
311 ah_domain_error_if(not (p > 0.0 and p < 1.0))
312 << "DynSkipList: probability " << p << " is not in (0, 1)";
313 header = new Node(maxLevel);
314 }
315
324 explicit DynSkipList(double p = defaultProbability)
325 : probability(p)
326 {
327 ah_domain_error_if(not (p > 0.0 and p < 1.0))
328 << "DynSkipList: probability " << p << " is not in (0, 1)";
329 header = new Node(maxLevel);
330 }
331
333
342 : GenericTraverse<DynSkipList<Key, Compare>>(),
343 SpecialCtors<DynSkipList<Key, Compare>, Key>(),
344 LocateFunctions<DynSkipList<Key, Compare>, Key>(),
345 FunctionalMethods<DynSkipList<Key, Compare>, Key>(),
346 GenericItems<DynSkipList<Key, Compare>, Key>(),
347 StlAlephIterator<DynSkipList<Key, Compare>>(),
348 probability(other.probability), cmp(other.cmp) // and a generator of its own
349 {
350 header = new Node(maxLevel);
351 try
352 {
353 for (auto it = other.begin(); it.has_curr(); it.next())
354 insert(it.get_curr());
355 }
356 catch (...)
357 {
358 // the copy is not built and its destructor does not run: what it
359 // took is freed here
360 empty();
361 delete header;
362 throw;
363 }
364 }
365
384 {
385 // the comparison is already taken from other: exchanging it again would
386 // need its move assignment
387 swap_but_comparison(other);
388 }
389
392 {
393 empty();
394 delete header;
395 }
396
399 {
400 if (this == &other)
401 return *this;
402
403 empty();
404 probability = other.probability;
405 cmp = other.cmp;
406 // Keep our own random number generator
407
408 for (auto it = other.begin(); it.has_curr(); it.next())
409 insert(it.get_curr());
410
411 return *this;
412 }
413
428 DynSkipList & operator=(DynSkipList && other) noexcept(noexcept(swap(other)))
429 {
430 if (this == &other)
431 return *this;
432
433 empty();
434 swap(other);
435 return *this;
436 }
437
445 void swap(DynSkipList & other) noexcept(std::is_nothrow_swappable_v<Compare>)
446 {
447 // the swap that the specification evaluates: that of Compare found by
448 // its arguments, else std::swap(); first, since it may throw
449 using std::swap;
450 swap(cmp, other.cmp);
451 swap_but_comparison(other);
452 }
453
457 void empty() noexcept
458 {
459 Node * curr = header->forward[0];
460 while (curr != nullptr)
461 {
462 Node * next = curr->forward[0];
463 delete curr;
464 curr = next;
465 }
466 for (int i = 0; i < maxLevel; ++i)
467 header->forward[i] = nullptr;
468 num_nodes = 0;
469 current_level = 1;
470 }
471
477 void clear() noexcept { empty(); }
478
480 [[nodiscard]] size_t size() const noexcept { return num_nodes; }
481
483 [[nodiscard]] bool is_empty() const noexcept { return num_nodes == 0; }
484
486 Compare & get_compare() noexcept { return cmp; }
487
489 const Compare & get_compare() const noexcept { return cmp; }
490
499 Key * insert(const Key & key)
500 {
501 Node * update[maxLevel];
502 Node * x = header;
503
504 // Find position
505 for (int i = current_level - 1; i >= 0; --i)
506 {
507 while (x->forward[i] != nullptr and cmp(x->forward[i]->key, key))
508 x = x->forward[i];
509 update[i] = x;
510 }
511
512 x = x->forward[0];
513
514 // Key already exists?
515 if (x != nullptr and keys_equal(x->key, key))
516 return nullptr;
517
518 int lvl = random_level();
519
520 if (lvl > current_level)
521 {
522 for (int i = current_level; i < lvl; ++i)
523 update[i] = header;
524 current_level = lvl;
525 }
526
527 Node * new_node = new Node(key, lvl);
528
529 for (int i = 0; i < lvl; ++i)
530 {
531 new_node->forward[i] = update[i]->forward[i];
532 update[i]->forward[i] = new_node;
533 }
534
535 ++num_nodes;
536 return &new_node->key;
537 }
538
545 Key * insert(Key && key)
546 {
547 Node * update[maxLevel];
548 Node * x = header;
549
550 for (int i = current_level - 1; i >= 0; --i)
551 {
552 while (x->forward[i] != nullptr and cmp(x->forward[i]->key, key))
553 x = x->forward[i];
554 update[i] = x;
555 }
556
557 x = x->forward[0];
558
559 if (x != nullptr and keys_equal(x->key, key))
560 return nullptr;
561
562 int lvl = random_level();
563
564 if (lvl > current_level)
565 {
566 for (int i = current_level; i < lvl; ++i)
567 update[i] = header;
568 current_level = lvl;
569 }
570
571 Node * new_node = new Node(std::move(key), lvl);
572
573 for (int i = 0; i < lvl; ++i)
574 {
575 new_node->forward[i] = update[i]->forward[i];
576 update[i]->forward[i] = new_node;
577 }
578
579 ++num_nodes;
580 return &new_node->key;
581 }
582
590 Key & insert_unique(const Key & key)
591 {
592 Key * ptr = insert(key);
593 ah_domain_error_if(ptr == nullptr)
594 << "DynSkipList::insert_unique: key already exists";
595 return *ptr;
596 }
597
599 Key & append(const Key & key)
600 {
601 Key * ptr = insert(key);
602 if (ptr == nullptr)
603 return *search(key); // Return existing if duplicate
604 return *ptr;
605 }
606
608 Key & append(Key && key)
609 {
610 if (Key * ptr = insert(std::move(key)); ptr != nullptr)
611 return *ptr;
612
613 // A repeated key: insert() moves the key only when it inserts it, so
614 // `key` keeps its value here. As append(const Key &) does, return the
615 // key already in the set.
616 return *search(key);
617 }
618
624 Key * search_or_insert(const Key & key)
625 {
626 Key * existing = search(key);
627 if (existing != nullptr)
628 return existing;
629 return insert(key);
630 }
631
637 [[nodiscard]] const Key * search(const Key & key) const noexcept
638 {
639 Node * x = header;
640
641 for (int i = current_level - 1; i >= 0; --i)
642 while (x->forward[i] != nullptr and cmp(x->forward[i]->key, key))
643 x = x->forward[i];
644
645 x = x->forward[0];
646
647 if (x != nullptr and keys_equal(x->key, key))
648 return &x->key;
649
650 return nullptr;
651 }
652
655 [[nodiscard]] Key * search(const Key & key) noexcept
656 {
657 return const_cast<Key *>(std::as_const(*this).search(key));
658 }
659
661 [[nodiscard]] bool has(const Key & key) const noexcept
662 {
663 return search(key) != nullptr;
664 }
665
672 [[nodiscard]] bool contains(const Key & key) const noexcept { return has(key); }
673
675 [[nodiscard]] bool exist(const Key & key) const noexcept { return has(key); }
676
683 [[nodiscard]] Key & find(const Key & key)
684 {
685 Key * ptr = search(key);
686 ah_domain_error_if(ptr == nullptr)
687 << "DynSkipList::find: key not found";
688 return *ptr;
689 }
690
692 [[nodiscard]] const Key & find(const Key & key) const
693 {
694 const Key * ptr = search(key);
695 ah_domain_error_if(ptr == nullptr)
696 << "DynSkipList::find: key not found";
697 return *ptr;
698 }
699
705 size_t remove(const Key & key)
706 {
707 Node * update[maxLevel];
708 Node * x = header;
709
710 for (int i = current_level - 1; i >= 0; --i)
711 {
712 while (x->forward[i] != nullptr and cmp(x->forward[i]->key, key))
713 x = x->forward[i];
714 update[i] = x;
715 }
716
717 x = x->forward[0];
718
719 if (x == nullptr or not keys_equal(x->key, key))
720 return 0;
721
722 for (int i = 0; i < current_level; ++i)
723 {
724 if (update[i]->forward[i] != x)
725 break;
726 update[i]->forward[i] = x->forward[i];
727 }
728
729 delete x;
730
731 while (current_level > 1 and header->forward[current_level - 1] == nullptr)
733
734 --num_nodes;
735 return 1;
736 }
737
744 Key del(const Key & key)
745 {
746 Node * update[maxLevel];
747 Node * x = header;
748
749 for (int i = current_level - 1; i >= 0; --i)
750 {
751 while (x->forward[i] != nullptr and cmp(x->forward[i]->key, key))
752 x = x->forward[i];
753 update[i] = x;
754 }
755
756 x = x->forward[0];
757
758 ah_domain_error_if(x == nullptr or not keys_equal(x->key, key))
759 << "DynSkipList::del: key not found";
760
761 Key ret_val = std::move(x->key);
762
763 for (int i = 0; i < current_level; ++i)
764 {
765 if (update[i]->forward[i] != x)
766 break;
767 update[i]->forward[i] = x->forward[i];
768 }
769
770 delete x;
771
772 while (current_level > 1 and header->forward[current_level - 1] == nullptr)
774
775 --num_nodes;
776 return ret_val;
777 }
778
780 [[nodiscard]] const Key & min() const
781 {
782 ah_domain_error_if(is_empty()) << "DynSkipList::min: set is empty";
783 return header->forward[0]->key;
784 }
785
787 [[nodiscard]] const Key & get_first() const { return min(); }
788
790 [[nodiscard]] const Key & max() const
791 {
792 ah_domain_error_if(is_empty()) << "DynSkipList::max: set is empty";
793
794 Node * x = header->forward[0];
795 while (x->forward[0] != nullptr)
796 x = x->forward[0];
797 return x->key;
798 }
799
801 [[nodiscard]] const Key & get_last() const { return max(); }
802
803 // =========================================================================
804 // Set operations
805 // =========================================================================
806
812 DynSkipList join(const DynSkipList & other) const
813 {
814 DynSkipList result(*this);
815 for (auto it = other.begin(); it.has_curr(); it.next())
816 result.insert(it.get_curr());
817 return result;
818 }
819
825 DynSkipList intersect(const DynSkipList & other) const
826 {
827 DynSkipList result;
828 for (auto it = begin(); it.has_curr(); it.next())
829 if (other.has(it.get_curr()))
830 result.insert(it.get_curr());
831 return result;
832 }
833
839 DynSkipList diff(const DynSkipList & other) const
840 {
841 DynSkipList result;
842 for (auto it = begin(); it.has_curr(); it.next())
843 if (not other.has(it.get_curr()))
844 result.insert(it.get_curr());
845 return result;
846 }
847
848 // =========================================================================
849 // Iterator
850 // =========================================================================
851
857 {
858 const DynSkipList * list_ptr = nullptr;
859 Node * curr = nullptr;
860
861 public:
863
864 Iterator() noexcept = default;
865
866 explicit Iterator(const DynSkipList & list) noexcept
867 : list_ptr(&list), curr(list.header->forward[0])
868 {}
869
870 [[nodiscard]] bool has_curr() const noexcept { return curr != nullptr; }
871
872 [[nodiscard]] bool is_last() const noexcept
873 {
874 return curr != nullptr and curr->forward[0] == nullptr;
875 }
876
877 [[nodiscard]] const Key & get_curr() const
878 {
879 ah_overflow_error_if(curr == nullptr) << "DynSkipList::Iterator overflow";
880 return curr->key;
881 }
882
883 [[nodiscard]] const Key & get_curr_ne() const noexcept
884 {
885 return curr->key;
886 }
887
888 [[nodiscard]] const Key & get_key() const { return get_curr(); }
889
890 void next()
891 {
892 ah_overflow_error_if(curr == nullptr) << "DynSkipList::Iterator::next overflow";
893 next_ne();
894 }
895
896 void next_ne() noexcept
897 {
898 if (curr != nullptr)
899 curr = curr->forward[0];
900 }
901
902 void reset_first() noexcept
903 {
904 if (list_ptr != nullptr)
906 }
907
908 void reset() noexcept { reset_first(); }
909
910 Iterator & operator=(const Iterator &) noexcept = default;
911
912 [[nodiscard]] bool operator==(const Iterator & it) const noexcept
913 {
914 return curr == it.curr;
915 }
916
917 [[nodiscard]] bool operator!=(const Iterator & it) const noexcept
918 {
919 return curr != it.curr;
920 }
921
922 Iterator & operator++() noexcept
923 {
924 next_ne();
925 return *this;
926 }
927
928 Iterator operator++(int) noexcept
929 {
930 Iterator ret = *this;
931 next_ne();
932 return ret;
933 }
934
935 [[nodiscard]] const Key & operator*() const { return get_curr(); }
936 [[nodiscard]] const Key * operator->() const { return &get_curr(); }
937 };
938
939 [[nodiscard]] Iterator begin() const noexcept { return Iterator(*this); }
940 [[nodiscard]] Iterator end() const noexcept { return Iterator(); }
941
943 [[nodiscard]] Iterator get_it() const noexcept { return begin(); }
944
945 // =========================================================================
946 // Functional operations
947 // =========================================================================
948
961 template <class Operation>
963 bool traverse(Operation & op) const
965 {
966 for (auto it = begin(); it.has_curr(); it.next_ne())
967 if (not static_cast<bool>(op(static_cast<const Key &>(it.get_curr_ne()))))
968 return false;
969 return true;
970 }
971
973 template <class Operation>
975 bool traverse(Operation && op = Operation()) const
976 noexcept(Aleph::NothrowPredicateWith<Operation &, const Key &>)
977 {
978 return traverse<Operation>(op);
979 }
980};
981
982} // end namespace Aleph
983
984# endif // TPL_DYNSKIPLIST_H
Variadic constructor macros for containers.
Container traversal and functional operation mixins.
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
Definition ah-errors.H:611
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Definition ah-errors.H:670
STL-compatible iterator adapters for Aleph containers.
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
DRY (Don't Repeat Yourself) utilities and macros.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
Definition ahDry.H:123
Functional programming utilities for Aleph-w containers.
Iterator traits and STL-compatible iterator wrappers.
Forward iterator for DynSkipList.
Iterator & operator=(const Iterator &) noexcept=default
bool operator!=(const Iterator &it) const noexcept
bool is_last() const noexcept
const Key * operator->() const
const Key & get_curr_ne() const noexcept
Iterator operator++(int) noexcept
Iterator() noexcept=default
bool operator==(const Iterator &it) const noexcept
const Key & operator*() const
bool has_curr() const noexcept
Iterator & operator++() noexcept
Dynamic ordered set implemented with a Skip List.
Key & append(const Key &key)
Append method for Special_Ctors compatibility (aliases to insert)
Key * search_or_insert(const Key &key)
Search and insert if not found.
static unsigned long generator_seed(const unsigned long seed) noexcept
size_t remove(const Key &key)
Remove a key from the set.
void empty() noexcept
Remove all elements from the set.
static constexpr int maxLevel
Maximum number of levels (supports up to 2^32 elements efficiently)
DynSkipList(const DynSkipList &other)
Copy constructor: the copy draws the levels of its nodes from a SplitMix64 with a seed of its own,...
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.
Iterator begin() const noexcept
DynSkipList(const double p, Compare &&c)
static constexpr double defaultProbability
Default probability for level generation (0.5 = geometric distribution)
bool exist(const Key &key) const noexcept
Alias for has()
void clear() noexcept
Empties the container.
bool traverse(Operation &op) const noexcept(Aleph::NothrowPredicateWith< Operation &, const Key & >)
Traverse the keys in increasing order.
Key * insert(Key &&key)
Insert an element into the set (move version).
void set_seed(unsigned long seed)
Seeds the Mersenne Twister of the list, as gsl_rng_set() did: the levels are from then on those of GS...
Key del(const Key &key)
Remove and return a key.
Key Item_Type
The type of element that stores the container.
DynSkipList & operator=(DynSkipList &&other) noexcept(noexcept(swap(other)))
Move assignment: free the nodes of this list, and exchange it with another, which is left empty with ...
Iterator get_it() const noexcept
Alias for begin() - for generic programming.
static decltype(auto) comparison_to_take(Compare &c) noexcept
Random_Source & random_source() noexcept
The source of random numbers, which draws the levels.
Key & append(Key &&key)
See append(const Key & key).
Compare & get_compare() noexcept
Get the comparison functor.
bool contains(const Key &key) const noexcept
Checks if a key exists in the set.
DynSkipList(double p=defaultProbability)
Construct a DynSkipList that draws its levels from a SplitMix64 with a seed of its own.
DynSkipList(const double p, const Compare &c)
DynSkipList & operator=(const DynSkipList &other)
Copy assignment operator.
~DynSkipList()
Destructor - frees all nodes and the random number generator.
Key & find(const Key &key)
Find a key, throwing if not found.
Key * search(const Key &key) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
DynSkipList intersect(const DynSkipList &other) const
Compute the intersection of two sets.
DynSkipList diff(const DynSkipList &other) const
Compute the difference of two sets.
const Key & min() const
Return the minimum element (first in sorted order)
void swap(DynSkipList &other) noexcept(std::is_nothrow_swappable_v< Compare >)
Swap contents with another DynSkipList.
const Compare & get_compare() const noexcept
Get the comparison functor (const version)
Key * insert(const Key &key)
Insert an element into the set.
Key & insert_unique(const Key &key)
Insert an element, throwing if it already exists.
DynSkipList join(const DynSkipList &other) const
Compute the union of two sets.
Iterator end() const noexcept
bool is_empty() const noexcept
Return true if the set is empty.
DynSkipList(DynSkipList &&other)
Move constructor: take the nodes, the generator and the comparison criterion of another list,...
const Key & find(const Key &key) const
Const version of find()
size_t size() const noexcept
Return the number of elements in the set.
bool traverse(Operation &&op=Operation()) const noexcept(Aleph::NothrowPredicateWith< Operation &, const Key & >)
See traverse(Operation & op) const.
bool keys_equal(const Key &k1, const Key &k2) const noexcept
DynSkipList(unsigned long seed, double p=defaultProbability)
Construct a DynSkipList with given seed and probability, whose levels are those of GSL for the seed: ...
void swap_but_comparison(DynSkipList &other) noexcept
bool has(const Key &key) const noexcept
Return true if the key exists in the set.
const Key & get_first() const
Alias for min()
const Key & max() const
Return the maximum element (last in sorted order)
const Key * search(const Key &key) const noexcept
Search for a key in the set.
const Key & get_last() const
Alias for max()
int random_level() const noexcept
Gsl_Compatible_Rng & rng()
The Mersenne Twister of the list, which a list that was given no seed makes here, and draws from it f...
Key Key_Type
The type of element that stores the container.
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
double uniform() noexcept
A real number in [0, 1).
Definition ah-random.H:1181
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
Common methods to the Aleph-w ( ) containers.
Definition ah-dry.H:1235
and
Insert a new element into the container by constructing it from the given args.
Definition ah-dry.H:1273
Common sequential searching methods on containers.
Definition ah-dry.H:555
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
PredicateWith<F, Args...>, and neither the call nor the conversion of its result to bool can throw.
f(args...) is a valid call whose result is usable as a condition.
Main namespace for Aleph-w library functions.
void next()
Advance all underlying iterators (bounds-checked).
Definition ah-zip.H:236
STL namespace.
Internal node structure.
Node(const Key &k, int lvl)
Generic list of items stored in a container.
Definition ah-dry.H:2896
Generic traversal of the container through its iterator.
Definition ah-dry.H:363
Special constructors common to Aleph-w ( ) containers.
Definition ah-dry.H:1100
ValueArg< size_t > seed
Definition testHash.C:53
static int * k