Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
condition_conversions_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
32
39// A comparison, or a filter of arcs or of items, may return a type that
40// converts to bool in two ways: implicitly, where it is returned or
41// assigned, and explicitly, where it is a condition. The intervals and
42// their trees, the filtered iterators of the graphs and of the containers,
43// Kruskal, the searches of the containers and the sorts take such a result
44// as a condition, and were noexcept when the implicit conversion did not
45// throw, or the call alone in the searches and the sorts: with a result
46// whose conversion there throws, the program ended instead of the exception
47// reaching the caller. They are now noexcept when the conversion that they
48// make is. So are the functors that compare by default, as Aleph::less,
49// the equality of an interval, the searches of the stack and of the queue
50// of lists and those of a graph by what its nodes and arcs hold, and the
51// iterators on the arcs of a node with a filter of the caller. And
52// traverse() of the containers converts what its operation returns, where
53// it negated it.
54
55#include <gtest/gtest.h>
56
57#include <stdexcept>
58#include <tuple>
59#include <type_traits>
60#include <utility>
61
62#include <Kruskal.H>
63#include <ahFunction.H>
64#include <filter_iterator.H>
65#include <htlist.H>
66#include <tpl_agraph.H>
67#include <tpl_array.H>
68#include <tpl_arrayHeap.H>
69#include <tpl_arrayQueue.H>
70#include <tpl_arrayStack.H>
71#include <tpl_dynArray.H>
72#include <tpl_dynArrayHeap.H>
73#include <tpl_dynDlist.H>
74#include <tpl_dynListQueue.H>
75#include <tpl_dynListStack.H>
76#include <tpl_dynSkipList.H>
77#include <tpl_graph.H>
78#include <tpl_interval_tree.H>
79#include <tpl_sgraph.H>
80#include <tpl_sort_utils.H>
81
82using namespace Aleph;
83
84namespace
85{
86 struct Conversion_Error : std::runtime_error
87 {
88 Conversion_Error() : std::runtime_error("the conversion in a condition") {}
89 };
90
91 // What the comparison and the filters of these tests return. Its implicit
92 // conversion to bool does not throw; the explicit one, which a condition
93 // chooses for a result that has no name, throws while armed
94 struct Sly_Bool
95 {
96 static inline bool armed = false;
97 bool value;
98
99 operator bool () const & noexcept { return value; }
100
101 explicit operator bool () &&
102 {
103 if (armed)
104 throw Conversion_Error();
105 return value;
106 }
107 };
108
109 struct Arm
110 {
111 Arm() noexcept { Sly_Bool::armed = true; }
112 ~Arm() { Sly_Bool::armed = false; }
113 };
114
115 struct Sly_Less
116 {
117 Sly_Bool operator () (const int & a, const int & b) const noexcept { return {a < b}; }
118 };
119
120 // What the comparison of the sorts returns: it has one conversion to
121 // bool, which throws while armed
122 struct Loud_Bool
123 {
124 bool value;
125
126 operator bool () const
127 {
128 if (Sly_Bool::armed)
129 throw Conversion_Error();
130 return value;
131 }
132 };
133
134 struct Loud_Less
135 {
136 Loud_Bool operator () (const int & a, const int & b) const noexcept { return {a < b}; }
137 };
138
139 // An item whose comparisons do not throw, and return such a result
140 struct Loud_Item
141 {
142 int v = 0;
143 Loud_Item(const int x = 0) noexcept : v(x) {}
144 };
145 Loud_Bool operator < (const Loud_Item & a, const Loud_Item & b) noexcept { return {a.v < b.v}; }
146 Loud_Bool operator > (const Loud_Item & a, const Loud_Item & b) noexcept { return {a.v > b.v}; }
147 Loud_Bool operator <= (const Loud_Item & a, const Loud_Item & b) noexcept { return {a.v <= b.v}; }
148 Loud_Bool operator >= (const Loud_Item & a, const Loud_Item & b) noexcept { return {a.v >= b.v}; }
149 Loud_Bool operator == (const Loud_Item & a, const Loud_Item & b) noexcept { return {a.v == b.v}; }
150 Loud_Bool operator != (const Loud_Item & a, const Loud_Item & b) noexcept { return {a.v != b.v}; }
151
152 // A flag whose logical operators do the same
153 struct Loud_Flag
154 {
155 bool v = false;
156 };
157 Loud_Bool operator && (const Loud_Flag & a, const Loud_Flag & b) noexcept { return {a.v and b.v}; }
158 Loud_Bool operator || (const Loud_Flag & a, const Loud_Flag & b) noexcept { return {a.v or b.v}; }
159 Loud_Bool operator ! (const Loud_Flag & a) noexcept { return {not a.v}; }
160
161 // A predicate for unary_negate
162 struct Loud_Odd
163 {
164 using argument_type = int;
165 Loud_Bool operator () (const int & x) const noexcept { return {x % 2 != 0}; }
166 };
167
168 // Another one, whose result has a negation that does not throw and a
169 // conversion that does while armed: unary_negate converts it
170 struct Quiet_Not
171 {
172 bool value;
173 explicit operator bool () const
174 {
175 if (Sly_Bool::armed)
176 throw Conversion_Error();
177 return value;
178 }
179 bool operator ! () const noexcept { return not value; }
180 };
181 struct Quiet_Not_Odd
182 {
183 using argument_type = int;
184 Quiet_Not operator () (const int & x) const noexcept { return {x % 2 != 0}; }
185 };
186
187 // What an operation of traverse() may return: its conversion to bool
188 // does not throw, and its negation throws while armed
189 struct Not_Throws
190 {
191 bool value;
192 explicit operator bool () const noexcept { return value; }
193 bool operator ! () const
194 {
195 if (Sly_Bool::armed)
196 throw Conversion_Error();
197 return not value;
198 }
199 };
200
201 // How many times each of the items 1 to 5 is in a container, as a number
202 // of five digits: 11111 if each one is there once
203 template <class Container>
204 long census(const Container & c)
205 {
206 long digits = 0;
207 c.for_each([&digits] (const int & x)
208 {
209 long unit = 1;
210 for (int i = 1; i < x; ++i)
211 unit *= 10;
212 digits += unit;
213 });
214 return digits;
215 }
216
217 template <class Item>
218 struct Sly_Show
219 {
220 Sly_Bool operator () (const Item &) const noexcept { return {true}; }
221 };
222
223 // the old test of the specifications says that nothing throws
224 static_assert(std::is_nothrow_invocable_r_v<bool, const Sly_Less &, const int &, const int &>);
225 static_assert(not NothrowPredicateWith<const Sly_Less &, const int &, const int &>);
226
229 using Arc_Show = Sly_Show<Edges::Arc *>;
230 using Darc_Show = Sly_Show<Arrows::Arc *>;
231
232 // a -> b -> c, and a -> c
233 template <class GT>
234 struct Triangle
235 {
236 GT g;
237 typename GT::Node * a = g.insert_node(1);
238 typename GT::Node * b = g.insert_node(2);
239 typename GT::Node * c = g.insert_node(3);
240
241 Triangle()
242 {
243 g.insert_arc(a, b, 1);
244 g.insert_arc(b, c, 2);
245 g.insert_arc(a, c, 3);
246 }
247 };
248
249 // A filter of the arcs of a node of the kind that In_Iterator and
250 // Out_Iterator give to Digraph_Iterator: it shows every arc
251 template <class GT>
252 struct Sly_Arc_Filter
253 {
254 Sly_Arc_Filter(typename GT::Node * = nullptr) noexcept {}
255 Sly_Bool operator () (typename GT::Arc *) const noexcept { return {true}; }
256 typename GT::Node * get_node(typename GT::Arc * a) const noexcept
257 {
258 return static_cast<typename GT::Node *>(a->tgt_node);
259 }
260 };
261
262 // A filter that tells an item that has a name from one that has none,
263 // and counts the calls with each: only the second one is noexcept
264 template <class Item>
265 struct Two_Calls
266 {
267 static inline size_t named = 0, unnamed = 0;
268
269 bool operator () (Item *&) const
270 {
271 ++named;
272 return true;
273 }
274
275 bool operator () (Item *&&) const noexcept
276 {
277 ++unnamed;
278 return true;
279 }
280 };
281
282 // Whether next_ne() of the iterator It, built with args and taken to
283 // its end, is noexcept exactly when no call that It made of its
284 // filter is the one that may throw
285 template <class It, class Item, class... Args>
286 bool says_what_it_calls(Args &&... args)
287 {
288 Two_Calls<Item>::named = Two_Calls<Item>::unnamed = 0;
289 for (It it(std::forward<Args>(args)...); it.has_curr(); it.next_ne())
290 ;
291 const size_t named = Two_Calls<Item>::named;
292 return named + Two_Calls<Item>::unnamed > 0
293 and noexcept(std::declval<It &>().next_ne()) == (named == 0);
294 }
295
296 // The five filtered iterators of a graph type
297 template <class GT>
298 void each_iterator_says_what_it_calls()
299 {
300 using Arcs = Two_Calls<typename GT::Arc>;
301 using Nodes = Two_Calls<typename GT::Node>;
302 Triangle<GT> t;
303 EXPECT_TRUE((says_what_it_calls<Node_Arc_Iterator<GT, Arcs>, typename GT::Arc>(t.a)));
304 EXPECT_TRUE((says_what_it_calls<Arc_Iterator<GT, Arcs>, typename GT::Arc>(t.g)));
305 EXPECT_TRUE((says_what_it_calls<Out_Iterator<GT, Arcs>, typename GT::Arc>(t.a)));
306 EXPECT_TRUE((says_what_it_calls<In_Iterator<GT, Arcs>, typename GT::Arc>(t.g, t.c)));
307 EXPECT_TRUE((says_what_it_calls<Node_Iterator<GT, Nodes>, typename GT::Node>(t.g)));
308 }
309}
310
311// The functors that compare by default return a bool: they convert what
312// the operator of the items returns
313TEST(ConditionConversions, TheDefaultFunctors)
314{
315 const Loud_Item a(1), b(2);
316 const Loud_Flag yes{true}, no{false};
317 static_assert(not noexcept(Aleph::less<Loud_Item>()(a, b)));
318 static_assert(not noexcept(Aleph::greater<Loud_Item>()(a, b)));
319 static_assert(not noexcept(Aleph::less_equal<Loud_Item>()(a, b)));
320 static_assert(not noexcept(Aleph::greater_equal<Loud_Item>()(a, b)));
321 static_assert(not noexcept(Aleph::equal_to<Loud_Item>()(a, b)));
322 static_assert(not noexcept(Aleph::not_equal_to<Loud_Item>()(a, b)));
323 static_assert(not noexcept(Aleph::logical_and<Loud_Flag>()(yes, no)));
324 static_assert(not noexcept(Aleph::logical_or<Loud_Flag>()(yes, no)));
325 static_assert(not noexcept(Aleph::logical_not<Loud_Flag>()(yes)));
326 // the call alone: the constructor of unary_negate says nothing
327 static_assert(not noexcept(std::declval<const Aleph::unary_negate<Loud_Odd> &>()(1)));
328 static_assert(not noexcept(std::declval<const Aleph::unary_negate<Quiet_Not_Odd> &>()(1)));
329 // and with operators that return a bool they are, as before
330 static_assert(noexcept(Aleph::less<int>()(1, 2)));
331 static_assert(noexcept(Aleph::greater<int>()(1, 2)));
332 static_assert(noexcept(Aleph::less_equal<int>()(1, 2)));
333 static_assert(noexcept(Aleph::greater_equal<int>()(1, 2)));
334 static_assert(noexcept(Aleph::equal_to<int>()(1, 2)));
335 static_assert(noexcept(Aleph::not_equal_to<int>()(1, 2)));
336 static_assert(noexcept(Aleph::logical_and<bool>()(true, false)));
337 static_assert(noexcept(Aleph::logical_or<bool>()(true, false)));
338 static_assert(noexcept(Aleph::logical_not<bool>()(true)));
339
340 EXPECT_TRUE(Aleph::less<Loud_Item>()(a, b));
341 EXPECT_FALSE(Aleph::greater<Loud_Item>()(a, b));
342 EXPECT_TRUE(Aleph::less_equal<Loud_Item>()(a, a));
343 EXPECT_FALSE(Aleph::greater_equal<Loud_Item>()(a, b));
344 EXPECT_FALSE(Aleph::equal_to<Loud_Item>()(a, b));
345 EXPECT_TRUE(Aleph::not_equal_to<Loud_Item>()(a, b));
346 EXPECT_FALSE(Aleph::logical_and<Loud_Flag>()(yes, no));
347 EXPECT_TRUE(Aleph::logical_or<Loud_Flag>()(yes, no));
348 EXPECT_FALSE(Aleph::logical_not<Loud_Flag>()(yes));
349 EXPECT_TRUE(Aleph::unary_negate<Loud_Odd>(Loud_Odd())(2));
350 EXPECT_TRUE(Aleph::unary_negate<Quiet_Not_Odd>(Quiet_Not_Odd())(2));
351
352 // a heap that compares with the default functor lets the exception out,
353 // and is as it was
354 ArrayHeap<Loud_Item> heap(8);
355 heap.insert(b);
356
357 const Arm arm;
358 EXPECT_THROW((void) Aleph::less<Loud_Item>()(a, b), Conversion_Error);
359 EXPECT_THROW((void) Aleph::greater<Loud_Item>()(a, b), Conversion_Error);
360 EXPECT_THROW((void) Aleph::less_equal<Loud_Item>()(a, b), Conversion_Error);
361 EXPECT_THROW((void) Aleph::greater_equal<Loud_Item>()(a, b), Conversion_Error);
362 EXPECT_THROW((void) Aleph::equal_to<Loud_Item>()(a, b), Conversion_Error);
363 EXPECT_THROW((void) Aleph::not_equal_to<Loud_Item>()(a, b), Conversion_Error);
364 EXPECT_THROW((void) Aleph::logical_and<Loud_Flag>()(yes, no), Conversion_Error);
365 EXPECT_THROW((void) Aleph::logical_or<Loud_Flag>()(yes, no), Conversion_Error);
366 EXPECT_THROW((void) Aleph::logical_not<Loud_Flag>()(yes), Conversion_Error);
367 EXPECT_THROW((void) Aleph::unary_negate<Loud_Odd>(Loud_Odd())(2), Conversion_Error);
368 EXPECT_THROW((void) Aleph::unary_negate<Quiet_Not_Odd>(Quiet_Not_Odd())(2), Conversion_Error);
369 EXPECT_THROW(heap.insert(a), Conversion_Error);
370 EXPECT_EQ(heap.size(), 1u);
371}
372
373// overlaps(), contains() and is_valid() of an interval, and Interval_Less
374TEST(ConditionConversions, Intervals)
375{
376 using I = Interval<int>;
377 static_assert(not noexcept(std::declval<const I &>().overlaps(std::declval<const I &>(), Sly_Less())));
378 static_assert(not noexcept(std::declval<const I &>().contains(1, Sly_Less())));
379 static_assert(not noexcept(std::declval<const I &>().is_valid(Sly_Less())));
380 static_assert(not noexcept(std::declval<const Interval_Less<int, Sly_Less> &>()(std::declval<const I &>(),
381 std::declval<const I &>())));
382 // and with a comparison whose result is a bool they are, as before
383 static_assert(noexcept(std::declval<const I &>().overlaps(std::declval<const I &>())));
384 static_assert(noexcept(std::declval<const I &>().contains(1)));
385 static_assert(noexcept(std::declval<const I &>().is_valid()));
386 static_assert(noexcept(std::declval<const Interval_Less<int> &>()(std::declval<const I &>(),
387 std::declval<const I &>())));
388
389 const I a(1, 5), b(4, 9), c(7, 8);
390 const Sly_Less less;
392 EXPECT_TRUE(a.overlaps(b, less));
393 EXPECT_FALSE(a.overlaps(c, less));
394 EXPECT_TRUE(a.contains(5, less));
395 EXPECT_FALSE(a.contains(6, less));
396 EXPECT_TRUE(a.is_valid(less));
397 EXPECT_TRUE(before(a, b));
398 EXPECT_FALSE(before(b, a));
399
400 const Arm arm;
401 EXPECT_THROW((void) a.overlaps(b, less), Conversion_Error);
402 EXPECT_THROW((void) a.contains(5, less), Conversion_Error);
403 EXPECT_THROW((void) a.is_valid(less), Conversion_Error);
404 EXPECT_THROW((void) before(a, b), Conversion_Error);
405}
406
407// The equality of two intervals, by that of their endpoints
408TEST(ConditionConversions, EqualityOfIntervals)
409{
410 using L = Interval<Loud_Item>;
411 static_assert(not noexcept(std::declval<const L &>() == std::declval<const L &>()));
412 static_assert(not noexcept(std::declval<const L &>() != std::declval<const L &>()));
413 static_assert(noexcept(std::declval<const Interval<int> &>() == std::declval<const Interval<int> &>()));
414 static_assert(noexcept(std::declval<const Interval<int> &>() != std::declval<const Interval<int> &>()));
415
416 const L x(Loud_Item(1), Loud_Item(5)), y(Loud_Item(1), Loud_Item(5)), z(Loud_Item(1), Loud_Item(6));
417 EXPECT_TRUE(x == y);
418 EXPECT_FALSE(x == z);
419 EXPECT_TRUE(x != z);
420
421 const Arm arm;
422 EXPECT_THROW((void) (x == y), Conversion_Error);
423 EXPECT_THROW((void) (x != z), Conversion_Error);
424}
425
426// search() of a tree of intervals
427TEST(ConditionConversions, IntervalTree)
428{
430 static_assert(not noexcept(std::declval<const Tree &>().search(std::declval<const Interval<int> &>())));
431 static_assert(noexcept(std::declval<const DynIntervalTree<int> &>().search(std::declval<const Interval<int> &>())));
432
433 Tree tree;
434 for (int i = 0; i < 20; ++i)
435 tree.insert(Interval<int>(i, i + 3));
436 EXPECT_TRUE(tree.search(Interval<int>(7, 10)));
437 EXPECT_FALSE(tree.search(Interval<int>(7, 11)));
438
439 const Arm arm;
440 EXPECT_THROW((void) tree.search(Interval<int>(7, 10)), Conversion_Error);
441}
442
443// The iterators on the arcs of a node that take a filter, and the searches
444// through them
445TEST(ConditionConversions, ArcFiltersOfANode)
446{
449 using Node_Arcs = Node_Arc_Iterator<Edges, Arc_Show>;
450 static_assert(not nothrow_arc_filter_v<Edges, Arc_Show>);
451 static_assert(nothrow_arc_filter_v<Edges, Dft_Show_Arc<Edges>>);
452 static_assert(not noexcept(std::declval<Out &>().next_ne()));
453 static_assert(not noexcept(std::declval<In &>().next_ne()));
454 static_assert(not noexcept(std::declval<Node_Arcs &>().next_ne()));
455 static_assert(noexcept(std::declval<Out_Iterator<Arrows> &>().next_ne()));
456 static_assert(noexcept(std::declval<In_Iterator<Edges> &>().next_ne()));
457 static_assert(noexcept(std::declval<Node_Arc_Iterator<Edges> &>().next_ne()));
458 static_assert(not noexcept(search_arc(std::declval<const Edges &>(), std::declval<Edges::Node *>(),
459 std::declval<Edges::Node *>(), Arc_Show())));
460 static_assert(noexcept(search_arc(std::declval<const Edges &>(), std::declval<Edges::Node *>(),
461 std::declval<Edges::Node *>())));
462
465 {
466 Out out(d.a);
467 size_t n = 0;
468 for (; out.has_curr(); out.next_ne())
469 ++n;
470 EXPECT_EQ(n, 2u);
471
472 In in(u.c);
473 n = 0;
474 for (; in.has_curr(); in.next_ne())
475 ++n;
476 EXPECT_EQ(n, 2u);
477 EXPECT_NE(search_arc(u.g, u.a, u.c, Arc_Show()), nullptr);
478 }
479
480 Out out(d.a);
481 In in(u.c);
482 Node_Arcs arcs(u.a);
483 const Arm arm;
484 EXPECT_THROW(out.next_ne(), Conversion_Error);
485 EXPECT_THROW(in.next_ne(), Conversion_Error);
486 EXPECT_THROW(arcs.next_ne(), Conversion_Error);
487 EXPECT_THROW(Out again(d.a), Conversion_Error);
488 EXPECT_THROW((void) search_arc(u.g, u.a, u.c, Arc_Show()), Conversion_Error);
489}
490
491// The walk on the arcs into a node of a digraph, among the arcs of the graph
492TEST(ConditionConversions, ArcsIntoANodeOfADigraph)
493{
495 static_assert(not noexcept(std::declval<In &>().next_ne()));
496 static_assert(noexcept(std::declval<In_Iterator<Arrows> &>().next_ne()));
497
499 {
500 size_t n = 0;
501 for (In in(d.g, d.c); in.has_curr(); in.next_ne())
502 ++n;
503 EXPECT_EQ(n, 2u);
504 }
505
506 In in(d.g, d.c);
507 const Arm arm;
508 EXPECT_THROW(in.next_ne(), Conversion_Error);
509}
510
511// A specification looks at the call of the filter that the iterator
512// makes, with the item as the iterator gives it: the walk on the arcs
513// into a node of a digraph gives an arc that has a name, and the other
514// iterators give one that has none. A filter may tell the two apart
515TEST(ConditionConversions, EachFilteredIteratorLooksAtTheCallThatItMakes)
516{
517 using Named = Two_Calls<Arrows::Arc>;
518 static_assert(not NothrowPredicateWith<Named &, Arrows::Arc *&>);
519 static_assert(NothrowPredicateWith<Named &, Arrows::Arc *>);
520 static_assert(not noexcept(std::declval<In_Iterator<Arrows, Named> &>().next_ne()));
521 static_assert(noexcept(std::declval<Out_Iterator<Arrows, Named> &>().next_ne()));
522
523 {
524 SCOPED_TRACE("List_Graph");
525 each_iterator_says_what_it_calls<Edges>();
526 }
527 {
528 SCOPED_TRACE("List_Digraph");
529 each_iterator_says_what_it_calls<Arrows>();
530 }
531 {
532 SCOPED_TRACE("List_SGraph");
533 each_iterator_says_what_it_calls<List_SGraph<Graph_Snode<int>, Graph_Sarc<int>>>();
534 }
535 {
536 SCOPED_TRACE("List_SDigraph");
537 each_iterator_says_what_it_calls<List_SDigraph<Graph_Snode<int>, Graph_Sarc<int>>>();
538 }
539 {
540 SCOPED_TRACE("Array_Graph");
541 each_iterator_says_what_it_calls<Array_Graph<Graph_Anode<int>, Graph_Aarc<int>>>();
542 }
543 {
544 SCOPED_TRACE("Array_Digraph");
545 each_iterator_says_what_it_calls<Array_Digraph<Graph_Anode<int>, Graph_Aarc<int>>>();
546 }
547}
548
549// The filtered iterator of the containers
550TEST(ConditionConversions, FilterIterator)
551{
552 using List = DynList<int>;
554 static_assert(not noexcept(std::declval<It &>().next_ne()));
555
556 List l = {1, 2, 3};
557 {
558 size_t n = 0;
559 for (It it(l); it.has_curr(); it.next_ne())
560 ++n;
561 EXPECT_EQ(n, 3u);
562 }
563
564 It it(l);
565 const Arm arm;
566 EXPECT_THROW(it.next_ne(), Conversion_Error);
567 EXPECT_THROW(It again(l), Conversion_Error);
568}
569
570// The searches of the containers: find_ptr(), find_index() and find_item()
571TEST(ConditionConversions, SearchesOfAContainer)
572{
573 using List = DynList<int>;
574 Sly_Show<int> show; // shows every item: the first one is found
575 const auto second = [] (const int & x) noexcept { return x == 2; };
576 static_assert(not noexcept(std::declval<const List &>().find_ptr(show)));
577 static_assert(not noexcept(std::declval<List &>().find_ptr(show)));
578 static_assert(not noexcept(std::declval<const List &>().find_index(show)));
579 static_assert(not noexcept(std::declval<const List &>().find_item(show)));
580 static_assert(noexcept(std::declval<const List &>().find_ptr(second)));
581 static_assert(noexcept(std::declval<List &>().find_ptr(second)));
582 static_assert(noexcept(std::declval<const List &>().find_index(second)));
583
584 List l = {1, 2, 3};
585 const List & cl = l;
586 ASSERT_NE(cl.find_ptr(show), nullptr);
587 EXPECT_EQ(*cl.find_ptr(show), 1);
588 EXPECT_EQ(cl.find_index(show), 0u);
589 ASSERT_NE(l.find_ptr(second), nullptr);
590 EXPECT_EQ(*l.find_ptr(second), 2);
591 EXPECT_TRUE(std::get<0>(cl.find_item(show)));
592
593 const Arm arm;
594 EXPECT_THROW((void) cl.find_ptr(show), Conversion_Error);
595 EXPECT_THROW((void) l.find_ptr(show), Conversion_Error);
596 EXPECT_THROW((void) cl.find_index(show), Conversion_Error);
597 EXPECT_THROW((void) cl.find_item(show), Conversion_Error);
598}
599
600// The searches of the stack and of the queue of lists, by the == of their
601// items
602TEST(ConditionConversions, SearchesOfAStackAndOfAQueue)
603{
604 using Stack = DynListStack<Loud_Item>;
605 using Queue = DynListQueue<Loud_Item>;
606 const Loud_Item one(1), two(2), three(3);
607 static_assert(not noexcept(std::declval<Stack &>().search(one)));
608 static_assert(not noexcept(std::declval<const Stack &>().search(one)));
609 static_assert(not noexcept(std::declval<const Stack &>().contains(one)));
610 static_assert(not noexcept(std::declval<const Stack &>().has(one)));
611 static_assert(not noexcept(std::declval<Queue &>().search(one)));
612 static_assert(not noexcept(std::declval<const Queue &>().search(one)));
613 static_assert(noexcept(std::declval<const DynListStack<int> &>().contains(1)));
614 static_assert(noexcept(std::declval<const DynListQueue<int> &>().search(1)));
615
616 Stack stack;
617 Queue queue;
618 for (const Loud_Item & item : {one, two})
619 {
620 stack.push(item);
621 queue.put(item);
622 }
623 const Stack & cstack = stack;
624 const Queue & cqueue = queue;
625 ASSERT_NE(stack.search(one), nullptr);
626 EXPECT_EQ(stack.search(one)->v, 1);
627 ASSERT_NE(cstack.search(two), nullptr);
628 EXPECT_TRUE(cstack.contains(two));
629 EXPECT_FALSE(cstack.has(three));
630 ASSERT_NE(queue.search(two), nullptr);
631 EXPECT_EQ(queue.search(two)->v, 2);
632 EXPECT_EQ(cqueue.search(three), nullptr);
633
634 const Arm arm;
635 EXPECT_THROW((void) stack.search(one), Conversion_Error);
636 EXPECT_THROW((void) cstack.search(one), Conversion_Error);
637 EXPECT_THROW((void) cstack.contains(one), Conversion_Error);
638 EXPECT_THROW((void) cstack.has(one), Conversion_Error);
639 EXPECT_THROW((void) queue.search(one), Conversion_Error);
640 EXPECT_THROW((void) cqueue.search(one), Conversion_Error);
641}
642
643// find_node() and find_arc() of a graph, by the == of what its nodes and
644// its arcs hold
645TEST(ConditionConversions, SearchesOfAGraphByWhatItHolds)
646{
648 const Loud_Item two(2), three(3), seven(7);
649 static_assert(not noexcept(std::declval<const Loud_Graph &>().find_node(two)));
650 static_assert(not noexcept(std::declval<const Loud_Graph &>().find_arc(three)));
651 static_assert(noexcept(std::declval<const Edges &>().find_node(1)));
652 static_assert(noexcept(std::declval<const Edges &>().find_arc(1)));
653
654 Loud_Graph g;
655 auto p = g.insert_node(Loud_Item(1));
656 auto q = g.insert_node(two);
657 auto a = g.insert_arc(p, q, three);
658 EXPECT_EQ(g.find_node(two), q);
659 EXPECT_EQ(g.find_node(seven), nullptr);
660 EXPECT_EQ(g.find_arc(three), a);
661 EXPECT_EQ(g.find_arc(seven), nullptr);
662
663 const Arm arm;
664 EXPECT_THROW((void) g.find_node(two), Conversion_Error);
665 EXPECT_THROW((void) g.find_arc(three), Conversion_Error);
666}
667
668// The iterators on the arcs of a node with a filter of the caller: the one
669// of tpl_graph.H and the one of the graph classes
670TEST(ConditionConversions, ArcsOfANodeThroughAFilterOfTheCaller)
671{
672 using Filter = Sly_Arc_Filter<Edges>;
674 using Member = Edges::Digraph_Iterator<Filter>;
675 static_assert(not Free::shows_ne);
676 static_assert(not Member::shows_ne);
677 static_assert(not noexcept(std::declval<Free &>().next_ne()));
678 static_assert(not noexcept(std::declval<Free &>().reset_first()));
679 static_assert(not noexcept(std::declval<Free &>().reset_last()));
680 static_assert(not noexcept(std::declval<Free &>().end()));
681 static_assert(noexcept(std::declval<Aleph::Digraph_Iterator<Edges, __Out_Filt<Edges>> &>().end()));
682 static_assert(not noexcept(std::declval<Member &>().next_ne()));
683 static_assert(not noexcept(std::declval<Member &>().reset_first()));
684 // and with the filters of the library they are, as before
685 static_assert(Edges::Out_Iterator::shows_ne);
686 static_assert(noexcept(std::declval<Edges::Out_Iterator &>().next_ne()));
687 static_assert(noexcept(std::declval<Edges::Out_Iterator &>().reset_first()));
688 static_assert(noexcept(std::declval<Edges::In_Iterator &>().next_ne()));
689 static_assert(noexcept(std::declval<Edges::In_Iterator &>().reset_first()));
690
692 Free free(u.a);
693 Member member(u.a);
694 size_t n = 0;
695 for (; free.has_curr(); free.next_ne())
696 ++n;
697 EXPECT_EQ(n, 2u);
698 for (n = 0; member.has_curr(); member.next_ne())
699 ++n;
700 EXPECT_EQ(n, 2u);
701 free.reset_first();
702 member.reset_first();
703 ASSERT_TRUE(free.has_curr());
704 ASSERT_TRUE(member.has_curr());
705
706 const Arm arm;
707 EXPECT_THROW(free.next_ne(), Conversion_Error);
708 EXPECT_THROW(free.reset_first(), Conversion_Error);
709 EXPECT_THROW(free.reset_last(), Conversion_Error);
710 EXPECT_THROW(free.end(), Conversion_Error);
711 EXPECT_THROW(member.next_ne(), Conversion_Error);
712 EXPECT_THROW(member.reset_first(), Conversion_Error);
713}
714
715// traverse() takes what its operation returns as a condition: it converts
716// it, where it negated it, which is another operator of the result
717TEST(ConditionConversions, TraverseConvertsWhatItsOperationReturns)
718{
719 const auto all = [] (const int &) noexcept { return Not_Throws{true}; };
720 const auto none = [] (const int &) noexcept { return Not_Throws{false}; };
721
722 DynList<int> list;
723 ArrayHeap<int> heap(8);
724 DynArrayHeap<int> dyn_heap;
725 MemArray<int> mem;
726 ArrayStack<int> stack;
727 FixedStack<int> fixed_stack;
728 ArrayQueue<int> queue;
729 FixedQueue<int> fixed;
730 DynArray<int> array;
731 DynSkipList<int> skip;
732 for (int i = 1; i <= 3; ++i)
733 {
734 list.append(i);
735 heap.insert(i);
736 dyn_heap.insert(i);
737 mem.append(i);
738 stack.push(i);
739 fixed_stack.push(i);
740 queue.put(i);
741 fixed.put(i);
742 array.append(i);
743 skip.insert(i);
744 }
745 static_assert(noexcept(std::declval<const DynList<int> &>().traverse(all)));
746 static_assert(noexcept(std::declval<const ArrayHeap<int> &>().traverse(all)));
747
748 const Arm arm;
749 const auto check = [&all, &none] (const auto & container, const char * name)
750 {
751 SCOPED_TRACE(name);
752 EXPECT_NO_THROW(EXPECT_TRUE(container.traverse(all)));
753 EXPECT_NO_THROW(EXPECT_FALSE(container.traverse(none)));
754 };
755 check(list, "DynList");
756 check(heap, "ArrayHeap");
757 check(dyn_heap, "DynArrayHeap");
758 check(mem, "MemArray");
759 check(stack, "ArrayStack");
760 check(fixed_stack, "FixedStack");
761 check(queue, "ArrayQueue");
762 check(fixed, "FixedQueue");
763 check(array, "DynArray");
764 check(skip, "DynSkipList");
765 // and so do the containers that are not const
766 EXPECT_NO_THROW(EXPECT_TRUE(list.traverse(all)));
767 EXPECT_NO_THROW(EXPECT_TRUE(heap.traverse(all)));
768 EXPECT_NO_THROW(EXPECT_TRUE(dyn_heap.traverse(all)));
769 EXPECT_NO_THROW(EXPECT_TRUE(mem.traverse(all)));
770 EXPECT_NO_THROW(EXPECT_TRUE(stack.traverse(all)));
771 EXPECT_NO_THROW(EXPECT_TRUE(fixed_stack.traverse(all)));
772 EXPECT_NO_THROW(EXPECT_TRUE(queue.traverse(all)));
773 EXPECT_NO_THROW(EXPECT_TRUE(fixed.traverse(all)));
774 EXPECT_NO_THROW(EXPECT_TRUE(array.traverse(all)));
775}
776
777// The sorts of arrays that are noexcept when the comparison is, and the
778// comparisons that the other sorts go through
779TEST(ConditionConversions, SortsOfArrays)
780{
781 int a[] = {3, 1, 2, 5, 4};
782 const long last = 4;
783 const size_t n = 5;
784 const Loud_Less less;
785 static_assert(not noexcept(selection_sort(a, n, less)));
786 static_assert(not noexcept(insertion_sort(a, 0L, last, less)));
787 static_assert(not noexcept(select_pivot(a, 0L, last, less)));
788 static_assert(not noexcept(partition(a, 0L, last, less)));
789 static_assert(not noexcept(bucket_sort_detail::insertion_sort_range(a, size_t{0}, n, less)));
790 static_assert(not noexcept(timsort_detail::binary_insertion_sort(a, size_t{0}, n, size_t{1}, less)));
791 static_assert(not noexcept(timsort_detail::gallop_left(a[0], a, n, size_t{0}, less)));
792 static_assert(not noexcept(timsort_detail::gallop_right(a[0], a, n, size_t{0}, less)));
793 static_assert(not noexcept(std::declval<const Negate_Compare<int, Loud_Less> &>()(1, 2)));
794 static_assert(not noexcept(std::declval<const Inversed_Compare<int, Loud_Less> &>()(1, 2)));
795 static_assert(not noexcept(std::declval<const Compare_Dnode<int, Loud_Less> &>()(
796 std::declval<Dlink *>(), std::declval<Dlink *>())));
797 static_assert(not noexcept(std::declval<const Compare_Dnode<int, Loud_Less> &>()(std::declval<Dlink *>(), 1)));
798 // and with a comparison that returns a bool they are, as before
799 static_assert(noexcept(selection_sort(a, n)));
800 static_assert(noexcept(insertion_sort(a, 0L, last)));
801 static_assert(noexcept(select_pivot(a, 0L, last)));
802 static_assert(noexcept(partition(a, 0L, last)));
803 static_assert(noexcept(timsort_detail::gallop_left(a[0], a, n, size_t{0}, Aleph::less<int>())));
804 static_assert(noexcept(std::declval<const Negate_Compare<int, Aleph::less<int>> &>()(1, 2)));
805 static_assert(noexcept(std::declval<const Inversed_Compare<int, Aleph::less<int>> &>()(1, 2)));
806 static_assert(noexcept(std::declval<const Compare_Dnode<int, Aleph::less<int>> &>()(
807 std::declval<Dlink *>(), std::declval<Dlink *>())));
808
809 selection_sort(a, n, less);
810 EXPECT_EQ(Array<int>({a[0], a[1], a[2], a[3], a[4]}), Array<int>({1, 2, 3, 4, 5}));
811
812 // each sort lets the conversion throw, and keeps the items
813 const auto fails = [&a] (auto sort)
814 {
815 const int unsorted[] = {3, 1, 2, 5, 4};
816 for (size_t i = 0; i < 5; ++i)
817 a[i] = unsorted[i];
818 const Arm arm;
819 EXPECT_THROW(sort(), Conversion_Error);
820 long digits = 0;
821 for (const int x : a)
822 {
823 long unit = 1;
824 for (int i = 1; i < x; ++i)
825 unit *= 10;
826 digits += unit;
827 }
828 EXPECT_EQ(digits, 11111);
829 };
830 fails([&] { selection_sort(a, n, less); });
831 fails([&] { (void) select_pivot(a, 0L, last, less); });
832 fails([&] { (void) partition(a, 0L, last, less); });
833 fails([&] { heapsort(a, n, less); });
834 fails([&] { faster_heapsort(a, n, less); });
835 fails([&] { (void) timsort_detail::gallop_left(a[0], a, n, size_t{0}, less); });
836 fails([&] { (void) timsort_detail::gallop_right(a[0], a, n, size_t{0}, less); });
837}
838
839// The sorts of lists, which link the nodes again: they take the way that
840// undoes when the conversion may throw, and the list keeps every item
841TEST(ConditionConversions, SortsOfLists)
842{
843 const Loud_Less less;
844 const auto expect_keeps_every_item = [] (auto & list, auto sort)
845 {
846 for (const int x : {3, 1, 2, 5, 4})
847 list.append(x);
848 {
849 const Arm arm;
850 EXPECT_THROW(sort(list), Conversion_Error);
851 }
852 EXPECT_EQ(list.size(), 5u);
853 EXPECT_EQ(census(list), 11111);
854 sort(list); // and it sorts them, when the conversion does not throw
855 EXPECT_EQ(list.get_first(), 1);
856 EXPECT_EQ(list.get_last(), 5);
857 EXPECT_EQ(census(list), 11111);
858 };
860 expect_keeps_every_item(l1, [&less] (DynList<int> & l) { mergesort(l, less); });
861 expect_keeps_every_item(l2, [&less] (DynList<int> & l) { insertion_sort(l, less); });
862 expect_keeps_every_item(l3, [&less] (DynList<int> & l) { mergeinsertsort(l, less); });
863 DynDlist<int> d1, d2, d3;
864 expect_keeps_every_item(d1, [&less] (DynDlist<int> & l) { mergesort(l, less); });
865 expect_keeps_every_item(d2, [&less] (DynDlist<int> & l) { insertion_sort(l, less); });
866 expect_keeps_every_item(d3, [&less] (DynDlist<int> & l) { mergeinsertsort(l, less); });
867}
868
869// sort_nodes() and sort_arcs() of a graph, which compare pointers
870TEST(ConditionConversions, SortsOfTheNodesAndArcsOfAGraph)
871{
872 struct By_Info
873 {
874 Loud_Bool operator () (Edges::Node * p, Edges::Node * q) const noexcept
875 {
876 return {p->get_info() > q->get_info()};
877 }
878
879 Loud_Bool operator () (Edges::Arc * a, Edges::Arc * b) const noexcept
880 {
881 return {a->get_info() > b->get_info()};
882 }
883 };
884 struct Plain
885 {
886 bool operator () (Edges::Node * p, Edges::Node * q) const noexcept { return p->get_info() > q->get_info(); }
887 };
888 static_assert(not noexcept(std::declval<Edges &>().sort_nodes(std::declval<By_Info &>())));
889 static_assert(not noexcept(std::declval<Edges &>().sort_arcs(std::declval<By_Info &>())));
890 static_assert(noexcept(std::declval<Edges &>().sort_nodes(std::declval<Plain &>())));
891
893 By_Info by_info;
894 {
895 const Arm arm;
896 EXPECT_THROW(u.g.sort_nodes(by_info), Conversion_Error);
897 EXPECT_THROW(u.g.sort_arcs(by_info), Conversion_Error);
898 }
899 EXPECT_EQ(u.g.get_num_nodes(), 3u);
900 EXPECT_EQ(u.g.get_num_arcs(), 3u);
901 size_t nodes = 0, arcs = 0;
902 for (Edges::Node_Iterator it(u.g); it.has_curr(); it.next_ne())
903 ++nodes;
904 for (Edges::Arc_Iterator it(u.g); it.has_curr(); it.next_ne())
905 ++arcs;
906 EXPECT_EQ(nodes, 3u);
907 EXPECT_EQ(arcs, 3u);
908
909 u.g.sort_nodes(by_info);
910 EXPECT_EQ(u.g.get_first_node()->get_info(), 3);
911 u.g.sort_arcs(by_info);
912 EXPECT_EQ(u.g.get_first_arc()->get_info(), 3);
913}
914
915// The filter of the arcs that Kruskal paints
916TEST(ConditionConversions, PaintedArcsOfKruskal)
917{
918 using Kruskal = Kruskal_Min_Spanning_Tree<Edges, Dft_Dist<Edges>, Arc_Show>;
919 using Filter = Kruskal::Paint_Filt<Edges, Arc_Show>;
920 static_assert(not noexcept(std::declval<const Filter &>()(std::declval<Edges::Arc *>())));
922 static_assert(noexcept(std::declval<const Plain &>()(std::declval<Edges::Arc *>())));
923
925 Arc_Show show;
926 const Filter painted(show);
927 Edges::Arc * arc = u.g.get_first_arc();
928 EXPECT_FALSE(painted(arc));
929
930 // it gives the filter of the caller the arc by its name
931 using Named = Two_Calls<Edges::Arc>;
932 using Through = Kruskal::Paint_Filt<Edges, Named>;
933 static_assert(not noexcept(std::declval<const Through &>()(std::declval<Edges::Arc *>())));
934 Named named;
935 const Through through(named);
936 Named::named = Named::unnamed = 0;
937 EXPECT_FALSE(through(arc));
938 EXPECT_EQ(Named::named, 1u);
939 EXPECT_EQ(Named::unnamed, 0u);
940
941 const Arm arm;
942 EXPECT_THROW((void) painted(arc), Conversion_Error);
943}
Kruskal's minimum spanning tree algorithm.
bool operator>=(const Time &l, const Time &r)
Definition ah-time.H:173
bool operator>(const Time &l, const Time &r)
Definition ah-time.H:167
bool operator<(const Time &l, const Time &r)
Definition ah-time.H:143
bool operator<=(const Time &l, const Time &r)
Definition ah-time.H:155
Standard functor implementations and comparison objects.
size_t size_t int32_t value
Definition ca-c-api.h:116
size_t size_t int32_t * out
Definition ca-c-api.h:120
Fixed-capacity binary heap backed by a raw array.
bool traverse(Operation &operation) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
Traverse all elements (const overload).
T & insert(const T &key)
Insert an element into the heap.
constexpr size_t size() const noexcept
Return the number of elements currently stored.
Queue implemented with a single dynamic array.
T & put(const T &item)
Copy and put an item in the queue.
bool traverse(Operation &operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
Traverse all the elements from the oldest to the youngest and execute operation on each on them.
Stack implemented with simple dynamic array and with bounds verification.
T & push(const T &data)
Push into stack a copy of data
bool traverse(Operation &operation) noexcept(noexcept(array.traverse(operation)))
Traverse all the items of stack from the youngest to oldest and conditionally performs an operation.
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:141
Filtered iterator on directed graphs.
Definition tpl_graph.H:1770
Generic directed graph (digraph) wrapper template.
Definition graph-dry.H:4377
Node belonging to a double circular linked list with header node.
Definition tpl_dnode.H:106
Dynamic heap (priority queue) backed by DynArray.
T & insert(const T &key)
Insert a copy of key into the heap.
bool traverse(Operation &operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
Traverse all elements in the heap.
bool traverse(Operation &operation) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
Traverse a constant array and execute a conditioned operation, which must have the signature:
T & append()
Allocate a new entry to the end of array.
Dynamic doubly linked list with O(1) size and bidirectional access.
High-level interval tree with automatic memory management.
Dynamic queue of elements of generic type T based on single linked list.
Dynamic stack of elements of generic type T based on a singly linked list.
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
T & append(const T &item)
Definition htlist.H:1362
Dynamic ordered set implemented with a Skip List.
Key * insert(const Key &key)
Insert an element into the set.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Very simple queue implemented with a contiguous array.
T & put(const T &item) noexcept
Put an item into the queue by copy.
bool traverse(Operation &operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
Traverse all the elements from the youngest to the oldest and execute operation on each on them.
Fixed length stack.
T & push(const T &data) noexcept(std::is_nothrow_copy_assignable_v< T >)
Push a copy of data
bool traverse(Operation &operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
Traverse all the items of stack from the youngest to oldest and conditionally performs an operation.
Arc for graphs implemented with simple adjacency lists.
Definition tpl_sgraph.H:197
bool has_curr() const noexcept
Definition htlist.H:969
Filtered iterator for incoming arcs of a node.
Definition tpl_graph.H:2045
Computes the minimum spanning tree of a graph using Kruskal's algorithm.
Definition Kruskal.H:94
Graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:439
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Definition tpl_graph.H:535
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Definition tpl_graph.H:618
Simple, scalable and fast dynamic array.
bool traverse(Operation &operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
Traverse all the elements from index 0 to n - 1 and execute operation on each on them.
T & append(const T &item)
See put(const T & item).
Filtered iterator on the nodes of a graph.
Definition tpl_graph.H:1287
Filtered iterator for outcoming arcs of a node.
Definition tpl_graph.H:1942
A non-degenerate triangle defined by three points.
Definition point.H:1512
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, Type > Type * find_ptr(Operation &operation) noexcept(mutable_search_is_noexcept< Operation >())
Find a pointer to an item in the container according to a searching criterion.
Definition ah-dry.H:825
QuadTree - Hierarchical spatial index for 2D points.
Definition quadtree.H:126
Point * search(const Point &p) noexcept
Search for a point in the tree.
Definition quadtree.H:524
Point * insert(Node *&r, const Point &p)
Recursive insert helper.
Definition quadtree.H:281
#define TEST(name)
Generic filter iterator wrapper for Aleph containers.
bool operator!=(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Definition gmpfrxx.h:4120
DynArray< Graph::Node * > nodes
Definition graphpic.C:406
DynArray< Graph::Arc * > arcs
Definition graphpic.C:408
GT::Arc * search_arc(const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept(nothrow_arc_filter_v< GT, SA >)
Arc filtered searching given two nodes.
Definition tpl_graph.H:3574
bool traverse(Node *root, Op op)
See infix_traverse().
Singly linked list implementations with head-tail access.
static mpfr_t y
Definition mpfr_mul_d.c:3
void insertion_sort_range(T *a, const size_t lo, const size_t hi, const Compare &cmp) noexcept(std::is_nothrow_move_constructible_v< T > and std::is_nothrow_move_assignable_v< T > and noexcept(static_cast< bool >(std::declval< const Compare & >()(std::declval< T & >(), std::declval< T & >()))))
Insertion sort a sub-array [lo, hi).
GT::Node * get_node(DynArray< typename GT::Node * > &nodes, long i)
Get node pointer from sorted node array by index.
void binary_insertion_sort(T *a, const size_t lo, const size_t hi, const size_t start, const Compare &cmp) noexcept(std::is_nothrow_move_constructible_v< T > and std::is_nothrow_move_assignable_v< T > and noexcept(static_cast< bool >(std::declval< const Compare & >()(std::declval< T & >(), std::declval< T & >()))))
Binary insertion sort on [lo, hi) starting from start.
size_t gallop_left(const T &key, const T *a, const size_t len, const size_t hint, const Compare &cmp) noexcept(noexcept(static_cast< bool >(std::declval< const Compare & >()(std::declval< const T & >(), std::declval< const T & >()))))
Gallop left: find the insertion point for a key in a sorted range.
size_t gallop_right(const T &key, const T *a, const size_t len, const size_t hint, const Compare &cmp) noexcept(noexcept(static_cast< bool >(std::declval< const Compare & >()(std::declval< const T & >(), std::declval< const T & >()))))
Gallop right: find the insertion point for a key in a sorted range.
Main namespace for Aleph-w library functions.
void insertion_sort(T *a, const long l, const long r, const Compare &cmp=Compare()) noexcept(noexcept(static_cast< bool >(cmp(std::declval< T & >(), std::declval< T & >()))) and std::is_nothrow_move_constructible_v< T > and std::is_nothrow_move_assignable_v< T >)
Sort an array using insertion sort.
bool operator==(const DynList< T > &l1, const DynList< T > &l2)
Equality operator for DynList.
std::pair< TgtContainer< typename SrcContainer::Item_Type >, TgtContainer< typename SrcContainer::Item_Type > > partition(const SrcContainer &c, std::function< bool(const typename SrcContainer::Item_Type &)> operation)
Partition a container into two based on a predicate.
void mergeinsertsort(Tlist< T > &list, const Compare &cmp=Compare(), const size_t lsz=Aleph::Insertion_Threshold)
Sort a list by mergesort combined with the insert method.
bool all(Container &container, Operation &operation)
Return true if all elements satisfy a predicate.
bool contains(const std::string_view &str, const std::string_view &substr)
Check if substr appears inside str.
DynArray< T > sort(const DynArray< T > &a, Cmp &&cmp=Cmp())
Returns a sorted copy of a DynArray.
Definition ahSort.H:234
and
Check uniqueness with explicit hash + equality functors.
void mergesort(T *a, const long l, const long r, Array< T > &buf, Compare cmp)
Sort an array using merge sort with a reusable buffer.
void selection_sort(T *a, const size_t n, const Compare &cmp=Compare()) noexcept(noexcept(static_cast< bool >(cmp(a[0], a[0]))) and std::is_nothrow_swappable_v< T >)
Sort an array using the selection sort algorithm.
Itor1 search(Itor1 beg, const Itor1 &end, Itor2 searchBeg, const Itor2 &searchEnd, BinaryPredicate op=BinaryPredicate())
Search for a subrange within a range.
Definition ahAlgo.H:309
constexpr void faster_heapsort(T *array, const size_t n, const Compare &cmp=Compare())
Optimized version of heapsort.
constexpr void heapsort(T *array, const size_t n, const Compare &cmp=Compare())
Sort an array using the heapsort algorithm.
long select_pivot(T *a, long l, long r, const Compare &cmp=Compare()) noexcept(noexcept(static_cast< bool >(cmp(a[0], a[0]))) and std::is_nothrow_swappable_v< T >)
Select a pivot for partitioning using median-of-three.
bool none(const Container &container, Operation &operation)
Return true if no element satisfies operation.
void next_ne() noexcept(noexcept(std::declval< Aleph::const_iterator_t< HeadC > & >().next_ne()) and noexcept(std::declval< ZipIterator< TailC... > & >().next_ne()))
Advance all underlying iterators (unchecked variant).
Definition ah-zip.H:252
@ Named
Named type such as Int or T.
STL namespace.
Filtered iterator on all the arcs of a graph.
Definition tpl_graph.H:1200
Default filter for filtered iterators on arcs.
Definition tpl_graph.H:1024
Arc of graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:231
BST comparator for intervals: order by (low, then high).
Closed interval [low, high].
Filter for arcs painted by Kruskal's algorithm.
Definition Kruskal.H:139
Filtered iterator of adjacent arcs of a node.
Definition tpl_graph.H:1155
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation, typename Aleph::concepts_detail::traverse_arg< Container, Operation >::type, Container & >())
Traverse the container via its iterator and performs a conditioned operation on each item.
Definition ah-dry.H:411
bool check(GT &g)
DynList< char > l3
DynList< int > l1
DynList< int > l2
Array-based graph implementation.
Fixed-capacity binary heap and heapsort algorithms.
Circular queue implementations backed by arrays.
Stack implementations backed by dynamic or fixed arrays.
Dynamic array container with automatic resizing.
Array-based dynamic binary heap.
Lazy and scalable dynamic array implementation.
Dynamic doubly linked list implementation.
Dynamic queue implementation based on linked lists.
Dynamic stack implementation based on linked lists.
Dynamic ordered set implemented with a Skip List.
Generic graph and digraph implementations.
Interval tree: augmented BST for overlap/stabbing queries.
Simple graph implementation with adjacency lists.
Comprehensive sorting algorithms and search utilities for Aleph-w.
DynList< int > l