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 {
1372 ret_val.append(transformation(p));
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 {
1400 ret_val.append(transformation(p));
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 {
2249 return traverse_arcs<GT, _Out_Iterator<GT>, Op>(p, op);
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
2831 void clear() { empty(); }
2832
2834 Path(const Path & path) : g(path.g), list(path.list) {}
2835
2837 Path(Path && path) noexcept : g(path.g), list(std::move(path.list)) {}
2838
2840 Path &operator=(const Path & path)
2841 {
2842 if (this == &path)
2843 return *this;
2844
2845 empty();
2846 g = path.g;
2847 list = path.list;
2848 return *this;
2849 }
2850
2852 Path &operator=(Path && path) noexcept
2853 {
2854 std::swap(g, path.g);
2855 list.swap(path.list);
2856 return *this;
2857 }
2858
2872 void append(Arc *arc)
2873 {
2874 assert(arc != nullptr);
2875 check_graph();
2876
2877 ah_domain_error_if(list.is_empty()) << "path is empty";
2878
2879 auto & last_path_desc = list.get_last();
2880 auto last_node = last_path_desc.node;
2881 ah_invalid_argument_if(arc->src_node != last_node and arc->tgt_node != last_node)
2882 << "arc has not link to last node of path";
2883
2884 last_path_desc.arc = arc;
2886 }
2887
2905 void append(Node *node)
2906 {
2907 check_graph();
2908
2909 if (list.is_empty())
2910 {
2911 init(node);
2912 return;
2913 }
2914
2916 Arc *arc = search_arc(*g, last_node, node);
2917
2918 ah_invalid_argument_if(arc == nullptr)
2919 << "There is no an arc connecting to the node";
2920
2921 append(arc);
2922 }
2923
2945 {
2946 assert(p != nullptr);
2947 check_graph();
2948 if (list.is_empty())
2949 {
2950 init(p);
2951 return;
2952 }
2953
2954 auto & last_path_desc = list.get_last();
2956 Arc *arc = search_directed_arc(*g, last_node, p);
2957
2958 ah_invalid_argument_if(arc == nullptr) << "There is no an arc connecting to the node";
2959
2960 assert(arc->src_node == last_path_desc.node);
2961
2962 last_path_desc.arc = arc;
2963 list.append(Path_Desc(static_cast<Node *>(arc->tgt_node)));
2964 }
2965
2985 {
2986 assert(arc != nullptr);
2987 check_graph();
2988
2989 ah_domain_error_if(list.is_empty()) << "path is empty";
2990
2991 auto & last_path_desc = list.get_last();
2993 ah_invalid_argument_if(arc->src_node != last_node)
2994 << "The arc does not connect the last node";
2995
2996 last_path_desc.arc = arc;
2997 list.append(Path_Desc(static_cast<Node *>(arc->tgt_node)));
2998 }
2999
3015 void insert(Arc *arc)
3016 {
3017 assert(arc != nullptr);
3018 check_graph();
3019
3020 ah_domain_error_if(list.is_empty()) << "path is empty";
3021
3022 auto & first_path_desc = list.get_first();
3023 auto first_node = first_path_desc.node;
3024 ah_invalid_argument_if(arc->src_node != first_node and arc->tgt_node != first_node)
3025 << "arc has not link to first node of path";
3026
3027 Path_Desc item(g->get_connected_node(arc, first_node), arc);
3028 list.insert(item);
3029 }
3030
3046 void insert(Node *node)
3047 {
3048 check_graph();
3049
3050 if (list.is_empty())
3051 {
3052 init(node);
3053 return;
3054 }
3055
3057 Arc *arc = search_arc(*g, node, first_node); // search arc first_node-node
3058 ah_domain_error_if(arc == nullptr) << "There is no arc connecting node";
3059
3060 Path_Desc item(node, arc);
3061 list.insert(item);
3062 }
3063
3083 {
3084 assert(p != nullptr);
3085 check_graph();
3086
3087 if (list.is_empty())
3088 {
3089 init(p);
3090 return;
3091 }
3092
3094 Arc *arc = search_directed_arc(*g, p, first_node);
3095 ah_domain_error_if(arc == nullptr) << "There is no an arc connecting to the node";
3096
3097 list.insert(Path_Desc(p, arc));
3098 }
3099
3116 {
3117 assert(arc != nullptr);
3118 check_graph();
3119
3120 ah_domain_error_if(list.is_empty()) << "path is empty";
3121
3122 auto & first_path_desc = list.get_first();
3124 ah_invalid_argument_if(arc->tgt_node != first_node)
3125 << "The arc does not connect the first node";
3126
3127 list.insert(Path_Desc(static_cast<Node *>(arc->src_node), arc));
3128 }
3129
3133 {
3134 return list.get_first().node;
3135 }
3136
3140 {
3141 auto & last_path_desc = list.get_last();
3142 assert(last_path_desc.arc == nullptr);
3143 return last_path_desc.node;
3144 }
3145
3149 {
3150 return list.get_first().arc;
3151 }
3152
3156 {
3157 ah_domain_error_if(list.is_unitarian())
3158 << "Path with only a node (without any arc)";
3159
3161 it.reset_last();
3162 it.prev();
3163 return it.get_curr().arc;
3164 }
3165
3167 [[nodiscard]] bool is_cycle() const
3168 {
3169 return get_first_node() == get_last_node();
3170 }
3171
3178 {
3179 auto d = list.remove_last();
3180 list.get_last().arc = nullptr;
3181 return d.node;
3182 }
3183
3190 {
3191 auto d = list.remove_first();
3192 return d.node;
3193 }
3194
3196 void swap(Path & path) noexcept
3197 {
3198 std::swap(g, path.g);
3199 list.swap(path.list);
3200 }
3201
3207 class Iterator : public DynDlist<Path_Desc>::Iterator
3208 {
3209 public:
3211 Iterator(const Path & path) noexcept
3213 {}
3214
3215 private:
3220
3222 {
3224 }
3225
3226 public:
3230 {
3231 return this->get_curr_path_desc().node;
3232 }
3233
3235 {
3236 return this->get_curr_path_desc_ne().node;
3237 }
3238
3250 {
3251 ah_overflow_error_if(this->is_in_last()) << "Path iterator is in last node of path";
3252
3253 return this->get_curr_path_desc().arc;
3254 }
3255
3257 {
3258 return this->get_curr_path_desc_ne().arc;
3259 }
3260
3263 {
3264 return get_current_node_ne();
3265 }
3266
3267 Node * get_curr() const
3268 {
3269 return get_current_node();
3270 }
3271
3282 std::pair<Node *, Arc *> get_pair() const
3283 {
3284 return std::make_pair(get_current_node(), get_current_arc());
3285 }
3286
3297 std::tuple<Node *, Arc *> get_tuple() const
3298 {
3299 return std::make_tuple(get_current_node(), get_current_arc());
3300 }
3301
3302 std::tuple<Node *, Arc *> get_tuple_ne() const noexcept
3303 {
3304 return std::make_tuple(get_current_node_ne(), get_current_arc_ne());
3305 }
3306
3316 {
3317 return this->has_curr() and not this->is_in_last();
3318 }
3319
3322 {
3323 return this->has_curr();
3324 }
3325 };
3326
3329 {
3330 return Iterator(*this);
3331 }
3332
3337 template <class Operation>
3339 {
3340 for (Iterator it(*this); it.has_current_node(); it.next_ne())
3341 op(it.get_current_node_ne());
3342 }
3343
3348 template <class Operation>
3350 {
3351 for (Iterator it(*this); it.has_current_arc(); it.next_ne())
3352 op(it.get_current_arc_ne());
3353 }
3354
3356 bool contains_node(Node *node) const noexcept
3357 {
3358 for (Iterator it(*this); it.has_current_node(); it.next_ne())
3359 if (it.get_current_node_ne() == node)
3360 return true;
3361 return false;
3362 }
3363
3365 bool contains_arc(Arc *arc) const noexcept
3366 {
3367 for (Iterator it(*this); it.has_current_arc(); it.next_ne())
3368 if (it.get_current_arc_ne() == arc)
3369 return true;
3370 return false;
3371 }
3372
3375 {
3378 {
3379 ret_val.append(p);
3380 });
3381 return ret_val;
3382 }
3383
3386 {
3388 for_each_arc([&ret_val](Arc *a)
3389 {
3390 ret_val.append(a);
3391 });
3392 return ret_val;
3393 }
3394
3405 bool operator==(const Path & p) const noexcept
3406 {
3407 return eq(this->list, p.list);
3408 }
3409
3411 bool operator!=(const Path & p) const noexcept
3412 {
3413 return not eq(this->list, p.list);
3414 }
3415 };
3416
3417 template <class GT>
3418 inline
3420 typename GT::Node *end_node);
3421
3422 template <class GT>
3423 static inline
3425 typename GT::Arc *curr_arc,
3426 typename GT::Node *end_node, Path<GT> & path)
3427 {
3428 if (curr_node == end_node) // this test must be first in order to find cycles
3429 {
3430 path.append(curr_arc);
3431 return true;
3432 }
3433
3435 return false;
3436
3437 path.append(curr_arc);
3438 NODE_BITS(curr_node).set_bit(Find_Path, true);
3439
3440 for (auto it = g.get_arc_it(curr_node); it.has_curr(); it.next_ne())
3441 {
3442 auto next_arc = it.get_curr();
3444 continue;
3445
3446 ARC_BITS(next_arc).set_bit(Find_Path, true);
3447 if (auto next_node = it.get_tgt_node(); __find_path_depth_first<GT>(g, next_node, next_arc, end_node, path))
3448 {
3449 assert(path.get_last_node () == end_node);
3450 return true;
3451 }
3452 }
3453
3454 path.remove_last_node();
3455
3456 return false;
3457 }
3458
3473 template <class GT>
3474 inline
3476 typename GT::Node *end_node)
3477 {
3478 Path<GT> path(g, start_node);
3479
3482 NODE_BITS(start_node).set_bit(Find_Path, true);
3483
3484 for (auto it = g.get_arc_it(start_node); it.has_curr(); it.next_ne())
3485 {
3486 auto arc = it.get_current_arc_ne();
3487 ARC_BITS(arc).set_bit(Find_Path, true);
3488 auto next_node = it.get_tgt_node();
3490 continue;
3491
3493 return path;
3494 }
3495
3496 path.empty();
3497
3498 return path;
3499 }
3500
3510 template <class GTS, class GTT>
3511 void map_nodes(typename GTS::Node *p, typename GTT::Node *q) noexcept
3512 {
3513 assert(p != nullptr and q != nullptr);
3514
3515 // Use reinterpret_cast to preserve an exact pointer value without any
3516 // implicit base class pointer adjustment from multiple inheritance
3517 if (NODE_COOKIE(p) == nullptr)
3518 {
3519 NODE_COOKIE(p) = reinterpret_cast<void *>(q);
3520 NODE_COOKIE(q) = reinterpret_cast<void *>(p);
3521 return;
3522 }
3523
3524 NODE_COOKIE(q) = NODE_COOKIE(p);
3525 NODE_COOKIE(p) = reinterpret_cast<void *>(q);
3526 }
3527
3538 template <class GTS, class GTT>
3539 void map_arcs(typename GTS::Arc *p, typename GTT::Arc *q) noexcept
3540 {
3541 assert(p != nullptr and q != nullptr);
3542
3543 if (ARC_COOKIE(p) == nullptr)
3544 {
3545 ARC_COOKIE(p) = q;
3546 ARC_COOKIE(q) = p;
3547
3548 return;
3549 }
3550
3551 ARC_COOKIE(q) = ARC_COOKIE(p);
3552 ARC_COOKIE(p) = q;
3553 }
3554
3555 template <class GT>
3556 void clear_graph(GT & g) noexcept
3557 {
3558 for (typename GT::Arc_Iterator it(g); it.has_curr();) // remove arcs
3559 {
3560 typename GT::Arc *arc = it.get_curr_ne();
3561 it.next_ne();
3562 g.remove_arc(arc);
3563 }
3564
3565 for (typename GT::Node_Iterator it(g); it.has_curr();) // remove nodes
3566 {
3567 typename GT::Node *p = it.get_curr_ne();
3568 it.next_ne(); // advance before deletion (iterator consistency)
3569 g.remove_node(p); // remove it from the graph
3570 }
3571 }
3572
3573 template <class GT>
3574 void copy_graph(GT & gtgt, const GT & gsrc, const bool cookie_map)
3575 {
3576 try
3577 {
3578 clear_graph(gtgt); // clear this before copying
3580
3581 // phase 1: traverse nodes of src_graph and insert copy in this
3582 for (typename GT::Node_Iterator it(gsrc); it.has_curr(); it.next_ne())
3583 {
3584 typename GT::Node *src_node = it.get_current_node_ne();
3585 std::unique_ptr<typename GT::Node>
3586 tgt_node(new typename GT::Node(src_node->get_info()));
3587 map.insert(src_node, tgt_node.get());
3588
3589 typename GT::Node *tgt = tgt_node.release();
3590 assert(tgt->get_info () == src_node->get_info ());
3591 gtgt.insert_node(tgt); // insert in the target graph
3592
3593 if (cookie_map)
3594 GT::map_nodes(src_node, tgt);
3595 }
3596
3597 assert(gtgt.get_num_nodes() == gsrc.get_num_nodes());
3598
3599 // phase 2: for each arc of src_graph, create in this an
3600 // arc connecting the mapped nodes from map
3601 for (typename GT::Arc_Iterator it(gsrc); it.has_curr(); it.next_ne())
3602 {
3603 typename GT::Arc *src_arc = it.get_current_arc_ne();
3604
3605 // get node images in target graph and create arc
3606 typename GT::Node *src_node = map[gsrc.get_src_node(src_arc)];
3607 typename GT::Node *tgt_node = map[gsrc.get_tgt_node(src_arc)];
3608 typename GT::Arc *tgt_arc = gtgt.insert_arc(src_node, tgt_node);
3609 // tgt_arc->get_info() = src_arc->get_info();
3610 *tgt_arc = *src_arc;
3611 if (cookie_map)
3613 }
3614
3615 assert(gtgt.get_num_arcs() == gsrc.get_num_arcs());
3616 }
3617 catch (...)
3618 { // If an exception occurs, clean this
3620 throw;
3621 }
3622 }
3623
3628 template <class GTT, class GTS>
3630 {
3631 void operator()(typename GTT::Node *tgt, typename GTS::Node *src) noexcept
3632 {
3633 tgt->get_info() = src->get_info();
3634 }
3635 };
3636
3641 template <class GTT, class GTS>
3643 {
3644 void operator()(typename GTT::Arc *tgt, typename GTS::Arc *src)
3645 {
3646 tgt->get_info() = src->get_info();
3647 }
3648 };
3649
3658 template <class GTT, class GTS,
3662 const bool cookie_map = false)
3663 {
3664 try
3665 {
3666 clear_graph(gtgt); // clear this before copying
3668 // phase 1: traverse nodes of src_graph and insert a copy in this
3669 for (typename GTS::Node_Iterator it(gsrc); it.has_curr(); it.next_ne())
3670 {
3671 typename GTS::Node *src_node = it.get_current_node_ne();
3672 std::unique_ptr<typename GTT::Node> tgt_node(new typename GTT::Node);
3673 Copy_Node()(tgt_node.get(), src_node);
3674 map.insert(src_node, tgt_node.get());
3675
3676 typename GTT::Node *tgt = tgt_node.release();
3677 gtgt.insert_node(tgt); // insert in the target graph
3678
3679 if (cookie_map)
3680 map_nodes<GTS, GTT>(src_node, tgt);
3681 }
3682
3683 assert(gtgt.get_num_nodes() == gsrc.get_num_nodes());
3684
3685 // phase 2: for each arc of src_graph, create in this an
3686 // arc connecting the mapped nodes from the map
3687 for (typename GTS::Arc_Iterator it(gsrc); it.has_curr(); it.next_ne())
3688 {
3689 typename GTS::Arc *src_arc = it.get_current_arc_ne();
3690
3691 // get node images in target graph and create arc
3692 typename GTT::Node *src_node = map[gsrc.get_src_node(src_arc)];
3693 typename GTT::Node *tgt_node = map[gsrc.get_tgt_node(src_arc)];
3694 typename GTT::Arc *tgt_arc = gtgt.insert_arc(src_node, tgt_node);
3696 if (cookie_map)
3698 }
3699
3700 assert(gtgt.get_num_arcs() == gsrc.get_num_arcs());
3701 }
3702 catch (...)
3703 { // If an exception occurs, clean this
3705 throw;
3706 }
3707 }
3708
3721 template <class GT, class SN = Dft_Show_Node<GT>, class SA = Dft_Show_Arc<GT>>
3723 {
3726
3727 public:
3734 {
3735 // empty
3736 }
3737
3738 private:
3739 void copy(GT & gtgt, const GT & gsrc, const bool cookie_map)
3740 {
3741 try
3742 {
3743 clear_graph(gtgt); // clear this before copying
3745
3746 // phase 1: traverse nodes of src_graph and insert a copy in this
3747 for (Node_Iterator<GT, SN> it(gsrc, sn); it.has_curr(); it.next_ne())
3748 {
3749 typename GT::Node *src_node = it.get_curr();
3750 std::unique_ptr<typename GT::Node>
3751 tgt_node(new typename GT::Node(src_node));
3752 map.insert(src_node, tgt_node.get());
3753
3754 typename GT::Node *tgt = tgt_node.release();
3755 gtgt.insert_node(tgt); // insert in target graph
3756
3757 if (cookie_map)
3758 GT::map_nodes(src_node, tgt);
3759 }
3760
3761 // phase 2: for each arc of src_graph, create in this an
3762 // arc connecting the mapped nodes from a map
3763 for (Arc_Iterator<GT, SA> it(gsrc, sa); it.has_curr(); it.next_ne())
3764 {
3765 typename GT::Arc *src_arc = it.get_curr();
3766
3767 // get node images in target graph and create arc
3768 typename GT::Node *src_node = map[gsrc.get_src_node(src_arc)];
3769 typename GT::Node *tgt_node = map[gsrc.get_tgt_node(src_arc)];
3770 typename GT::Arc *tgt_arc =
3771 gtgt.insert_arc(src_node, tgt_node, src_arc->get_info());
3772
3773 if (cookie_map)
3775 }
3776 }
3777 catch (...)
3778 { // If an exception occurs, it is cleaned this
3780 throw;
3781 }
3782 }
3783
3784 public:
3792 void operator()(GT & gtgt, GT & gsrc, const bool cookie_map = true)
3793 {
3795 }
3796 };
3797
3808 template <class GT, class Distance>
3810 {
3813
3815 { /* empty */
3816 }
3817
3818 bool operator()(typename GT::Arc *a) noexcept
3819 {
3821 return false;
3822
3823 dist = dist + Distance()(a);
3824
3825 return true;
3826 }
3827 };
3828
3848 template <class GT>
3849 inline
3850 bool are_equal(const GT & g1, const GT & g2);
3851
3885 template <class GT,
3886 template <class, class> class Tree = Treap>
3888 {
3889 public:
3890 using Node = typename GT::Node;
3891 using Arc = typename GT::Arc;
3892 using Node_Type = typename GT::Node_Type;
3893 using Arc_Type = typename GT::Arc_Type;
3894
3895 private:
3898
3900 void build_copy(const GT & src)
3901 {
3902 // Phase 1: Copy all nodes and build mapping
3903 for (typename GT::Node_Iterator it(src); it.has_curr(); it.next_ne())
3904 {
3905 Node *src_node = it.get_curr();
3906 Node *tgt_node = copied_graph.insert_node(src_node->get_info());
3907 node_map.insert(src_node, tgt_node);
3908 }
3909
3910 // Phase 2: Copy all arcs using the node mapping
3911 for (typename GT::Arc_Iterator it(src); it.has_curr(); it.next_ne())
3912 {
3913 Arc *src_arc = it.get_curr();
3916
3917 Node *tgt_src = node_map.find(src_src);
3918 Node *tgt_tgt = node_map.find(src_tgt);
3919
3921 }
3922 }
3923
3924 public:
3935 explicit GraphCopyWithMapping(const GT & src)
3936 {
3937 build_copy(src);
3938 }
3939
3949
3961
3975
3976 // Disable copy (graphs can be large)
3978
3980
3989
3998
4011 {
4012 auto *ptr = node_map.search(orig);
4013 ah_domain_error_if(ptr == nullptr)
4014 << "Node not found in mapping (not from original graph?)";
4015 return ptr->second;
4016 }
4017
4029 Node * search_copy(Node *orig) const noexcept
4030 {
4031 auto *ptr = node_map.search(orig);
4032 return ptr ? ptr->second : nullptr;
4033 }
4034
4043 bool has_copy(Node *orig) const noexcept
4044 {
4045 return node_map.search(orig) != nullptr;
4046 }
4047
4055 [[nodiscard]] size_t num_nodes() const noexcept { return node_map.size(); }
4056
4065
4076 template <typename Op>
4077 void for_each_mapping(Op op) const
4078 {
4079 node_map.for_each([&op](const auto & pair)
4080 {
4081 op(pair.first, pair.second);
4082 });
4083 }
4084
4097 {
4099 }
4100
4113 {
4114 return copied_graph.insert_node(std::forward<Node_Type>(info));
4115 }
4116
4127 void remove_node(Node *node)
4128 {
4129 // Maintain node_map consistency when a copied node is removed:
4130 // perform a reverse lookup (value -> key) and erase the corresponding entry.
4131 // This is O(N) because DynMapTree is keyed by original node, not by copy.
4132 Node *original_node = nullptr;
4133 node_map.for_each([&](const auto & pair)
4134 {
4135 if (pair.second == node)
4136 {
4137 original_node = pair.first;
4138 }
4139 });
4140
4141 if (original_node)
4142 node_map.remove(original_node);
4143
4145 }
4146
4157 Arc * insert_arc(Node *src, Node *tgt, const Arc_Type & info = Arc_Type())
4158 {
4159 return copied_graph.insert_arc(src, tgt, info);
4160 }
4161
4169 void remove_arc(Arc *arc)
4170 {
4172 }
4173
4182 void clear()
4183 {
4184 node_map.empty();
4186 }
4187 };
4188} // end namespace Aleph
4189
4190# 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
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
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:3723
Copy_Graph(SA __sa=SA(), SN __sn=SN())
Constructor.
Definition tpl_graph.H:3733
void copy(GT &gtgt, const GT &gsrc, const bool cookie_map)
Definition tpl_graph.H:3739
void operator()(GT &gtgt, GT &gsrc, const bool cookie_map=true)
Perform the copy from gsrc to gtgt.
Definition tpl_graph.H:3792
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:3854
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:1155
T & append(const T &item)
Definition htlist.H:1271
T & get_first() const
Return the first item of the list.
Definition htlist.H:1375
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:3888
Node * search_copy(Node *orig) const noexcept
Search for the copy of an original node (no exception).
Definition tpl_graph.H:4029
typename GT::Arc_Type Arc_Type
Definition tpl_graph.H:3893
bool has_copy(Node *orig) const noexcept
Check if an original node is in the mapping.
Definition tpl_graph.H:4043
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:4112
void build_copy(const GT &src)
Build the copy and mapping.
Definition tpl_graph.H:3900
GraphCopyWithMapping()=default
Default constructor.
const GT & get_graph() const noexcept
Get the copied graph (const version).
Definition tpl_graph.H:3997
DynMapTree< Node *, Node *, Tree > node_map
Definition tpl_graph.H:3897
void remove_node(Node *node)
Remove a node from the copied graph.
Definition tpl_graph.H:4127
Node * get_copy(Node *orig) const
Get the copy of an original node.
Definition tpl_graph.H:4010
void clear()
Clear the copied graph and mapping.
Definition tpl_graph.H:4182
Arc * insert_arc(Node *src, Node *tgt, const Arc_Type &info=Arc_Type())
Insert an arc into the copied graph.
Definition tpl_graph.H:4157
GraphCopyWithMapping(const GT &src)
Construct a copy of the given graph with node mapping.
Definition tpl_graph.H:3935
void remove_arc(Arc *arc)
Remove an arc from the copied graph.
Definition tpl_graph.H:4169
void for_each_mapping(Op op) const
Apply a function to each (original, copy) node pair.
Definition tpl_graph.H:4077
size_t num_arcs() const noexcept
Get the number of arcs in the copied graph.
Definition tpl_graph.H:4064
Node * insert_unmapped_node(const Node_Type &info=Node_Type())
Insert a new node into the copied graph (not mapped).
Definition tpl_graph.H:4096
typename GT::Node_Type Node_Type
Definition tpl_graph.H:3892
GraphCopyWithMapping(GraphCopyWithMapping &&other) noexcept=default
Move constructor.
size_t num_nodes() const noexcept
Get the number of mapped nodes.
Definition tpl_graph.H:4055
typename GT::Node Node
Definition tpl_graph.H:3890
GT & get_graph() noexcept
Get the copied graph.
Definition tpl_graph.H:3988
GraphCopyWithMapping(const GraphCopyWithMapping &)=delete
GraphCopyWithMapping & operator=(GraphCopyWithMapping &&other) noexcept=default
Move assignment operator.
bool is_unitarian_or_empty() const noexcept
Return true if list contains one element or is empty.
Definition htlist.H:431
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:3208
Node * get_current_node_ne() const noexcept
Definition tpl_graph.H:3234
std::tuple< Node *, Arc * > get_tuple() const
Return a tuple with the current node and arc.
Definition tpl_graph.H:3297
Node * get_current_node() const
Return the current node of a path.
Definition tpl_graph.H:3229
std::tuple< Node *, Arc * > get_tuple_ne() const noexcept
Definition tpl_graph.H:3302
Node * get_curr_ne() const noexcept
Definition tpl_graph.H:3262
Arc * get_current_arc_ne() const noexcept
Definition tpl_graph.H:3256
Arc * get_current_arc() const
Return the current arc of a path.
Definition tpl_graph.H:3249
Iterator(const Path &path) noexcept
Create an iterator on the first node of path
Definition tpl_graph.H:3211
Path_Desc & get_curr_path_desc() const
Definition tpl_graph.H:3221
bool has_current_node() const noexcept
Return true if the iterator has a current node.
Definition tpl_graph.H:3321
Node * get_curr() const
Definition tpl_graph.H:3267
Path_Desc & get_curr_path_desc_ne() const noexcept
Definition tpl_graph.H:3216
std::pair< Node *, Arc * > get_pair() const
Return a pair with the current node and arc.
Definition tpl_graph.H:3282
bool has_current_arc() const noexcept
Return true if iterator has current arc.
Definition tpl_graph.H:3315
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:3167
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:3015
void for_each_node(Operation op=Operation()) const
Execute an operation on each node of path.
Definition tpl_graph.H:3338
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:2840
DynList< Arc * > arcs() const
Return a list with the arcs of a path (order, according to the path)
Definition tpl_graph.H:3385
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:2905
Path & operator=(Path &&path) noexcept
Move assignment.
Definition tpl_graph.H:2852
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:3356
void insert_directed(Node *p)
Append a node to a directed path.
Definition tpl_graph.H:3082
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:3132
bool operator==(const Path &p) const noexcept
Return true if this is equal to p,.
Definition tpl_graph.H:3405
bool operator!=(const Path &p) const noexcept
Return true if this is not equal to p,.
Definition tpl_graph.H:3411
void check_graph()
Definition tpl_graph.H:2709
Iterator get_it() const
Returns an iterator on the path.
Definition tpl_graph.H:3328
Path(Path &&path) noexcept
Move constructor.
Definition tpl_graph.H:2837
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:3155
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:3365
void swap(Path &path) noexcept
Fast swap between two paths (constant time)
Definition tpl_graph.H:3196
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:3189
Arc * get_first_arc() const
Return the first arc of path; throws overflow_error if path is empty.
Definition tpl_graph.H:3148
void clear()
Empties the container.
Definition tpl_graph.H:2831
DynDlist< Path_Desc > list
Definition tpl_graph.H:2707
void append(Arc *arc)
Append an arc to the path.
Definition tpl_graph.H:2872
void append_directed(Node *p)
Append a node to a directed path.
Definition tpl_graph.H:2944
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:3115
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:3374
Node * get_last_node() const
Return the last node of path; throws overflow_error if path is empty.
Definition tpl_graph.H:3139
Path(const Path &path)
Copy constructor.
Definition tpl_graph.H:2834
Node * remove_last_node()
Remove the last node of path.
Definition tpl_graph.H:3177
void insert(Node *node)
Insert a node to the path.
Definition tpl_graph.H:3046
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:3349
void append_directed(Arc *arc)
Append an arc to a directed path.
Definition tpl_graph.H:2984
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
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:1046
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:2808
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:1122
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Definition graph-dry.H:737
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:1032
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
Definition graph-dry.H:778
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:1052
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:1199
constexpr size_t get_num_arcs() const noexcept
Definition graph-dry.H:784
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Definition graph-dry.H:743
static void map_nodes(N1 *p, N2 *q) noexcept
Map the nodes through their cookies.
Definition graph-dry.H:1001
void remove_arcs_if(Predicate pred)
Remove all arcs matching a predicate.
Definition graph-dry.H:3671
QuadTree - Hierarchical spatial index for 2D points.
Definition quadtree.H:126
Generic filter iterator wrapper for Aleph containers.
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:3539
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:3792
#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:3661
#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:3556
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:3574
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:3511
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:3475
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
and
Check uniqueness with explicit hash + equality functors.
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
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:105
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
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:3424
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.
static std::atomic< bool > init
Definition hash-fct.C:53
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
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:3643
void operator()(typename GTT::Arc *tgt, typename GTS::Arc *src)
Definition tpl_graph.H:3644
Default copy node functor.
Definition tpl_graph.H:3630
void operator()(typename GTT::Node *tgt, typename GTS::Node *src) noexcept
Definition tpl_graph.H:3631
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:3810
bool operator()(typename GT::Arc *a) noexcept
Definition tpl_graph.H:3818
Distance::Distance_Type dist
Accumulative distance from the first seen arc until the last seen.
Definition tpl_graph.H:3812
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:614
Distance accessor.
Common node iterator for graph having its node derived from Dlink class.
Definition graph-dry.H:256
gsl_rng * r
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
Treap< int >::Node * last_node
Definition writeTreap.C:55