Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
graph-dry.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
48# ifndef GRAPH_DRY_H
49# define GRAPH_DRY_H
50
51#include <concepts>
52#include <optional>
53#include <type_traits>
54#include <utility>
55#include <ah-concepts.H>
56#include <ah-graph-concepts.H>
57
59{
69 template <class GT, class D>
70 struct node_curr
71 {
72 using type = decltype(std::declval<typename concepts_detail::defer<GT, D>::type::Node_Iterator &>().get_curr());
73 };
74
79 template <class GT, class D>
80 struct arc_curr
81 {
82 using type = decltype(std::declval<typename concepts_detail::defer<GT, D>::type::Arc_Iterator &>().get_curr());
83 };
84
89 template <class GT, class D>
91 {
92 using type = decltype(std::declval<typename concepts_detail::defer<GT, D>::type::Node_Arc_Iterator &>().get_curr());
93 };
94
106 template <class It>
107 [[gnu::always_inline]] inline decltype(auto) curr_ne(It & it)
108 {
109 if constexpr (AlephUncheckedIterator<It>)
110 return it.get_curr_ne();
111 else
112 return it.get_curr();
113 }
114
131 template <class GT, class SA>
133 {
134 using Node = typename GT::Node;
135 using Arc = typename GT::Arc;
136 using Arc_Itor = typename GT::Arc_Iterator;
137
138 // Empty only in the form that takes the node, which does not compile
139 std::optional<Arc_Itor> arcs;
140 Node *tgt = nullptr;
142
143 // Whether show_arc throws nothing, called as forward() and backward()
144 // call it, with an arc that has a name, and so the moves without checks
146
147 // Moves forward, from the current arc, to the first one into tgt that
148 // show_arc shows, or to the end
149 void forward()
150 {
151 for (; arcs->has_curr(); arcs->next_ne())
152 if (Arc *a = arcs->get_curr_ne(); a->tgt_node == tgt and static_cast<bool>(show_arc(a)))
153 return;
154 }
155
156 // Moves back, from the current arc, to the first one into tgt that
157 // show_arc shows, or before the first arc
158 void backward()
159 {
160 for (; arcs->has_curr(); arcs->prev())
161 if (Arc *a = arcs->get_curr_ne(); a->tgt_node == tgt and static_cast<bool>(show_arc(a)))
162 return;
163 }
164
165 public:
167 using Item_Type = Arc *;
168
171 static constexpr bool goes_back = requires (Arc_Itor & a) { a.prev(); };
172
174 static constexpr bool goes_to_last = requires (Arc_Itor & a) { a.reset_last(); a.prev(); };
175
179 In_Arcs_Walk(const GT & g, Node *p, SA sa = SA())
180 : arcs(std::in_place, g), tgt(p), show_arc(sa)
181 {
182 forward();
183 }
184
188 In_Arcs_Walk(Node *, SA sa = SA()) : show_arc(sa)
189 {
190 static_assert(not Aleph::DigraphType<GT>,
191 "In_Iterator(p) does not see the arcs into p on a digraph, whose list of p "
192 "holds only the arcs that leave p: use In_Iterator(g, p), or In_Arcs_Index "
193 "for many nodes");
194 }
195
197 [[nodiscard]] bool has_curr() const noexcept { return arcs->has_curr(); }
198
200 Arc * get_curr() const { return arcs->get_curr(); }
201
203 Arc * get_curr_ne() const noexcept { return arcs->get_curr_ne(); }
204
206 Arc * get_current_arc() const { return get_curr(); }
207
209 Arc * get_current_arc_ne() const noexcept { return get_curr_ne(); }
210
212 Node * get_node(Arc *a) const noexcept { return static_cast<Node *>(a->src_node); }
213
216 Node * get_node() const { return get_node(get_curr()); }
217
219 Node * get_node_ne() const noexcept { return get_node(get_curr_ne()); }
220
222 Node * get_tgt_node() const { return get_node(); }
223
225 Node * get_tgt_node_ne() const noexcept { return get_node_ne(); }
226
229 void next()
230 {
231 arcs->next();
232 forward();
233 }
234
237 void next_ne() noexcept(shows_ne)
238 {
239 arcs->next_ne();
240 forward();
241 }
242
245 void prev() requires goes_back
246 {
247 arcs->prev();
248 backward();
249 }
250
253 void prev_ne() noexcept(shows_ne) requires goes_back
254 {
255 if (not arcs->has_curr())
256 return;
257 arcs->prev();
258 backward();
259 }
260
263 {
264 arcs->reset_first();
265 forward();
266 }
267
270 void reset_last() requires goes_to_last
271 {
272 arcs->reset_last();
273 backward();
274 }
275
277 void end() noexcept { arcs->end(); }
278 };
279
282 {
284 template <class Arc>
285 bool operator () (Arc *) const noexcept { return true; }
286 };
287
288} // namespace Aleph::graph_dry_detail
289
290// ============================================================================
291// C++20 Concepts for Graph Iterators
292// ============================================================================
293
392template <typename It>
393concept BasicGraphIterator = requires(It it, const It cit)
394{
395 { cit.has_curr() } -> std::convertible_to<bool>;
396 { it.next() } -> std::same_as<void>;
397 { it.get_curr() };
398};
399
412template <typename It>
414{
415 { it.reset_first() } -> std::same_as<void>;
416};
431template <typename It, typename Node>
432concept GraphNodeIterator = BasicGraphIterator<It> && requires(const It cit)
433{
434 { cit.get_curr() } -> std::convertible_to<Node*>;
435};
436
450template <typename It, typename Arc>
451concept GraphArcIterator = BasicGraphIterator<It> && requires(const It cit)
452{
453 { cit.get_curr() } -> std::convertible_to<Arc*>;
454};
455
474template <typename It, typename Node, typename Arc>
475concept NodeArcIterator = GraphArcIterator<It, Arc> && requires(const It cit)
476{
477 { cit.get_tgt_node() } -> std::convertible_to<Node*>;
478};
479
// end of GraphConcepts group
481
482// ============================================================================
483// End of C++20 Concepts
484// ============================================================================
485
495template <class GT>
496struct GTNodeIterator : public Dlink::Iterator
497{
498 using Node = typename GT::Node;
499
501 using Item_Type = Node *;
502
504 using Set_Type = GT;
505
506 GTNodeIterator() noexcept
507 { /* empty */
508 }
509
511 GTNodeIterator(Dlink & head) noexcept : Dlink::Iterator(head)
512 { /* empty */
513 }
514
516 Node * get_curr_ne() const noexcept
517 {
518 return static_cast<Node *>(Dlink::Iterator::get_curr_ne());
519 }
520
522 Node * get_curr() const { return static_cast<Node *>(Dlink::Iterator::get_curr()); }
523
525 Node * get_current_node() const { return get_curr(); }
526
527 Node * get_current_node_ne() const { return get_curr_ne(); }
528};
529
530
540template <class GT>
541struct GTArcIterator : public Dlink::Iterator
542{
543 using Node = typename GT::Node;
544 using Arc = typename GT::Arc;
545
547 using Item_Type = Arc *;
548
550 using Set_Type = GT;
551
552 GTArcIterator() noexcept
553 { /* empty */
554 }
555
557 GTArcIterator(Dlink & head) noexcept
558 : Dlink::Iterator(head)
559 { /* empty */
560 }
561
563 Arc * get_curr_ne() const noexcept
564 {
565 return static_cast<Arc *>(Dlink::Iterator::get_curr_ne());
566 }
567
569 Arc * get_curr() const { return static_cast<Arc *>(Dlink::Iterator::get_curr()); }
570
572 Arc * get_current_arc() const { return get_curr(); }
573
575 Arc * get_current_arc_ne() const noexcept { return get_curr_ne(); }
576
578 Node * get_src_node_ne() const noexcept
579 {
580 return static_cast<Node *>(get_curr_ne()->src_node);
581 }
582
584 Node * get_tgt_node_ne() const noexcept
585 {
586 return static_cast<Node *>(get_curr_ne()->tgt_node);
587 }
588
591 {
592 return static_cast<Node *>(get_curr()->src_node);
593 }
594
597 {
598 return static_cast<Node *>(get_curr()->tgt_node);
599 }
600};
601
602
607template <class GT, class Cmp>
609{
610 using Node = typename GT::Node;
611
613
614 // From a temporary, cmp would refer to it once it is gone
615 Cmp_Dlink_Node(Cmp &&) = delete;
616
617 Cmp_Dlink_Node(Cmp & __cmp) noexcept : cmp(__cmp)
618 { /* empty */
619 }
620
629 bool operator ()(Dlink *d1, Dlink *d2) const
630 noexcept(noexcept(static_cast<bool>(std::declval<Cmp &>()(std::declval<Node *&>(),
631 std::declval<Node *&>()))))
632 {
633 Node *p1 = static_cast<Node *>(d1);
634 Node *p2 = static_cast<Node *>(d2);
635 return static_cast<bool>(cmp(p1, p2));
636 }
637};
638
643template <class GT, class Cmp>
645{
646 using Arc = typename GT::Arc;
647
649
650 // From a temporary, cmp would refer to it once it is gone
651 Cmp_Dlink_Arc(Cmp &&) = delete;
652
653 Cmp_Dlink_Arc(Cmp & __cmp) noexcept : cmp(__cmp)
654 { /* empty */
655 }
656
665 bool operator ()(Dlink *d1, Dlink *d2) const
666 noexcept(noexcept(static_cast<bool>(std::declval<Cmp &>()(std::declval<Arc *&>(),
667 std::declval<Arc *&>()))))
668 {
669 Arc *arc1 = static_cast<Arc *>(d1);
670 Arc *arc2 = static_cast<Arc *>(d2);
671 return static_cast<bool>(cmp(arc1, arc2));
672 }
673};
674
692template <typename NodeInfo>
694{
695public:
700 Graph_Attr attrs;
701
703
704
713 size_t num_arcs = 0;
714
716
718
720
722 GTNodeCommon() noexcept = default;
723
725 GTNodeCommon(const NodeInfo & info) : node_info(info) {}
726
728 GTNodeCommon(NodeInfo && info) : node_info(std::move(info)) {}
729
731 GTNodeCommon(const GTNodeCommon & other) : node_info(other.node_info) {}
732
734 GTNodeCommon(GTNodeCommon && other) noexcept : node_info(std::move(other.node_info)) {}
735
738 {
739 if (this != &other)
740 node_info = other.node_info;
741 return *this;
742 }
743
746 {
747 if (this != &other)
748 node_info = std::move(other.node_info);
749 return *this;
750 }
751
753 NodeInfo &get_info() noexcept { return node_info; }
754
756 const NodeInfo &get_info() const noexcept { return node_info; }
757
759 unsigned int state() const noexcept { return NODE_BITS(this).state; }
760
762 void set_state(unsigned int s) noexcept
763 {
764 NODE_BITS(this).state = s;
765 }
766};
767
768
785template <typename ArcInfo>
787{
788public:
791
792 void *src_node = nullptr;
793 void *tgt_node = nullptr;
794
799 Graph_Attr attrs;
800
802
804 GTArcCommon() noexcept = default;
805
807 GTArcCommon(const ArcInfo & info) : arc_info(info) {}
808
810 GTArcCommon(ArcInfo && info) : arc_info(std::move(info)) {}
811
813 GTArcCommon(void *src, void *tgt, const ArcInfo & data)
814 : src_node(src), tgt_node(tgt), arc_info(data) {}
815
817 GTArcCommon(void *src, void *tgt, ArcInfo && data = ArcInfo())
818 : src_node(src), tgt_node(tgt), arc_info(std::move(data)) {}
819
822 : src_node(other.src_node), tgt_node(other.tgt_node), arc_info(other.arc_info) {}
823
825 GTArcCommon(GTArcCommon && other) noexcept
826 : src_node(other.src_node), tgt_node(other.tgt_node), arc_info(std::move(other.arc_info)) {}
827
830 {
831 if (this != &other)
832 arc_info = other.arc_info;
833 return *this;
834 }
835
837 GTArcCommon & operator=(GTArcCommon && other) noexcept
838 {
839 if (this != &other)
840 arc_info = std::move(other.arc_info);
841 return *this;
842 }
843
845 unsigned int state() const noexcept { return ARC_BITS(this).state; }
846
848 void set_state(unsigned int s) noexcept
849 {
850 ARC_BITS(this).state = s;
851 }
852
854 ArcInfo &get_info() noexcept { return arc_info; }
855
857 const ArcInfo &get_info() const noexcept { return arc_info; }
858
859 void * get_connected_node(void *node) noexcept
860 {
861 return src_node == node ? tgt_node : src_node;
862 }
863
864 void * get_img_node(void *node) noexcept
865 {
866 return src_node == node ? src_node : tgt_node;
867 }
868};
869
870
875template <class GT, class Node, class Arc>
877{
878 GT * me() { return static_cast<GT *>(this); }
879
880 const GT * const_me() const { return static_cast<const GT *>(this); }
881
882 // The graph takes arc, made with new by the caller. Either the graph
883 // links it, or it throws as it was, with arc in none of its lists, and
884 // then the guard frees arc. The guard is not a unique_ptr: its release()
885 // would say that the caller takes the arc, and the arc is the graph's
886 Arc * insert_new_arc(Node *src, Node *tgt, Arc *arc)
887 {
888 struct Guard
889 {
890 Arc *arc;
891 ~Guard() { delete arc; }
892 } guard{arc};
893
894 me()->insert_arc(src, tgt, arc);
895 guard.arc = nullptr; // the graph took arc
896 return arc;
897 }
898
899protected:
900 void *cookie = nullptr;
901 size_t num_nodes = 0;
902 size_t num_arcs = 0;
903 bool digraph = false;
904
905public:
906 using Node_Type = typename Node::Node_Type;
907 using Arc_Type = typename Arc::Arc_Type;
908
909protected:
910 void init() noexcept
911 {
912 num_nodes = num_arcs = 0;
913 cookie = nullptr;
914 digraph = false;
915 }
916
917 // Each graph links its arcs as its flag says, so the flags go with the
918 // arcs: a graph of an undirected type can say that it is directed (see
919 // set_digraph()). Digraph deletes the swap with its base, which would
920 // leave a digraph with the arcs and the flag of an undirected graph.
921 void common_swap(GT & g) noexcept
922 {
923 std::swap(num_nodes, g.num_nodes);
924 std::swap(num_arcs, g.num_arcs);
925 std::swap(digraph, g.digraph);
926 std::swap(cookie, g.cookie);
927 }
928
929public:
931 void *&get_cookie() noexcept { return cookie; }
932
934 void * get_cookie() const noexcept { return cookie; }
935
937 bool is_digraph() const noexcept { return digraph; }
938
972 void set_digraph(bool val) { digraph = val; } // TODO: delete after
973
975 [[nodiscard]] constexpr size_t get_num_nodes() const noexcept { return num_nodes; }
976
981 [[nodiscard]] constexpr bool is_empty() const noexcept { return num_nodes == 0; }
982
984 [[nodiscard]] constexpr size_t vsize() const noexcept { return get_num_nodes(); }
985
994 Node * get_node() const { return const_me()->get_first_node(); }
995
1004 Arc * get_arc() const { return const_me()->get_first_arc(); }
1005
1014 Arc * get_arc(Node *p) const { return const_me()->get_first_arc(p); }
1015
1017 Node * get_src_node(Arc *arc) const noexcept
1018 {
1019 return static_cast<Node *>(arc->src_node);
1020 }
1021
1023 Node * get_tgt_node(Arc *arc) const noexcept
1024 {
1025 return static_cast<Node *>(arc->tgt_node);
1026 }
1027
1058 Node * get_connected_node(Arc *arc, Node *node) const noexcept
1059 {
1060 return static_cast<Node *>(arc->get_connected_node(node));
1061 }
1062
1064 [[nodiscard]] constexpr size_t get_num_arcs() const noexcept { return num_arcs; }
1065
1068 size_t get_num_arcs(Node *node) const noexcept
1069 {
1070 return node->num_arcs;
1071 }
1072
1075 size_t degree(Node *p) const noexcept { return get_num_arcs(p); }
1076
1078 size_t esize() const noexcept { return get_num_arcs(); }
1079
1081 Bit_Fields &get_control_bits(Node *node) const noexcept
1082 {
1083 return NODE_BITS(node);
1084 }
1085
1087 void reset_bit(Node *node, int bit) const noexcept
1088 {
1089 NODE_BITS(node).reset(bit);
1090 }
1091
1093 void reset_bits(Node *node) const noexcept
1094 {
1095 NODE_BITS(node).reset();
1096 }
1097
1099 int get_bit(Node *node, int bit) const noexcept
1100 {
1101 return NODE_BITS(node).get_bit(bit);
1102 }
1103
1105 void set_bit(Node *node, int bit, int value) const noexcept
1106 {
1107 NODE_BITS(node).set_bit(bit, value);
1108 }
1109
1111 Bit_Fields &get_control_bits(Arc *arc) const noexcept
1112 {
1113 return ARC_BITS(arc);
1114 }
1115
1117 void reset_bit(Arc *arc, int bit) const noexcept
1118 {
1119 ARC_BITS(arc).reset(bit);
1120 }
1121
1123 void reset_bits(Arc *arc) const noexcept
1124 {
1125 ARC_BITS(arc).reset();
1126 }
1127
1129 int get_bit(Arc *arc, int bit) const noexcept
1130 {
1131 return ARC_BITS(arc).get_bit(bit);
1132 }
1133
1135 void set_bit(Arc *arc, int bit, int value) const noexcept
1136 {
1137 ARC_BITS(arc).set_bit(bit, value);
1138 }
1139
1141 void *&get_cookie(Node *node) const noexcept
1142 {
1143 return NODE_COOKIE(node);
1144 }
1145
1147 void *&get_cookie(Arc *arc) const noexcept
1148 {
1149 return ARC_COOKIE(arc);
1150 }
1151
1153 long &get_counter(Node *node) const noexcept
1154 {
1155 return NODE_COUNTER(node);
1156 }
1157
1159 void reset_counter(Node *node) const noexcept
1160 {
1161 NODE_COUNTER(node) = 0;
1162 }
1163
1165 void reset_node_counters() const noexcept
1166 {
1167 for_each_node([this](auto p) { this->reset_counter(p); });
1168 }
1169
1173 void reset_node(Node *p) const noexcept
1174 {
1175 p->attrs.reset();
1176 }
1177
1179 long &get_counter(Arc *arc) const noexcept
1180 {
1181 return ARC_COUNTER(arc);
1182 }
1183
1185 void reset_counter(Arc *arc) const noexcept
1186 {
1187 ARC_COUNTER(arc) = No_Visited;
1188 }
1189
1191 void reset_arc_counters() const noexcept
1192 {
1193 for_each_arc([this](auto a) { this->reset_counter(a); });
1194 }
1195
1199 void reset_arc(Arc *arc) const noexcept
1200 {
1201 arc->attrs.reset();
1202 }
1203
1206 void reset_nodes() const
1207 {
1208 for_each_node([](auto p) { p->attrs.reset(); });
1209 }
1210
1213 void reset_arcs() const
1214 {
1215 for_each_arc([](auto a) { a->attrs.reset(); });
1216 }
1217
1279 template <class N1, class N2 = N1>
1280 static
1281 void map_nodes(N1 *p, N2 *q) noexcept
1282 {
1283 assert(p != nullptr and q != nullptr);
1284 // Use reinterpret_cast to preserve exact pointer values without any
1285 // implicit base class pointer adjustment from multiple inheritance
1286 if (NODE_COOKIE(p) == nullptr)
1287 {
1288 NODE_COOKIE(p) = reinterpret_cast<void *>(q);
1289 NODE_COOKIE(q) = reinterpret_cast<void *>(p);
1290 return;
1291 }
1292 NODE_COOKIE(q) = NODE_COOKIE(p);
1293 NODE_COOKIE(p) = reinterpret_cast<void *>(q);
1294 }
1295
1310 template <class A1, class A2 = A1>
1311 static
1312 void map_arcs(A1 *p, A2 *q) noexcept
1313 {
1314 assert(p != nullptr and q != nullptr);
1315 if (ARC_COOKIE(p) == nullptr)
1316 {
1317 ARC_COOKIE(p) = q;
1318 ARC_COOKIE(q) = p;
1319 return;
1320 }
1321 ARC_COOKIE(q) = ARC_COOKIE(p);
1322 ARC_COOKIE(p) = q;
1323 }
1324
1326 void reset_bit_nodes(int bit) const noexcept
1327 {
1328 for_each_node([bit, this](auto p) { this->reset_bit(p, bit); });
1329 }
1330
1332 void reset_bit_arcs(int bit) const noexcept
1333 {
1334 for_each_arc([bit, this](auto a) { this->reset_bit(a, bit); });
1335 }
1336
1338 void reset_bit_nodes() const noexcept
1339 {
1340 for_each_node([this](auto p) { this->reset_bits(p); });
1341 }
1342
1344 void reset_bit_arcs() const noexcept
1345 {
1346 for_each_arc([this](auto a) { this->reset_bits(a); });
1347 }
1348
1350 void reset_counter_nodes() const noexcept
1351 {
1352 for_each_node([this](auto p) { this->reset_counter(p); });
1353 }
1354
1356 void reset_counter_arcs() const noexcept
1357 {
1358 for_each_arc([this](auto a) { this->reset_counter(a); });
1359 }
1360
1367 void reset_cookie_nodes() const noexcept
1368 {
1369 for_each_node([](auto p) { NODE_COOKIE(p) = nullptr; });
1370 }
1371
1378 void reset_cookie_arcs() const noexcept
1379 {
1380 for_each_arc([](auto a) { ARC_COOKIE(a) = nullptr; });
1381 }
1382
1402 Node * insert_node(const Node_Type & node_info)
1403 {
1404 return me()->insert_node(new Node(node_info));
1405 }
1406
1427 {
1428 return me()->insert_node(new Node(std::forward<Node_Type>(node_info)));
1429 }
1430
1451 template <typename... Args>
1452 Node * emplace_node(Args &&... args)
1453 {
1454 return me()->insert_node(Node_Type(std::forward<Args>(args)...));
1455 }
1456
1479 Arc * insert_arc(Node *src, Node *tgt, const Arc_Type & arc_info)
1480 {
1481 return insert_new_arc(src, tgt, new Arc(arc_info));
1482 }
1483
1507 Arc * insert_arc(Node *src, Node *tgt, Arc_Type && arc_info = Arc_Type())
1508 {
1509 return insert_new_arc(src, tgt, new Arc(std::forward<Arc_Type>(arc_info)));
1510 }
1511
1533 template <typename... Args>
1534 Arc * emplace_arc(Node *src, Node *tgt, Args &&... args)
1535 {
1536 return me()->insert_arc(src, tgt, Arc_Type(std::forward<Args>(args)...));
1537 }
1538
1585 template <class Operation>
1587 bool traverse_nodes(Operation & op) const
1588 {
1589 for (typename GT::Node_Iterator it(*const_me()); it.has_curr(); it.next_ne())
1590 if (not op(graph_dry_detail::curr_ne(it)))
1591 return false;
1592 return true;
1593 }
1594
1596 template <class Operation>
1598 bool traverse_nodes(Operation && op = Operation()) const
1599 {
1600 return traverse_nodes(op);
1601 }
1602
1652 template <class Operation>
1654 bool traverse_arcs(Operation & op) const
1655 {
1656 for (typename GT::Arc_Iterator it(*const_me()); it.has_curr(); it.next_ne())
1657 if (not op(graph_dry_detail::curr_ne(it)))
1658 return false;
1659 return true;
1660 }
1661
1663 template <class Operation>
1665 bool traverse_arcs(Operation && op = Operation()) const
1666 {
1667 return traverse_arcs(op);
1668 }
1669
1721 template <class Operation>
1723 bool traverse_arcs(Node *p, Operation & op) const
1724 {
1725 for (typename GT::Node_Arc_Iterator it(p); it.has_curr(); it.next_ne())
1726 if (not op(graph_dry_detail::curr_ne(it)))
1727 return false;
1728 return true;
1729 }
1730
1732 template <class Operation>
1734 bool traverse_arcs(Node *p, Operation && op = Operation()) const
1735 {
1736 return traverse_arcs(p, op);
1737 }
1738
1763 template <class Operation>
1765 void for_each_node(Operation & operation) const
1766 {
1767 for (typename GT::Node_Iterator it(*const_me()); it.has_curr(); it.next_ne())
1768 operation(graph_dry_detail::curr_ne(it));
1769 }
1770
1772 template <class Operation>
1774 void for_each_node(Operation && operation = Operation()) const
1775 {
1776 for_each_node(operation);
1777 }
1778
1803 template <class Operation>
1805 void for_each_arc(Operation & op) const
1806 {
1807 for (typename GT::Arc_Iterator it(*const_me()); it.has_curr(); it.next_ne())
1808 op(graph_dry_detail::curr_ne(it));
1809 }
1810
1812 template <class Operation>
1814 void for_each_arc(Operation && operation = Operation()) const
1815 {
1816 for_each_arc(operation);
1817 }
1818
1852 template <class Operation>
1854 void for_each_arc(Node *p, Operation & op) const
1855 {
1856 for (typename GT::Node_Arc_Iterator it(p); it.has_curr(); it.next_ne())
1857 op(graph_dry_detail::curr_ne(it));
1858 }
1859
1861 template <class Operation>
1863 void for_each_arc(Node *p, Operation && op = Operation()) const
1864 {
1865 for_each_arc(p, op);
1866 }
1867
1897 template <class Operation>
1899 bool all_nodes(Operation & op) const
1900 {
1901 return traverse_nodes(op);
1902 }
1903
1905 template <class Operation>
1907 bool all_nodes(Operation && op = Operation()) const
1908 {
1909 return all_nodes(op);
1910 }
1911
1941 template <class Operation>
1943 bool all_arcs(Operation & op) const
1944 {
1945 return traverse_arcs(op);
1946 }
1947
1949 template <class Operation>
1951 bool all_arcs(Operation && op = Operation()) const
1952 {
1953 return all_arcs(op);
1954 }
1955
1988 template <class Operation>
1990 bool all_arcs(Node *p, Operation & op) const
1991 {
1992 return traverse_arcs(p, op);
1993 }
1994
1996 template <class Operation>
1998 bool all_arcs(Node *p, Operation && op = Operation()) const
1999 {
2000 return all_arcs(p, op);
2001 }
2002
2042 template <typename T = Node_Type, class Op>
2043 requires std::is_invocable_r_v<T, Op &, Node *>
2044 auto nodes_map(Op op) const
2045 {
2046 DynList<T> ret_val;
2047 for_each_node([&ret_val, &op](Node *p) { ret_val.append(Aleph::concepts_detail::invoke_as<T(Node *)>::call(op, p)); });
2048 return ret_val;
2049 }
2050
2090 template <typename T = Arc_Type, class Op>
2091 requires std::is_invocable_r_v<T, Op &, Arc *>
2092 auto arcs_map(Op operation) const
2093 {
2094 DynList<T> ret_val;
2095 for_each_arc([&ret_val, &operation](Arc *p)
2096 {
2097 ret_val.append(Aleph::concepts_detail::invoke_as<T(Arc *)>::call(operation, p));
2098 });
2099 return ret_val;
2100 }
2101
2142 template <typename T = Arc_Type, class Op>
2143 requires std::is_invocable_r_v<T, Op &, Arc *>
2144 auto arcs_map(Node *p, Op operation) const
2145 {
2146 DynList<T> ret_val;
2147 for_each_arc(p, [&ret_val, &operation](Arc *a)
2148 {
2149 ret_val.append(Aleph::concepts_detail::invoke_as<T(Arc *)>::call(operation, a));
2150 });
2151 return ret_val;
2152 }
2153
2188 template <typename T = Node_Type, class Op>
2189 requires std::is_invocable_r_v<T, Op &, const T &, Node *>
2190 T foldl_nodes(const T & init,
2191 Op op) const
2192 {
2193 T ret = init;
2194 for_each_node([&ret, &op](Node *p) { ret = Aleph::concepts_detail::invoke_as<T(const T &, Node *)>::call(op, ret, p); });
2195 return ret;
2196 }
2197
2231 template <typename T = Arc_Type, class Op>
2232 requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
2233 T foldl_arcs(const T & init,
2234 Op op) const
2235 {
2236 T ret = init;
2237 for_each_arc([&ret, &op](Arc *p) { ret = Aleph::concepts_detail::invoke_as<T(const T &, Arc *)>::call(op, ret, p); });
2238 return ret;
2239 }
2240
2275 template <typename T = Arc_Type, class Op>
2276 requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
2277 T foldl_arcs(Node *p, const T & init,
2278 Op op) const
2279 {
2280 T ret = init;
2281 for_each_arc(p, [&ret, &op](Arc *a) { ret = Aleph::concepts_detail::invoke_as<T(const T &, Arc *)>::call(op, ret, a); });
2282 return ret;
2283 }
2284
2306 template <class Op>
2308 auto filter_nodes(Op & op) const
2309 {
2310 DynList<Node *> ret;
2311 for_each_node([&ret, &op](Node *p)
2312 {
2313 if (op(p))
2314 ret.append(p);
2315 });
2316 return ret;
2317 }
2318
2320 template <class Op>
2322 auto filter_nodes(Op && op) const
2323 {
2324 return filter_nodes(op);
2325 }
2326
2348 template <class Op>
2350 auto filter_arcs(Op & op) const
2351 {
2352 DynList<Arc *> ret;
2353 for_each_arc([&ret, &op](Arc *a)
2354 {
2355 if (op(a))
2356 ret.append(a);
2357 });
2358 return ret;
2359 }
2360
2362 template <class Op>
2364 auto filter_arcs(Op && op) const
2365 {
2366 return filter_arcs(op);
2367 }
2368
2399 template <class Op>
2401 auto filter_arcs(Node *p, Op & op) const
2402 {
2403 DynList<Arc *> ret;
2404 for_each_arc(p, [&ret, &op](Arc *a)
2405 {
2406 if (op(a))
2407 ret.append(a);
2408 });
2409 return ret;
2410 }
2411
2413 template <class Op>
2415 auto filter_arcs(Node *p, Op && op) const
2416 {
2417 return filter_arcs(p, op);
2418 }
2419
2438 template <class Operation>
2440 bool exists_node(Operation & op) const
2441 {
2442 return not traverse_nodes([&op](Node *p) { return not op(p); });
2443 }
2444
2446 template <class Operation>
2448 bool exists_node(Operation && op = Operation()) const
2449 {
2450 return exists_node(op);
2451 }
2452
2471 template <class Operation>
2473 bool exists_arc(Operation & op) const
2474 {
2475 return not traverse_arcs([&op](Arc *a) { return not op(a); });
2476 }
2477
2479 template <class Operation>
2481 bool exists_arc(Operation && op = Operation()) const
2482 {
2483 return exists_arc(op);
2484 }
2485
2508 template <class Operation>
2510 bool exists_arc(Node *p, Operation & op) const
2511 {
2512 return not traverse_arcs(p, [&op](Arc *a) { return not op(a); });
2513 }
2514
2516 template <class Operation>
2518 bool exists_arc(Node *p, Operation && op = Operation()) const
2519 {
2520 return exists_arc(p, op);
2521 }
2522
2537 template <class Operation>
2539 bool none_node(Operation & op) const
2540 {
2541 return not exists_node(op);
2542 }
2543
2545 template <class Operation>
2547 bool none_node(Operation && op) const
2548 {
2549 return none_node(op);
2550 }
2551
2566 template <class Operation>
2568 bool none_arc(Operation & op) const
2569 {
2570 return not exists_arc(op);
2571 }
2572
2574 template <class Operation>
2576 bool none_arc(Operation && op) const
2577 {
2578 return none_arc(op);
2579 }
2580
2588 template <class Operation>
2590 bool none_arc(Node *p, Operation & op) const
2591 {
2592 return not exists_arc(p, op);
2593 }
2594
2596 template <class Operation>
2598 bool none_arc(Node *p, Operation && op) const
2599 {
2600 return none_arc(p, op);
2601 }
2602
2619 template <class Operation = std::function<bool(Node*)>>
2621 size_t count_nodes(Operation op = [](Node*) { return true; }) const
2622 {
2623 size_t count = 0;
2624 for_each_node([&count, &op](Node *p) { if (op(p)) ++count; });
2625 return count;
2626 }
2627
2644 template <class Operation = std::function<bool(Arc*)>>
2646 size_t count_arcs(Operation op = [](Arc*) { return true; }) const
2647 {
2648 size_t count = 0;
2649 for_each_arc([&count, &op](Arc *a) { if (op(a)) ++count; });
2650 return count;
2651 }
2652
2659 template <class Operation = std::function<bool(Arc*)>>
2661 size_t count_arcs(Node *p, Operation op = [](Arc*) { return true; }) const
2662 {
2663 size_t count = 0;
2664 for_each_arc(p, [&count, &op](Arc *a) { if (op(a)) ++count; });
2665 return count;
2666 }
2667
2684 template <typename T = double, class Extract>
2685 requires requires(T &sum, Extract &extract, Arc *a) { sum += extract(a); }
2686 T sum_arcs(Node *p, Extract extract) const
2687 {
2688 T sum = T{0};
2689 for_each_arc(p, [&sum, &extract](Arc *a) { sum += extract(a); });
2690 return sum;
2691 }
2692
2694 template <typename T = double>
2695 T sum_arcs(Node *p) const
2696 {
2697 T sum = T{0};
2698 for_each_arc(p, [&sum](Arc *a) { sum += static_cast<T>(a->get_info()); });
2699 return sum;
2700 }
2701
2717 template <class Compare = std::function<bool(Arc*, Arc*)>>
2719 Arc* min_arc(Node *p, Compare cmp = [](Arc *a, Arc *b) {
2720 return a->get_info() < b->get_info();
2721 }) const
2722 {
2723 Arc* result = nullptr;
2724 for_each_arc(p, [&result, &cmp](Arc *a) {
2725 if (result == nullptr or cmp(a, result))
2726 result = a;
2727 });
2728 return result;
2729 }
2730
2746 template <class Compare = std::function<bool(Arc*, Arc*)>>
2748 Arc* max_arc(Node *p, Compare cmp = [](Arc *a, Arc *b) {
2749 return a->get_info() < b->get_info();
2750 }) const
2751 {
2752 Arc* result = nullptr;
2753 for_each_arc(p, [&result, &cmp](Arc *a) {
2754 if (result == nullptr or cmp(result, a))
2755 result = a;
2756 });
2757 return result;
2758 }
2759
2765 template <class Compare = std::function<bool(Arc*, Arc*)>>
2767 Arc* min_arc(Compare cmp = [](Arc *a, Arc *b) {
2768 return a->get_info() < b->get_info();
2769 }) const
2770 {
2771 Arc* result = nullptr;
2772 for_each_arc([&result, &cmp](Arc *a) {
2773 if (result == nullptr or cmp(a, result))
2774 result = a;
2775 });
2776 return result;
2777 }
2778
2784 template <class Compare = std::function<bool(Arc*, Arc*)>>
2786 Arc* max_arc(Compare cmp = [](Arc *a, Arc *b) {
2787 return a->get_info() < b->get_info();
2788 }) const
2789 {
2790 Arc* result = nullptr;
2791 for_each_arc([&result, &cmp](Arc *a) {
2792 if (result == nullptr or cmp(result, a))
2793 result = a;
2794 });
2795 return result;
2796 }
2797
2813 template <class Operation>
2815 std::pair<DynList<Node*>, DynList<Node*>> partition_nodes(Operation op) const
2816 {
2817 DynList<Node*> yes, no;
2818 for_each_node([&yes, &no, &op](Node *p) {
2819 if (op(p))
2820 yes.append(p);
2821 else
2822 no.append(p);
2823 });
2824 return {std::move(yes), std::move(no)};
2825 }
2826
2837 template <class Operation>
2839 std::pair<DynList<Arc*>, DynList<Arc*>> partition_arcs(Operation op) const
2840 {
2841 DynList<Arc*> yes, no;
2842 for_each_arc([&yes, &no, &op](Arc *a) {
2843 if (op(a))
2844 yes.append(a);
2845 else
2846 no.append(a);
2847 });
2848 return {std::move(yes), std::move(no)};
2849 }
2850
2864 DynList<Node*> adjacent_nodes(Node *p) const
2865 {
2866 DynList<Node*> result;
2867 for_each_arc(p, [this, p, &result](Arc *a) {
2868 result.append(get_connected_node(a, p));
2869 });
2870 return result;
2871 }
2872
2889 template <class Op>
2891 Node * search_node(Op & op) const
2892 {
2893 for (typename GT::Node_Iterator it(*const_me()); it.has_curr(); it.next_ne())
2894 {
2895 auto p = it.get_curr();
2896 if (op(p))
2897 return p;
2898 }
2899 return nullptr;
2900 }
2901
2903 template <class Op>
2905 Node * search_node(Op && op) const
2906 {
2907 return search_node(op);
2908 }
2909
2921 Node * find_node(const Node_Type & info) const
2922 noexcept(noexcept(static_cast<bool>(std::declval<Node_Type &>() == std::declval<const Node_Type &>())))
2923 {
2924 return search_node([&info](auto p) { return static_cast<bool>(p->get_info() == info); });
2925 }
2926
2943 template <class Op>
2945 Arc * search_arc(Op & op) const
2946 {
2947 for (typename GT::Arc_Iterator it(*const_me()); it.has_curr(); it.next_ne())
2948 {
2949 auto a = it.get_curr();
2950 if (op(a))
2951 return a;
2952 }
2953 return nullptr;
2954 }
2955
2957 template <class Op>
2959 Arc * search_arc(Op && op) const
2960 {
2961 return search_arc(op);
2962 }
2963
2975 Arc * find_arc(const Arc_Type & info) const
2976 noexcept(noexcept(static_cast<bool>(std::declval<Arc_Type &>() == std::declval<const Arc_Type &>())))
2977 {
2978 return search_arc([&info](auto a) { return static_cast<bool>(a->get_info() == info); });
2979 }
2980
2999 template <class Operation>
3001 Arc * search_arc(Node *p, Operation & op) const
3002 {
3003 for (typename GT::Node_Arc_Iterator it(p); it.has_curr(); it.next_ne())
3004 {
3005 Arc *arc = it.get_curr();
3006 if (op(arc))
3007 return arc;
3008 }
3009 return nullptr;
3010 }
3011
3013 template <class Operation>
3015 Arc * search_arc(Node *p, Operation && op = Operation()) const
3016 {
3017 return search_arc(p, op);
3018 }
3019
3043 Arc * search_arc(Node *src, Node *tgt) const noexcept
3044 {
3045 for (typename GT::Node_Arc_Iterator it(src); it.has_curr(); it.next_ne())
3046 if (it.get_tgt_node_ne() == tgt)
3047 return it.get_curr();
3048 return nullptr;
3049 }
3050
3061 template <template <typename> class Container = Aleph::DynList>
3063 {
3065 for_each_node([&ret](Node *p) { ret.append(p); });
3066 return ret;
3067 }
3068
3079 template <template <typename> class Container = Aleph::DynList>
3081 {
3082 Container<Arc *> ret;
3083 for_each_arc([&ret](Arc *a) { ret.append(a); });
3084 return ret;
3085 }
3086
3097 template <template <typename> class Container = Aleph::DynList>
3099 {
3100 Container<Arc *> ret;
3101 this->for_each_arc(p, [&ret](Arc *a) { ret.append(a); });
3102 return ret;
3103 }
3104
3122 auto get_node_it() const noexcept
3123 {
3124 return typename GT::Node_Iterator(*const_me());
3125 }
3126
3144 auto get_arc_it() const noexcept
3145 {
3146 return typename GT::Arc_Iterator(*const_me());
3147 }
3148
3167 auto get_arc_it(Node *p) const noexcept
3168 {
3169 return typename GT::Node_Arc_Iterator(p);
3170 }
3171
3204 struct In_Filt
3205 {
3206 Node *tgt = nullptr;
3207
3209 In_Filt(Node *__tgt = nullptr) noexcept : tgt(__tgt)
3210 { /* empty */
3211 }
3212
3215 bool operator ()(Arc *a) const noexcept
3216 {
3217 assert(tgt);
3218 return a->tgt_node == tgt;
3219 }
3220
3222 Node * get_node(Arc *a) const noexcept
3223 {
3224 assert(tgt);
3225 return (typename GT::Node *) a->src_node;
3226 }
3227 };
3228
3262 {
3263 Node *src = nullptr;
3264
3266 Out_Filt(Node *__src) noexcept : src(__src)
3267 { /* empty */
3268 }
3269
3272 bool operator ()(Arc *a) const noexcept
3273 {
3274 assert(src);
3275 return a->src_node == src;
3276 }
3277
3279 Node * get_node(Arc *a) const noexcept
3280 {
3281 assert(src);
3282 return (Node *) a->tgt_node;
3283 }
3284 };
3285
3311 template <class Filter>
3313 {
3314 using Itor = Filter_Iterator<Node *, typename GT::Node_Arc_Iterator, Filter>;
3315
3316 Filter filt;
3318
3319 public:
3323 static constexpr bool shows_ne = noexcept(std::declval<Itor &>().next_ne());
3324
3325 using Item_Type = typename Itor::Item_Type;
3326
3328
3331 static constexpr bool goes_back = Itor::goes_back;
3332
3334 static constexpr bool goes_to_last = Itor::goes_to_last;
3335
3338 {
3339 // empty
3340 }
3341
3344 void next_ne() noexcept(shows_ne) { it.next_ne(); }
3345
3348 void next() { it.next(); }
3349
3352 void prev() requires goes_back { it.prev(); }
3353
3355 void prev_ne() requires goes_back { it.prev_ne(); }
3356
3358 bool has_curr() const noexcept { return it.has_curr(); }
3359
3362 typename GT::Arc * get_curr() const { return it.get_curr(); }
3363
3364 typename GT::Arc * get_curr_ne() const noexcept { return it.get_curr_ne(); }
3365
3367 auto get_current_arc() const { return get_curr(); }
3368
3369 auto get_current_arc_ne() const noexcept { return get_curr_ne(); }
3370
3373 typename GT::Node * get_node(typename GT::Arc *a) const noexcept
3374 {
3375 return filt.get_node(a);
3376 }
3377
3380 typename GT::Node * get_node_ne() const noexcept
3381 {
3382 return this->get_node(this->get_curr_ne());
3383 }
3384
3386 auto get_tgt_node_ne() const noexcept { return get_node_ne(); }
3387
3388 typename GT::Node * get_node() const
3389 {
3390 return this->get_node(this->get_curr());
3391 }
3392
3394 auto get_tgt_node() const { return get_node(); }
3395
3397 void reset_first() noexcept(shows_ne) { it.reset_first(); }
3398
3401 void reset_last() noexcept(shows_ne) requires goes_to_last { it.reset_last(); }
3402 };
3403
3405 // template <class Filt> using Filter_Iterator = Digraph_Iterator<Filt>;
3406
3430 {
3431 private:
3433
3434 // Throws the domain_error of In_Iterator(g, p) on a graph that says
3435 // that it is directed; out of line, so that the iterator on a graph
3436 // that is not directed costs only the test
3437 [[gnu::noinline, gnu::cold]] static void refuse_a_digraph()
3438 {
3440 << "In_Iterator(g, p): the graph says that it is directed, so that its arcs into p "
3441 << "are not in the list of p: use the in_ methods of the graph, or In_Arcs_Index";
3442 }
3443
3444 // The node of a graph that is not directed, whose list holds the arcs
3445 // into it
3446 static Node * of_lists(const GT & g, Node *p)
3447 {
3448 if (g.is_digraph()) [[unlikely]]
3450 return p;
3451 }
3452
3453 public:
3460 {
3461 // empty
3462 }
3463
3471 In_Iterator(const GT & g, Node *p) : Base(of_lists(g, p))
3472 {
3473 // empty
3474 }
3475 };
3476
3477 // /** Iterator on incoming arcs of node */
3479 {
3480 using Digraph_Iterator<Out_Filt>::Digraph_Iterator;
3481 };
3482
3507 In_Iterator get_in_it(Node *p) const { return In_Iterator(*const_me(), p); }
3508
3527 Out_Iterator get_out_it(Node *p) const noexcept { return Out_Iterator(p); }
3528
3539 Arc * search_directed_arc(Node *src, Node *tgt) const noexcept
3540 {
3541 for (typename GT::Out_Iterator it(src); it.has_curr(); it.next_ne())
3542 if (it.get_tgt_node() == tgt)
3543 return it.get_curr();
3544 return nullptr;
3545 }
3546
3547private:
3548 // Calls op(a) on each arc of a digraph whose target is p, in the order
3549 // of the arc iterator, while op returns true; tells whether it went
3550 // through them all. A digraph keeps each arc only in the list of its
3551 // source, so that its arcs into p are found among those of the graph.
3552 // Out of line, and with op by value (a lambda that refers to what it
3553 // changes), so that the methods on the arcs into a node keep, on a
3554 // graph that is not directed, the code that they had.
3555 template <class Op>
3556 [[gnu::noinline]] bool traverse_digraph_arcs_into(Node *p, Op op) const
3557 {
3558 for (typename GT::Arc_Iterator it(*const_me()); it.has_curr(); it.next_ne())
3559 if (Arc *a = it.get_curr_ne(); a->tgt_node == p and not op(a))
3560 return false;
3561 return true;
3562 }
3563
3564 // The number of arcs of a digraph whose target is p; out of line, as
3565 // traverse_digraph_arcs_into()
3566 [[gnu::noinline]] size_t digraph_in_degree(Node *p) const noexcept
3567 {
3568 size_t count = 0;
3569 for (typename GT::Arc_Iterator it(*const_me()); it.has_curr(); it.next_ne())
3570 if (it.get_curr_ne()->tgt_node == p)
3571 ++count;
3572 return count;
3573 }
3574
3575public:
3587 DynList<Node *> in_nodes(Node *p) const
3588 {
3589 DynList<Node *> ret;
3590 if (digraph)
3591 {
3592 traverse_digraph_arcs_into(p, [&ret] (Arc *a)
3593 {
3594 ret.append(static_cast<Node *>(a->src_node));
3595 return true;
3596 });
3597 return ret;
3598 }
3599 for (In_Iterator it(p); it.has_curr(); it.next_ne())
3600 ret.append(it.get_node());
3601 return ret;
3602 }
3603
3614 DynList<Node *> out_nodes(Node *p) const
3615 {
3616 DynList<Node *> ret;
3617 for (Out_Iterator it(p); it.has_curr(); it.next_ne())
3618 ret.append(it.get_node_ne());
3619 return ret;
3620 }
3621
3631 DynList<Arc *> out_arcs(Node *p) const
3632 {
3633 DynList<Arc *> ret;
3634 for (Out_Iterator it(p); it.has_curr(); it.next_ne())
3635 ret.append(it.get_curr());
3636 return ret;
3637 }
3638
3648 DynList<Arc *> in_arcs(Node *p) const
3649 {
3650 DynList<Arc *> ret;
3651 if (digraph)
3652 {
3653 traverse_digraph_arcs_into(p, [&ret] (Arc *a)
3654 {
3655 ret.append(a);
3656 return true;
3657 });
3658 return ret;
3659 }
3660 for (In_Iterator it(p); it.has_curr(); it.next_ne())
3661 ret.append(it.get_curr());
3662 return ret;
3663 }
3664
3666 using ArcPair = std::tuple<Arc *, Node *>;
3667
3681 auto in_pairs(Node *p) const
3682 {
3683 DynList<ArcPair> ret;
3684 if (digraph)
3685 {
3686 traverse_digraph_arcs_into(p, [&ret, p] (Arc *a)
3687 {
3688 auto q = (Node *) a->get_connected_node(p);
3689 ret.append(std::make_tuple(a, q));
3690 return true;
3691 });
3692 return ret;
3693 }
3694 for (In_Iterator it(p); it.has_curr(); it.next_ne())
3695 {
3696 auto a = it.get_curr();
3697 ret.append(std::make_tuple(a, (Node *) a->get_connected_node(p)));
3698 }
3699 return ret;
3700 }
3701
3714 auto out_pairs(Node *p) const
3715 {
3716 DynList<ArcPair> ret;
3717 for (Out_Iterator it(p); it.has_curr(); it.next_ne())
3718 {
3719 auto a = it.get_curr();
3720 ret.append(std::make_tuple(a, (Node *) a->get_connected_node(p)));
3721 }
3722 return ret;
3723 }
3724
3740 size_t in_degree(Node *p) const noexcept
3741 {
3742 if (digraph)
3743 return digraph_in_degree(p);
3744 size_t count = 0;
3745 for (In_Iterator it(p); it.has_curr(); it.next_ne())
3746 ++count;
3747 return count;
3748 }
3749
3765 size_t out_degree(Node *p) const noexcept
3766 {
3767 size_t count = 0;
3768 for (Out_Iterator it(p); it.has_curr(); it.next_ne())
3769 ++count;
3770 return count;
3771 }
3772
3791 template <class Itor, class Operation>
3793 bool traverse_arcs(Node *p, Operation & op) const
3794 {
3795 for (Itor it(p); it.has_curr(); it.next_ne())
3796 if (not op(graph_dry_detail::curr_ne(it)))
3797 return false;
3798 return true;
3799 }
3800
3802 template <class Itor, class Operation>
3804 void for_each_arc(Node *p, Operation & op) const
3805 {
3806 for (Itor it(p); it.has_curr(); it.next_ne())
3807 op(graph_dry_detail::curr_ne(it));
3808 }
3809
3814 template <class Op>
3815 bool traverse_in_arcs(Node *p, Op & op) const
3816 {
3817 if (digraph)
3818 return traverse_digraph_arcs_into(p, [&op] (Arc *a) -> bool { return op(a); });
3819 return traverse_arcs<In_Iterator, Op>(p, op);
3820 }
3821
3823 template <class Op>
3824 bool traverse_in_arcs(Node *p, Op && op = Op()) const
3825 {
3826 return traverse_in_arcs(p, op);
3827 }
3828
3831 template <class Op>
3832 void for_each_in_arc(Node *p, Op & op) const
3833 {
3834 if (digraph)
3835 {
3836 traverse_digraph_arcs_into(p, [&op] (Arc *a)
3837 {
3838 op(a);
3839 return true;
3840 });
3841 return;
3842 }
3843 for_each_arc<In_Iterator>(p, op);
3844 }
3845
3847 template <class Op>
3848 void for_each_in_arc(Node *p, Op && op = Op()) const
3849 {
3850 for_each_in_arc(p, op);
3851 }
3852
3854 template <class Op>
3855 bool all_in_arcs(Node *p, Op & op) const
3856 {
3857 return traverse_in_arcs(p, [&op](auto a) { return op(a); });
3858 }
3859
3861 template <class Op>
3862 bool all_in_arcs(Node *p, Op && op = Op()) const
3863 {
3864 return all_in_arcs(p, op);
3865 }
3866
3869 template <class Op>
3870 bool exists_in_arc(Node *p, Op & op) const
3871 {
3872 return not traverse_in_arcs(p, [&op](auto a) { return not op(a); });
3873 }
3874
3876 template <class Op>
3877 bool exists_in_arc(Node *p, Op && op = Op()) const
3878 {
3879 return exists_in_arc(p, op);
3880 }
3881
3895 template <class Op>
3896 auto search_in_arc(Node *p, Op & op) const
3897 {
3898 Arc *ret = nullptr;
3899 traverse_in_arcs(p, [&op, &ret](auto a)
3900 {
3901 if (op(a))
3902 {
3903 ret = a;
3904 return false;
3905 }
3906 return true;
3907 });
3908 return ret;
3909 }
3910
3912 template <class Op>
3913 auto search_in_arc(Node *p, Op && op = Op()) const
3914 {
3915 return search_in_arc(p, op);
3916 }
3917
3926 template <typename T, class Op>
3927 requires std::is_invocable_r_v<T, Op &, Arc *>
3928 auto in_arcs_map(Node *p, Op op) const
3929 {
3930 DynList<T> ret;
3931 for_each_in_arc(p, [&ret, &op](auto a) { ret.append(Aleph::concepts_detail::invoke_as<T(Arc *)>::call(op, a)); });
3932 return ret;
3933 }
3934
3942 template <typename T = Arc_Type, class Op>
3943 requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
3944 T foldl_in_arcs(Node *p, const T & init,
3945 Op op) const
3946 {
3947 T ret = init;
3948 for_each_in_arc(p, [&ret, &op](auto a) { ret = Aleph::concepts_detail::invoke_as<T(const T &, Arc *)>::call(op, ret, a); });
3949 return ret;
3950 }
3951
3959 template <class Op>
3960 DynList<Arc *> filter_in_arcs(Node *p, Op & op) const
3961 {
3962 DynList<Arc *> ret;
3963 for_each_in_arc(p, [&ret, &op](auto a)
3964 {
3965 if (op(a))
3966 ret.append(a);
3967 });
3968 return ret;
3969 }
3970
3972 template <class Op>
3973 auto filter_in_arcs(Node *p, Op && op = Op()) const
3974 {
3975 return filter_in_arcs(p, op);
3976 }
3977
3980 template <class Op>
3981 bool traverse_out_arcs(Node *p, Op & op) const
3982 {
3983 return traverse_arcs<Out_Iterator>(p, op);
3984 }
3985
3987 template <class Op>
3988 bool traverse_out_arcs(Node *p, Op && op = Op()) const
3989 {
3990 return traverse_out_arcs(p, op);
3991 }
3992
3994 template <class Op>
3995 void for_each_out_arc(Node *p, Op & op) const
3996 {
3997 for_each_arc<Out_Iterator>(p, op);
3998 }
3999
4001 template <class Op>
4002 void for_each_out_arc(Node *p, Op && op = Op()) const
4003 {
4004 for_each_out_arc(p, op);
4005 }
4006
4008 template <class Op>
4009 bool all_out_arcs(Node *p, Op & op) const
4010 {
4011 return traverse_out_arcs(p, [&op](auto a) { return op(a); });
4012 }
4013
4015 template <class Op>
4016 bool all_out_arcs(Node *p, Op && op = Op()) const
4017 {
4018 return all_out_arcs(p, op);
4019 }
4020
4023 template <class Op>
4024 bool exists_out_arc(Node *p, Op & op) const
4025 {
4026 return not traverse_out_arcs(p, [&op](auto a) { return not op(a); });
4027 }
4028
4030 template <class Op>
4031 bool exists_out_arc(Node *p, Op && op = Op()) const
4032 {
4033 return exists_out_arc(p, op);
4034 }
4035
4049 template <class Op>
4050 auto search_out_arc(Node *p, Op & op) const
4051 {
4052 typename GT::Arc *ret = nullptr;
4053 traverse_out_arcs(p, [&op, &ret](auto a)
4054 {
4055 if (op(a))
4056 {
4057 ret = a;
4058 return false;
4059 }
4060 return true;
4061 });
4062 return ret;
4063 }
4064
4066 template <class Op>
4067 auto search_out_arc(Node *p, Op && op = Op()) const
4068 {
4069 return search_out_arc(p, op);
4070 }
4071
4080 template <typename T = Arc_Type, class Op>
4081 requires std::is_invocable_r_v<T, Op &, Arc *>
4082 auto out_arcs_map(Node *p, Op op) const
4083 {
4084 DynList<T> ret;
4085 for_each_out_arc(p, [&ret, &op](auto a) { ret.append(Aleph::concepts_detail::invoke_as<T(Arc *)>::call(op, a)); });
4086 return ret;
4087 }
4088
4090 template <typename T = Arc_Type, class Op>
4091 requires std::is_invocable_r_v<T, Op &, const T &, Arc *>
4092 T foldl_out_arcs(Node *p, const T & init,
4093 Op op) const
4094 {
4095 T ret = init;
4096 for_each_out_arc(p, [&ret, &op](auto a) { ret = Aleph::concepts_detail::invoke_as<T(const T &, Arc *)>::call(op, ret, a); });
4097 return ret;
4098 }
4099
4107 template <class Op>
4108 DynList<Arc *> filter_out_arcs(Node *p, Op & op) const
4109 {
4110 DynList<Arc *> ret;
4111 for_each_out_arc(p, [&ret, &op](auto a)
4112 {
4113 if (op(a))
4114 ret.append(a);
4115 });
4116 return ret;
4117 }
4118
4120 template <class Op>
4121 auto filter_out_arcs(Node *p, Op && op = Op()) const
4122 {
4123 return filter_out_arcs(p, op);
4124 }
4125
4126 // ===========================================================================
4127 // Arc Removal Helpers (protected, for use in remove_node implementations)
4128 // ===========================================================================
4129
4130protected:
4145 template <class Predicate>
4146 DynList<Arc*> collect_arcs_if(Predicate pred) const
4147 {
4148 DynList<Arc*> result;
4149 for (typename GT::Arc_Iterator it(*const_me()); it.has_curr(); it.next_ne())
4150 if (pred(it.get_curr_ne()))
4151 result.append(it.get_curr_ne());
4152 return result;
4153 }
4154
4176 template <class Predicate>
4177 void remove_arcs_if(Predicate pred)
4178 {
4179 collect_arcs_if(pred).for_each([this](auto a) { me()->remove_arc(a); });
4180 }
4181
4182public:
4183 // ===========================================================================
4184 // Sorting Methods (for Dlink-based graphs)
4185 // ===========================================================================
4186
4188 template <class U>
4189 static constexpr bool has_node_dlink_v =
4190 requires(U & u) { { u.get_node_dlink() } -> std::same_as<Dlink&>; };
4191
4192 template <class U>
4193 static constexpr bool has_arc_dlink_v =
4194 requires(U & u) { { u.get_arc_dlink() } -> std::same_as<Dlink&>; };
4195
4196 // Whether cmp, which compares pointers to T, does not throw, nor the
4197 // conversion of what it returns to bool: what Cmp_Dlink_Node and
4198 // Cmp_Dlink_Arc do with it
4199 template <class Compare, class T>
4200 static constexpr bool nothrow_cmp_v =
4201 noexcept(static_cast<bool>(std::declval<Compare &>()(std::declval<T *&>(),
4202 std::declval<T *&>())));
4203
4224 template <class Compare>
4225 void sort_nodes(Compare & cmp) noexcept(nothrow_cmp_v<Compare, Node>)
4226 requires(has_node_dlink_v<GT>)
4227 {
4229 mergesort(me()->get_node_dlink(), c);
4230 }
4231
4233 template <class Compare>
4234 void sort_nodes(Compare && cmp = Compare()) noexcept(nothrow_cmp_v<Compare, Node>)
4235 requires(has_node_dlink_v<GT>)
4236 {
4237 sort_nodes(cmp);
4238 }
4239
4260 template <class Compare>
4261 void sort_arcs(Compare & cmp) noexcept(nothrow_cmp_v<Compare, Arc>)
4262 requires(has_arc_dlink_v<GT>)
4263 {
4265 mergesort(me()->get_arc_dlink(), c);
4266 }
4267
4269 template <class Compare>
4270 void sort_arcs(Compare && cmp = Compare()) noexcept(nothrow_cmp_v<Compare, Arc>)
4271 requires(has_arc_dlink_v<GT>)
4272 {
4273 sort_arcs(cmp);
4274 }
4275};
4276
4277
4278// ============================================================================
4279// Macro for Copy/Move/Swap Pattern
4280// ============================================================================
4281
4311#define ALEPH_GRAPH_COPY_MOVE_CTORS(GraphClass) \
4312 \
4313 GraphClass(const GraphClass & g) \
4314 { \
4315 copy_graph(*this, g); \
4316 } \
4317 \
4318 \
4319 GraphClass(GraphClass && g) noexcept \
4320 { \
4321 swap(g); \
4322 } \
4323 \
4324 \
4327 GraphClass & operator=(const GraphClass & g) \
4328 { \
4329 if (this == &g) \
4330 return *this; \
4331 GraphClass copy; \
4332 copy.digraph = this->digraph; \
4333 copy_graph(copy, g); \
4334 copy.cookie = this->cookie; \
4335 swap(copy); \
4336 return *this; \
4337 } \
4338 \
4339 \
4340 GraphClass & operator=(GraphClass && g) noexcept \
4341 { \
4342 swap(g); \
4343 return *this; \
4344 }
4345
4346
4347namespace Aleph
4348{
4349
4377template <class BaseGraph>
4378class Digraph : public BaseGraph
4380public:
4381 using GT = BaseGraph;
4382 using Node = typename BaseGraph::Node;
4383 using Arc = typename BaseGraph::Arc;
4384
4389 Digraph() noexcept
4390 {
4391 this->digraph = true;
4392 }
4393
4401 Digraph(const Digraph & dg) : GT()
4402 {
4403 this->digraph = true;
4404 copy_graph(*this, dg, false);
4405 }
4406
4414 Digraph(Digraph && dg) noexcept : GT()
4415 {
4416 this->digraph = true;
4417 this->swap(dg);
4418 }
4419
4424 void swap(Digraph & g) noexcept
4425 {
4426 BaseGraph::swap(g);
4427 }
4428
4433 void swap(BaseGraph & g) = delete;
4434
4444 struct In_Iterator
4445 : Aleph::graph_dry_detail::In_Arcs_Walk<Digraph, Aleph::graph_dry_detail::Show_Every_Arc>
4448 using Walk =
4450
4453 using Walk::Walk;
4454 };
4455
4461 In_Iterator get_in_it(Node *p) const { return In_Iterator(*this, p); }
4462
4473 Digraph & operator = (const Digraph & g)
4474 {
4475 if (this == &g)
4476 return *this;
4477
4478 Digraph copy(g);
4479 copy.cookie = this->cookie;
4480 swap(copy);
4481
4482 return *this;
4483 }
4484
4493 Digraph & operator = (Digraph && g) noexcept
4494 {
4495 this->digraph = true;
4496 this->swap(g);
4497
4498 return *this;
4499 }
4500};
4501
4502} // namespace Aleph
4503
4504
4505# endif // GRAPH_DRY_H
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
#define ah_domain_error()
Throws std::domain_error unconditionally.
Definition ah-errors.H:702
C++20 concepts for the protocol shared by graph algorithms.
WeightedDigraph::Node Node
WeightedDigraph::Arc Arc
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
size_t size_t int32_t value
Definition ca-c-api.h:116
Generic directed graph (digraph) wrapper template.
Definition graph-dry.H:4377
In_Iterator get_in_it(Node *p) const
Return an iterator on the arcs that go into p: those of the arcs of the digraph whose target is p,...
Definition graph-dry.H:4459
Digraph & operator=(const Digraph &g)
Copy assignment operator.
Definition graph-dry.H:4471
typename BaseGraph::Arc Arc
Definition graph-dry.H:4381
typename BaseGraph::Node Node
Definition graph-dry.H:4380
void swap(Digraph &g) noexcept
Swap in constant time this digraph with g.
Definition graph-dry.H:4422
Digraph() noexcept
Default constructor.
Definition graph-dry.H:4387
BaseGraph GT
Definition graph-dry.H:4379
T & get_curr() const
Return the current item.
Definition htlist.H:1679
T & get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Definition htlist.H:1669
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
T & append(const T &item)
Definition htlist.H:1362
void next()
Advances the iterator to the next filtered element.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
void reset_first()
Resets the iterator to the first filtered element.
bool has_curr() const noexcept
Definition htlist.H:969
Node * get_first_node() const
Return any node in the graph.
Definition tpl_graph.H:590
Arc * get_first_arc(Node *node) const
Return any arc adjacent to a node.
Definition tpl_graph.H:609
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Definition tpl_graph.H:535
virtual void remove_arc(Arc *arc) noexcept
Remove an arc from the graph and free it.
Definition tpl_graph.H:673
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Definition tpl_graph.H:618
The iterator on the arcs into a node of a digraph type, which In_Iterator is on a type built with the...
Definition graph-dry.H:133
std::optional< Arc_Itor > arcs
Definition graph-dry.H:139
static constexpr bool goes_to_last
Whether the walk goes to its last arc, which reset_last() needs.
Definition graph-dry.H:174
Node * get_node_ne() const noexcept
Return the source of the current arc, which must exist.
Definition graph-dry.H:219
void prev_ne() noexcept(shows_ne)
prev() without its exception: nothing if there is no current arc; noexcept when the filter is,...
Definition graph-dry.H:253
In_Arcs_Walk(const GT &g, Node *p, SA sa=SA())
The arcs of g into p that sa shows, from the first one.
Definition graph-dry.H:179
void end() noexcept
Put the walk past the last arc.
Definition graph-dry.H:277
void reset_last()
Put the walk on the last arc.
Definition graph-dry.H:270
void prev()
Move to the previous arc.
Definition graph-dry.H:245
Node * get_node(Arc *a) const noexcept
Return the source of a.
Definition graph-dry.H:212
Arc * get_current_arc() const
See get_curr().
Definition graph-dry.H:206
void next()
Move to the next arc.
Definition graph-dry.H:229
void reset_first()
Put the walk on the first arc.
Definition graph-dry.H:262
In_Arcs_Walk(Node *, SA sa=SA())
The form that takes only the node, which does not compile: the list of a node of a digraph holds only...
Definition graph-dry.H:188
bool has_curr() const noexcept
Return true if there is a current arc.
Definition graph-dry.H:197
typename GT::Arc_Iterator Arc_Itor
Definition graph-dry.H:136
Node * get_tgt_node_ne() const noexcept
Alias of get_node_ne().
Definition graph-dry.H:225
Node * get_node() const
Return the source of the current arc.
Definition graph-dry.H:216
Arc * Item_Type
The type of the items: arcs.
Definition graph-dry.H:167
static constexpr bool goes_back
Whether the walk moves back: the arc iterators of List_SGraph and List_SDigraph go only forward.
Definition graph-dry.H:171
Arc * get_curr_ne() const noexcept
Return the current arc, which must exist.
Definition graph-dry.H:203
Node * get_tgt_node() const
Alias of get_node().
Definition graph-dry.H:222
Arc * get_curr() const
Return the current arc. Throws overflow_error if there is none.
Definition graph-dry.H:200
Arc * get_current_arc_ne() const noexcept
See get_curr_ne().
Definition graph-dry.H:209
void next_ne() noexcept(shows_ne)
Move to the next arc, which must exist; noexcept when the filter is, else what the filter throws goes...
Definition graph-dry.H:237
void for_each(Operation &operation) const
Traverse all the container and performs an operation on each element.
Definition ah-dry.H:1475
Common methods for the arc of a graph.
Definition graph-dry.H:787
GTArcCommon() noexcept=default
data contained in arc
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
Definition graph-dry.H:854
void * tgt_node
Please don't use.
Definition graph-dry.H:793
void * get_connected_node(void *node) noexcept
Definition graph-dry.H:859
GTArcCommon(const GTArcCommon &other)
Copy constructor.
Definition graph-dry.H:821
GTArcCommon(void *src, void *tgt, const ArcInfo &data)
Construct with endpoints and info (copy)
Definition graph-dry.H:813
const ArcInfo & get_info() const noexcept
Return a constant reference to the arc data.
Definition graph-dry.H:857
GTArcCommon(GTArcCommon &&other) noexcept
Move constructor.
Definition graph-dry.H:825
Graph_Attr attrs
Please don't use.
Definition graph-dry.H:799
ArcInfo arc_info
Definition graph-dry.H:801
GTArcCommon(ArcInfo &&info)
Construct from info value (move)
Definition graph-dry.H:810
GTArcCommon & operator=(const GTArcCommon &other)
Copy assignment operator.
Definition graph-dry.H:829
void set_state(unsigned int s) noexcept
Set the state of arc to value s
Definition graph-dry.H:848
void * get_img_node(void *node) noexcept
Definition graph-dry.H:864
GTArcCommon(void *src, void *tgt, ArcInfo &&data=ArcInfo())
Construct with endpoints and info (move)
Definition graph-dry.H:817
unsigned int state() const noexcept
Return the state of arc.
Definition graph-dry.H:845
void * src_node
Definition graph-dry.H:792
GTArcCommon & operator=(GTArcCommon &&other) noexcept
Move assignment operator.
Definition graph-dry.H:837
Common attributes and methods for nodes (vertexes) belonging to graphs.
Definition graph-dry.H:694
NodeInfo Item_Type
Definition graph-dry.H:715
const NodeInfo & get_info() const noexcept
Return a constant reference to the data contained in the node.
Definition graph-dry.H:756
GTNodeCommon() noexcept=default
another alias for set type
NodeInfo node_info
Definition graph-dry.H:702
GTNodeCommon & operator=(const GTNodeCommon &other)
Copy assignment operator.
Definition graph-dry.H:737
GTNodeCommon(NodeInfo &&info)
Move constructor from info value.
Definition graph-dry.H:728
Graph_Attr attrs
Attributes of node.
Definition graph-dry.H:700
unsigned int state() const noexcept
Return the state's value.
Definition graph-dry.H:759
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
Definition graph-dry.H:753
NodeInfo Node_Type
The node.
Definition graph-dry.H:719
GTNodeCommon & operator=(GTNodeCommon &&other) noexcept
Move assignment operator.
Definition graph-dry.H:745
GTNodeCommon(GTNodeCommon &&other) noexcept
Move constructor.
Definition graph-dry.H:734
GTNodeCommon(const GTNodeCommon &other)
Copy constructor.
Definition graph-dry.H:731
void set_state(unsigned int s) noexcept
Set the state to value s
Definition graph-dry.H:762
size_t num_arcs
data associated to the node. Access it with get_info()
Definition graph-dry.H:713
Special iterator for distinguishing input arcs of output ones.
Definition graph-dry.H:3313
static constexpr bool goes_to_last
Whether the iterator goes to its last arc, which reset_last() needs.
Definition graph-dry.H:3334
typename Itor::Item_Type Item_Type
Definition graph-dry.H:3325
void next()
Advance to next arc.
Definition graph-dry.H:3348
void reset_first() noexcept(shows_ne)
Reset the iterator to first arc.
Definition graph-dry.H:3397
Digraph_Iterator(Node *p)
Instantiate an filtered iterator for arcs on the node p
Definition graph-dry.H:3337
void next_ne() noexcept(shows_ne)
next() without its check: the current arc must exist.
Definition graph-dry.H:3344
static constexpr bool shows_ne
Whether what the filter says of an arc cannot throw, nor its conversion to bool: the moves without ch...
Definition graph-dry.H:3323
void prev_ne()
prev() without exceptions. Only where the iterator moves back
Definition graph-dry.H:3355
Filter_Iterator< Node *, typename GT::Node_Arc_Iterator, Filter > Itor
Definition graph-dry.H:3314
GT::Arc * get_curr_ne() const noexcept
Definition graph-dry.H:3364
void prev()
back to previous item.
Definition graph-dry.H:3352
GT::Arc * get_curr() const
Return the current arc.
Definition graph-dry.H:3362
GT::Node * get_node(typename GT::Arc *a) const noexcept
Return the node connected to p (passed during construction) and linked through a
Definition graph-dry.H:3373
Itor Iterator_Type
the type of items (Arc*)
Definition graph-dry.H:3327
void reset_last() noexcept(shows_ne)
Reset the iterator to last arc.
Definition graph-dry.H:3401
auto get_current_arc() const
See get_curr().
Definition graph-dry.H:3367
static constexpr bool goes_back
Whether the iterator moves back: the iterators of the lists of List_SGraph go only forward,...
Definition graph-dry.H:3331
auto get_tgt_node_ne() const noexcept
Backward-compatible alias: return target node (same as get_node_ne()).
Definition graph-dry.H:3386
auto get_current_arc_ne() const noexcept
Definition graph-dry.H:3369
GT::Node * get_node_ne() const noexcept
Return the node connected to p (passed during construction) and linked through the current arc.
Definition graph-dry.H:3380
bool has_curr() const noexcept
Return true is the iterator has a current arc.
Definition graph-dry.H:3358
auto get_tgt_node() const
Backward-compatible alias: return target node (same as get_node()).
Definition graph-dry.H:3394
GT::Node * get_node() const
Definition graph-dry.H:3388
Common methods to the Aleph-w ( ) graph classes.
Definition graph-dry.H:877
void init() noexcept
Definition graph-dry.H:910
void sort_arcs(Compare &cmp) noexcept(nothrow_cmp_v< Compare, Arc >)
Sort all the arcs of the graph according to a specific criteria.
Definition graph-dry.H:4261
void sort_nodes(Compare &cmp) noexcept(nothrow_cmp_v< Compare, Node >)
Sort all the nodes of the graph according to a specific criteria.
Definition graph-dry.H:4225
Arc * min_arc(Node *p, Compare cmp=[](Arc *a, Arc *b) { return a->get_info()< b->get_info();}) const
Find the minimum arc adjacent to a node.
Definition graph-dry.H:2719
In_Iterator get_in_it(Node *p) const
Return an input iterator on the incoming arcs to p
Definition graph-dry.H:3507
void for_each_arc(Node *p, Operation &op) const
Unconditionally traverse all the arcs adjacnt to a node and on each one perform an operation.
Definition graph-dry.H:1854
void reset_bit_nodes(int bit) const noexcept
Reset bit to zero for all the nodes of graph.
Definition graph-dry.H:1326
auto out_arcs_map(Node *p, Op op) const
Return a list of outcoming arcs of a node mapped to items of type given by transformation op.
Definition graph-dry.H:4082
typename Arc::Arc_Type Arc_Type
Definition graph-dry.H:907
auto search_in_arc(Node *p, Op &op) const
Search an incoming arc to a node satisfaying a condition.
Definition graph-dry.H:3896
T sum_arcs(Node *p, Extract extract) const
Sum values derived from arcs adjacent to a node.
Definition graph-dry.H:2686
void for_each_out_arc(Node *p, Op &op) const
Perform op on each outcoming arc of node p
Definition graph-dry.H:3995
auto filter_arcs(Node *p, Op &&op) const
Overload of filter_arcs(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:2415
Node * find_node(const Node_Type &info) const noexcept(noexcept(static_cast< bool >(std::declval< Node_Type & >()==std::declval< const Node_Type & >())))
Find a node mathing a content.
Definition graph-dry.H:2921
T foldl_arcs(Node *p, const T &init, Op op) const
Folding of arcs of a node.
Definition graph-dry.H:2277
bool exists_in_arc(Node *p, Op &op) const
Return true if it exists a incoming arc to p returning true for op
Definition graph-dry.H:3870
void for_each_arc(Node *p, Operation &&op=Operation()) const
Overload of for_each_arc(Node*, Operation&) that accepts rvalues.
Definition graph-dry.H:1863
void * get_cookie() const noexcept
Return a constant reference to graph's cookie.
Definition graph-dry.H:934
Arc * emplace_arc(Node *src, Node *tgt, Args &&... args)
Insert a new arc in the graph by constructing its associated data in-place with the given args.
Definition graph-dry.H:1534
void reset_arcs() const
Reset all the arcs of graph (the control bits, the state, the counter and the cookie)
Definition graph-dry.H:1213
bool all_arcs(Node *p, Operation &&op=Operation()) const
Overload of all_arcs(Node*, Operation&) that accepts rvalues.
Definition graph-dry.H:1998
auto filter_in_arcs(Node *p, Op &&op=Op()) const
Overload of filter_in_arcs(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:3973
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Definition graph-dry.H:975
void reset_cookie_arcs() const noexcept
Reset all the cookies to `nullptr for all the arcs of graph.
Definition graph-dry.H:1378
bool traverse_digraph_arcs_into(Node *p, Op op) const
Definition graph-dry.H:3556
Container< Arc * > arcs() const
Return a container with all the arcs of the graph.
Definition graph-dry.H:3080
int get_bit(Arc *arc, int bit) const noexcept
Get the control bit of arc
Definition graph-dry.H:1129
size_t get_num_arcs(Node *node) const noexcept
Return the total of arcs of a node.
Definition graph-dry.H:1068
size_t num_nodes
Definition graph-dry.H:901
void for_each_arc(Operation &op) const
Unconditionally traverse all the arcs of graph and on each one perform an operation.
Definition graph-dry.H:1805
bool all_nodes(Operation &&op=Operation()) const
Overload of all_nodes(Operation&) that accepts rvalues.
Definition graph-dry.H:1907
bool exists_out_arc(Node *p, Op &op) const
Return true if it exists a outcoming arc to p returning true for op
Definition graph-dry.H:4024
void for_each_in_arc(Node *p, Op &op) const
Perform op on each incoming arc of node p; on a digraph, among the arcs of the graph,...
Definition graph-dry.H:3832
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
Definition graph-dry.H:3144
void reset_counter(Node *node) const noexcept
Reset the node counter to zero.
Definition graph-dry.H:1159
void for_each_out_arc(Node *p, Op &&op=Op()) const
Overload of for_each_out_arc(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:4002
Node * insert_node(Node_Type &&node_info=Node_Type())
Allocate a new node, set by moving its data content and insert it into the graph.
Definition graph-dry.H:1426
void sort_nodes(Compare &&cmp=Compare()) noexcept(nothrow_cmp_v< Compare, Node >)
See sort_nodes(Compare & cmp).
Definition graph-dry.H:4234
Node * insert_node(const Node_Type &node_info)
Allocate a new node, set by copy its data content and insert it into the graph.
Definition graph-dry.H:1402
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Definition graph-dry.H:1017
Node * get_node() const
Return any node in the graph.
Definition graph-dry.H:994
Out_Iterator get_out_it(Node *p) const noexcept
Return an output iterator on the incoming nodes to p
Definition graph-dry.H:3527
auto search_out_arc(Node *p, Op &op) const
Search an outcoming arc to a node satisfaying a condition.
Definition graph-dry.H:4050
std::tuple< Arc *, Node * > ArcPair
Pair of arc and node (topologically related)
Definition graph-dry.H:3666
DynList< Node * > in_nodes(Node *p) const
Return a list with the incoming nodes to p
Definition graph-dry.H:3587
void for_each_arc(Node *p, Operation &op) const
Perform op on each arc of node p
Definition graph-dry.H:3804
bool traverse_nodes(Operation &op) const
Conditioned traversal of all the nodes of a graph.
Definition graph-dry.H:1587
T foldl_in_arcs(Node *p, const T &init, Op op) const
Fold the incoming arcs of a node.
Definition graph-dry.H:3944
Arc * search_arc(Op &&op) const
Overload of search_arc(Op&) that accepts rvalues.
Definition graph-dry.H:2959
bool traverse_arcs(Node *p, Operation &op) const
Conditioned traversal of all the adjacent arcs of a node.
Definition graph-dry.H:1723
bool traverse_in_arcs(Node *p, Op &&op=Op()) const
Overload of traverse_in_arcs(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:3824
void reset_bit_nodes() const noexcept
Reset all the bits for all the nodes of graph.
Definition graph-dry.H:1338
bool exists_arc(Node *p, Operation &op) const
Determine if exists at least a arc adjacent to a node satisfying a condition.
Definition graph-dry.H:2510
auto search_in_arc(Node *p, Op &&op=Op()) const
Overload of search_in_arc(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:3913
auto search_out_arc(Node *p, Op &&op=Op()) const
Overload of search_out_arc(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:4067
void for_each_in_arc(Node *p, Op &&op=Op()) const
Overload of for_each_in_arc(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:3848
T sum_arcs(Node *p) const
Overload of sum_arcs(Node*, Extract) using the arc info as extractor.
Definition graph-dry.H:2695
Arc * max_arc(Compare cmp=[](Arc *a, Arc *b) { return a->get_info()< b->get_info();}) const
Find the maximum arc in the entire graph.
Definition graph-dry.H:2786
Arc * insert_new_arc(Node *src, Node *tgt, Arc *arc)
Definition graph-dry.H:886
Arc * insert_arc(Node *src, Node *tgt, Arc_Type &&arc_info=Arc_Type())
Create and insert a new arc linking two nodes and moving the received data.
Definition graph-dry.H:1507
bool none_arc(Node *p, Operation &&op) const
Overload of none_arc(Node*, Operation&) that accepts rvalues.
Definition graph-dry.H:2598
bool none_node(Operation &&op) const
Overload of none_node(Operation&) that accepts rvalues.
Definition graph-dry.H:2547
void set_bit(Node *node, int bit, int value) const noexcept
Set the control bit of node to value
Definition graph-dry.H:1105
DynList< Arc * > out_arcs(Node *p) const
Return a list with the outcoming arcs to p`.
Definition graph-dry.H:3631
bool exists_in_arc(Node *p, Op &&op=Op()) const
Overload of exists_in_arc(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:3877
void set_bit(Arc *arc, int bit, int value) const noexcept
Set the control bit of arc to value
Definition graph-dry.H:1135
Arc * search_arc(Node *p, Operation &op) const
Linear search of an arc.
Definition graph-dry.H:3001
bool is_digraph() const noexcept
Return true if the graph this is directed.
Definition graph-dry.H:937
void reset_cookie_nodes() const noexcept
Reset all the cookies to `nullptr for all the nodes of graph.
Definition graph-dry.H:1367
void reset_counter(Arc *arc) const noexcept
Reset the acr counter to zero.
Definition graph-dry.H:1185
size_t num_arcs
Definition graph-dry.H:902
T foldl_nodes(const T &init, Op op) const
Folding of nodes on a graph.
Definition graph-dry.H:2190
auto filter_arcs(Node *p, Op &op) const
Filter the arcs adjacent to a node satisfying a condition.
Definition graph-dry.H:2401
void set_digraph(bool val)
Temporal indication for preventing to other algorithms that an graph must be treated as a directed gr...
Definition graph-dry.H:972
bool traverse_out_arcs(Node *p, Op &&op=Op()) const
Overload of traverse_out_arcs(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:3988
bool traverse_arcs(Node *p, Operation &&op=Operation()) const
Overload of traverse_arcs(Node*, Operation&) that accepts rvalues.
Definition graph-dry.H:1734
bool all_arcs(Operation &op) const
Check if all the arcs of graph satisfy a boolean condition.
Definition graph-dry.H:1943
auto nodes_map(Op op) const
Map the nodes of a graph to a specific range.
Definition graph-dry.H:2044
void *& get_cookie() noexcept
Return a modifiable reference to graph's cookie.
Definition graph-dry.H:931
T foldl_arcs(const T &init, Op op) const
Folding of arcs on a graph.
Definition graph-dry.H:2233
bool all_nodes(Operation &op) const
Check if all the nodes of graph satisfy an boolean condition.
Definition graph-dry.H:1899
DynList< Arc * > filter_in_arcs(Node *p, Op &op) const
Filter the incoming arcs of a node.
Definition graph-dry.H:3960
auto arcs_map(Op operation) const
Map the arcs of a graph to a specific range.
Definition graph-dry.H:2092
bool all_in_arcs(Node *p, Op &op) const
Return true if op is true for all the incoming arcs to node p
Definition graph-dry.H:3855
void reset_bit_arcs() const noexcept
Reset all the bits for all the arcs of graph.
Definition graph-dry.H:1344
Arc * get_arc() const
Return any arc in the graph.
Definition graph-dry.H:1004
static void map_arcs(A1 *p, A2 *q) noexcept
Map the arcs through their cookies.
Definition graph-dry.H:1312
auto in_pairs(Node *p) const
Return a list of pair incoming arcs and nodes.
Definition graph-dry.H:3681
void reset_counter_nodes() const noexcept
Reset all the counters to zero for all the nodes of graph.
Definition graph-dry.H:1350
Arc * search_arc(Node *src, Node *tgt) const noexcept
Search an arc linking two nodes.
Definition graph-dry.H:3043
bool traverse_in_arcs(Node *p, Op &op) const
Traverse the incoming arcs of node p executing the conditioned operation.
Definition graph-dry.H:3815
size_t digraph_in_degree(Node *p) const noexcept
Definition graph-dry.H:3566
typename Node::Node_Type Node_Type
Definition graph-dry.H:906
size_t count_arcs(Node *p, Operation op=[](Arc *) { return true;}) const
Count arcs adjacent to a node satisfying a condition.
Definition graph-dry.H:2661
auto arcs_map(Node *p, Op operation) const
Map the adjacent arcs of a node to a specific range.
Definition graph-dry.H:2144
DynList< Arc * > in_arcs(Node *p) const
Return a list with the incoming arcs to p
Definition graph-dry.H:3648
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
Definition graph-dry.H:1058
bool traverse_out_arcs(Node *p, Op &op) const
Traverse the outcoming arcs of node p executing the conditioned operation
Definition graph-dry.H:3981
void common_swap(GT &g) noexcept
Definition graph-dry.H:921
std::pair< DynList< Node * >, DynList< Node * > > partition_nodes(Operation op) const
Partition nodes into two groups based on a predicate.
Definition graph-dry.H:2815
constexpr bool is_empty() const noexcept
Checks if the graph is empty (has no nodes).
Definition graph-dry.H:981
Arc * find_arc(const Arc_Type &info) const noexcept(noexcept(static_cast< bool >(std::declval< Arc_Type & >()==std::declval< const Arc_Type & >())))
Find an arc mathing a content.
Definition graph-dry.H:2975
bool exists_arc(Operation &&op=Operation()) const
Overload of exists_arc(Operation&) that accepts rvalues.
Definition graph-dry.H:2481
long & get_counter(Node *node) const noexcept
Get a modifiable reference to the counter of node
Definition graph-dry.H:1153
bool traverse_arcs(Node *p, Operation &op) const
Traverse of arcs of a node according to specific arcs iterator.
Definition graph-dry.H:3793
bool all_out_arcs(Node *p, Op &op) const
Return true if op is true for all the outcoming arcs to node p
Definition graph-dry.H:4009
void reset_bit(Node *node, int bit) const noexcept
Reset the bit of node (to zero)
Definition graph-dry.H:1087
auto filter_nodes(Op &&op) const
Overload of filter_nodes(Op&) that accepts rvalues.
Definition graph-dry.H:2322
void reset_bit_arcs(int bit) const noexcept
Reset bit to zero for all the arcs of graph.
Definition graph-dry.H:1332
GT * me()
Definition graph-dry.H:878
size_t out_degree(Node *p) const noexcept
Compute the output degree of a node.
Definition graph-dry.H:3765
Node * emplace_node(Args &&... args)
Insert a new node in the graph by constructing it in-place with the given args.
Definition graph-dry.H:1452
Arc * insert_arc(Node *src, Node *tgt, const Arc_Type &arc_info)
Create and insert a new arc linking two nodes and copying data.
Definition graph-dry.H:1479
void for_each_node(Operation &operation) const
Unconditionally traverse all the nodes of graph and on each one perform an operation.
Definition graph-dry.H:1765
void reset_node_counters() const noexcept
Reset all the node counters of graph to zero.
Definition graph-dry.H:1165
Arc * max_arc(Node *p, Compare cmp=[](Arc *a, Arc *b) { return a->get_info()< b->get_info();}) const
Find the maximum arc adjacent to a node.
Definition graph-dry.H:2748
bool none_node(Operation &op) const
Determine if no node satisfies a condition.
Definition graph-dry.H:2539
bool traverse_nodes(Operation &&op=Operation()) const
Overload of traverse_nodes(Operation&) that accepts rvalues.
Definition graph-dry.H:1598
Bit_Fields & get_control_bits(Node *node) const noexcept
Return a reference to control fields of node
Definition graph-dry.H:1081
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
Definition graph-dry.H:1064
size_t degree(Node *p) const noexcept
Return the total of arcs (or degree) of a node.
Definition graph-dry.H:1075
Arc * search_arc(Op &op) const
Linear search of an arc.
Definition graph-dry.H:2945
void reset_counter_arcs() const noexcept
Reset all the counters to zero for all the arcs of graph.
Definition graph-dry.H:1356
constexpr size_t vsize() const noexcept
See get_num_nodes().
Definition graph-dry.H:984
void reset_bits(Node *node) const noexcept
Reset all the control bits of node
Definition graph-dry.H:1093
bool all_out_arcs(Node *p, Op &&op=Op()) const
Overload of all_out_arcs(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:4016
Arc * search_directed_arc(Node *src, Node *tgt) const noexcept
Search a directed arc linking two nodes.
Definition graph-dry.H:3539
long & get_counter(Arc *arc) const noexcept
Get a modifiable reference to the counter of arc
Definition graph-dry.H:1179
bool traverse_arcs(Operation &&op=Operation()) const
Overload of traverse_arcs(Operation&) that accepts rvalues.
Definition graph-dry.H:1665
bool all_arcs(Node *p, Operation &op) const
Check if all the arcs adjacent to a node satisfy an boolean condition.
Definition graph-dry.H:1990
const GT * const_me() const
Definition graph-dry.H:880
size_t esize() const noexcept
Return the total of arcs of graph.
Definition graph-dry.H:1078
void reset_arc(Arc *arc) const noexcept
Reset all the control attributes of arc.
Definition graph-dry.H:1199
void reset_nodes() const
Reset all the nodes of graph (the control bits, the state, the counter and the cookie)
Definition graph-dry.H:1206
Arc * get_arc(Node *p) const
Return any arc adjacent to a node.
Definition graph-dry.H:1014
void reset_node(Node *p) const noexcept
Reset all the control attributes of node p.
Definition graph-dry.H:1173
auto in_arcs_map(Node *p, Op op) const
Return a list of incoming arcs of a node mapped to items of type given by transformation op.
Definition graph-dry.H:3928
size_t in_degree(Node *p) const noexcept
Compute the input degree of a node.
Definition graph-dry.H:3740
auto filter_arcs(Op &op) const
Filter the arcs of graph satisfying a condition.
Definition graph-dry.H:2350
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
Definition graph-dry.H:3122
Arc * search_arc(Node *p, Operation &&op=Operation()) const
Overload of search_arc(Node*, Operation&) that accepts rvalues.
Definition graph-dry.H:3015
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Definition graph-dry.H:1023
auto filter_out_arcs(Node *p, Op &&op=Op()) const
Overload of filter_out_arcs(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:4121
DynList< Arc * > collect_arcs_if(Predicate pred) const
Collect all arcs matching a predicate.
Definition graph-dry.H:4146
void for_each_arc(Operation &&operation=Operation()) const
Overload of for_each_arc(Operation&) that accepts rvalues.
Definition graph-dry.H:1814
bool all_in_arcs(Node *p, Op &&op=Op()) const
Overload of all_in_arcs(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:3862
void reset_bits(Arc *arc) const noexcept
Reset all the control bits of arc
Definition graph-dry.H:1123
bool exists_node(Operation &op) const
Determine if exists at least a node satisfying a condition.
Definition graph-dry.H:2440
auto get_arc_it(Node *p) const noexcept
Obtains an iterator to the adjacent arcs of a node.
Definition graph-dry.H:3167
DynList< Node * > out_nodes(Node *p) const
Return a list with the outcoming nodes to p
Definition graph-dry.H:3614
void *& get_cookie(Arc *arc) const noexcept
Get a modifiable reference to the cookie pointer of arc
Definition graph-dry.H:1147
Container< Node * > nodes() const
Return a container with all the nodes of the graph.
Definition graph-dry.H:3062
static void map_nodes(N1 *p, N2 *q) noexcept
Map the nodes through their cookies.
Definition graph-dry.H:1281
std::pair< DynList< Arc * >, DynList< Arc * > > partition_arcs(Operation op) const
Partition arcs into two groups based on a predicate.
Definition graph-dry.H:2839
Container< Arc * > arcs(Node *p) const
Return a container with all the arcs adjacent to a node.
Definition graph-dry.H:3098
static constexpr bool nothrow_cmp_v
Definition graph-dry.H:4200
void sort_arcs(Compare &&cmp=Compare()) noexcept(nothrow_cmp_v< Compare, Arc >)
See sort_arcs(Compare & cmp).
Definition graph-dry.H:4270
void reset_arc_counters() const noexcept
Reset all the arc counters of graph to zero.
Definition graph-dry.H:1191
void reset_bit(Arc *arc, int bit) const noexcept
Reset the bit of arc to zero.
Definition graph-dry.H:1117
auto filter_nodes(Op &op) const
Filter the nodes satisfying a condition.
Definition graph-dry.H:2308
bool all_arcs(Operation &&op=Operation()) const
Overload of all_arcs(Operation&) that accepts rvalues.
Definition graph-dry.H:1951
Node * search_node(Op &op) const
Linear search of a node.
Definition graph-dry.H:2891
Node * search_node(Op &&op) const
Overload of search_node(Op&) that accepts rvalues.
Definition graph-dry.H:2905
Bit_Fields & get_control_bits(Arc *arc) const noexcept
Return a reference to the control bits of arc
Definition graph-dry.H:1111
DynList< Arc * > filter_out_arcs(Node *p, Op &op) const
Filter the outcoming arcs of a node.
Definition graph-dry.H:4108
bool traverse_arcs(Operation &op) const
Conditioned traversal of all the arcs of a graph.
Definition graph-dry.H:1654
DynList< Node * > adjacent_nodes(Node *p) const
Get all adjacent nodes (neighbors) of a node.
Definition graph-dry.H:2864
bool none_arc(Operation &&op) const
Overload of none_arc(Operation&) that accepts rvalues.
Definition graph-dry.H:2576
auto filter_arcs(Op &&op) const
Overload of filter_arcs(Op&) that accepts rvalues.
Definition graph-dry.H:2364
static constexpr bool has_arc_dlink_v
Definition graph-dry.H:4193
void remove_arcs_if(Predicate pred)
Remove all arcs matching a predicate.
Definition graph-dry.H:4177
bool none_arc(Node *p, Operation &op) const
Determine if no arc adjacent to a node satisfies a condition.
Definition graph-dry.H:2590
void *& get_cookie(Node *node) const noexcept
Get a modifiable reference to the cookie pointer of node
Definition graph-dry.H:1141
bool exists_node(Operation &&op=Operation()) const
Overload of exists_node(Operation&) that accepts rvalues.
Definition graph-dry.H:2448
size_t count_arcs(Operation op=[](Arc *) { return true;}) const
Count the arcs satisfying a condition.
Definition graph-dry.H:2646
void for_each_node(Operation &&operation=Operation()) const
Overload of for_each_node(Operation&) that accepts rvalues.
Definition graph-dry.H:1774
T foldl_out_arcs(Node *p, const T &init, Op op) const
Fold-left over outcoming arcs of a node.
Definition graph-dry.H:4092
Arc * min_arc(Compare cmp=[](Arc *a, Arc *b) { return a->get_info()< b->get_info();}) const
Find the minimum arc in the entire graph.
Definition graph-dry.H:2767
bool exists_out_arc(Node *p, Op &&op=Op()) const
Overload of exists_out_arc(Node*, Op&) that accepts rvalues.
Definition graph-dry.H:4031
static constexpr bool has_node_dlink_v
Whether U::get_node_dlink() returns a Dlink &.
Definition graph-dry.H:4189
auto out_pairs(Node *p) const
Return a list of pair outcoming arcs and nodes.
Definition graph-dry.H:3714
int get_bit(Node *node, int bit) const noexcept
Get the control bit of node
Definition graph-dry.H:1099
void * cookie
Definition graph-dry.H:900
bool none_arc(Operation &op) const
Determine if no arc satisfies a condition.
Definition graph-dry.H:2568
bool exists_arc(Node *p, Operation &&op=Operation()) const
Overload of exists_arc(Node*, Operation&) that accepts rvalues.
Definition graph-dry.H:2518
bool exists_arc(Operation &op) const
Determine if exists at least a arc satisfying a condition.
Definition graph-dry.H:2473
size_t count_nodes(Operation op=[](Node *) { return true;}) const
Count the nodes satisfying a condition.
Definition graph-dry.H:2621
An AlephIterator whose get_curr_ne() gives what get_curr() gives, without its check.
f(args...) is a valid call expression, exactly as written.
A graph type built with the Digraph template.
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.
Concept for basic graph iterators.
Definition graph-dry.H:393
Concept for graph arc iterators.
Definition graph-dry.H:451
Concept for graph node iterators.
Definition graph-dry.H:432
Concept for node adjacency iterators.
Definition graph-dry.H:475
Concept for resettable graph iterators.
Definition graph-dry.H:413
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Definition gmpfrxx.h:4196
List_Digraph< Node, Arc > Digraph
Definition graphpic.C:400
#define ARC_COOKIE(p)
Return the arc cookie
#define NODE_COUNTER(p)
Get the counter of a node.
#define ARC_COUNTER(p)
Return the counter of arc p.
#define ARC_BITS(p)
Return the control bits of arc p.
#define NODE_COOKIE(p)
Return the node cookie
#define NODE_BITS(p)
Get the control bits of a node.
void copy_graph(GT &gtgt, const GT &gsrc, bool cookie_map=false)
Explicit copy of graph.
Definition tpl_graph.H:4794
Freq_Node * pred
Predecessor node in level-order traversal.
decltype(auto) curr_ne(It &it)
The current item of it, which must have one.
Definition graph-dry.H:107
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
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:152
auto get_curr() const
Return the current tuple (bounds-checked).
Definition ah-zip.H:192
and
Check uniqueness with explicit hash + equality functors.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
STL namespace.
Empty_Class ArcInfo
string NodeInfo
Iterator on the arcs that go into a node of the digraph.
Definition graph-dry.H:4444
Empty placeholder class with no data members.
Definition ahDefs.H:107
The filter of a walk that shows every arc.
Definition graph-dry.H:282
bool operator()(Arc *) const noexcept
Every arc is shown.
Definition graph-dry.H:285
What GT::Arc_Iterator::get_curr() yields, deferred on D.
Definition graph-dry.H:81
decltype(std::declval< typename concepts_detail::defer< GT, D >::type::Arc_Iterator & >().get_curr()) type
Definition graph-dry.H:82
What GT::Node_Arc_Iterator::get_curr() yields, deferred on D.
Definition graph-dry.H:91
decltype(std::declval< typename concepts_detail::defer< GT, D >::type::Node_Arc_Iterator & >().get_curr()) type
Definition graph-dry.H:92
What GT::Node_Iterator::get_curr() yields, deferred on D.
Definition graph-dry.H:71
decltype(std::declval< typename concepts_detail::defer< GT, D >::type::Node_Iterator & >().get_curr()) type
Definition graph-dry.H:72
Common arc iterator for graph having its arcs derived from Dlink class.
Definition graph-dry.H:542
Arc * get_curr() const
Return current arc.
Definition graph-dry.H:569
typename GT::Node Node
Definition graph-dry.H:543
Arc * Item_Type
The type of item that returns the iterator.
Definition graph-dry.H:547
Arc * get_curr_ne() const noexcept
Return current arc without exception.
Definition graph-dry.H:563
GTArcIterator() noexcept
Definition graph-dry.H:552
Node * get_tgt_node() const
Return the target node of current arc (if it is a directed graph)
Definition graph-dry.H:596
Arc * get_current_arc() const
Return the current arc.
Definition graph-dry.H:572
typename GT::Arc Arc
Definition graph-dry.H:544
Node * get_src_node_ne() const noexcept
Return the source node of current arc (if it is a directed graph)
Definition graph-dry.H:578
Arc * get_current_arc_ne() const noexcept
Return the current arc without exception.
Definition graph-dry.H:575
Node * get_tgt_node_ne() const noexcept
Return the target node of current arc (if it is a directed graph)
Definition graph-dry.H:584
Node * get_src_node() const
Return the source node of current arc (if it is a directed graph)
Definition graph-dry.H:590
GTArcIterator(Dlink &head) noexcept
Build a iterator for all the arcs of g.
Definition graph-dry.H:557
Common node iterator for graph having its node derived from Dlink class.
Definition graph-dry.H:497
GTNodeIterator() noexcept
Definition graph-dry.H:506
Node * Item_Type
The type of item that returns the iterator.
Definition graph-dry.H:501
Node * get_current_node() const
Return the current node.
Definition graph-dry.H:525
GTNodeIterator(Dlink &head) noexcept
Build a iterator for all the nodes of g.
Definition graph-dry.H:511
Node * get_curr_ne() const noexcept
Return the current node without exception.
Definition graph-dry.H:516
typename GT::Node Node
Definition graph-dry.H:498
Node * get_current_node_ne() const
Definition graph-dry.H:527
Node * get_curr() const
Return the current node.
Definition graph-dry.H:522
Filter for input arcs of a node.
Definition graph-dry.H:3205
Node * get_node(Arc *a) const noexcept
Return the source node of arc a
Definition graph-dry.H:3222
In_Filt(Node *__tgt=nullptr) noexcept
target node of iteration
Definition graph-dry.H:3209
bool operator()(Arc *a) const noexcept
Return true if the arc a is incoming arc to tgt; false otherwise.
Definition graph-dry.H:3215
Alias for Digraph_Iterator
Definition graph-dry.H:3430
In_Iterator(Node *p)
Iterator on the list of p, which holds the arcs into p only in a graph that is not directed.
Definition graph-dry.H:3459
In_Iterator(const GT &g, Node *p)
Iterator on the arcs into p of g, a graph that is not directed: those of the list of p.
Definition graph-dry.H:3471
static Node * of_lists(const GT &g, Node *p)
Definition graph-dry.H:3446
static void refuse_a_digraph()
Definition graph-dry.H:3437
Filter for output arcs of a node.
Definition graph-dry.H:3262
Out_Filt(Node *__src) noexcept
source node of iteration
Definition graph-dry.H:3266
Node * get_node(Arc *a) const noexcept
Return the source node of arc a (whose target is tgt)
Definition graph-dry.H:3279
bool operator()(Arc *a) const noexcept
Return true if a is a outcoming arc from src; false otherwise.
Definition graph-dry.H:3272