Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_graph.H
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
31
44# ifndef TPL_GRAPH_H
45# define TPL_GRAPH_H
46
47# include <memory>
48# include <cassert>
49# include <tuple>
50# include <utility>
51# include <functional>
52# include <bitArray.H>
53# include <tpl_dynArray.H>
54# include <tpl_sort_utils.H>
55# include <tpl_dynMapTree.H>
56# include <tpl_dynDlist.H>
57# include <tpl_treapRk.H>
58# include <filter_iterator.H>
59# include <aleph-graph.H>
60# include <graph-dry.H>
61# include <ah-errors.H>
62
63using namespace Aleph;
64
65namespace Aleph
66{
67 template <typename Node_Info>
68 struct Graph_Node;
69
70 template <typename Arc_Info>
71 struct Graph_Arc;
72
73 class Arc_Node;
74
75 template <class GT>
76 class Path;
77
78 template <typename __Graph_Node, typename __Graph_Arc>
79 class List_Graph;
80
81 // List_Digraph is defined as a type alias later in this file
82 // using the generic Digraph<> template wrapper
83
84 template <class GT>
85 class Mat_Graph;
86
87 template <typename MT, typename Entry_Info, typename Copy>
88 class Ady_MaT;
89
117 template <typename __Node_Info = Empty_Class>
119 : public Dlink,
120 public GTNodeCommon<__Node_Info>
121 {
122 friend class GTNodeCommon<__Node_Info>;
123 friend class Arc_Node;
124
127
138 { /* empty */
139 }
140
151 : Base(std::move(info))
152 {
153 /* empty */
154 }
155
157 : Graph_Node(node.node_info)
158 {
159 // empty
160 }
161
163 {
164 if (&node == this)
165 return *this;
166 this->node_info = node.node_info;
167 return *this;
168 }
169
185 : Base(node->get_info())
186 {
187 /* empty */
188 }
189
191 };
192
218 template <typename _Arc_Info = Empty_Class>
220 : public Dlink,
221 public GTArcCommon<_Arc_Info>
222 {
223 friend class GTArcCommon<_Arc_Info>;
224
226
228
229 Arc_Node *src_arc_node = nullptr; // pointer to source node
230 Arc_Node *tgt_arc_node = nullptr; // pointer to target node
231
242 : Base(info)
243 {
244 /* empty */
245 }
246
257 : Base(std::move(info))
258 {
259 /* empty */
260 }
261
262 Graph_Arc(const Graph_Arc & arc)
263 : Graph_Arc(arc.arc_info)
264 {
265 /* empty */
266 }
267
269 {
270 if (&arc == this)
271 return *this;
272 this->arc_info = arc.arc_info;
273 return *this;
274 }
275 };
276
277 class Arc_Node : public Dlink
278 {
279 public:
280 void *arc = nullptr;
281
282 Arc_Node() noexcept : arc(nullptr) {}
283
285 };
286
423 template <typename _Graph_Node = Graph_Node<unsigned long>,
424 typename _Graph_Arc = Graph_Arc<unsigned long>>
426 : public GraphCommon<List_Graph<_Graph_Node, _Graph_Arc>,
427 _Graph_Node, _Graph_Arc>
428 {
429 public:
430 using GT = List_Graph;
431
433 using Arc = _Graph_Arc;
434
436 using Node_Type = typename Node::Node_Type;
437
439 using Arc_Type = typename Arc::Arc_Type;
440
443
446
449
450 private:
453
454 static Node * dlink_to_node(Dlink *p) noexcept
455 {
456 return static_cast<Node *>(p);
457 }
458
459 static Arc * dlink_to_arc(Dlink *p) noexcept
460 {
461 return static_cast<Arc *>(p);
462 }
463
464 static Arc_Node * dlink_to_arc_node(Dlink *p) noexcept
465 {
466 return static_cast<Arc_Node *>(p);
467 }
468
469 static Arc * void_to_arc(Arc_Node *arc_node) noexcept
470 {
471 return static_cast<Arc *>(arc_node->arc);
472 }
473
474 public:
488
524 virtual Node * insert_node(Node *node) noexcept
525 {
526 ++this->num_nodes;
527 node_list.append(node);
528 return node;
529 }
530
543 virtual void remove_node(Node *node) noexcept
544 {
545 assert(node != nullptr);
546 if (not this->digraph)
547 while (not node->arc_list.is_empty()) // remove each arc related to node
548 {
549 Arc_Node *arc_node = dlink_to_arc_node(node->arc_list.get_next());
550 Arc *arc = void_to_arc(arc_node);
551 remove_arc(arc);
552 }
553 else // Scan all the arcs and remove those related to node
554 this->remove_arcs_if([node, this](auto a)
555 {
556 return this->get_src_node(a) == node or this->get_tgt_node(a) == node;
557 });
558
559 // At this point the node has not more arcs
560 node->del(); // unlink it from arc_list
561 --this->num_nodes;
562 delete node;
563 }
564
577 {
578 ah_range_error_if(this->num_nodes == 0) << "Graph has not nodes";
579
580 return dlink_to_node(const_cast<Dlink &>(node_list).get_next());
581 }
582
595 Arc * get_first_arc(Node *node) const
596 {
597 ah_range_error_if(get_num_arcs (node) == 0) << "node has not arcs";
598
599 void *arc = dlink_to_arc_node(node->arc_list.get_next())->arc;
600 return reinterpret_cast<Arc *>(arc);
601 }
602
603 private:
604 Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
605 {
606 assert(src_node != nullptr and tgt_node != nullptr and a != nullptr);
607 Arc *arc = static_cast<Arc *>(a);
608 arc->src_node = src_node;
609 arc->tgt_node = tgt_node;
610
611 // step 3 (partial): allocate Arc_Node for src_node
612 std::unique_ptr<Arc_Node> src_arc_node = std::make_unique<Arc_Node>(arc);
613
614 // step 2: if graph ==> allocate Arc_Node for tgt_node
615 if (not this->digraph) // if digraph ==> do not insert in another node
616 { // insertion in the target node
617 if (src_node == tgt_node) // is it a loop?
618 arc->tgt_arc_node = src_arc_node.get();
619 else
620 { // allocate arc node for tgt_node
621 std::unique_ptr<Arc_Node> tgt_arc_node = std::make_unique<Arc_Node>(arc);
622
623 // insertion in an adjacency list of tgt_node
624 arc->tgt_arc_node = tgt_arc_node.get();
625 tgt_node->arc_list.append(tgt_arc_node.get());
626 ++tgt_node->num_arcs;
627 tgt_arc_node.release();
628 }
629 }
630
631 // step 3 (remainder): insertion in the adjacency list of src_node
632 arc->src_arc_node = src_arc_node.get();
633 src_node->arc_list.append(src_arc_node.get());
634 ++src_node->num_arcs;
635
636 arc_list.append(arc); // step 4: insert in graph arc list
637 ++this->num_arcs;
638 src_arc_node.release();
639
640 return arc;
641 }
642
643 public:
649 virtual void remove_arc(Arc *arc) noexcept
650 {
651 assert(arc != nullptr);
652 // step 1: remove Arc_node from src_node
653 Node *src_node = this->get_src_node(arc);
654 Arc_Node *src_arc_node = arc->src_arc_node;
655
656 src_arc_node->del(); // unlink src_node from node list
657 --src_node->num_arcs; // decrement arc counter of src_node
658 delete src_arc_node; // free memory
659
660 if (not this->digraph)
661 { // arc removal in target node
662 Node *tgt_node = this->get_tgt_node(arc);
663 if (src_node != tgt_node) // check for loop removal
664 { // step 2: remove Arc_node from tgt_node
665 Arc_Node *tgt_arc_node = arc->tgt_arc_node;
666 tgt_arc_node->del();
667 --tgt_node->num_arcs;
668 delete tgt_arc_node;
669 }
670 }
671
672 // arc removal from graph
673 arc->del(); // unlink arc from the graph arc list
674 --this->num_arcs;
675 delete arc;
676 }
677
699 virtual void disconnect_arc(Arc *arc) noexcept
700 {
701 assert(arc != nullptr);
702 Node *src_node = this->get_src_node(arc);
703 Arc_Node *src_arc_node = arc->src_arc_node;
704 src_arc_node->del(); // unlink src_node from node list
705 --src_node->num_arcs; // decrement arc counter of src_node
706
707 if (not this->digraph)
708 { // arc removal in target node
709 Node *tgt_node = this->get_tgt_node(arc);
710 if (src_node != tgt_node) // check for loop removal
711 { // step 2: remove Arc_node from target node tgt_node
712 Arc_Node *tgt_arc_node = arc->tgt_arc_node;
713 tgt_arc_node->del();
714 --tgt_node->num_arcs;
715 }
716 }
717
718 // arc removal from graph
719 arc->del(); // unlink arc from graph arc list
720 --this->num_arcs;
721 }
722
733 virtual Arc * connect_arc(Arc *arc) noexcept
734 {
735 assert(arc != nullptr);
736 Node *src_node = this->get_src_node(arc);
737 Node *tgt_node = this->get_tgt_node(arc);
738 Arc_Node *src_arc_node = arc->src_arc_node;
739 Arc_Node *tgt_arc_node = arc->tgt_arc_node;
740
741 if (not this->digraph) // if digraph ==> no need to insert in other node
742 { // insertion in target node
743 if (src_node != tgt_node) // check if it is a loop
744 { // insertion in adjacency list of tgt_node
745 tgt_node->arc_list.append(tgt_arc_node);
746 ++tgt_node->num_arcs;
747 }
748 }
749
750 src_node->arc_list.append(src_arc_node);
751 ++src_node->num_arcs;
752 arc_list.append(arc);
753 ++this->num_arcs;
754
755 return arc;
756 }
757
770 {
771 ah_range_error_if(this->get_num_arcs() == 0) << "Graph has not arcs";
772
773 return dlink_to_arc(const_cast<Dlink &>(arc_list).get_next());
774 }
775
776 // sort_nodes() and sort_arcs() are inherited from GraphCommon via CRTP
777 // They use the get_node_dlink() and get_arc_dlink() accessors defined above
778
781
782
784 {
785 clear_graph(*this);
786 }
787
794 struct Node_Iterator : public GTNodeIterator<List_Graph>
795 {
797
801 {
802 // empty
803 }
804 };
805
830 {
832
833 public:
834 using Item_Type = Arc *;
835
836 using Set_Type = Node *;
837
838 Node_Arc_Iterator() = default;
839
845 : Dlink::Iterator(&(src->arc_list)), src_node(src)
846 {
847 // empty
848 }
849
854
859
861 Arc * get_curr() const
862 {
863 return static_cast<Arc *>(get_current_arc_node()->arc);
864 }
865
868 {
869 return static_cast<Arc *>(get_current_arc_node_ne()->arc);
870 }
871
875 {
876 return get_curr();
877 }
878
880 {
881 return get_curr_ne();
882 }
883
888 {
889 return static_cast<Node *>(get_current_arc()->get_connected_node(src_node));
890 }
891
893 {
894 return static_cast<Node *>(get_current_arc_ne()->get_connected_node(src_node));
895 }
896
897 Node * get_node() const
898 {
899 return get_tgt_node();
900 }
901
903 {
904 return get_tgt_node_ne();
905 }
906 };
907
917 {
918 using Item_Type = Arc *;
919
921
922 Arc_Iterator() = default;
923
926 : Dlink::Iterator(&const_cast<Dlink &>(g.arc_list))
927 {
928 // empty
929 }
930
936
938 {
939 return dlink_to_arc(const_cast<Dlink *>(Dlink::Iterator::get_curr()));
940 }
941
942 Arc * get_curr() const
943 {
944 return get_current_arc();
945 }
946
948 {
949 return get_current_arc_ne();
950 }
951
956 {
957 return static_cast<Node *>(get_current_arc()->src_node);
958 }
959
961 {
962 return static_cast<Node *>(get_current_arc_ne()->src_node);
963 }
964
969 {
970 return static_cast<Node *>(get_current_arc()->tgt_node);
971 }
972
974 {
975 return static_cast<Node *>(get_current_arc_ne()->tgt_node);
976 }
977 };
978
980 List_Graph() = default;
981
983 void swap(List_Graph & g) noexcept
984 {
985 this->common_swap(g);
986 node_list.swap(&g.node_list);
987 arc_list.swap(&g.arc_list);
988 }
989 };
990
998 template <class GT>
1000 {
1001 bool operator()(typename GT::Arc * /* arc */) const noexcept
1002 {
1003 return true;
1004 }
1005
1006 void set_cookie(void *) noexcept
1007 { /* empty */
1008 }
1009 };
1010
1114 template <class GT, class Show_Arc = Dft_Show_Arc<GT>>
1116 public Filter_Iterator<typename GT::Node *,
1117 typename GT::Node_Arc_Iterator,
1118 Show_Arc>
1119 {
1121 typename GT::Node_Arc_Iterator,
1122 Show_Arc>;
1123
1124 using Itor = Filter_Iterator<typename GT::Node *,
1125 typename GT::Node_Arc_Iterator,
1126 Show_Arc>;
1127
1128 using Item_Type = typename Itor::Item_Type;
1129 using Set_Type = typename Itor::Set_Type;
1130
1132
1139 : Itor(p, sa)
1140 {
1141 // empty
1142 }
1143 };
1144
1161 template <class GT, class Show_Arc = Dft_Show_Arc<GT>>
1163 public Filter_Iterator<GT, typename GT::Arc_Iterator, Show_Arc>
1164 {
1166
1167 using Item_Type = typename Itor::Item_Type;
1168 using Set_Type = typename Itor::Set_Type;
1169
1170 Arc_Iterator() = default;
1171
1178 : Itor(g, sa)
1179 {
1180 // empty
1181 }
1182 };
1183
1190 template <class GT>
1192 {
1193 bool operator()(typename GT::Node *) const noexcept
1194 {
1195 return true;
1196 }
1197 };
1198
1203 template <class GT, class Show_Node = Dft_Show_Node<GT>>
1205 public Filter_Iterator<GT, typename GT::Node_Iterator, Show_Node>
1206 {
1207 public:
1209
1210 using Item_Type = typename Itor::Item_Type;
1211
1212 using Set_Type = typename Itor::Set_Type;
1213
1214 Node_Iterator() = default;
1215
1222 : Itor(g, sn)
1223 {
1224 /* empty */
1225 }
1226 };
1227
1237 template <class GT, class SN = Dft_Show_Node<GT>>
1238 void for_each_node(const GT & g,
1239 std::function<void (typename GT::Node *)> operation,
1240 SN sn = SN())
1241 {
1242 for (Node_Iterator<GT, SN> it(g, sn); it.has_curr(); it.next_ne())
1243 operation(it.get_curr());
1244 }
1245
1255 template <class GT, class SA = Dft_Show_Arc<GT>>
1256 void for_each_arc(const GT & g,
1257 std::function<void (typename GT::Arc *)> operation,
1258 SA sa = SA())
1259 {
1260 for (Arc_Iterator<GT, SA> it(g, sa); it.has_curr(); it.next_ne())
1261 operation(it.get_curr());
1262 }
1263
1274 template <class GT, class SA = Dft_Show_Arc<GT>>
1275 void for_each_arc(const GT & g,
1276 typename GT::Node *p,
1277 std::function<void (typename GT::Arc *)> operation,
1278 SA sa = SA())
1279 {
1280 (void) g;
1281 for (Node_Arc_Iterator<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
1282 operation(it.get_curr());
1283 }
1284
1295 template <class GT, class SN = Dft_Show_Node<GT>>
1296 bool forall_node(const GT & g,
1297 std::function<bool (typename GT::Node *)> cond,
1298 SN sn = SN())
1299 {
1300 for (Node_Iterator<GT, SN> it(g, sn); it.has_curr(); it.next_ne())
1301 if (not cond(it.get_curr()))
1302 return false;
1303 return true;
1304 }
1305
1316 template <class GT, class SA = Dft_Show_Arc<GT>>
1317 bool forall_arc(const GT & g,
1318 std::function<bool (typename GT::Arc *)> cond,
1319 SA sa = SA())
1320 {
1321 for (Arc_Iterator<GT, SA> it(g, sa); it.has_curr(); it.next_ne())
1322 if (not cond(it.get_curr()))
1323 return false;
1324 return true;
1325 }
1326
1337 template <class GT, class SA = Dft_Show_Arc<GT>>
1338 bool forall_arc(typename GT::Node *p,
1339 std::function<bool (typename GT::Arc *)> cond,
1340 SA sa = SA())
1341 {
1342 for (Node_Arc_Iterator<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
1343 if (not cond(it.get_curr()))
1344 return false;
1345 return true;
1346 }
1347
1362 template <class GT, typename T,
1363 template<typename> class Container = DynList,
1364 class SN = Dft_Show_Node<GT>>
1366 std::function<T (typename GT::Node *)> transformation,
1367 SN sn = SN())
1368 {
1371 {
1373 }, sn);
1374 return ret_val;
1375 }
1376
1390 template <class GT, typename T,
1391 template<typename> class Container = DynList,
1392 class SA = Dft_Show_Arc<GT>>
1394 std::function<T (typename GT::Arc *)> transformation,
1395 SA sa = SA())
1396 {
1399 {
1401 }, sa);
1402 return ret_val;
1403 }
1404
1425 template <class GT, typename T,
1426 template<typename> class Container = DynList,
1427 class SA = Dft_Show_Arc<GT>>
1429 typename GT::Node *p,
1430 std::function<T (typename GT::Arc *)> transformation,
1431 SA sa = SA())
1432 {
1434 for_each_arc<GT, SA>(g, p, [&ret_val, &transformation](typename GT::Arc *p)
1435 {
1437 }, sa);
1438 return ret_val;
1439 }
1440
1451 template <class GT, typename T, class SN = Dft_Show_Node<GT>>
1452 T foldl_nodes(GT & g, const T & init,
1453 std::function<T (const T &, typename GT::Node *)> operation,
1454 SN sn = SN())
1455 {
1456 T ret_val = init;
1457 for_each_node<GT, SN>(g, [&ret_val, &operation](typename GT::Node *p)
1458 {
1460 }, sn);
1461 return ret_val;
1462 }
1463
1473 template <class GT, typename T, class SA = Dft_Show_Arc<GT>>
1474 T foldl_arcs(GT & g, const T & init,
1475 std::function<T (const T &, typename GT::Arc *)> operation,
1476 SA sa = SA())
1477 {
1478 T ret_val = init;
1479 for_each_arc<GT, SA>(g, [&ret_val, &operation](typename GT::Arc *a)
1480 {
1482 }, sa);
1483 return ret_val;
1484 }
1485
1496 template <class GT, typename T, class SA = Dft_Show_Arc<GT>>
1497 T foldl_arcs(GT & g, typename GT::Node *p,
1498 const T & init,
1499 std::function<T (const T &, typename GT::Arc *)> operation,
1500 SA sa = SA())
1501 {
1502 T ret_val = init;
1503 for_each_arc<GT, SA>(g, p, [&ret_val, &operation](typename GT::Arc *a)
1504 {
1506 }, sa);
1507 return ret_val;
1508 }
1509
1530 template <typename __Graph_Node = Graph_Node<int>,
1531 typename __Graph_Arc = Graph_Arc<int>>
1533
1534
1540 template <class GT>
1541 using ArcPair = std::tuple<typename GT::Arc *, typename GT::Node *>;
1542
1550 template <class GT>
1552 {
1553 typename GT::Node *src = nullptr;
1554
1555 public:
1557 { /* empty */
1558 }
1559
1560 bool operator()(typename GT::Arc *a) const noexcept
1561 {
1562 assert(src);
1563 return a->src_node == src;
1564 }
1565
1566 typename GT::Node * get_node(typename GT::Arc *a) const noexcept
1567 {
1568 assert(src);
1569 return static_cast<typename GT::Node *>(a->tgt_node);
1570 }
1571 };
1572
1580 template <class GT>
1582 {
1583 typename GT::Node *tgt = nullptr;
1584
1585 public:
1587 { /* empty */
1588 }
1589
1590 bool operator()(typename GT::Arc *a) const noexcept
1591 {
1592 assert(tgt);
1593 return a->tgt_node == tgt;
1594 }
1595
1596 typename GT::Node * get_node(typename GT::Arc *a) const noexcept
1597 {
1598 assert(tgt);
1599 return static_cast<typename GT::Node *>(a->src_node);
1600 }
1601 };
1602
1607 template <class GT, class Filter>
1609 {
1610 using Itor = Filter_Iterator<typename GT::Node *,
1611 typename GT::Node_Arc_Iterator, Filter>;
1612
1615
1616 public:
1617 using Item_Type = typename Itor::Item_Type;
1618
1620
1623 : filt(p), it(p, filt)
1624 {
1625 // empty
1626 }
1627
1630 void next()
1631 {
1632 it.next();
1633 }
1634
1636 {
1637 it.next_ne();
1638 }
1639
1642 void prev() { it.prev(); }
1643
1646 {
1647 return it.has_curr();
1648 }
1649
1652 typename GT::Arc * get_curr() const
1653 {
1654 return it.get_curr();
1655 }
1656
1660 {
1661 return it.get_curr_ne();
1662 }
1663
1666 auto get_current_arc() const
1667 {
1668 return get_curr();
1669 }
1670
1673 typename GT::Node * get_node(typename GT::Arc *a) const noexcept
1674 {
1675 return filt.get_node(a);
1676 }
1677
1679 typename GT::Node * get_node() const
1680 {
1681 return this->get_node(this->get_curr());
1682 }
1683
1686 auto get_tgt_node() const
1687 {
1688 return get_node();
1689 }
1690
1692 typename GT::Node * get_node_ne() const noexcept
1693 {
1694 return this->get_node(this->get_curr_ne());
1695 }
1696
1700 {
1701 return get_node_ne();
1702 }
1703
1706 {
1707 it.reset_first();
1708 }
1709
1712 {
1713 it.reset_last();
1714 }
1715
1718 {
1719 put_itor_at_the_end(*this);
1720 }
1721 };
1722
1723
1728 template <class GT>
1730
1731
1736 template <class GT>
1738
1748 template <class GT, class Show_Arc = Dft_Show_Arc<GT>>
1749 class Out_Iterator : public Digraph_Iterator<GT, __Out_Filt<GT>>
1750 {
1753
1755 {
1757 Base::next_ne();
1758 }
1759
1760 public:
1761 using Item_Type = typename GT::Arc *;
1762
1763 Out_Iterator() = default;
1764
1766 : Base(p), show_arc(sa)
1767 {
1769 }
1770
1771 void next()
1772 {
1773 Base::next();
1775 }
1776
1778 {
1779 Base::next_ne();
1781 }
1782 };
1783
1793 template <class GT, class SA = Dft_Show_Arc<GT>>
1794 class In_Iterator : public Digraph_Iterator<GT, __In_Filt<GT>>
1795 {
1798
1800 {
1802 Base::next_ne();
1803 }
1804
1805 public:
1806 using Item_Type = typename GT::Arc *;
1807
1808 In_Iterator() = default;
1809
1810 In_Iterator(typename GT::Node *p, SA sa = SA())
1811 : Base(p), show_arc(sa)
1812 {
1814 }
1815
1816 void next()
1817 {
1818 Base::next();
1820 }
1821
1823 {
1824 Base::next_ne();
1826 }
1827 };
1828
1838 template <class GT, class SA = Dft_Show_Arc<GT>>
1840 {
1842 for (Out_Iterator<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
1843 ret.append(it.get_node_ne());
1844 return ret;
1845 }
1846
1855 template <class GT, class SA = Dft_Show_Arc<GT>>
1857 {
1859 for (In_Iterator<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
1860 ret.append(it.get_node_ne());
1861 return ret;
1862 }
1863
1871 template <class GT, class SA = Dft_Show_Arc<GT>>
1873 {
1875 for (Out_Iterator<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
1876 ret.append(it.get_curr());
1877 return ret;
1878 }
1879
1887 template <class GT, class SA = Dft_Show_Arc<GT>>
1889 {
1891 for (In_Iterator<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
1892 ret.append(it.get_curr());
1893 return ret;
1894 }
1895
1902 template <class GT, class SA = Dft_Show_Arc<GT>>
1904 {
1906 for (Node_Arc_Iterator<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
1907 ret.append(it.get_curr());
1908 return ret;
1909 }
1910
1917 template <class GT, class SA = Dft_Show_Arc<GT>>
1919 {
1921 for (In_Iterator<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
1922 {
1923 typename GT::Arc *a = it.get_curr();
1924 ret.append(std::make_tuple(a, static_cast<typename GT::Node *>(a->get_connected_node(p))));
1925 }
1926 return ret;
1927 }
1928
1936 template <class GT, class SA = Dft_Show_Arc<GT>>
1938 {
1940 for (Out_Iterator<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
1941 {
1942 typename GT::Arc *a = it.get_curr();
1943 ret.append(std::make_tuple(a, static_cast<typename GT::Node *>(a->get_connected_node(p))));
1944 }
1945 return ret;
1946 }
1947
1957 template <class GT, class SA = Dft_Show_Arc<GT>>
1958 size_t in_degree(typename GT::Node *p, SA sa = SA())
1959 {
1960 size_t count = 0;
1961 for (In_Iterator<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
1962 ++count;
1963 return count;
1964 }
1965
1966 template <class GT>
1967 size_t in_degree(typename GT::Node *p)
1968 {
1969 size_t count = 0;
1970 for (_In_Iterator<GT> it(p); it.has_curr(); it.next_ne())
1971 ++count;
1972 return count;
1973 }
1974
1985 template <class GT, class SA = Dft_Show_Arc<GT>>
1986 size_t out_degree(typename GT::Node *p, SA sa = SA())
1987 {
1988 size_t count = 0;
1989 for (Out_Iterator<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
1990 ++count;
1991 return count;
1992 }
1993
1994 template <class GT>
1995 size_t out_degree(typename GT::Node *p)
1996 {
1997 size_t count = 0;
1998 for (_Out_Iterator<GT> it(p); it.has_curr(); it.next_ne())
1999 ++count;
2000 return count;
2001 }
2002
2025 template <class GT, class Itor, class Operation>
2026 inline
2027 bool traverse_arcs(typename GT::Node *p, Operation op = Operation())
2028 {
2029 for (Itor it(p); it.has_curr(); it.next_ne())
2030 if (not op(it.get_curr()))
2031 return false;
2032 return true;
2033 }
2034
2052 template <class GT, class Itor, class Operation>
2053 inline
2054 void for_each_arc(typename GT::Node *p, Operation op = Operation())
2055 {
2056 for (Itor it(p); it.has_curr(); it.next_ne())
2057 op(it.get_curr());
2058 }
2059
2060
2061 // Functional operations on input arcs
2062
2072 template <class GT, class Op>
2073 inline
2074 bool traverse_in_arcs(typename GT::Node *p, Op op = Op())
2075 {
2076 return traverse_arcs<GT, _In_Iterator<GT>, Op>(p, op);
2077 }
2078
2085 template <class GT, class Op>
2086 inline
2087 void for_each_in_arc(typename GT::Node *p, Op op = Op())
2088 {
2090 }
2091
2102 template <class GT, class Op>
2103 inline
2104 bool all_in_arc(typename GT::Node *p, Op op = Op())
2105 {
2106 return traverse_in_arcs(p, [&op](auto a)
2107 {
2108 return op(a);
2109 });
2110 }
2111
2122 template <class GT, class Op>
2123 inline
2124 bool exists_in_arc(typename GT::Node *p, Op op = Op())
2125 {
2126 return not traverse_in_arcs<GT, Op>(p, [&op](auto a)
2127 {
2128 return not op(a);
2129 });
2130 }
2131
2143 template <class GT, class Op>
2144 inline
2145 auto search_in_arc(typename GT::Node *p, Op op = Op())
2146 {
2147 typename GT::Arc *ret = nullptr;
2148 traverse_in_arcs(p, [&op, &ret](auto a)
2149 {
2150 if (op(a))
2151 {
2152 ret = a;
2153 return false;
2154 }
2155 return true;
2156 });
2157 return ret;
2158 }
2159
2173 template <class GT, typename T>
2174 inline
2175 auto map_in_arcs(typename GT::Node *p, std::function<T (typename GT::Arc *)> op)
2176 {
2178 for_each_in_arc(p, [&ret, &op](auto a)
2179 {
2180 ret.append(op(a));
2181 });
2182 return ret;
2183 }
2184
2201 template <class GT, typename T>
2202 inline
2203 T foldl_in_arcs(typename GT::Node *p, const T & init,
2204 std::function<T (const T &, typename GT::Arc *)> op)
2205 {
2206 T ret = init;
2207 for_each_in_arc(p, [&ret, &op](auto a)
2208 {
2209 ret = op(ret, a);
2210 });
2211 return ret;
2212 }
2213
2220 template <class GT, class Op>
2221 inline
2223 {
2225 for_each_in_arc(p, [&ret, &cond](auto a)
2226 {
2227 if (cond(a))
2228 ret.append(a);
2229 });
2230 return ret;
2231 }
2232
2233
2234 // Functional operation on output arcs
2235
2245 template <class GT, class Op>
2246 inline
2247 bool traverse_out_arcs(typename GT::Node *p, Op op = Op())
2248 {
2250 }
2251
2258 template <class GT, class Op>
2259 inline
2260 void for_each_out_arc(typename GT::Node *p, Op op = Op())
2261 {
2263 }
2264
2275 template <class GT, class Op>
2276 inline
2277 bool all_out_arc(typename GT::Node *p, Op op = Op())
2278 {
2279 return traverse_out_arcs(p, [&op](auto a)
2280 {
2281 return op(a);
2282 });
2283 }
2284
2295 template <class GT, class Op>
2296 inline
2297 bool exists_out_arc(typename GT::Node *p, Op op = Op())
2298 {
2299 return not traverse_out_arcs<GT, Op>(p, [&op](auto a)
2300 {
2301 return not op(a);
2302 });
2303 }
2304
2316 template <class GT, class Op>
2317 inline
2318 auto search_out_arc(typename GT::Node *p, Op op = Op())
2319 {
2320 typename GT::Arc *ret = nullptr;
2321 traverse_out_arcs<GT>(p, [&op, &ret](auto a)
2322 {
2323 if (op(a))
2324 {
2325 ret = a;
2326 return false;
2327 }
2328 return true;
2329 });
2330 return ret;
2331 }
2332
2346 template <class GT, typename T>
2347 inline
2348 auto map_out_arcs(typename GT::Node *p, std::function<T (typename GT::Arc *)> op)
2349 {
2351 for_each_out_arc(p, [&ret, &op](auto a)
2352 {
2353 ret.append(op(a));
2354 });
2355 return ret;
2356 }
2357
2374 template <class GT, typename T>
2375 inline
2376 T foldl_out_arcs(typename GT::Node *p, const T & init,
2377 std::function<T (const T &, typename GT::Arc *)> op)
2378 {
2379 T ret = init;
2380 for_each_out_arc(p, [&ret, &op](auto a)
2381 {
2382 ret = op(ret, a);
2383 });
2384 return ret;
2385 }
2386
2393 template <class GT, class Op>
2394 inline
2396 {
2398 for_each_out_arc(p, [&ret, &cond](auto a)
2399 {
2400 if (cond(a))
2401 ret.append(a);
2402 });
2403 return ret;
2404 }
2405
2419 template <class GT, class SA = Dft_Show_Arc<GT>>
2420 typename GT::Arc *
2421 search_arc(const GT & g,
2422 typename GT::Node *src, typename GT::Node *tgt,
2423 SA sa = SA()) noexcept
2424 {
2425 assert(src != nullptr and tgt != nullptr);
2426
2427 if (not g.is_digraph() and tgt->num_arcs < src->num_arcs)
2428 std::swap(tgt, src); // select the node with less arcs
2429
2430 for (Node_Arc_Iterator<GT, SA> itor(src, sa); itor.has_curr(); itor.next_ne())
2431 if (itor.get_tgt_node_ne() == tgt)
2432 return itor.get_current_arc_ne();
2433
2434 return nullptr;
2435 }
2436
2447 template <class GT, class SA = Dft_Show_Arc<GT>>
2448 typename GT::Arc *
2450 typename GT::Node *src, typename GT::Node *tgt,
2451 SA sa = SA()) noexcept
2452 {
2453 (void) g;
2454 assert(src != nullptr and tgt != nullptr);
2455
2456 for (Node_Arc_Iterator<GT, SA> it(src, sa); it.has_curr(); it.next_ne())
2457 if (typename GT::Arc *a = it.get_curr(); a->src_node == src and a->tgt_node == tgt)
2458 return a;
2459
2460 return nullptr;
2461 }
2462
2467 template <class GT>
2468 typename GT::Node * mapped_node(typename GT::Node *p) noexcept
2469 {
2470 return static_cast<typename GT::Node *>(NODE_COOKIE(p));
2471 }
2472
2474 template <class GT>
2475 typename GT::Arc * mapped_arc(typename GT::Arc *a) noexcept
2476 {
2477 return static_cast<typename GT::Arc *>(ARC_COOKIE(a));
2478 }
2479
2481 template <class GTSRC, class GTTGT>
2482 typename GTTGT::Node * mapped_node(typename GTSRC::Node *p) noexcept
2483 {
2484 return static_cast<typename GTTGT::Node *>(NODE_COOKIE(p));
2485 }
2486
2488 template <class GTSRC, class GTTGT>
2489 typename GTTGT::Arc * mapped_arc(typename GTSRC::Arc *a) noexcept
2490 {
2491 return static_cast<typename GTTGT::Arc *>(ARC_COOKIE(a));
2492 }
2493
2511 template <class GT>
2512 inline
2513 void copy_graph(GT & gtgt, const GT & gsrc, bool cookie_map = false);
2514
2520 template <class GT>
2521 inline void clear_graph(GT & g) noexcept;
2522
2533 template <class GT, class Operation, class SN = Dft_Show_Node<GT>>
2535 {
2537
2538 public:
2541 : sn(__sn)
2542 { /* empty */
2543 }
2544
2550 void operator()(const GT & g, Operation op = Operation())
2551 {
2552 for (Node_Iterator<GT, SN> it(g, sn); it.has_curr(); it.next_ne())
2553 op(g, it.get_curr());
2554 }
2555
2562 {
2563 for (Node_Iterator<GT, SN> it(g, sn); it.has_curr(); it.next_ne())
2564 op(g, it.get_curr());
2565 }
2566 };
2567
2578 template <class GT, class Operation, class SA = Dft_Show_Arc<GT>>
2580 {
2582
2583 public:
2586 : sa(__sa)
2587 { /* empty */
2588 }
2589
2595 void operator()(const GT & g, Operation op = Operation()) const
2596 {
2597 for (Arc_Iterator<GT, SA> it(g, sa); it.has_curr(); it.next_ne())
2598 op(g, it.get_curr());
2599 }
2600
2601 void operator()(GT & g, Operation op = Operation()) const
2602 {
2603 for (Arc_Iterator<GT, SA> it(g, sa); it.has_curr(); it.next_ne())
2604 op(g, it.get_curr());
2605 }
2606
2613 void operator()(const GT & g, typename GT::Node *p,
2614 Operation op = Operation()) const
2615 {
2616 for (Node_Arc_Iterator<GT, SA> it(p); it.has_curr(); it.next_ne())
2617 op(g, it.get_current_arc_ne());
2618 }
2619
2620 void operator()(GT & g, typename GT::Node *p,
2621 Operation op = Operation()) const
2622 {
2623 for (Node_Arc_Iterator<GT, SA> it(p); it.has_curr(); it.next_ne())
2624 op(g, it.get_current_arc_ne());
2625 }
2626 };
2627
2667 template <class GT>
2668 class Path
2669 {
2670 public:
2672 using Node_Type = typename GT::Node_Type;
2673
2675 using Arc_Type = typename GT::Arc_Type;
2676
2677 private:
2678 const GT *g = nullptr;
2679
2680 using Node = typename GT::Node;
2681 using Arc = typename GT::Arc;
2682
2684 {
2685 Node *node; // source node
2686 Arc *arc; // adjacent arc
2687
2688 Path_Desc(Node *_node = nullptr, Arc *_arc = nullptr) noexcept
2689 : node(_node), arc(_arc)
2690 {}
2691
2692 bool operator==(const Path_Desc & r) const noexcept
2693 {
2694 if (not (node->get_info() == r.node->get_info()))
2695 return false;
2696
2697 if (arc == nullptr)
2698 return r.arc == nullptr;
2699
2700 if (r.arc == nullptr)
2701 return false;
2702
2703 return arc->get_info() == r.arc->get_info();
2704 }
2705 };
2706
2708
2710 {
2711 ah_domain_error_if(g == nullptr) << "Path: Graph has not been specified";
2712 }
2713
2714 public:
2716 [[nodiscard]] bool check() const
2717 {
2718 auto l = list;
2719 while (not l.is_unitarian_or_empty())
2720 {
2721 auto d = l.remove_first();
2722 auto nxt = l.get_first().node;
2723 if (nxt == g->get_connected_node(d.arc, d.node))
2724 return false;
2725 }
2726
2727 return true;
2728 }
2729
2731 [[nodiscard]] bool check_directed() const
2732 {
2733 return list.all([this](auto d)
2734 {
2735 return g->get_src_node(d.arc) == d.node;
2736 })
2737 and list.get_last().arc == nullptr;
2738 }
2739
2742 {
2743 return *g;
2744 }
2745
2747 bool inside_graph(const GT & gr) const noexcept
2748 {
2749 return g == &gr;
2750 }
2751
2753 Path(const GT & __g) noexcept : g(&__g)
2754 {}
2755
2756 Path() noexcept : g(nullptr)
2757 { /* empty */
2758 }
2759
2768 {
2769 assert(start_node != nullptr);
2770 list.append(Path_Desc(start_node));
2771 }
2772
2779 Path(const GT & _g, Node *start_node) : g(&_g)
2780 {
2782 }
2783
2797 void set_graph(const GT & __g, Node *start_node = nullptr)
2798 {
2799 empty();
2800 g = &__g;
2801 if (start_node == nullptr)
2802 return;
2804 }
2805
2808 {
2809 return list.size();
2810 }
2811
2814 {
2815 return list.is_empty();
2816 }
2817
2819 void empty()
2820 {
2821 check_graph();
2822 while (not list.is_empty())
2823 list.remove_first();
2824 }
2825
2827 Path(const Path & path) : g(path.g), list(path.list) {}
2828
2830 Path(Path && path) noexcept : g(path.g), list(std::move(path.list)) {}
2831
2833 Path &operator=(const Path & path)
2834 {
2835 if (this == &path)
2836 return *this;
2837
2838 empty();
2839 g = path.g;
2840 list = path.list;
2841 return *this;
2842 }
2843
2845 Path &operator=(Path && path) noexcept
2846 {
2847 std::swap(g, path.g);
2848 list.swap(path.list);
2849 return *this;
2850 }
2851
2865 void append(Arc *arc)
2866 {
2867 assert(arc != nullptr);
2868 check_graph();
2869
2870 ah_domain_error_if(list.is_empty()) << "path is empty";
2871
2872 auto & last_path_desc = list.get_last();
2873 auto last_node = last_path_desc.node;
2874 ah_invalid_argument_if(arc->src_node != last_node and arc->tgt_node != last_node)
2875 << "arc has not link to last node of path";
2876
2877 last_path_desc.arc = arc;
2879 }
2880
2898 void append(Node *node)
2899 {
2900 check_graph();
2901
2902 if (list.is_empty())
2903 {
2904 init(node);
2905 return;
2906 }
2907
2909 Arc *arc = search_arc(*g, last_node, node);
2910
2911 ah_invalid_argument_if(arc == nullptr)
2912 << "There is no an arc connecting to the node";
2913
2914 append(arc);
2915 }
2916
2938 {
2939 assert(p != nullptr);
2940 check_graph();
2941 if (list.is_empty())
2942 {
2943 init(p);
2944 return;
2945 }
2946
2947 auto & last_path_desc = list.get_last();
2949 Arc *arc = search_directed_arc(*g, last_node, p);
2950
2951 ah_invalid_argument_if(arc == nullptr) << "There is no an arc connecting to the node";
2952
2953 assert(arc->src_node == last_path_desc.node);
2954
2955 last_path_desc.arc = arc;
2956 list.append(Path_Desc(static_cast<Node *>(arc->tgt_node)));
2957 }
2958
2978 {
2979 assert(arc != nullptr);
2980 check_graph();
2981
2982 ah_domain_error_if(list.is_empty()) << "path is empty";
2983
2984 auto & last_path_desc = list.get_last();
2986 ah_invalid_argument_if(arc->src_node != last_node)
2987 << "The arc does not connect the last node";
2988
2989 last_path_desc.arc = arc;
2990 list.append(Path_Desc(static_cast<Node *>(arc->tgt_node)));
2991 }
2992
3008 void insert(Arc *arc)
3009 {
3010 assert(arc != nullptr);
3011 check_graph();
3012
3013 ah_domain_error_if(list.is_empty()) << "path is empty";
3014
3015 auto & first_path_desc = list.get_first();
3016 auto first_node = first_path_desc.node;
3017 ah_invalid_argument_if(arc->src_node != first_node and arc->tgt_node != first_node)
3018 << "arc has not link to first node of path";
3019
3020 Path_Desc item(g->get_connected_node(arc, first_node), arc);
3021 list.insert(item);
3022 }
3023
3039 void insert(Node *node)
3040 {
3041 check_graph();
3042
3043 if (list.is_empty())
3044 {
3045 init(node);
3046 return;
3047 }
3048
3050 Arc *arc = search_arc(*g, node, first_node); // search arc first_node-node
3051 ah_domain_error_if(arc == nullptr) << "There is no arc connecting node";
3052
3053 Path_Desc item(node, arc);
3054 list.insert(item);
3055 }
3056
3076 {
3077 assert(p != nullptr);
3078 check_graph();
3079
3080 if (list.is_empty())
3081 {
3082 init(p);
3083 return;
3084 }
3085
3087 Arc *arc = search_directed_arc(*g, p, first_node);
3088 ah_domain_error_if(arc == nullptr) << "There is no an arc connecting to the node";
3089
3090 list.insert(Path_Desc(p, arc));
3091 }
3092
3109 {
3110 assert(arc != nullptr);
3111 check_graph();
3112
3113 ah_domain_error_if(list.is_empty()) << "path is empty";
3114
3115 auto & first_path_desc = list.get_first();
3117 ah_invalid_argument_if(arc->tgt_node != first_node)
3118 << "The arc does not connect the first node";
3119
3120 list.insert(Path_Desc(static_cast<Node *>(arc->src_node), arc));
3121 }
3122
3126 {
3127 return list.get_first().node;
3128 }
3129
3133 {
3134 auto & last_path_desc = list.get_last();
3135 assert(last_path_desc.arc == nullptr);
3136 return last_path_desc.node;
3137 }
3138
3142 {
3143 return list.get_first().arc;
3144 }
3145
3149 {
3150 ah_domain_error_if(list.is_unitarian())
3151 << "Path with only a node (without any arc)";
3152
3154 it.reset_last();
3155 it.prev();
3156 return it.get_curr().arc;
3157 }
3158
3160 [[nodiscard]] bool is_cycle() const
3161 {
3162 return get_first_node() == get_last_node();
3163 }
3164
3171 {
3172 auto d = list.remove_last();
3173 list.get_last().arc = nullptr;
3174 return d.node;
3175 }
3176
3183 {
3184 auto d = list.remove_first();
3185 return d.node;
3186 }
3187
3189 void swap(Path & path) noexcept
3190 {
3191 std::swap(g, path.g);
3192 list.swap(path.list);
3193 }
3194
3200 class Iterator : public DynDlist<Path_Desc>::Iterator
3201 {
3202 public:
3204 Iterator(const Path & path) noexcept
3206 {}
3207
3208 private:
3213
3215 {
3217 }
3218
3219 public:
3223 {
3224 return this->get_curr_path_desc().node;
3225 }
3226
3228 {
3229 return this->get_curr_path_desc_ne().node;
3230 }
3231
3243 {
3244 ah_overflow_error_if(this->is_in_last()) << "Path iterator is in last node of path";
3245
3246 return this->get_curr_path_desc().arc;
3247 }
3248
3250 {
3251 return this->get_curr_path_desc_ne().arc;
3252 }
3253
3256 {
3257 return get_current_node_ne();
3258 }
3259
3260 Node * get_curr() const
3261 {
3262 return get_current_node();
3263 }
3264
3275 std::pair<Node *, Arc *> get_pair() const
3276 {
3277 return std::make_pair(get_current_node(), get_current_arc());
3278 }
3279
3290 std::tuple<Node *, Arc *> get_tuple() const
3291 {
3292 return std::make_tuple(get_current_node(), get_current_arc());
3293 }
3294
3295 std::tuple<Node *, Arc *> get_tuple_ne() const noexcept
3296 {
3297 return std::make_tuple(get_current_node_ne(), get_current_arc_ne());
3298 }
3299
3309 {
3310 return this->has_curr() and not this->is_in_last();
3311 }
3312
3315 {
3316 return this->has_curr();
3317 }
3318 };
3319
3322 {
3323 return Iterator(*this);
3324 }
3325
3330 template <class Operation>
3332 {
3333 for (Iterator it(*this); it.has_current_node(); it.next_ne())
3334 op(it.get_current_node_ne());
3335 }
3336
3341 template <class Operation>
3343 {
3344 for (Iterator it(*this); it.has_current_arc(); it.next_ne())
3345 op(it.get_current_arc_ne());
3346 }
3347
3349 bool contains_node(Node *node) const noexcept
3350 {
3351 for (Iterator it(*this); it.has_current_node(); it.next_ne())
3352 if (it.get_current_node_ne() == node)
3353 return true;
3354 return false;
3355 }
3356
3358 bool contains_arc(Arc *arc) const noexcept
3359 {
3360 for (Iterator it(*this); it.has_current_arc(); it.next_ne())
3361 if (it.get_current_arc_ne() == arc)
3362 return true;
3363 return false;
3364 }
3365
3368 {
3371 {
3372 ret_val.append(p);
3373 });
3374 return ret_val;
3375 }
3376
3379 {
3381 for_each_arc([&ret_val](Arc *a)
3382 {
3383 ret_val.append(a);
3384 });
3385 return ret_val;
3386 }
3387
3398 bool operator==(const Path & p) const noexcept
3399 {
3400 return eq(this->list, p.list);
3401 }
3402
3404 bool operator!=(const Path & p) const noexcept
3405 {
3406 return not eq(this->list, p.list);
3407 }
3408 };
3409
3410 template <class GT>
3411 inline
3413 typename GT::Node *end_node);
3414
3415 template <class GT>
3416 static inline
3418 typename GT::Arc *curr_arc,
3419 typename GT::Node *end_node, Path<GT> & path)
3420 {
3421 if (curr_node == end_node) // this test must be first in order to find cycles
3422 {
3423 path.append(curr_arc);
3424 return true;
3425 }
3426
3428 return false;
3429
3430 path.append(curr_arc);
3431 NODE_BITS(curr_node).set_bit(Find_Path, true);
3432
3433 for (auto it = g.get_arc_it(curr_node); it.has_curr(); it.next_ne())
3434 {
3435 auto next_arc = it.get_curr();
3437 continue;
3438
3439 ARC_BITS(next_arc).set_bit(Find_Path, true);
3440 if (auto next_node = it.get_tgt_node(); __find_path_depth_first<GT>(g, next_node, next_arc, end_node, path))
3441 {
3442 assert(path.get_last_node () == end_node);
3443 return true;
3444 }
3445 }
3446
3447 path.remove_last_node();
3448
3449 return false;
3450 }
3451
3466 template <class GT>
3467 inline
3469 typename GT::Node *end_node)
3470 {
3471 Path<GT> path(g, start_node);
3472
3475 NODE_BITS(start_node).set_bit(Find_Path, true);
3476
3477 for (auto it = g.get_arc_it(start_node); it.has_curr(); it.next_ne())
3478 {
3479 auto arc = it.get_current_arc_ne();
3480 ARC_BITS(arc).set_bit(Find_Path, true);
3481 auto next_node = it.get_tgt_node();
3483 continue;
3484
3486 return path;
3487 }
3488
3489 path.empty();
3490
3491 return path;
3492 }
3493
3503 template <class GTS, class GTT>
3504 void map_nodes(typename GTS::Node *p, typename GTT::Node *q) noexcept
3505 {
3506 assert(p != nullptr and q != nullptr);
3507
3508 // Use reinterpret_cast to preserve an exact pointer value without any
3509 // implicit base class pointer adjustment from multiple inheritance
3510 if (NODE_COOKIE(p) == nullptr)
3511 {
3512 NODE_COOKIE(p) = reinterpret_cast<void *>(q);
3513 NODE_COOKIE(q) = reinterpret_cast<void *>(p);
3514 return;
3515 }
3516
3517 NODE_COOKIE(q) = NODE_COOKIE(p);
3518 NODE_COOKIE(p) = reinterpret_cast<void *>(q);
3519 }
3520
3531 template <class GTS, class GTT>
3532 void map_arcs(typename GTS::Arc *p, typename GTT::Arc *q) noexcept
3533 {
3534 assert(p != nullptr and q != nullptr);
3535
3536 if (ARC_COOKIE(p) == nullptr)
3537 {
3538 ARC_COOKIE(p) = q;
3539 ARC_COOKIE(q) = p;
3540
3541 return;
3542 }
3543
3544 ARC_COOKIE(q) = ARC_COOKIE(p);
3545 ARC_COOKIE(p) = q;
3546 }
3547
3548 template <class GT>
3549 void clear_graph(GT & g) noexcept
3550 {
3551 for (typename GT::Arc_Iterator it(g); it.has_curr();) // remove arcs
3552 {
3553 typename GT::Arc *arc = it.get_curr_ne();
3554 it.next_ne();
3555 g.remove_arc(arc);
3556 }
3557
3558 for (typename GT::Node_Iterator it(g); it.has_curr();) // remove nodes
3559 {
3560 typename GT::Node *p = it.get_curr_ne();
3561 it.next_ne(); // advance before deletion (iterator consistency)
3562 g.remove_node(p); // remove it from the graph
3563 }
3564 }
3565
3566 template <class GT>
3567 void copy_graph(GT & gtgt, const GT & gsrc, const bool cookie_map)
3568 {
3569 try
3570 {
3571 clear_graph(gtgt); // clear this before copying
3573
3574 // phase 1: traverse nodes of src_graph and insert copy in this
3575 for (typename GT::Node_Iterator it(gsrc); it.has_curr(); it.next_ne())
3576 {
3577 typename GT::Node *src_node = it.get_current_node_ne();
3578 std::unique_ptr<typename GT::Node>
3579 tgt_node(new typename GT::Node(src_node->get_info()));
3580 map.insert(src_node, tgt_node.get());
3581
3582 typename GT::Node *tgt = tgt_node.release();
3583 assert(tgt->get_info () == src_node->get_info ());
3584 gtgt.insert_node(tgt); // insert in the target graph
3585
3586 if (cookie_map)
3587 GT::map_nodes(src_node, tgt);
3588 }
3589
3590 assert(gtgt.get_num_nodes() == gsrc.get_num_nodes());
3591
3592 // phase 2: for each arc of src_graph, create in this an
3593 // arc connecting the mapped nodes from map
3594 for (typename GT::Arc_Iterator it(gsrc); it.has_curr(); it.next_ne())
3595 {
3596 typename GT::Arc *src_arc = it.get_current_arc_ne();
3597
3598 // get node images in target graph and create arc
3599 typename GT::Node *src_node = map[gsrc.get_src_node(src_arc)];
3600 typename GT::Node *tgt_node = map[gsrc.get_tgt_node(src_arc)];
3601 typename GT::Arc *tgt_arc = gtgt.insert_arc(src_node, tgt_node);
3602 // tgt_arc->get_info() = src_arc->get_info();
3603 *tgt_arc = *src_arc;
3604 if (cookie_map)
3606 }
3607
3608 assert(gtgt.get_num_arcs() == gsrc.get_num_arcs());
3609 }
3610 catch (...)
3611 { // If an exception occurs, clean this
3613 throw;
3614 }
3615 }
3616
3621 template <class GTT, class GTS>
3623 {
3624 void operator()(typename GTT::Node *tgt, typename GTS::Node *src) noexcept
3625 {
3626 tgt->get_info() = src->get_info();
3627 }
3628 };
3629
3634 template <class GTT, class GTS>
3636 {
3637 void operator()(typename GTT::Arc *tgt, typename GTS::Arc *src)
3638 {
3639 tgt->get_info() = src->get_info();
3640 }
3641 };
3642
3651 template <class GTT, class GTS,
3655 const bool cookie_map = false)
3656 {
3657 try
3658 {
3659 clear_graph(gtgt); // clear this before copying
3661 // phase 1: traverse nodes of src_graph and insert a copy in this
3662 for (typename GTS::Node_Iterator it(gsrc); it.has_curr(); it.next_ne())
3663 {
3664 typename GTS::Node *src_node = it.get_current_node_ne();
3665 std::unique_ptr<typename GTT::Node> tgt_node(new typename GTT::Node);
3666 Copy_Node()(tgt_node.get(), src_node);
3667 map.insert(src_node, tgt_node.get());
3668
3669 typename GTT::Node *tgt = tgt_node.release();
3670 gtgt.insert_node(tgt); // insert in the target graph
3671
3672 if (cookie_map)
3673 map_nodes<GTS, GTT>(src_node, tgt);
3674 }
3675
3676 assert(gtgt.get_num_nodes() == gsrc.get_num_nodes());
3677
3678 // phase 2: for each arc of src_graph, create in this an
3679 // arc connecting the mapped nodes from the map
3680 for (typename GTS::Arc_Iterator it(gsrc); it.has_curr(); it.next_ne())
3681 {
3682 typename GTS::Arc *src_arc = it.get_current_arc_ne();
3683
3684 // get node images in target graph and create arc
3685 typename GTT::Node *src_node = map[gsrc.get_src_node(src_arc)];
3686 typename GTT::Node *tgt_node = map[gsrc.get_tgt_node(src_arc)];
3687 typename GTT::Arc *tgt_arc = gtgt.insert_arc(src_node, tgt_node);
3689 if (cookie_map)
3691 }
3692
3693 assert(gtgt.get_num_arcs() == gsrc.get_num_arcs());
3694 }
3695 catch (...)
3696 { // If an exception occurs, clean this
3698 throw;
3699 }
3700 }
3701
3714 template <class GT, class SN = Dft_Show_Node<GT>, class SA = Dft_Show_Arc<GT>>
3716 {
3719
3720 public:
3727 {
3728 // empty
3729 }
3730
3731 private:
3732 void copy(GT & gtgt, const GT & gsrc, const bool cookie_map)
3733 {
3734 try
3735 {
3736 clear_graph(gtgt); // clear this before copying
3738
3739 // phase 1: traverse nodes of src_graph and insert a copy in this
3740 for (Node_Iterator<GT, SN> it(gsrc, sn); it.has_curr(); it.next_ne())
3741 {
3742 typename GT::Node *src_node = it.get_curr();
3743 std::unique_ptr<typename GT::Node>
3744 tgt_node(new typename GT::Node(src_node));
3745 map.insert(src_node, tgt_node.get());
3746
3747 typename GT::Node *tgt = tgt_node.release();
3748 gtgt.insert_node(tgt); // insert in target graph
3749
3750 if (cookie_map)
3751 GT::map_nodes(src_node, tgt);
3752 }
3753
3754 // phase 2: for each arc of src_graph, create in this an
3755 // arc connecting the mapped nodes from a map
3756 for (Arc_Iterator<GT, SA> it(gsrc, sa); it.has_curr(); it.next_ne())
3757 {
3758 typename GT::Arc *src_arc = it.get_curr();
3759
3760 // get node images in target graph and create arc
3761 typename GT::Node *src_node = map[gsrc.get_src_node(src_arc)];
3762 typename GT::Node *tgt_node = map[gsrc.get_tgt_node(src_arc)];
3763 typename GT::Arc *tgt_arc =
3764 gtgt.insert_arc(src_node, tgt_node, src_arc->get_info());
3765
3766 if (cookie_map)
3768 }
3769 }
3770 catch (...)
3771 { // If an exception occurs, it is cleaned this
3773 throw;
3774 }
3775 }
3776
3777 public:
3785 void operator()(GT & gtgt, GT & gsrc, const bool cookie_map = true)
3786 {
3788 }
3789 };
3790
3801 template <class GT, class Distance>
3803 {
3806
3808 { /* empty */
3809 }
3810
3811 bool operator()(typename GT::Arc *a) noexcept
3812 {
3814 return false;
3815
3816 dist = dist + Distance()(a);
3817
3818 return true;
3819 }
3820 };
3821
3841 template <class GT>
3842 inline
3843 bool are_equal(const GT & g1, const GT & g2);
3844
3878 template <class GT,
3879 template <class, class> class Tree = Treap>
3881 {
3882 public:
3883 using Node = typename GT::Node;
3884 using Arc = typename GT::Arc;
3885 using Node_Type = typename GT::Node_Type;
3886 using Arc_Type = typename GT::Arc_Type;
3887
3888 private:
3891
3893 void build_copy(const GT & src)
3894 {
3895 // Phase 1: Copy all nodes and build mapping
3896 for (typename GT::Node_Iterator it(src); it.has_curr(); it.next_ne())
3897 {
3898 Node *src_node = it.get_curr();
3899 Node *tgt_node = copied_graph.insert_node(src_node->get_info());
3900 node_map.insert(src_node, tgt_node);
3901 }
3902
3903 // Phase 2: Copy all arcs using the node mapping
3904 for (typename GT::Arc_Iterator it(src); it.has_curr(); it.next_ne())
3905 {
3906 Arc *src_arc = it.get_curr();
3909
3910 Node *tgt_src = node_map.find(src_src);
3911 Node *tgt_tgt = node_map.find(src_tgt);
3912
3914 }
3915 }
3916
3917 public:
3928 explicit GraphCopyWithMapping(const GT & src)
3929 {
3930 build_copy(src);
3931 }
3932
3942
3954
3968
3969 // Disable copy (graphs can be large)
3971
3973
3982
3991
4004 {
4005 auto *ptr = node_map.search(orig);
4006 ah_domain_error_if(ptr == nullptr)
4007 << "Node not found in mapping (not from original graph?)";
4008 return ptr->second;
4009 }
4010
4022 Node * search_copy(Node *orig) const noexcept
4023 {
4024 auto *ptr = node_map.search(orig);
4025 return ptr ? ptr->second : nullptr;
4026 }
4027
4036 bool has_copy(Node *orig) const noexcept
4037 {
4038 return node_map.search(orig) != nullptr;
4039 }
4040
4048 [[nodiscard]] size_t num_nodes() const noexcept { return node_map.size(); }
4049
4058
4069 template <typename Op>
4070 void for_each_mapping(Op op) const
4071 {
4072 node_map.for_each([&op](const auto & pair)
4073 {
4074 op(pair.first, pair.second);
4075 });
4076 }
4077
4090 {
4092 }
4093
4106 {
4107 return copied_graph.insert_node(std::forward<Node_Type>(info));
4108 }
4109
4120 void remove_node(Node *node)
4121 {
4122 // Maintain node_map consistency when a copied node is removed:
4123 // perform a reverse lookup (value -> key) and erase the corresponding entry.
4124 // This is O(N) because DynMapTree is keyed by original node, not by copy.
4125 Node *original_node = nullptr;
4126 node_map.for_each([&](const auto & pair)
4127 {
4128 if (pair.second == node)
4129 {
4130 original_node = pair.first;
4131 }
4132 });
4133
4134 if (original_node)
4135 node_map.remove(original_node);
4136
4138 }
4139
4150 Arc * insert_arc(Node *src, Node *tgt, const Arc_Type & info = Arc_Type())
4151 {
4152 return copied_graph.insert_arc(src, tgt, info);
4153 }
4154
4162 void remove_arc(Arc *arc)
4163 {
4165 }
4166
4175 void clear()
4176 {
4177 node_map.empty();
4179 }
4180 };
4181} // end namespace Aleph
4182
4183# endif /* TPL_GRAPH_H */
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
Definition ah-errors.H:463
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Definition ah-errors.H:522
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
Definition ah-errors.H:639
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
Definition ah-errors.H:207
Simplified graph interface for common use cases.
void put_itor_at_the_end(Itor &it) noexcept
Definition aleph.H:54
Space-efficient bit array implementation.
Arc_Node(void *__arc) noexcept
Definition tpl_graph.H:284
Arc_Node() noexcept
Definition tpl_graph.H:282
Filtered copy of graphs.
Definition tpl_graph.H:3716
Copy_Graph(SA __sa=SA(), SN __sn=SN())
Constructor.
Definition tpl_graph.H:3726
void copy(GT &gtgt, const GT &gsrc, const bool cookie_map)
Definition tpl_graph.H:3732
void operator()(GT &gtgt, GT &gsrc, const bool cookie_map=true)
Perform the copy from gsrc to gtgt.
Definition tpl_graph.H:3785
Filtered iterator on directed graphs.
Definition tpl_graph.H:1609
GT::Arc * get_curr_ne() const noexcept
Return the current arc.
Definition tpl_graph.H:1659
void reset_last() noexcept
Reset the iterator to the last arc.
Definition tpl_graph.H:1711
void reset_first() noexcept
Reset the iterator to the first arc.
Definition tpl_graph.H:1705
void next_ne() noexcept
Definition tpl_graph.H:1635
GT::Node * get_node_ne() const noexcept
Return the connected node to current arc.
Definition tpl_graph.H:1692
GT::Node * get_node() const
Return the connected node to current arc.
Definition tpl_graph.H:1679
GT::Arc * get_curr() const
Return the current arc.
Definition tpl_graph.H:1652
Digraph_Iterator(typename GT::Node *p)
Iterator type.
Definition tpl_graph.H:1622
Filter_Iterator< typename GT::Node *, typename GT::Node_Arc_Iterator, Filter > Itor
Definition tpl_graph.H:1611
auto get_tgt_node_ne() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition tpl_graph.H:1699
void end() noexcept
Put the iterator in end state.
Definition tpl_graph.H:1717
auto get_tgt_node() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition tpl_graph.H:1686
bool has_curr() const noexcept
Return true the iterator has an current arc.
Definition tpl_graph.H:1645
auto get_current_arc() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition tpl_graph.H:1666
GT::Node * get_node(typename GT::Arc *a) const noexcept
Return the connected node to arc.
Definition tpl_graph.H:1673
void prev()
Move the iterator one position backward.
Definition tpl_graph.H:1642
typename Itor::Item_Type Item_Type
Definition tpl_graph.H:1617
void next()
Move the iterator one position forward.
Definition tpl_graph.H:1630
Generic directed graph (digraph) wrapper template.
Definition graph-dry.H:3848
Iterator dynamic list.
T & get_curr() const
Return the current item; throw overflow_error if there is no current item.
void reset_last() noexcept
Reset the iterator to the last item.
void prev()
Move the iterator one item backward.
T & get_curr_ne() const noexcept
Dynamic doubly linked list with O(1) size and bidirectional access.
Dynamic singly linked list with functional programming support.
Definition htlist.H:1423
T & insert(const T &item)
Insert a new item by copy.
Definition htlist.H:1502
T & append(const T &item)
Append a new item by copy.
Definition htlist.H:1562
T & get_last() const
Return the last item of the list.
Definition htlist.H:1663
T & get_first() const
Return the first item of the list.
Definition htlist.H:1675
Dynamic map implemented with an AVL tree.
Generic key-value map implemented on top of a binary search tree.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
Generic filter iterator wrapper.
void next()
Advances the iterator to the next filtered element.
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
void reset_last()
Resets the iterator to the last filtered element.
void prev()
Moves the iterator backward to the previous filtered element.
typename It::Item_Type Item_Type
The type of element returned by get_curr()
void reset_first()
Resets the iterator to the first filtered element.
Graph copy with explicit node mapping.
Definition tpl_graph.H:3881
Node * search_copy(Node *orig) const noexcept
Search for the copy of an original node (no exception).
Definition tpl_graph.H:4022
typename GT::Arc_Type Arc_Type
Definition tpl_graph.H:3886
bool has_copy(Node *orig) const noexcept
Check if an original node is in the mapping.
Definition tpl_graph.H:4036
GraphCopyWithMapping & operator=(const GraphCopyWithMapping &)=delete
Node * insert_unmapped_node(Node_Type &&info)
Insert a new node into the copied graph (not mapped, move version).
Definition tpl_graph.H:4105
void build_copy(const GT &src)
Build the copy and mapping.
Definition tpl_graph.H:3893
GraphCopyWithMapping()=default
Default constructor.
const GT & get_graph() const noexcept
Get the copied graph (const version).
Definition tpl_graph.H:3990
DynMapTree< Node *, Node *, Tree > node_map
Definition tpl_graph.H:3890
void remove_node(Node *node)
Remove a node from the copied graph.
Definition tpl_graph.H:4120
Node * get_copy(Node *orig) const
Get the copy of an original node.
Definition tpl_graph.H:4003
void clear()
Clear the copied graph and mapping.
Definition tpl_graph.H:4175
Arc * insert_arc(Node *src, Node *tgt, const Arc_Type &info=Arc_Type())
Insert an arc into the copied graph.
Definition tpl_graph.H:4150
GraphCopyWithMapping(const GT &src)
Construct a copy of the given graph with node mapping.
Definition tpl_graph.H:3928
void remove_arc(Arc *arc)
Remove an arc from the copied graph.
Definition tpl_graph.H:4162
void for_each_mapping(Op op) const
Apply a function to each (original, copy) node pair.
Definition tpl_graph.H:4070
size_t num_arcs() const noexcept
Get the number of arcs in the copied graph.
Definition tpl_graph.H:4057
Node * insert_unmapped_node(const Node_Type &info=Node_Type())
Insert a new node into the copied graph (not mapped).
Definition tpl_graph.H:4089
typename GT::Node_Type Node_Type
Definition tpl_graph.H:3885
GraphCopyWithMapping(GraphCopyWithMapping &&other) noexcept=default
Move constructor.
size_t num_nodes() const noexcept
Get the number of mapped nodes.
Definition tpl_graph.H:4048
typename GT::Node Node
Definition tpl_graph.H:3883
GT & get_graph() noexcept
Get the copied graph.
Definition tpl_graph.H:3981
GraphCopyWithMapping(const GraphCopyWithMapping &)=delete
GraphCopyWithMapping & operator=(GraphCopyWithMapping &&other) noexcept=default
Move assignment operator.
constexpr bool is_empty() const noexcept
Return true if list is empty.
Definition htlist.H:523
size_t size() const noexcept
Count the number of elements of the list.
Definition htlist.H:1319
bool is_unitarian_or_empty() const noexcept
Return true if list contains one element or is empty.
Definition htlist.H:535
Filtered iterator for incoming arcs of a node.
Definition tpl_graph.H:1795
typename GT::Arc * Item_Type
Definition tpl_graph.H:1806
In_Iterator()=default
In_Iterator(typename GT::Node *p, SA sa=SA())
Definition tpl_graph.H:1810
void next_ne() noexcept
Definition tpl_graph.H:1822
Iterator on the arcs of a graph.
Definition tpl_graph.H:830
Node_Arc_Iterator(Node *src) noexcept
Constructs an iterator on the node src.
Definition tpl_graph.H:844
Node * get_node_ne() const noexcept
Definition tpl_graph.H:902
Node * get_tgt_node_ne() const noexcept
Definition tpl_graph.H:892
Arc_Node * get_current_arc_node() const
Definition tpl_graph.H:850
Arc * get_current_arc() const
Return the current arc.
Definition tpl_graph.H:874
Arc * get_curr_ne() const noexcept
Definition tpl_graph.H:867
Node_Arc_Iterator()=default
The container type (a node)
Arc_Node * get_current_arc_node_ne() const noexcept
Definition tpl_graph.H:855
Arc * get_current_arc_ne() const noexcept
Definition tpl_graph.H:879
Node * Set_Type
The type of data of set.
Definition tpl_graph.H:836
Node * get_tgt_node() const
Return the connected node to source node (src passed in construction time) through the current arc.
Definition tpl_graph.H:887
Graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:428
Dlink & get_node_dlink() noexcept
Return a reference to the internal node Dlink for sorting.
Definition tpl_graph.H:487
Node * get_first_node() const
Return any node in the graph.
Definition tpl_graph.H:576
Arc * get_first_arc(Node *node) const
Return any arc adjacent to a node.
Definition tpl_graph.H:595
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Definition tpl_graph.H:524
Dlink & get_arc_dlink() noexcept
Return a reference to the internal arc Dlink for sorting.
Definition tpl_graph.H:501
void swap(List_Graph &g) noexcept
Swap in constant time this with g
Definition tpl_graph.H:983
Arc * get_first_arc() const
Return any arc in the graph.
Definition tpl_graph.H:769
static Arc * dlink_to_arc(Dlink *p) noexcept
Definition tpl_graph.H:459
static Arc_Node * dlink_to_arc_node(Dlink *p) noexcept
Definition tpl_graph.H:464
virtual void remove_node(Node *node) noexcept
Remove a node from the graph and free its memory.
Definition tpl_graph.H:543
static Node * dlink_to_node(Dlink *p) noexcept
Definition tpl_graph.H:454
virtual Arc * connect_arc(Arc *arc) noexcept
Connect a previously disconnected arc to the graph.
Definition tpl_graph.H:733
typename Node::Node_Type Node_Type
The arc class type.
Definition tpl_graph.H:436
virtual void remove_arc(Arc *arc) noexcept
Remove an arc from the graph and free it.
Definition tpl_graph.H:649
static Arc * void_to_arc(Arc_Node *arc_node) noexcept
Definition tpl_graph.H:469
_Graph_Node Node
The graph type.
Definition tpl_graph.H:432
virtual void disconnect_arc(Arc *arc) noexcept
Disconnect an arc from graph.
Definition tpl_graph.H:699
_Graph_Arc Arc
The node class type.
Definition tpl_graph.H:433
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Definition tpl_graph.H:604
List_Graph()=default
Construct an empty graph.
typename Arc::Arc_Type Arc_Type
The type of data stored in the arc.
Definition tpl_graph.H:439
Filtered iterator on the nodes of a graph.
Definition tpl_graph.H:1206
typename Itor::Item_Type Item_Type
Definition tpl_graph.H:1210
typename Itor::Set_Type Set_Type
The element type: Node*.
Definition tpl_graph.H:1212
Node_Iterator()=default
The set: the arcs of a graph.
Node_Iterator(const GT &g, Show_Node sn=Show_Node())
Construct a iterator with filter sn
Definition tpl_graph.H:1221
Functor that traverses the arcs of a graph and performs an operation.
Definition tpl_graph.H:2580
void operator()(const GT &g, typename GT::Node *p, Operation op=Operation()) const
Call to `op on each arc of a node.
Definition tpl_graph.H:2613
void operator()(GT &g, Operation op=Operation()) const
Definition tpl_graph.H:2601
void operator()(const GT &g, Operation op=Operation()) const
Call to `op on each arc.
Definition tpl_graph.H:2595
Operate_On_Arcs(SA __sa=SA())
Initialize the functor with the filter sa
Definition tpl_graph.H:2585
void operator()(GT &g, typename GT::Node *p, Operation op=Operation()) const
Definition tpl_graph.H:2620
Functor that traverses the nodes of a graph and performs an operation.
Definition tpl_graph.H:2535
Operate_On_Nodes(SN __sn=SN())
Initialize the functor with the filter sa
Definition tpl_graph.H:2540
void operator()(const GT &g, Operation op=Operation())
Call to operation on each node.
Definition tpl_graph.H:2550
void operator()(GT &g, Operation op=Operation())
Call to operation on each node.
Definition tpl_graph.H:2561
Filtered iterator for outcoming arcs of a node.
Definition tpl_graph.H:1750
Out_Iterator()=default
Out_Iterator(typename GT::Node *p, Show_Arc sa=Show_Arc())
Definition tpl_graph.H:1765
void next_ne() noexcept
Definition tpl_graph.H:1777
typename GT::Arc * Item_Type
Definition tpl_graph.H:1761
Iterator on nodes and arcs of a path.
Definition tpl_graph.H:3201
Node * get_current_node_ne() const noexcept
Definition tpl_graph.H:3227
std::tuple< Node *, Arc * > get_tuple() const
Return a tuple with the current node and arc.
Definition tpl_graph.H:3290
Node * get_current_node() const
Return the current node of a path.
Definition tpl_graph.H:3222
std::tuple< Node *, Arc * > get_tuple_ne() const noexcept
Definition tpl_graph.H:3295
Node * get_curr_ne() const noexcept
Definition tpl_graph.H:3255
Arc * get_current_arc_ne() const noexcept
Definition tpl_graph.H:3249
Arc * get_current_arc() const
Return the current arc of a path.
Definition tpl_graph.H:3242
Iterator(const Path &path) noexcept
Create an iterator on the first node of path
Definition tpl_graph.H:3204
Path_Desc & get_curr_path_desc() const
Definition tpl_graph.H:3214
bool has_current_node() const noexcept
Return true if the iterator has a current node.
Definition tpl_graph.H:3314
Node * get_curr() const
Definition tpl_graph.H:3260
Path_Desc & get_curr_path_desc_ne() const noexcept
Definition tpl_graph.H:3209
std::pair< Node *, Arc * > get_pair() const
Return a pair with the current node and arc.
Definition tpl_graph.H:3275
bool has_current_arc() const noexcept
Return true if iterator has current arc.
Definition tpl_graph.H:3308
Path on a graph.
Definition tpl_graph.H:2669
bool is_cycle() const
Return true if this is a cycle; throws if path is empty.
Definition tpl_graph.H:3160
typename GT::Node Node
Definition tpl_graph.H:2680
void insert(Arc *arc)
Insert an arc as the first of a path.
Definition tpl_graph.H:3008
void for_each_node(Operation op=Operation()) const
Execute an operation on each node of path.
Definition tpl_graph.H:3331
void empty()
Clean the path: all the nodes and arc are removed.
Definition tpl_graph.H:2819
Path & operator=(const Path &path)
Copy assignment.
Definition tpl_graph.H:2833
DynList< Arc * > arcs() const
Return a list with the arcs of a path (order, according to the path)
Definition tpl_graph.H:3378
typename GT::Arc_Type Arc_Type
The type of data stored in the arc.
Definition tpl_graph.H:2675
void init(Node *start_node)
Set the first node of a path.
Definition tpl_graph.H:2767
void append(Node *node)
Append a node to the path.
Definition tpl_graph.H:2898
Path & operator=(Path &&path) noexcept
Move assignment.
Definition tpl_graph.H:2845
Path() noexcept
Definition tpl_graph.H:2756
size_t size() const noexcept
Return the path length in nodes.
Definition tpl_graph.H:2807
bool check_directed() const
Return true if the directed path is consistent.
Definition tpl_graph.H:2731
bool contains_node(Node *node) const noexcept
Return true if node belongs to the path.
Definition tpl_graph.H:3349
void insert_directed(Node *p)
Append a node to a directed path.
Definition tpl_graph.H:3075
const GT * g
Definition tpl_graph.H:2678
Node * get_first_node() const
Return the first node of path; throws overflow_error if path is empty.
Definition tpl_graph.H:3125
bool operator==(const Path &p) const noexcept
Return true if this is equal to p,.
Definition tpl_graph.H:3398
bool operator!=(const Path &p) const noexcept
Return true if this is not equal to p,.
Definition tpl_graph.H:3404
void check_graph()
Definition tpl_graph.H:2709
Iterator get_it() const
Returns an iterator on the path.
Definition tpl_graph.H:3321
Path(Path &&path) noexcept
Move constructor.
Definition tpl_graph.H:2830
bool is_empty() const noexcept
Return true if the path is empty.
Definition tpl_graph.H:2813
typename GT::Node_Type Node_Type
The type of data stored in the nodes.
Definition tpl_graph.H:2672
bool check() const
Return true if the path is consistent.
Definition tpl_graph.H:2716
bool inside_graph(const GT &gr) const noexcept
Return true if this is on graph gr
Definition tpl_graph.H:2747
Arc * get_last_arc() const
Return the last arc of a path; throws overflow_error if the path is empty.
Definition tpl_graph.H:3148
Path(const GT &__g) noexcept
Construct a empty path on graph __g
Definition tpl_graph.H:2753
bool contains_arc(Arc *arc) const noexcept
Return true if arc belongs to the path.
Definition tpl_graph.H:3358
void swap(Path &path) noexcept
Fast swap between two paths (constant time)
Definition tpl_graph.H:3189
void set_graph(const GT &__g, Node *start_node=nullptr)
Set the graph of the path.
Definition tpl_graph.H:2797
Node * remove_first_node()
Remove the first node of a path.
Definition tpl_graph.H:3182
Arc * get_first_arc() const
Return the first arc of path; throws overflow_error if path is empty.
Definition tpl_graph.H:3141
DynDlist< Path_Desc > list
Definition tpl_graph.H:2707
void append(Arc *arc)
Append an arc to the path.
Definition tpl_graph.H:2865
void append_directed(Node *p)
Append a node to a directed path.
Definition tpl_graph.H:2937
typename GT::Arc Arc
Definition tpl_graph.H:2681
void insert_directed(Arc *arc)
Append an arc to a directed path.
Definition tpl_graph.H:3108
Path(const GT &_g, Node *start_node)
Construct a path starting from a given node.
Definition tpl_graph.H:2779
DynList< Node * > nodes() const
Return a list with the nodes of path (order according to the path)
Definition tpl_graph.H:3367
Node * get_last_node() const
Return the last node of path; throws overflow_error if path is empty.
Definition tpl_graph.H:3132
Path(const Path &path)
Copy constructor.
Definition tpl_graph.H:2827
Node * remove_last_node()
Remove the last node of path.
Definition tpl_graph.H:3170
void insert(Node *node)
Insert a node to the path.
Definition tpl_graph.H:3039
const GT & get_graph() const noexcept
Get a constant reference to the graph.
Definition tpl_graph.H:2741
void for_each_arc(Operation op=Operation()) const
Execute an operation on each arc of path.
Definition tpl_graph.H:3342
void append_directed(Arc *arc)
Append an arc to a directed path.
Definition tpl_graph.H:2977
Filter the incoming arcs.
Definition tpl_graph.H:1582
GT::Node * tgt
Definition tpl_graph.H:1583
bool operator()(typename GT::Arc *a) const noexcept
Definition tpl_graph.H:1590
GT::Node * get_node(typename GT::Arc *a) const noexcept
Definition tpl_graph.H:1596
__In_Filt(typename GT::Node *__tgt) noexcept
Definition tpl_graph.H:1586
Filter the outcoming arcs.
Definition tpl_graph.H:1552
bool operator()(typename GT::Arc *a) const noexcept
Definition tpl_graph.H:1560
GT::Node * get_node(typename GT::Arc *a) const noexcept
Definition tpl_graph.H:1566
__Out_Filt(typename GT::Node *__src) noexcept
Definition tpl_graph.H:1556
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Definition ah-dry.H:685
Common methods for the arc of a graph.
Definition graph-dry.H:528
void * get_connected_node(void *node) noexcept
Definition graph-dry.H:600
ArcInfo arc_info
Definition graph-dry.H:542
Common attributes and methods for nodes (vertexes) belonging to graphs.
Definition graph-dry.H:435
NodeInfo node_info
Definition graph-dry.H:443
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
Definition graph-dry.H:494
size_t num_arcs
data associated to the node. Access it with get_info()
Definition graph-dry.H:454
Common methods to the Aleph-w ( ) graph classes.
Definition graph-dry.H:618
void reset_bit_nodes(int bit) const noexcept
Reset bit to zero for all the nodes of graph.
Definition graph-dry.H:1040
size_t num_nodes
Definition graph-dry.H:625
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
Definition graph-dry.H:2802
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:1116
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Definition graph-dry.H:731
bool is_digraph() const noexcept
Return true if the graph this is directed.
Definition graph-dry.H:657
size_t num_arcs
Definition graph-dry.H:626
static void map_arcs(A1 *p, A2 *q) noexcept
Map the arcs through their cookies.
Definition graph-dry.H:1026
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
Definition graph-dry.H:772
void common_swap(GT &g) noexcept
Definition graph-dry.H:641
void reset_bit_arcs(int bit) const noexcept
Reset bit to zero for all the arcs of graph.
Definition graph-dry.H:1046
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:1193
constexpr size_t get_num_arcs() const noexcept
Definition graph-dry.H:778
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Definition graph-dry.H:737
static void map_nodes(N1 *p, N2 *q) noexcept
Map the nodes through their cookies.
Definition graph-dry.H:995
void remove_arcs_if(Predicate pred)
Remove all arcs matching a predicate.
Definition graph-dry.H:3665
Generic filter iterator wrapper for Aleph containers.
List_Graph< Graph_Node< int >, Graph_Arc< int > > GT
Graph base classes and common utilities via CRTP.
DynArray< Graph::Arc * > arcs
Definition graphpic.C:408
T foldl_arcs(GT &g, const T &init, std::function< T(const T &, typename GT::Arc *)> operation, SA sa=SA())
Fold the filtered arcs of a graph.
Definition tpl_graph.H:1474
T foldl_nodes(GT &g, const T &init, std::function< T(const T &, typename GT::Node *)> operation, SN sn=SN())
Fold the filtered nodes of a graph.
Definition tpl_graph.H:1452
DynList< typename GT::Node * > in_nodes(typename GT::Node *p, SA sa=SA())
Return the nodes connected to the filtered incoming arcs to p.
Definition tpl_graph.H:1856
void for_each_out_arc(typename GT::Node *p, Op op=Op())
Traverse the outcoming arcs of a node and executes an operation.
Definition tpl_graph.H:2260
#define ARC_COOKIE(p)
Return the arc cookie
void map_arcs(typename GTS::Arc *p, typename GTT::Arc *q) noexcept
Map two arcs of different types of graphs through their cookies.
Definition tpl_graph.H:3532
Container< T > nodes_map(GT &g, std::function< T(typename GT::Node *)> transformation, SN sn=SN())
Map the filtered nodes of a graph to a transformed type.
Definition tpl_graph.H:1365
bool traverse_in_arcs(typename GT::Node *p, Op op=Op())
Conditioned traversal of incoming arcs of a node.
Definition tpl_graph.H:2074
DynList< ArcPair< GT > > out_pairs(typename GT::Node *p, SA sa=SA())
Return the filtered outcoming pairs of (arc,node) related to node p
Definition tpl_graph.H:1937
void for_each_arc(const GT &g, std::function< void(typename GT::Arc *)> operation, SA sa=SA())
Traverse all the arcs of graph filtering some ones according to a condition and executing an operatio...
Definition tpl_graph.H:1256
bool traverse_arcs(typename GT::Node *p, Operation op=Operation())
Generic arcs traverse of a node.
Definition tpl_graph.H:2027
bool traverse_out_arcs(typename GT::Node *p, Op op=Op())
Conditioned traversal of outcoming arcs of a node.
Definition tpl_graph.H:2247
#define ALEPH_GRAPH_COPY_MOVE_CTORS(GraphClass)
Macro to generate copy/move constructors and assignment operators.
Definition graph-dry.H:3786
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
bool forall_node(const GT &g, std::function< bool(typename GT::Node *)> cond, SN sn=SN())
Return true if condition cond is met on every filtered node of the graph.
Definition tpl_graph.H:1296
void inter_copy_graph(GTT &gtgt, const GTS &gsrc, const bool cookie_map=false)
Copy between different types of graphs.
Definition tpl_graph.H:3654
#define ARC_BITS(p)
Return the control bits of arc p.
size_t out_degree(typename GT::Node *p, SA sa=SA())
Compute the filtered out degree of node p
Definition tpl_graph.H:1986
#define NODE_COOKIE(p)
Return the node cookie
void clear_graph(GT &g) noexcept
Clean a graph: all its nodes and arcs are removed and freed.
Definition tpl_graph.H:3549
DynList< typename GT::Node * > out_nodes(typename GT::Node *p, SA sa=SA())
Return the nodes connected to the filtered outcoming arcs of p.
Definition tpl_graph.H:1839
Container< T > arcs_map(GT &g, std::function< T(typename GT::Arc *)> transformation, SA sa=SA())
Map the filtered arcs of a graph to a transformed type.
Definition tpl_graph.H:1393
size_t in_degree(typename GT::Node *p, SA sa=SA())
Compute the filtered in degree of node p.
Definition tpl_graph.H:1958
GT::Node * mapped_node(typename GT::Node *p) noexcept
Return the mapped node through the cookie of p
Definition tpl_graph.H:2468
std::tuple< typename GT::Arc *, typename GT::Node * > ArcPair
Alias used for encapsulating a pair of arc and node (related between them).
Definition tpl_graph.H:1541
void for_each_node(const GT &g, std::function< void(typename GT::Node *)> operation, SN sn=SN())
Traverse all the nodes of graph filtering some ones according to a condition and executing an operati...
Definition tpl_graph.H:1238
bool forall_arc(const GT &g, std::function< bool(typename GT::Arc *)> cond, SA sa=SA())
Return true if condition cond is met on every filtered arc of the graph.
Definition tpl_graph.H:1317
DynList< typename GT::Arc * > in_arcs(typename GT::Node *p, SA sa=SA())
Return the filtered incoming arcs of p.
Definition tpl_graph.H:1888
#define IS_ARC_VISITED(p, bit)
Determine whether the bit field is or not set to one.
GT::Arc * search_arc(const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept
Arc filtered searching given two nodes.
Definition tpl_graph.H:2421
GT::Arc * search_directed_arc(const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept
Searching of directed arc linking two nodes.
Definition tpl_graph.H:2449
#define NODE_BITS(p)
Get the control bits of a node.
void for_each_in_arc(typename GT::Node *p, Op op=Op())
Traverse the incoming arcs of a node and executes an operation.
Definition tpl_graph.H:2087
void copy_graph(GT &gtgt, const GT &gsrc, bool cookie_map=false)
Explicit copy of graph.
Definition tpl_graph.H:3567
void map_nodes(typename GTS::Node *p, typename GTT::Node *q) noexcept
Map two nodes of different types of graphs through their cookies.
Definition tpl_graph.H:3504
DynList< ArcPair< GT > > in_pairs(typename GT::Node *p, SA sa=SA())
Return the filtered incoming pairs of (arc,node) related to node p
Definition tpl_graph.H:1918
Path< GT > find_path_depth_first(const GT &g, typename GT::Node *start_node, typename GT::Node *end_node)
Depth-first search of a path between two nodes.
Definition tpl_graph.H:3468
DynList< typename GT::Arc * > out_arcs(typename GT::Node *p, SA sa=SA())
Return the filtered incoming arcs of p.
Definition tpl_graph.H:1872
@ Spanning_Tree
Definition aleph-graph.H:79
@ Find_Path
Definition aleph-graph.H:76
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
T foldl_out_arcs(typename GT::Node *p, const T &init, std::function< T(const T &, typename GT::Arc *)> op)
Fold the outcoming arcs of a node.
Definition tpl_graph.H:2376
auto search_in_arc(typename GT::Node *p, Op op=Op())
Search an incoming arc to a node satisfying a condition op.
Definition tpl_graph.H:2145
DynList< typename GT::Arc * > filter_in_arcs(typename GT::Node *p, Op cond)
Filter the incoming arcs meeting an condition.
Definition tpl_graph.H:2222
bool eq(const C1 &c1, const C2 &c2, Eq e=Eq())
Check equality of two containers using a predicate.
auto map_out_arcs(typename GT::Node *p, std::function< T(typename GT::Arc *)> op)
Map the outcoming arcs to a transformation,.
Definition tpl_graph.H:2348
bool all_out_arc(typename GT::Node *p, Op op=Op())
Test if the outcoming arcs meet a condition.
Definition tpl_graph.H:2277
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:107
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
Definition ahPair.H:89
DynList< typename GT::Arc * > filter_out_arcs(typename GT::Node *p, Op cond)
Filter the outcoming arcs meeting an condition.
Definition tpl_graph.H:2395
static bool init
Definition hash-fct.C:47
auto search_out_arc(typename GT::Node *p, Op op=Op())
Search an outcoming arc to a node satisfying a condition op.
Definition tpl_graph.H:2318
T foldl_in_arcs(typename GT::Node *p, const T &init, std::function< T(const T &, typename GT::Arc *)> op)
Fold the incoming arcs of a node.
Definition tpl_graph.H:2203
static bool __find_path_depth_first(const GT &g, typename GT::Node *curr_node, typename GT::Arc *curr_arc, typename GT::Node *end_node, Path< GT > &path)
Definition tpl_graph.H:3417
bool all_in_arc(typename GT::Node *p, Op op=Op())
Test if the incoming arcs meet a condition.
Definition tpl_graph.H:2104
GT::Arc * mapped_arc(typename GT::Arc *a) noexcept
Return the mapped arc through the cookie of p
Definition tpl_graph.H:2475
bool exists_in_arc(typename GT::Node *p, Op op=Op())
Test if it exists an incoming arc satisfying an operation.
Definition tpl_graph.H:2124
bool exists_out_arc(typename GT::Node *p, Op op=Op())
Test if it exists an outcoming arc satisfying an operation.
Definition tpl_graph.H:2297
bool are_equal(const GT &g1, const GT &g2)
Fast graph comparison.
auto map_in_arcs(typename GT::Node *p, std::function< T(typename GT::Arc *)> op)
Map the incoming arcs to a transformation,.
Definition tpl_graph.H:2175
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
STL namespace.
Filtered iterator on all the arcs of a graph.
Definition tpl_graph.H:1164
Arc_Iterator()=default
Type of set all the arcs.
typename Itor::Item_Type Item_Type
Definition tpl_graph.H:1167
typename Itor::Set_Type Set_Type
Type of element: Arc*.
Definition tpl_graph.H:1168
Arc_Iterator(const GT &g, Show_Arc sa=Show_Arc())
Constructor,.
Definition tpl_graph.H:1177
Default copy arc functor.
Definition tpl_graph.H:3636
void operator()(typename GTT::Arc *tgt, typename GTS::Arc *src)
Definition tpl_graph.H:3637
Default copy node functor.
Definition tpl_graph.H:3623
void operator()(typename GTT::Node *tgt, typename GTS::Node *src) noexcept
Definition tpl_graph.H:3624
Default filter for filtered iterators on arcs.
Definition tpl_graph.H:1000
void set_cookie(void *) noexcept
Definition tpl_graph.H:1006
bool operator()(typename GT::Arc *) const noexcept
Definition tpl_graph.H:1001
Default filter for the graph nodes.
Definition tpl_graph.H:1192
bool operator()(typename GT::Node *) const noexcept
Definition tpl_graph.H:1193
Arc of graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:222
Arc_Node * src_arc_node
The type of data stored in the arc.
Definition tpl_graph.H:229
Graph_Arc(const Graph_Arc &arc)
Definition tpl_graph.H:262
Graph_Arc(const Arc_Info &info) noexcept
Copy constructor.
Definition tpl_graph.H:241
Graph_Arc(Arc_Info &&info=Arc_Info()) noexcept
Move or rvalue constructor.
Definition tpl_graph.H:256
GTArcCommon< _Arc_Info > Base
Definition tpl_graph.H:225
Graph_Arc & operator=(const Graph_Arc &arc)
Definition tpl_graph.H:268
_Arc_Info Arc_Info
Definition tpl_graph.H:227
Arc_Node * tgt_arc_node
Definition tpl_graph.H:230
Node belonging to a graph implemented with a double linked adjacency list.
Definition tpl_graph.H:121
GTNodeCommon< __Node_Info > Base
Definition tpl_graph.H:125
__Node_Info Node_Info
Definition tpl_graph.H:126
Graph_Node(const Graph_Node &node) noexcept
Definition tpl_graph.H:156
Graph_Node(Graph_Node *node)
Copy constructor from a node pointer.
Definition tpl_graph.H:184
Graph_Node(Node_Info &&info=Node_Info()) noexcept
Move or rvalue constructor.
Definition tpl_graph.H:150
Graph_Node(const Node_Info &info) noexcept
The type of data stored in the node.
Definition tpl_graph.H:137
Graph_Node & operator=(const Graph_Node &node)
Definition tpl_graph.H:162
Iterator on all arcs of a graph.
Definition tpl_graph.H:917
Arc_Iterator()=default
The type of set.
Node * get_tgt_node() const
Return the target node of current arc.
Definition tpl_graph.H:968
Arc_Iterator(const List_Graph &g) noexcept
Initialize an iterator for all the arc of g
Definition tpl_graph.H:925
Arc * get_curr_ne() const noexcept
Definition tpl_graph.H:947
Arc * get_current_arc_ne() const noexcept
Return the current arc. Throw overflow_error if there is no one.
Definition tpl_graph.H:932
Node * get_src_node() const
Return the source node of the current arc.
Definition tpl_graph.H:955
Node_Iterator(const List_Graph &g)
Construct an iterator on the nodes of g
Definition tpl_graph.H:799
Filtered iterator of adjacent arcs of a node.
Definition tpl_graph.H:1119
Node_Arc_Iterator(typename GT::Node *p, Show_Arc sa=Show_Arc())
Construct and filtered iterator according to condition sa.
Definition tpl_graph.H:1138
Node_Arc_Iterator()=default
Type of set: p's arcs.
typename Itor::Item_Type Item_Type
Definition tpl_graph.H:1128
typename Itor::Set_Type Set_Type
type of element: Arc*
Definition tpl_graph.H:1129
Filter of painter arcs with that are set the Spanning_Tree control bit.
Definition tpl_graph.H:3803
bool operator()(typename GT::Arc *a) noexcept
Definition tpl_graph.H:3811
Distance::Distance_Type dist
Accumulative distance from the first seen arc until the last seen.
Definition tpl_graph.H:3805
Path_Desc(Node *_node=nullptr, Arc *_arc=nullptr) noexcept
Definition tpl_graph.H:2688
bool operator==(const Path_Desc &r) const noexcept
Definition tpl_graph.H:2692
Treap (a special type of randomized binary search tree) using nodes without virtual destructor.
Definition tpl_treap.H:611
Distance accessor.
Common node iterator for graph having its node derived from Dlink class.
Definition graph-dry.H:256
Lazy and scalable dynamic array implementation.
Dynamic doubly linked list implementation.
Dynamic key-value map based on balanced binary search trees.
Comprehensive sorting algorithms and search utilities for Aleph-w.
Treap with rank (order statistics).
DynList< int > l