Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
moved_from_structures_test.cc
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
37#include "moved_from.H"
38
39#include <DP_Optimizations.H>
40#include <bitArray.H>
43#include <count-min-sketch.H>
44#include <cuckoo-filter.H>
45#include <hyperloglog.H>
46#include <minhash.H>
48#include <pointer_table.H>
49#include <quotient-filter.H>
50#include <reservoir-sampling.H>
51#include <tpl_b_tree.H>
52#include <tpl_bplus_tree.H>
53#include <tpl_cartesian_tree.H>
55#include <tpl_dynArrayHeap.H>
56#include <tpl_dynSkipList.H>
57#include <tpl_fenwick_tree.H>
60#include <tpl_rand_tree.H>
61#include <tpl_random_queue.H>
62#include <tpl_treap.H>
63#include <tpl_treapRk.H>
64#include <tpl_segment_tree.H>
65#include <tpl_sparse_table.H>
66
67// SkipList is left out with MSVC, as in random_structures_test.cc: its
68// nodes end in an array of zero length
69#if defined(_MSC_VER) && !defined(__clang__)
70# define MOVED_FROM_SKIP_LIST 0
71#else
72# define MOVED_FROM_SKIP_LIST 1
73# include <tpl_skipList.H>
74#endif
75
76#include <algorithm>
77#include <cstdint>
78#include <limits>
79#include <new>
80#include <optional>
81#include <stdexcept>
82
83using namespace Aleph;
84
85template <> struct Moved_From_Case<HyperLogLog<int>>
86{
87 static HyperLogLog<int> make(const size_t n)
88 {
90 for (size_t i = 0; i < n; ++i)
91 h.update(static_cast<int>(i));
92 return h;
93 }
94 static bool is_empty(const HyperLogLog<int> & h) { return h.estimate() == 0.0; }
95 static void use(HyperLogLog<int> & h)
96 {
97 (void) h.estimate();
98 h.update(7);
99 h.clear();
100 h.update(3);
101 EXPECT_GT(h.estimate(), 0.0);
102 }
103};
104
105template <> struct Moved_From_Case<Count_Min_Sketch<int>>
106{
107 static Count_Min_Sketch<int> make(const size_t n)
108 {
109 Count_Min_Sketch<int> s(n < 10 ? 8 : 64, 4);
110 for (size_t i = 0; i < n; ++i)
111 s.update(static_cast<int>(i));
112 return s;
113 }
114 static bool is_empty(const Count_Min_Sketch<int> & s) { return s.total_count() == 0; }
115 static void use(Count_Min_Sketch<int> & s)
116 {
117 s.update(7, 2);
118 EXPECT_GE(s.estimate(7), 2u);
119 s.clear();
120 EXPECT_EQ(s.estimate(7), 0u);
121 }
122};
123
124template <> struct Moved_From_Case<MinHash<int>>
125{
126 static MinHash<int> make(const size_t n)
127 {
128 MinHash<int> m(n < 10 ? 4 : 64);
129 for (size_t i = 0; i < n; ++i)
130 m.update(static_cast<int>(i));
131 return m;
132 }
133 static bool is_empty(const MinHash<int> & m)
134 {
135 for (size_t i = 0; i < m.size(); ++i)
136 if (m.get_signature()[i] != std::numeric_limits<uint64_t>::max())
137 return false;
138 return true;
139 }
140 static void use(MinHash<int> & m)
141 {
142 m.update(7);
143 MinHash<int> other = m;
144 EXPECT_DOUBLE_EQ(m.similarity(other), 1.0);
145 m.clear();
146 }
147};
148
149template <> struct Moved_From_Case<Reservoir_Sampler<int>>
150{
151 static Reservoir_Sampler<int> make(const size_t n)
152 {
153 Reservoir_Sampler<int> r(n < 10 ? 2 : 8, 1);
154 for (size_t i = 0; i < n; ++i)
155 r.update(static_cast<int>(i));
156 return r;
157 }
158 static bool is_empty(const Reservoir_Sampler<int> & r) { return r.total_seen() == 0; }
160 {
161 for (int i = 0; i < 20; ++i)
162 r.update(i);
163 EXPECT_EQ(r.get_sample().size(), r.sample_size());
164 }
165};
166
167template <> struct Moved_From_Case<Fenwick_Tree<int>>
168{
169 static Fenwick_Tree<int> make(const size_t n)
170 {
172 for (size_t i = 0; i < n; ++i)
173 f.update(i, 1);
174 return f;
175 }
176 static bool is_empty(const Fenwick_Tree<int> & f) { return f.is_empty(); }
177 static void use(Fenwick_Tree<int> & f)
178 {
179 for (size_t i = 0; i < f.size(); ++i)
180 f.update(i, 1);
181 if (not f.is_empty())
182 (void) f.prefix(f.size() - 1);
183 }
184};
185
186template <> struct Moved_From_Case<Range_Fenwick_Tree<int>>
187{
188 static Range_Fenwick_Tree<int> make(const size_t n)
189 {
191 if (n > 0)
192 f.update(0, n - 1, 1);
193 return f;
194 }
195 static bool is_empty(const Range_Fenwick_Tree<int> & f) { return f.is_empty(); }
197 {
198 if (f.is_empty())
199 return;
200 f.update(0, f.size() - 1, 2);
201 (void) f.query(0, f.size() - 1);
202 }
203};
204
205// The segment trees of point updates: Sum_, Min_ and Max_Segment_Tree
206template <class Tree> struct Point_Segment_Tree_Case
207{
208 static Tree make(const size_t n) { return Tree(n, 1); }
209 static bool is_empty(const Tree & t) { return t.is_empty(); }
210 static void use(Tree & t)
211 {
212 for (size_t i = 0; i < t.size(); ++i)
213 {
214 t.set(i, static_cast<int>(i));
215 EXPECT_EQ(t.get(i), static_cast<int>(i));
216 t.update(i, 1);
217 }
218 if (not t.is_empty())
219 (void) t.query(0, t.size() - 1);
220 EXPECT_EQ(t.values().size(), t.size());
221 }
222};
223
224template <> struct Moved_From_Case<Sum_Segment_Tree<int>>
225 : Point_Segment_Tree_Case<Sum_Segment_Tree<int>> {};
226template <> struct Moved_From_Case<Min_Segment_Tree<int>>
227 : Point_Segment_Tree_Case<Min_Segment_Tree<int>> {};
228template <> struct Moved_From_Case<Max_Segment_Tree<int>>
229 : Point_Segment_Tree_Case<Max_Segment_Tree<int>> {};
230
231// The lazy segment trees, whose updates add to a range
232template <class Tree> struct Lazy_Segment_Tree_Case
233{
234 static Tree make(const size_t n) { return Tree(n, 1); }
235 static bool is_empty(const Tree & t) { return t.is_empty(); }
236 static void use(Tree & t)
237 {
238 if (not t.is_empty())
239 t.update(0, t.size() - 1, 2);
240 for (size_t i = 0; i < t.size(); ++i)
241 {
242 t.set(i, static_cast<int>(i));
243 t.point_update(i, 1);
244 EXPECT_EQ(t.get(i), static_cast<int>(i) + 1);
245 }
246 if (not t.is_empty())
247 (void) t.query(0, t.size() - 1);
248 EXPECT_EQ(t.values().size(), t.size());
249 }
250};
251
253 : Lazy_Segment_Tree_Case<Lazy_Sum_Segment_Tree<int>> {};
255 : Lazy_Segment_Tree_Case<Lazy_Min_Segment_Tree<int>> {};
257 : Lazy_Segment_Tree_Case<Lazy_Max_Segment_Tree<int>> {};
258
259template <> struct Moved_From_Case<Segment_Tree_Beats<int>>
260{
261 static Segment_Tree_Beats<int> make(const size_t n) { return Segment_Tree_Beats<int>(n, 5); }
262 static bool is_empty(const Segment_Tree_Beats<int> & t) { return t.is_empty(); }
264 {
265 if (not t.is_empty())
266 {
267 const size_t last = t.size() - 1;
268 t.chmin(0, last, 3);
269 t.chmax(0, last, 1);
270 EXPECT_EQ(t.query_max(0, last), 3);
271 EXPECT_EQ(t.query_min(0, last), 3);
272 EXPECT_EQ(t.query_sum(0, last), 3 * static_cast<int>(t.size()));
273 }
274 for (size_t i = 0; i < t.size(); ++i)
275 EXPECT_EQ(t.get(i), 3);
276 EXPECT_EQ(t.values().size(), t.size());
277 }
278};
279
280// The sparse tables of minimum and of maximum, of equal values
281template <class Table> struct Sparse_Table_Case
282{
283 static Table make(const size_t n) { return Table(n, 7); }
284 static bool is_empty(const Table & t) { return t.is_empty() and t.num_levels() == 0; }
285 static void use(Table & t)
286 {
287 for (size_t i = 0; i < t.size(); ++i)
288 EXPECT_EQ(t.get(i), 7);
289 if (not t.is_empty())
290 {
291 EXPECT_EQ(t.query(0, t.size() - 1), 7);
292 }
293 EXPECT_EQ(t.values().size(), t.size());
294 }
295};
296
297template <> struct Moved_From_Case<Sparse_Table<int>> : Sparse_Table_Case<Sparse_Table<int>> {};
298template <> struct Moved_From_Case<Max_Sparse_Table<int>>
299 : Sparse_Table_Case<Max_Sparse_Table<int>> {};
300
302{
304 {
306 }
308 {
309 return t.is_empty() and t.num_levels() == 0;
310 }
312 {
313 for (size_t i = 0; i < t.size(); ++i)
314 EXPECT_EQ(t.get(i), 1);
315 if (not t.is_empty())
316 {
317 EXPECT_EQ(t.query(0, t.size() - 1), static_cast<int>(t.size()));
318 }
319 EXPECT_EQ(t.values().size(), t.size());
320 }
321};
322
323namespace
324{
325 // The values of the Cartesian trees: a fixed scramble, with repetitions
326 Array<int> scrambled_values(const size_t n)
327 {
328 auto a = Array<int>::create(n);
329 for (size_t i = 0; i < n; ++i)
330 a(i) = static_cast<int>((i * 37 + 11) % 101);
331 return a;
332 }
333} // namespace
334
335template <> struct Moved_From_Case<Cartesian_Tree<int>>
336{
337 static Cartesian_Tree<int> make(const size_t n) { return Cartesian_Tree<int>(scrambled_values(n)); }
338 static bool is_empty(const Cartesian_Tree<int> & t)
339 {
340 return t.is_empty() and t.root() == Cartesian_Tree<int>::NONE;
341 }
342 static void use(Cartesian_Tree<int> & t)
343 {
344 for (size_t i = 0; i < t.size(); ++i)
345 {
346 if (const size_t p = t.parent_of(i); p != Cartesian_Tree<int>::NONE)
347 {
348 EXPECT_LE(t.data_at(p), t.data_at(i));
349 }
350 (void) t.left_child(i);
351 (void) t.right_child(i);
352 (void) t.is_leaf(i);
353 }
354 EXPECT_EQ(t.inorder().size(), t.size());
355 EXPECT_EQ(t.values().size(), t.size());
356 EXPECT_LE(t.height(), t.size());
357 }
358};
359
360template <> struct Moved_From_Case<Euler_Tour_LCA<int>>
361{
362 static Euler_Tour_LCA<int> make(const size_t n) { return Euler_Tour_LCA<int>(scrambled_values(n)); }
363 static bool is_empty(const Euler_Tour_LCA<int> & l)
364 {
365 return l.is_empty() and l.euler_tour_size() == 0;
366 }
367 static void use(Euler_Tour_LCA<int> & l)
368 {
369 EXPECT_EQ(l.euler_tour().size(), l.euler_tour_size());
370 for (size_t i = 0; i < l.size(); ++i)
371 {
372 EXPECT_LE(l.depth_of(l.lca(0, i)), l.depth_of(i));
373 (void) l.distance(0, i);
374 }
375 EXPECT_EQ(l.tree().size(), l.size());
376 }
377};
378
379template <> struct Moved_From_Case<Cartesian_Tree_RMQ<int>>
380{
381 static Cartesian_Tree_RMQ<int> make(const size_t n)
382 {
383 return Cartesian_Tree_RMQ<int>(scrambled_values(n));
384 }
385 static bool is_empty(const Cartesian_Tree_RMQ<int> & q) { return q.is_empty(); }
387 {
388 int least = std::numeric_limits<int>::max();
389 for (size_t i = 0; i < q.size(); ++i)
390 {
391 least = std::min(least, q.get(i));
392 EXPECT_EQ(q.query(0, i), least);
393 EXPECT_EQ(q.get(q.query_idx(0, i)), least);
394 }
395 EXPECT_EQ(q.values().size(), q.size());
396 }
397};
398
399// The cuckoo filters, with a fixed seed so that every run kicks the same
400template <class Filter> struct Cuckoo_Filter_Case
401{
402 static Filter make(const size_t n)
403 {
404 Filter f(n < 10 ? 8 : n, 1);
405 for (size_t i = 0; i < n; ++i)
406 (void) f.insert(static_cast<int>(i));
407 return f;
408 }
409 static bool is_empty(const Filter & f) { return f.is_empty(); }
410 static void use(Filter & f)
411 {
412 if (f.is_empty()) // as a moved-from filter: one bucket, or none until it inserts
413 {
414 EXPECT_FALSE(f.contains(7));
415 EXPECT_FALSE(f.remove(7));
416 f.clear();
417 Filter copy(f);
418 EXPECT_TRUE(copy.insert(7));
419 EXPECT_TRUE(copy.contains(7));
420 }
421 EXPECT_TRUE(f.insert(7));
422 EXPECT_TRUE(f.contains(7));
423 EXPECT_TRUE(f.remove(7));
424 f.clear();
425 EXPECT_TRUE(f.is_empty());
426 EXPECT_TRUE(f.insert(3));
427 EXPECT_TRUE(f.contains(3));
428 }
429};
430
431template <> struct Moved_From_Case<Cuckoo_Filter<int>> : Cuckoo_Filter_Case<Cuckoo_Filter<int>> {};
433 : Cuckoo_Filter_Case<Compact_Cuckoo_Filter<int>> {};
434
435// The quotient filters: 16 slots for a small one, 4096 for a large one
436template <class Filter> struct Quotient_Filter_Case
437{
438 static Filter make(const size_t n)
439 {
440 Filter f(n < 10 ? 4 : 12, 8);
441 for (size_t i = 0; i < n; ++i)
442 f.insert(static_cast<int>(i));
443 return f;
444 }
445 static bool is_empty(const Filter & f) { return f.is_empty(); }
446 static void use(Filter & f)
447 {
448 if (f.is_empty()) // as a moved-from filter, of two slots
449 {
450 EXPECT_FALSE(f.contains(7));
451 EXPECT_FALSE(f.remove(7));
452 f.clear();
453 Filter copy(f), other(f.q(), f.r(), f.seed());
454 copy.merge(f);
455 other.insert(5);
456 f.merge(other);
457 EXPECT_TRUE(f.contains(5));
458 EXPECT_TRUE(f.remove(5));
459 }
460 f.insert(7);
461 EXPECT_TRUE(f.contains(7));
462 EXPECT_TRUE(f.remove(7));
463 f.clear();
464 EXPECT_TRUE(f.is_empty());
465 f.insert(3);
466 EXPECT_TRUE(f.contains(3));
467 }
468};
469
470template <> struct Moved_From_Case<Quotient_Filter<int>>
471 : Quotient_Filter_Case<Quotient_Filter<int>> {};
473 : Quotient_Filter_Case<Compact_Quotient_Filter<int>> {};
474
475template <> struct Moved_From_Case<BitArray>
476{
477 static BitArray make(const size_t n)
478 {
479 BitArray a;
480 for (size_t i = 0; i < n; ++i)
481 a.push((i * 37 + 11) % 3 == 0);
482 return a;
483 }
484 static bool is_empty(const BitArray & a) { return a.size() == 0; }
485 static void use(BitArray & a)
486 {
487 const size_t n = a.size();
488 a.push(1);
489 a.push(0);
490 EXPECT_EQ(a.size(), n + 2);
491 EXPECT_EQ(a.read_bit(n), 1);
492 EXPECT_EQ(a.read_bit(n + 1), 0);
493 a.pop();
494 EXPECT_EQ(a.size(), n + 1);
495 EXPECT_EQ(a.get_bit_str().size(), n + 1);
496 }
497};
498
499template <> struct Moved_From_Case<DynArrayHeap<int>>
500{
501 static DynArrayHeap<int> make(const size_t n)
502 {
504 for (size_t i = 0; i < n; ++i)
505 (void) h.insert(static_cast<int>((i * 37 + 11) % 101));
506 return h;
507 }
508 static bool is_empty(const DynArrayHeap<int> & h) { return h.is_empty(); }
509 static void use(DynArrayHeap<int> & h)
510 {
511 size_t count = 0;
512 h.for_each([&count] (const int) { ++count; });
513 EXPECT_EQ(count, h.size());
514 (void) h.insert(-1);
515 (void) h.insert(500);
516 EXPECT_EQ(h.top(), -1);
517 EXPECT_EQ(h.getMin(), -1);
518 }
519};
520
521// The B-Tree and the B+ Tree
522template <class Tree> struct Ordered_Tree_Case
523{
524 static Tree make(const size_t n)
525 {
526 Tree t;
527 for (size_t i = 0; i < n; ++i)
528 (void) t.insert(static_cast<int>(i));
529 return t;
530 }
531 static bool is_empty(const Tree & t) { return t.is_empty() and t.verify(); }
532 static void use(Tree & t)
533 {
534 EXPECT_TRUE(t.verify());
535 EXPECT_EQ(t.keys().size(), t.size());
536 EXPECT_EQ(t.min_key().has_value(), not t.is_empty());
537 EXPECT_TRUE(t.insert(-1));
538 EXPECT_TRUE(t.contains(-1));
539 EXPECT_EQ(t.min_key(), std::optional<int>(-1));
540 EXPECT_TRUE(t.remove(-1));
541 EXPECT_TRUE(t.verify());
542 }
543};
544
545template <> struct Moved_From_Case<B_Tree<int>> : Ordered_Tree_Case<B_Tree<int>> {};
546template <> struct Moved_From_Case<BPlus_Tree<int>> : Ordered_Tree_Case<BPlus_Tree<int>> {};
547
548template <> struct Moved_From_Case<PersistentVector<int>>
549{
550 static PersistentVector<int> make(const size_t n)
551 {
553 for (size_t i = 0; i < n; ++i)
554 v = v.push_back(static_cast<int>(i));
555 return v;
556 }
557 static bool is_empty(const PersistentVector<int> & v) { return v.is_empty() and v.verify(); }
558 static void use(PersistentVector<int> & v)
559 {
560 EXPECT_TRUE(v.verify());
561 for (size_t i = 0; i < v.size(); ++i)
562 (void) v.get(i);
563 EXPECT_EQ(v.to_array().size(), v.size());
564 const PersistentVector<int> w = v.push_back(7);
565 EXPECT_EQ(w.size(), v.size() + 1);
566 EXPECT_EQ(w[v.size()], 7);
567 if (not v.is_empty())
568 {
569 EXPECT_EQ(v.set(0, 9)[0], 9);
570 EXPECT_EQ(v.pop_back().size(), v.size() - 1);
571 }
572 v = w;
573 }
574};
575
576template <> struct Moved_From_Case<PersistentHashMap<int, int>>
577{
578 static PersistentHashMap<int, int> make(const size_t n)
579 {
581 for (size_t i = 0; i < n; ++i)
582 m = m.insert(static_cast<int>(i), static_cast<int>(i));
583 return m;
584 }
586 {
587 return m.is_empty() and m.verify();
588 }
590 {
591 EXPECT_TRUE(m.verify());
592 const Array<int> keys = m.keys();
593 EXPECT_EQ(keys.size(), m.size());
594 for (size_t i = 0; i < keys.size(); ++i)
595 EXPECT_NE(m.find(keys(i)), nullptr);
596 m = m.insert_or_assign(-1, 7);
597 ASSERT_NE(m.find(-1), nullptr);
598 EXPECT_EQ(*m.find(-1), 7);
599 m = m.erase(-1);
600 EXPECT_FALSE(m.contains(-1));
601 }
602};
603
604template <> struct Moved_From_Case<DynSkipList<int>>
605{
606 static DynSkipList<int> make(const size_t n)
607 {
608 DynSkipList<int> l(1UL);
609 for (size_t i = 0; i < n; ++i)
610 (void) l.insert(static_cast<int>(i));
611 return l;
612 }
613 static bool is_empty(const DynSkipList<int> & l) { return l.is_empty(); }
614 static void use(DynSkipList<int> & l)
615 {
616 size_t count = 0;
617 l.for_each([&count] (const int) { ++count; });
618 EXPECT_EQ(count, l.size());
619 EXPECT_NE(l.insert(-1), nullptr);
620 EXPECT_NE(l.insert(-2), nullptr);
621 EXPECT_TRUE(l.has(-1));
622 EXPECT_EQ(l.remove(-1), 1u);
623 l.clear();
624 EXPECT_TRUE(l.is_empty());
625 EXPECT_NE(l.insert(5), nullptr);
626 }
627};
628
629// The nodes of a tree that does not own them: make() frees those that it
630// gave to the tree if giving another one throws, as the tree is not
631// returned then
632template <class Tree>
633void fill_or_free(Tree & t, const size_t n)
634{
635 using Node = typename Tree::Node;
636 try
637 {
638 for (size_t i = 0; i < n; ++i)
639 {
640 Node * p = new Node(static_cast<int>(i));
641 if (t.insert(p) != p)
642 delete p;
643 }
644 }
645 catch (...)
646 {
647 destroyRec(t.getRoot());
648 throw;
649 }
650}
651
652// Inserts two nodes, finds one and removes the other, which it frees: the
653// one that remove() gave, so that a node that is left in the tree is not
654// freed while the tree still links it
655template <class Tree>
657{
658 using Node = typename Tree::Node;
659 Node * p = new Node(-1);
660 Node * q = new Node(-2);
661 EXPECT_EQ(t.insert(p), p);
662 EXPECT_EQ(t.insert(q), q);
663 EXPECT_EQ(t.search(-1), p);
664 Node * removed = t.remove(-2);
665 EXPECT_EQ(removed, q);
666 delete removed;
667}
668
669// A randomized tree does not own its nodes: use() frees them, as its user
670// would, so that none is left at the end
671template <> struct Moved_From_Case<Rand_Tree<int>>
672{
674
675 static Rand_Tree<int> make(const size_t n)
676 {
677 Rand_Tree<int> t(1);
678 fill_or_free(t, n);
679 return t;
680 }
681 static bool is_empty(const Rand_Tree<int> & t) { return t.is_empty() and t.size() == 0; }
682 static void use(Rand_Tree<int> & t)
683 {
684 EXPECT_TRUE(t.verify());
685 for (size_t i = 0; i < t.size(); ++i)
686 (void) t.select(i);
688 EXPECT_TRUE(t.verify());
689 destroyRec(t.getRoot());
690 EXPECT_TRUE(t.is_empty());
691 }
692};
693
694// A treap does not own its nodes either. One that is moved from keeps no
695// nodes and draws its priorities from a generator of its own: before 7.9.0
696// it was left without a generator, and could only be swapped or destroyed
697template <class Tree> struct Moved_From_Treap
698{
699 using Node = typename Tree::Node;
700
701 static Tree make(const size_t n)
702 {
703 Tree t(1);
704 fill_or_free(t, n);
705 return t;
706 }
707 static bool is_empty(Tree & t) { return t.getRoot() == Node::NullPtr; }
708 static size_t fingerprint(const Tree & t)
709 {
710 return compute_cardinality_rec(const_cast<Tree &>(t).getRoot());
711 }
712 static void use(Tree & t)
713 {
714 EXPECT_TRUE(t.verify());
716 EXPECT_TRUE(t.verify());
717 destroyRec(t.getRoot());
718 EXPECT_EQ(t.getRoot(), Node::NullPtr);
719 }
720};
721
722template <> struct Moved_From_Case<Treap<int>> : Moved_From_Treap<Treap<int>> {};
723
724template <> struct Moved_From_Case<Treap_Rk<int>> : Moved_From_Treap<Treap_Rk<int>> {};
725
726template <> struct Moved_From_Case<Random_Set<int>>
727{
728 static Random_Set<int> make(const size_t n)
729 {
731 q.set_seed(1);
732 for (size_t i = 0; i < n; ++i)
733 (void) q.append(static_cast<int>(i));
734 return q;
735 }
736 static bool is_empty(const Random_Set<int> & q) { return q.is_empty(); }
737 static void use(Random_Set<int> & q)
738 {
739 size_t count = 0;
740 q.for_each([&count] (const int) { ++count; });
741 EXPECT_EQ(count, q.size());
742 (void) q.append(-1);
743 q.put(-2);
744 (void) q.pick();
745 const size_t before = q.size();
746 (void) q.get();
747 EXPECT_EQ(q.size(), before - 1);
748 }
749};
750
751namespace
752{
753 // The pointers kept by the tables, which are never followed
754 void * pointer_cell(const size_t i)
755 {
756 static int cells[1024];
757 return &cells[i];
758 }
759} // namespace
760
762{
763 static Pointer_Table make(const size_t n)
764 {
765 Pointer_Table t(n < 10 ? 0 : 64);
766 for (size_t i = 0; i < n; ++i)
767 (void) t.insert_pointer(pointer_cell(i));
768 return t;
769 }
770 static bool is_empty(const Pointer_Table & t)
771 {
772 return t.is_empty() and t.get_heap_index() == 0 and t.frees() == 0;
773 }
774 static void use(Pointer_Table & t)
775 {
776 for (long i = 0; i < t.get_heap_index(); ++i)
777 if (void * p = t.get_pointer(i); p != nullptr)
778 {
779 EXPECT_EQ(t.verify_pointer(i, p), p);
780 }
781 const long i = t.insert_pointer(pointer_cell(0));
782 EXPECT_EQ(t.get_pointer(i), pointer_cell(0));
783 t.remove_pointer(i);
784 t.clear();
785 EXPECT_TRUE(t.is_empty());
786 (void) t.insert_pointer(pointer_cell(1));
787 }
788};
789
790template <> struct Moved_From_Case<Li_Chao_Tree<long>>
791{
792 static Li_Chao_Tree<long> make(const size_t n)
793 {
794 Li_Chao_Tree<long> t(-1000, 1000);
795 for (size_t i = 0; i < n; ++i)
796 t.add_line(static_cast<long>(i % 7) - 3, static_cast<long>(i));
797 return t;
798 }
799 static bool is_empty(const Li_Chao_Tree<long> & t)
800 {
801 return t.is_empty() and t.node_count() == 0;
802 }
803 static void use(Li_Chao_Tree<long> & t)
804 {
805 if (not t.is_empty())
806 (void) t.query(0);
807 t.add_line(0, -5000); // below the lines of make() on the whole domain
808 EXPECT_EQ(t.query(7), -5000);
809 t.clear();
810 EXPECT_TRUE(t.is_empty());
811 t.add_line(2, 1);
812 EXPECT_EQ(t.query(3), 7);
813 }
814};
815
816template <> struct Moved_From_Case<Convex_Hull_Trick<long>>
817{
818 static Convex_Hull_Trick<long> make(const size_t n)
819 {
821 for (size_t i = 0; i < n; ++i)
822 {
823 const auto k = static_cast<long>(i);
824 h.add_line(-k, k * k); // every line is on the hull, the k-th about x = 2k
825 }
826 if (n > 0) // the cursor of the monotone queries goes to the last line
827 (void) h.query_monotone(static_cast<long>(2 * n));
828 return h;
829 }
830 static bool is_empty(const Convex_Hull_Trick<long> & h) { return h.is_empty(); }
832 {
833 if (not h.is_empty())
834 {
835 EXPECT_EQ(h.query_monotone(1000000), h.query(1000000));
836 }
837 h.clear();
838 h.add_line(1, 0);
839 h.add_line(0, 2);
840 h.add_line(-1, 5);
841 EXPECT_EQ(h.query(0), 0);
842 EXPECT_EQ(h.query_monotone(10), -5);
843 }
844};
845
846// Two moduli, so that an object with the modulus of one and the tables of
847// the other is seen: below the modulus, n choose 0, 1 and n are 1, n and 1
849{
850 static ModularCombinatorics make(const size_t n)
851 {
852 return ModularCombinatorics(n, n < 10 ? 7 : 1000003);
853 }
854 static bool is_empty(const ModularCombinatorics & m)
855 {
856 try
857 {
858 (void) m.nCk(0, 0);
859 }
860 catch (const std::out_of_range &)
861 {
862 return true; // no table
863 }
864 return false;
865 }
867 {
868 for (uint64_t n = 0; ; ++n) // up to the end of the tables
869 {
870 uint64_t none = 0;
871 try
872 {
873 none = m.nCk(n, 0);
874 }
875 catch (const std::out_of_range &)
876 {
877 break;
878 }
879 EXPECT_EQ(none, 1u) << "n = " << n;
880 EXPECT_EQ(m.nCk(n, n), 1u) << "n = " << n;
881 if (n > 0)
882 {
883 EXPECT_EQ(m.lucas_nCk(n, 1), n) << "n = " << n;
884 }
885 }
886 EXPECT_EQ(m.nCk(3, 5), 0u);
887 }
888};
889
890using Structures = ::testing::Types<HyperLogLog<int>, Count_Min_Sketch<int>, MinHash<int>,
908
909#if MOVED_FROM_SKIP_LIST
910// The sentinel key of a skip list of int, which its user gives
911template <>
913{
914 return std::numeric_limits<int>::max();
915}
916
917namespace
918{
919 using Skip_List = SkipList<int, int>;
920
921 // A node of a skip list ends in its forward pointers: it is made with
922 // room for them
923 Skip_List::Node * new_skip_node(Skip_List & l, const int key)
924 {
925 const int level = l.generateRandomLevel();
926 void * mem = ::operator new(sizeof(Skip_List::Node) + sizeof(Skip_List::Node *) * level);
927 return new (mem) Skip_List::Node(key, key, level);
928 }
929} // namespace
930
931// A skip list does not own its nodes either: use() removes and frees them
932template <> struct Moved_From_Case<Skip_List>
933{
934 static Skip_List make(const size_t n)
935 {
936 Skip_List l(1UL);
937 for (size_t i = 0; i < n; ++i)
938 (void) l.insert(new_skip_node(l, static_cast<int>(i)));
939 return l;
940 }
941 static bool is_empty(const Skip_List & l) { return not Skip_List::Iterator(l).has_curr(); }
942 static void use(Skip_List & l)
943 {
945 for (Skip_List::Iterator it(l); it.has_curr(); it.next_ne())
946 nodes.append(it.get_curr_ne());
947 for (size_t i = 1; i < nodes.size(); ++i)
948 EXPECT_LT(nodes(i - 1)->get_key(), nodes(i)->get_key());
949 Skip_List::Node * p = l.insert(new_skip_node(l, -1));
950 EXPECT_EQ(l.search(-1), p);
951 EXPECT_TRUE(l.checkSkipList());
952 nodes.append(p);
953 for (size_t i = 0; i < nodes.size(); ++i)
954 {
955 EXPECT_EQ(l.remove(nodes(i)->get_key()), nodes(i));
956 nodes(i)->~Node();
957 ::operator delete(nodes(i));
958 }
959 EXPECT_TRUE(is_empty(l));
960 }
961};
962
963INSTANTIATE_TYPED_TEST_SUITE_P(Skip_List, MovedFrom, ::testing::Types<Skip_List>);
964#endif
Classical DP optimization toolkit: D&C DP, Knuth, CHT, Li Chao, and monotone-queue transitions.
INSTANTIATE_TYPED_TEST_SUITE_P(traverses, Container, Ctypes)
WeightedDigraph::Node Node
Space-efficient bit array implementation.
long double h
Definition btreepic.C:154
long double w
Definition btreepic.C:153
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:141
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
Definition tpl_array.H:450
static Array create(const size_t n)
Create an array with n logical elements.
Definition tpl_array.H:245
T & append(const T &data)
Append a copy of data
Definition tpl_array.H:331
Contiguous array of bits.
Definition bitArray.H:201
int read_bit(const size_t i) const
Read bit i.
Definition bitArray.H:409
std::string get_bit_str() const
Definition bitArray.H:981
void pop()
Removes the last bit of the array.
Definition bitArray.H:512
void push(const unsigned int value)
Inserts the value at the end of the array.
Definition bitArray.H:506
constexpr size_t size() const noexcept
Returns the dimension of the bit array.
Definition bitArray.H:350
Memory-optimized Cuckoo Filter with bit-packed fingerprints.
Memory-optimized quotient filter with bit-packed slots.
Convex Hull Trick for minimum queries.
void add_line(const T slope, const T intercept)
Insert a new line; slopes must be non-increasing.
Count-Min Sketch frequency estimator.
CounterT estimate(const T &val) const
Estimate frequency of an element.
CounterT total_count() const noexcept
Sum of all event weights inserted so far.
void clear()
Clear all counters.
void update(const T &val, CounterT count=1)
Increment count for an element.
Industrial-grade Cuckoo Filter implementation.
Dynamic heap (priority queue) backed by DynArray.
T & insert(const T &key)
Insert a copy of key into the heap.
T & insert(const T &item)
Definition htlist.H:1308
T remove()
Remove the first item of the list.
Definition htlist.H:1447
void clear() noexcept
Empties the container.
Definition htlist.H:1599
size_t size() const noexcept
Return the number of items of the list, in constant time.
Definition htlist.H:1264
Dynamic ordered set implemented with a Skip List.
Generic linear hash table.
const size_t & size() const noexcept
Returns the number of elements in the table.
bool is_empty() const noexcept
return true is table is empty
Generic B+ Tree with configurable minimum degree.
Generic B-Tree with configurable minimum degree.
Definition tpl_b_tree.H:135
constexpr size_t size() const noexcept
Number of elements.
T get(const size_t i) const
Retrieve the value at position i in O(1).
Array< T > values() const
Copy of the original values.
T query(const size_t l, const size_t r) const
Range query over [l, r] in O(1).
size_t query_idx(const size_t l, const size_t r) const
Return the index of the optimal element in a[l..r].
constexpr bool is_empty() const noexcept
True if empty.
Array< size_t > inorder() const
Inorder traversal of the tree.
constexpr size_t root() const noexcept
Index of the root node.
Array< T > values() const
Copy of the original data array.
const T & data_at(const size_t i) const
Value at node i.
size_t left_child(const size_t i) const
Left child of node i.
bool is_leaf(const size_t i) const
True if node i is a leaf (no children).
constexpr size_t size() const noexcept
Number of nodes.
size_t parent_of(const size_t i) const
Parent of node i.
size_t right_child(const size_t i) const
Right child of node i.
constexpr bool is_empty() const noexcept
True if the tree is empty.
size_t height() const
Height of the tree (longest root-to-leaf path).
constexpr bool is_empty() const noexcept
True if the table contains no elements.
Array< T > values() const
Reconstruct all original values into an Array.
T get(const size_t i) const
Retrieve the value a[i] in O(1).
constexpr size_t num_levels() const noexcept
Number of precomputed levels.
T query(const size_t l, const size_t r) const
Range query over [l, r] in O(1).
constexpr size_t size() const noexcept
Number of logical elements.
constexpr bool is_empty() const noexcept
True if the tree contains no elements.
T prefix(size_t i) const
Prefix query: Plus(a[0], a[1], ..., a[i]).
void update(size_t i, const T &delta)
Point update: a[i] = Plus(a[i], delta).
constexpr size_t size() const noexcept
Number of logical elements.
bool is_empty() const noexcept
Return true if the tree is empty.
bool verify() const
Return true if this is a consistent randomized tree.
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.
Node *& getRoot() noexcept
Return the tree's root.
constexpr bool is_empty() const noexcept
Definition htlist.H:434
HyperLogLog cardinality estimator.
Definition hyperloglog.H:69
Li Chao tree for min line queries on an integral x-domain.
void add_line(const T slope, const T intercept)
T query(const T x) const
bool is_empty() const noexcept
size_t node_count() const noexcept
MinHash signature generator.
Definition minhash.H:65
High-performance combinatorics operations modulo a prime.
constexpr bool contains(const Key &key) const noexcept
Alias for has().
Definition hashDry.H:769
Immutable unordered map backed by a Hash Array Mapped Trie (HAMT).
Immutable vector backed by a 32-way bitmapped trie.
Array< T > to_array() const
Return all values in an Aleph array.
PersistentVector push_back(const T &value) const
Return a new version with value appended by copy.
const T & get(const size_t index) const
Read a value by index.
bool verify() const noexcept
Verify trie shape and logical prefix invariants.
PersistentVector set(const size_t index, const T &value) const
Return a new version with one index replaced by copy.
size_t size() const noexcept
Return the number of values in this version.
bool is_empty() const noexcept
Return true when the vector has no values.
PersistentVector pop_back() const
Return a new version without the last value.
Quotient filter for probabilistic set membership with deletion.
void put(const T &item)
Insert an item by copy.
void set_seed(unsigned long seed) const
Seeds the Mersenne Twister of the set, as gsl_rng_set() did: the positions are from then on those of ...
bool is_empty() const
Return true if the queue is empty.
T get()
Extract randomly an item.
T & append(const T &item)
Insert randomly an item by copy.
size_t size() const
Return the number of items in the queue.
Fenwick tree supporting range updates and range queries.
void update(size_t l, const size_t r, const T &delta)
Range update: add delta to every a[i] with l <= i <= r.
constexpr bool is_empty() const noexcept
True if the tree contains no elements.
constexpr size_t size() const noexcept
Number of logical elements.
T query(const size_t l, const size_t r) const
Range query: sum of a[l..r].
Incremental reservoir sampler (Algorithm R).
Ji Driver's Segment Tree (Segment Tree Beats).
void chmax(const size_t l, const size_t r, const T &v)
Range chmax: for each i in [l, r], set a[i] = max(a[i], v).
constexpr size_t size() const noexcept
Number of logical elements.
T query_sum(const size_t l, const size_t r) const
Range sum query over [l, r].
T get(const size_t i) const
Retrieve the value at position i.
T query_max(const size_t l, const size_t r) const
Range max query over [l, r].
void chmin(const size_t l, const size_t r, const T &v)
Range chmin: for each i in [l, r], set a[i] = min(a[i], v).
Array< T > values() const
Reconstruct all values into an Array.
T query_min(const size_t l, const size_t r) const
Range min query over [l, r].
constexpr bool is_empty() const noexcept
True if the tree contains no elements.
Skip List - a probabilistic ordered data structure.
void for_each(Operation &operation) const
Traverse all the container and performs an operation on each element.
Definition ah-dry.H:1475
The typed suite of the moved-from tests.
Definition moved_from.H:115
constexpr size_t size() const noexcept
Returns the number of entries in the table.
Definition hashDry.H:954
void clear()
Empties the container.
Definition hashDry.H:949
constexpr bool is_empty() const noexcept
Checks if the table is empty.
Definition hashDry.H:959
DynList< Key > keys() const
Returns a list containing all keys in the table.
Definition hashDry.H:1247
Key * insert(const Key &key)
Inserts a key into the hash table (copy version).
Definition hashDry.H:507
Key & find(const Key &key)
Finds a key and returns a reference to it.
Definition hashDry.H:782
A dynamic table for managing void pointers with index recycling.
void * verify_pointer(long i, void *ptr) const
Verifies that a pointer matches the one stored at an index.
long frees() const noexcept
Returns the number of recyclable indices.
void remove_pointer(long i)
Removes the pointer at the given index.
bool is_empty() const noexcept
Checks if the table is empty.
long get_heap_index() const noexcept
Returns the current heap index (high water mark).
long insert_pointer(void *ptr)
Inserts a pointer and returns its assigned index.
void clear()
Clears all pointers from the table.
void * get_pointer(long i) const
Retrieves the pointer at the given index.
QuadTree - Hierarchical spatial index for 2D points.
Definition quadtree.H:126
void remove(const Point &p)
Remove a point from the tree.
Definition quadtree.H:565
Point * search(const Point &p) noexcept
Search for a point in the tree.
Definition quadtree.H:524
QuadNode Node
Definition quadtree.H:128
bool contains(const Point &p) const noexcept
Check if a point is within the tree's region.
Definition quadtree.H:487
Point * insert(Node *&r, const Point &p)
Recursive insert helper.
Definition quadtree.H:281
Memory-optimized Cuckoo filter with bit-packed fingerprints.
Memory-optimized quotient filter with bit-packed slots.
Count-Min Sketch for frequency estimation in streams.
Probabilistic set membership with Cuckoo filters.
DynArray< Graph::Node * > nodes
Definition graphpic.C:406
void destroyRec(Node *&root) noexcept
Free all the memory occupied by the tree root
size_t compute_cardinality_rec(Node *root) noexcept
Count the number of nodes of a binary tree.
HyperLogLog for approximate cardinality estimation.
LinearHashTable< int > Table
Definition lin-hash.cc:56
MinHash for estimating Jaccard similarity between sets.
Modular combinatorics utilities for computing binomial coefficients.
The pattern test of the moved-from objects.
::testing::Types< HyperLogLog< int >, Count_Min_Sketch< int >, MinHash< int >, Reservoir_Sampler< int >, Fenwick_Tree< int >, Range_Fenwick_Tree< int >, Sum_Segment_Tree< int >, Min_Segment_Tree< int >, Max_Segment_Tree< int >, Lazy_Sum_Segment_Tree< int >, Lazy_Min_Segment_Tree< int >, Lazy_Max_Segment_Tree< int >, Segment_Tree_Beats< int >, Sparse_Table< int >, Max_Sparse_Table< int >, Sum_Disjoint_Sparse_Table< int >, Cartesian_Tree< int >, Euler_Tour_LCA< int >, Cartesian_Tree_RMQ< int >, Cuckoo_Filter< int >, Compact_Cuckoo_Filter< int >, Quotient_Filter< int >, Compact_Quotient_Filter< int >, BitArray, DynArrayHeap< int >, B_Tree< int >, BPlus_Tree< int >, PersistentVector< int >, PersistentHashMap< int, int >, DynSkipList< int >, Rand_Tree< int >, Random_Set< int >, Treap< int >, Treap_Rk< int >, Pointer_Table, Li_Chao_Tree< long >, Convex_Hull_Trick< long >, ModularCombinatorics > Structures
void fill_or_free(Tree &t, const size_t n)
void insert_find_and_remove(Tree &t)
INSTANTIATE_TYPED_TEST_SUITE_P(Structures, MovedFrom, Structures)
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
Definition ahAlgo.H:584
and
Check uniqueness with explicit hash + equality functors.
@ Tree
Basic arc (in spanning tree).
bool none(const Container &container, Operation &operation)
Return true if no element satisfies operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
Pointer table with index reuse for efficient pointer management.
Quotient filter: a cache-friendly probabilistic set with deletion.
Reservoir sampling for random selection from data streams.
Range minimum queries via Cartesian Tree.
Cartesian Tree for min-heap (range minimum).
LCA on a min-heap Cartesian Tree.
Fenwick tree for arithmetic types with find_kth support.
Lazy segment tree for range add + range max.
Lazy segment tree for range add + range min.
Lazy segment tree for range add + range sum.
Max Segment Tree for range maximum queries with point updates.
Sparse Table for range maximum queries.
Min Segment Tree for range minimum queries with point updates.
Randomized binary search tree.
Sparse Table for range minimum queries.
Disjoint Sparse Table for range sum queries.
Sum Segment Tree for range sum queries with point updates.
Extended treap (a special type of randomized binary search tree) which manages selection and splittin...
Treap (a special type of randomized binary search tree) using nodes without virtual destructor.
Definition tpl_treap.H:797
static bool is_empty(const Filter &f)
static Filter make(const size_t n)
static bool is_empty(const Tree &t)
static Tree make(const size_t n)
static BitArray make(const size_t n)
static bool is_empty(const BitArray &a)
static bool is_empty(const Cartesian_Tree< int > &t)
static void use(Cartesian_Tree< int > &t)
static Cartesian_Tree< int > make(const size_t n)
static void use(Cartesian_Tree_RMQ< int > &q)
static bool is_empty(const Cartesian_Tree_RMQ< int > &q)
static Cartesian_Tree_RMQ< int > make(const size_t n)
static Convex_Hull_Trick< long > make(const size_t n)
static bool is_empty(const Convex_Hull_Trick< long > &h)
static void use(Convex_Hull_Trick< long > &h)
static bool is_empty(const Count_Min_Sketch< int > &s)
static void use(Count_Min_Sketch< int > &s)
static Count_Min_Sketch< int > make(const size_t n)
static DynArrayHeap< int > make(const size_t n)
static bool is_empty(const DynArrayHeap< int > &h)
static DynSkipList< int > make(const size_t n)
static bool is_empty(const DynSkipList< int > &l)
static bool is_empty(const Euler_Tour_LCA< int > &l)
static void use(Euler_Tour_LCA< int > &l)
static Euler_Tour_LCA< int > make(const size_t n)
static bool is_empty(const Fenwick_Tree< int > &f)
static Fenwick_Tree< int > make(const size_t n)
static bool is_empty(const HyperLogLog< int > &h)
static HyperLogLog< int > make(const size_t n)
static bool is_empty(const Li_Chao_Tree< long > &t)
static Li_Chao_Tree< long > make(const size_t n)
static bool is_empty(const MinHash< int > &m)
static MinHash< int > make(const size_t n)
static ModularCombinatorics make(const size_t n)
static bool is_empty(const ModularCombinatorics &m)
static void use(PersistentHashMap< int, int > &m)
static PersistentHashMap< int, int > make(const size_t n)
static bool is_empty(const PersistentHashMap< int, int > &m)
static PersistentVector< int > make(const size_t n)
static void use(PersistentVector< int > &v)
static bool is_empty(const PersistentVector< int > &v)
static Pointer_Table make(const size_t n)
static bool is_empty(const Pointer_Table &t)
static Rand_Tree< int > make(const size_t n)
static bool is_empty(const Rand_Tree< int > &t)
static Random_Set< int > make(const size_t n)
static bool is_empty(const Random_Set< int > &q)
static Range_Fenwick_Tree< int > make(const size_t n)
static bool is_empty(const Range_Fenwick_Tree< int > &f)
static void use(Range_Fenwick_Tree< int > &f)
static void use(Reservoir_Sampler< int > &r)
static bool is_empty(const Reservoir_Sampler< int > &r)
static Reservoir_Sampler< int > make(const size_t n)
static Segment_Tree_Beats< int > make(const size_t n)
static void use(Segment_Tree_Beats< int > &t)
static bool is_empty(const Segment_Tree_Beats< int > &t)
static bool is_empty(const Skip_List &l)
static Skip_List make(const size_t n)
static Sum_Disjoint_Sparse_Table< int > make(const size_t n)
static bool is_empty(const Sum_Disjoint_Sparse_Table< int > &t)
static void use(Sum_Disjoint_Sparse_Table< int > &t)
How the moved-from tests build, check and use objects of a class.
Definition moved_from.H:92
static size_t fingerprint(const Tree &t)
static bool is_empty(Tree &t)
static Tree make(const size_t n)
static bool is_empty(const Tree &t)
static Tree make(const size_t n)
static Tree make(const size_t n)
static bool is_empty(const Tree &t)
static bool is_empty(const Filter &f)
static Filter make(const size_t n)
static Table make(const size_t n)
static bool is_empty(const Table &t)
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
int keys[]
static int * k
Gsl_Compatible_Rng r
B-Tree implementation with configurable minimum degree.
B+ Tree implementation with linked leaves and configurable degree.
Cartesian Tree, LCA via Euler Tour, and RMQ via Cartesian Tree.
Disjoint Sparse Table for static range queries in O(1).
Array-based dynamic binary heap.
Dynamic ordered set implemented with a Skip List.
Fenwick tree (Binary Indexed Tree) for prefix queries.
Immutable path-copying hash map backed by a HAMT.
Immutable bitmapped-vector trie with structural sharing.
Randomized binary search tree.
Random access queue (bag) with O(1) random pop.
Segment trees for dynamic range queries with lazy propagation.
Skip list: probabilistic sorted linked structure.
Sparse Table for static range queries in O(1).
Treap with rank (order statistics).
Treap: randomized BST combining tree and heap properties.
DynList< int > l