Aleph-w  1.9
General library for algorithms and data structures
graph-dry.H
1 
2 /* Aleph-w
3 
4  / \ | | ___ _ __ | |__ __ __
5  / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6  / ___ \| | __/ |_) | | | |_____\ V V / version 1.9b
7  /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8  |_|
9 
10  This file is part of Aleph-w library
11 
12  Copyright (c) 2002-2018 Leandro Rabindranath Leon & Alejandro Mujica
13 
14  This program is free software: you can redistribute it and/or modify
15  it under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  This program is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27 
28 # ifndef GRAPH_DRY_H
29 # define GRAPH_DRY_H
30 
31 
41 template <class GT>
42 struct GTNodeIterator : public Dlink::Iterator
43 {
44  using Node = typename GT::Node;
45 
47  using Item_Type = Node*;
48 
50  using Set_Type = GT;
51 
52  GTNodeIterator() noexcept { /* empty */ }
53 
55  GTNodeIterator(Dlink & head) noexcept : Dlink::Iterator(head) { /* empty */ }
56 
58  Node * get_curr_ne() const noexcept
59  {
60  return (Node*) Dlink::Iterator::get_curr_ne();
61  }
62 
64  Node * get_curr() const { return (Node*) Dlink::Iterator::get_curr(); }
65 
67  Node * get_current_node() const { return get_curr(); }
68 
69  Node * get_current_node_ne() const { return get_curr_ne(); }
70 };
71 
72 
82 template <class GT>
83 struct GTArcIterator : public Dlink::Iterator
84 {
85  using Node = typename GT::Node;
86  using Arc = typename GT::Arc;
87 
89  using Item_Type = Arc*;
90 
92  using Set_Type = GT;
93 
94  GTArcIterator() noexcept { /* empty */ }
95 
97  GTArcIterator(Dlink & head) noexcept
98  : Dlink::Iterator(head)
99  { /* empty */ }
100 
102  Arc * get_curr_ne() const noexcept
103  {
104  return (Arc*) Dlink::Iterator::get_curr_ne();
105  }
106 
108  Arc * get_curr() const { return (Arc*) Dlink::Iterator::get_curr(); }
109 
111  Arc * get_current_arc() const { return get_curr(); }
112 
114  Arc * get_current_arc_ne() const noexcept { return get_curr_ne(); }
115 
117  Node * get_src_node_ne() const noexcept
118  {
119  return (Node*) get_curr_ne()->src_node;
120  }
121 
123  Node * get_tgt_node_ne() const noexcept
124  {
125  return (Node*) get_curr_ne()->tgt_node;
126  }
127 
129  Node * get_src_node() const
130  {
131  return (Node*) get_curr()->src_node;
132  }
133 
135  Node * get_tgt_node() const
136  {
137  return (Node*) get_curr()->tgt_node;
138  }
139 };
140 
141 
146 template <class GT, class Cmp>
148 {
149  using Node = typename GT::Node;
150 
151  Cmp & cmp;
152 
153  Cmp_Dlink_Node(Cmp && __cmp = Cmp()) noexcept : cmp(__cmp) { /* empty */ }
154 
155  Cmp_Dlink_Node(Cmp & __cmp) noexcept : cmp(__cmp) { /* empty */ }
156 
157  bool operator () (Dlink * d1, Dlink * d2) const noexcept
158  {
159  Node * p1 = static_cast<Node*>(d1);
160  Node * p2 = static_cast<Node*>(d2);
161  return cmp(p1, p2);
162  }
163 };
164 
169 template <class GT, class Cmp>
171 {
172  using Arc = typename GT::Arc;
173 
174  Cmp & cmp;
175 
176  Cmp_Dlink_Arc(Cmp && __cmp = Cmp()) noexcept : cmp(__cmp) { /* empty */ }
177 
178  Cmp_Dlink_Arc(Cmp & __cmp) noexcept : cmp(__cmp) { /* empty */ }
179 
180  bool operator () (Dlink * d1, Dlink * d2) const noexcept
181  {
182  Arc * arc1 = static_cast<Arc*>(d1);
183  Arc * arc2 = static_cast<Arc*>(d2);
184  return cmp(arc1, arc2);
185  }
186 };
187 
205 template <typename NodeInfo>
207 {
208 public:
209 
214  Graph_Attr attrs;
215 
216  NodeInfo node_info;
217 
218 
227  size_t num_arcs = 0;
228 
229  using Item_Type = NodeInfo;
230 
231  using Node = GTNodeCommon;
232 
233  using Node_Type = NodeInfo;
234 
235  GTNodeCommon() noexcept {}
236 
237  GTNodeCommon(const NodeInfo & info) : node_info(info) {}
238 
239  GTNodeCommon(NodeInfo && info) : node_info(move(info)) {}
240 
242  NodeInfo & get_info() noexcept { return node_info; }
243 
245  const NodeInfo & get_info() const noexcept { return node_info; }
246 
248  unsigned int state() const noexcept { return NODE_BITS(this).state; }
249 
251  void set_state(unsigned int s) noexcept { NODE_BITS(this).state = s; }
252 };
253 
254 
271 template <typename ArcInfo>
273 {
274 public:
275 
276  using Item_Type = ArcInfo;
277  using Arc_Type = ArcInfo;
278 
279  void * src_node = nullptr;
280  void * tgt_node = nullptr;
281 
286  Graph_Attr attrs;
287 
288  ArcInfo arc_info;
289 
290  GTArcCommon(const ArcInfo & info) : arc_info(info) {}
291 
292  GTArcCommon(ArcInfo && info) : arc_info(move(info)) {}
293 
294  GTArcCommon(void * src, void * tgt, const ArcInfo & data)
295  : src_node(src), tgt_node(tgt), arc_info(data) {}
296 
297  GTArcCommon(void * src, void * tgt, ArcInfo && data = ArcInfo())
298  : src_node(src), tgt_node(tgt), arc_info(move(data)) {}
299 
301  unsigned int state() const noexcept { return ARC_BITS(this).state; }
302 
304  void set_state(unsigned int s) noexcept { ARC_BITS(this).state = s; }
305 
307  ArcInfo & get_info() noexcept { return arc_info; }
308 
310  const ArcInfo & get_info() const noexcept { return arc_info; }
311 
312  void * get_connected_node(void * node) noexcept
313  {
314  return src_node == node ? tgt_node : src_node;
315  }
316 
317  void * get_img_node(void * node) noexcept
318  {
319  return src_node == node ? src_node : tgt_node;
320  }
321 };
322 
323 
328 template <class GT, class Node, class Arc>
330 {
331  GT * me() { return static_cast<GT*>(this); }
332 
333  const GT * const_me() const { return static_cast<const GT*>(this); }
334 
335 protected:
336 
337  void * cookie = nullptr;
338  size_t num_nodes = 0;
339  size_t num_arcs = 0;
340  bool digraph = false;
341 
342 public:
343 
344  using Node_Type = typename Node::Node_Type;
345  using Arc_Type = typename Arc::Arc_Type;
346 
347 protected:
348 
349  void init() noexcept
350  {
351  num_nodes = num_arcs = 0;
352  cookie = nullptr;
353  digraph = false;
354  }
355 
356  void common_swap(GT & g) noexcept
357  {
358  std::swap(num_nodes, g.num_nodes);
359  std::swap(num_arcs, g.num_arcs);
360  std::swap(digraph, g.digraph);
361  std::swap(cookie, g.cookie);
362  }
363 
364 public:
365 
367  void *& get_cookie() noexcept { return cookie; }
368 
370  void * get_cookie() const noexcept { return cookie; }
371 
373  bool is_digraph() const noexcept { return digraph; }
374 
408  void set_digraph(bool val) { digraph = val; } // TODO: delete after
409 
411  size_t get_num_nodes() const noexcept { return num_nodes; }
412 
414  size_t vsize() const noexcept { return get_num_nodes(); }
415 
424  Node * get_node() const { return const_me()->get_first_node(); }
425 
434  Node * get_arc() const { return const_me()->get_first_arc(); }
435 
444  Node * get_arc(Node * p) { return const_me()->get_first_arc(p); }
445 
447  Node * get_src_node(Arc * arc) const noexcept
448  {
449  return (Node*) arc->src_node;
450  }
451 
453  Node * get_tgt_node(Arc * arc) const noexcept
454  {
455  return (Node*) arc->tgt_node;
456  }
457 
488  Node * get_connected_node(Arc * arc, Node * node) const noexcept
489  {
490  return (Node*) arc->get_connected_node(node);
491  }
492 
494  size_t get_num_arcs() const noexcept { return num_arcs; }
495 
498  size_t get_num_arcs(Node * node) const noexcept
499  {
500  return node->num_arcs;
501  }
502 
505  size_t degree(Node * p) const noexcept { return get_num_arcs(p); }
506 
508  size_t esize() const noexcept { return get_num_arcs(); }
509 
511  Bit_Fields & get_control_bits(Node * node) const noexcept
512  {
513  return NODE_BITS(node).reset();
514  }
515 
517  void reset_bit(Node * node, int bit) const noexcept
518  {
519  NODE_BITS(node).reset(bit);
520  }
521 
523  void reset_bits(Node * node) const noexcept { NODE_BITS(node).reset(); }
524 
526  int get_bit(Node * node, int bit) const noexcept
527  {
528  return NODE_BITS(node).get_bit(bit);
529  }
530 
532  void set_bit(Node * node, int bit, int value) const noexcept
533  {
534  NODE_BITS(node).set_bit(bit, value);
535  }
536 
538  Bit_Fields & get_control_bits(Arc * arc) const noexcept
539  {
540  return ARC_BITS(arc);
541  }
542 
544  void reset_bit(Arc * arc, int bit) const noexcept
545  {
546  ARC_BITS(arc).reset(bit);
547  }
548 
550  void reset_bits(Arc * arc) const noexcept { ARC_BITS(arc).reset(); }
551 
553  int get_bit(Arc * arc, int bit) const noexcept
554  {
555  return ARC_BITS(arc).get_bit(bit);
556  }
557 
559  void set_bit(Arc * arc, int bit, int value) const noexcept
560  {
561  ARC_BITS(arc).set_bit(bit, value);
562  }
563 
565  void *& get_cookie(Node * node) const noexcept
566  {
567  return NODE_COOKIE(node);
568  }
569 
571  void *& get_cookie(Arc * arc) const noexcept
572  {
573  return ARC_COOKIE(arc);
574  }
575 
577  long & get_counter(Node * node) const noexcept
578  {
579  return NODE_COUNTER(node);
580  }
581 
583  void reset_counter(Node * node) const noexcept
584  {
585  NODE_COUNTER(node) = 0;
586  }
587 
589  void reset_node_counters() const noexcept
590  {
591  for_each_node([this] (auto p) { this->reset_counter(p); });
592  }
593 
597  void reset_node(Node * p) const noexcept
598  {
599  p->attrs.reset();
600  }
601 
603  long & get_counter(Arc * arc) const noexcept
604  {
605  return ARC_COUNTER(arc);
606  }
607 
609  void reset_counter(Arc * arc) const noexcept
610  {
611  ARC_COUNTER(arc) = No_Visited;
612  }
613 
615  void reset_arc_counters() const noexcept
616  {
617  for_each_arc([this] (auto a) { this->reset_counter(a); });
618  }
619 
623  void reset_arc(Arc * arc) const noexcept
624  {
625  arc->attrs.reset();
626  }
627 
630  void reset_nodes() const
631  {
632  for_each_node([] (auto p) { p->attrs.reset(); });
633  }
634 
637  void reset_arcs() const
638  {
639  for_each_arc([] (auto a) { a->attrs.reset(); });
640  }
641 
703  template <class N1, class N2 = N1> static
704  void map_nodes(N1 * p, N2 * q) noexcept
705  {
706  assert(p != nullptr and q != nullptr);
707  if (NODE_COOKIE(p) == nullptr)
708  {
709  NODE_COOKIE(p) = q;
710  NODE_COOKIE(q) = p;
711  return;
712  }
713  NODE_COOKIE(q) = NODE_COOKIE(p);
714  NODE_COOKIE(p) = q;
715  }
716 
731  template <class A1, class A2 = A1> static
732  void map_arcs(A1 * p, A2 * q) noexcept
733  {
734  assert(p != nullptr and q != nullptr);
735  if (ARC_COOKIE(p) == nullptr)
736  {
737  ARC_COOKIE(p) = q;
738  ARC_COOKIE(q) = p;
739  return;
740  }
741  ARC_COOKIE(q) = ARC_COOKIE(p);
742  ARC_COOKIE(p) = q;
743  }
744 
746  void reset_bit_nodes(int bit) const noexcept
747  {
748  for_each_node([bit, this] (auto p) { this->reset_bit(p, bit); });
749  }
750 
752  void reset_bit_arcs(int bit) const noexcept
753  {
754  for_each_arc([bit, this] (auto a) { this->reset_bit(a, bit); });
755  }
756 
758  void reset_bit_nodes() const noexcept
759  {
760  for_each_node([this] (auto p) { this->reset_bits(p); });
761  }
762 
764  void reset_bit_arcs() const noexcept
765  {
766  for_each_arc([this] (auto a) { this->reset_bits(a); });
767  }
768 
770  void reset_counter_nodes() const noexcept
771  {
772  for_each_node([this] (auto p) { this->reset_counter(p); });
773  }
774 
776  void reset_counter_arcs() const noexcept
777  {
778  for_each_arc([this] (auto a) { this->reset_counter(a); });
779  }
780 
787  void reset_cookie_nodes() const noexcept
788  {
789  for_each_node([] (auto p) { NODE_COOKIE(p) = nullptr; });
790  }
791 
798  void reset_cookie_arcs() const noexcept
799  {
800  for_each_arc([] (auto a) { ARC_COOKIE(a) = nullptr; });
801  }
802 
822  Node * insert_node(const Node_Type & node_info)
823  {
824  return me()->insert_node(new Node (node_info));
825  }
826 
846  Node * insert_node(Node_Type && node_info = Node_Type())
847  {
848  return me()->insert_node(new Node(std::forward<Node_Type>(node_info)));
849  }
850 
871  template <typename ...Args>
872  Node * emplace_node(Args && ... args)
873  {
874  return me()->insert_node(Node_Type(args...));
875  }
876 
899  Arc * insert_arc(Node * src, Node * tgt, const Arc_Type & arc_info)
900  {
901  std::unique_ptr<Arc> arc(new Arc(arc_info));
902  me()->insert_arc(src, tgt, arc.get());
903  return arc.release();
904  }
905 
929  Arc * insert_arc(Node * src, Node * tgt, Arc_Type && arc_info = Arc_Type())
930  {
931  std::unique_ptr<Arc> arc(new Arc(std::forward<Arc_Type>(arc_info)));
932  me()->insert_arc(src, tgt, arc.get());
933  return arc.release();
934  }
935 
957  template <typename ...Args>
958  Arc * emplace_arc(Node * src, Node * tgt, Args && ... args)
959  {
960  return me()->insert_arc(src, tgt, Arc_Type(args...));
961  }
962 
1009  template <class Operation>
1010  bool traverse_nodes(Operation & op) const noexcept(noexcept(op))
1011  {
1012  for (typename GT::Node_Iterator it(*const_me()); it.has_curr(); it.next_ne())
1013  if (not op(it.get_curr_ne()))
1014  return false;
1015  return true;
1016  }
1017 
1019  template <class Operation>
1020  bool traverse_nodes(Operation && op = Operation()) const noexcept(noexcept(op))
1021  {
1022  return traverse_nodes(op);
1023  }
1024 
1074  template <class Operation>
1075  bool traverse_arcs(Operation & op) const noexcept(noexcept(op))
1076  {
1077  for (typename GT::Arc_Iterator it(*const_me()); it.has_curr(); it.next_ne())
1078  if (not op(it.get_curr_ne()))
1079  return false;
1080  return true;
1081  }
1082 
1084  template <class Operation>
1085  bool traverse_arcs(Operation && op = Operation()) const noexcept(noexcept(op))
1086  {
1087  return traverse_arcs(op);
1088  }
1089 
1141  template <class Operation>
1142  bool traverse_arcs(Node * p, Operation & op) const noexcept(noexcept(op))
1143  {
1144  for (typename GT::Node_Arc_Iterator it(p); it.has_curr(); it.next_ne())
1145  if (not op(it.get_curr_ne()))
1146  return false;
1147  return true;
1148  }
1149 
1151  template <class Operation>
1152  bool traverse_arcs(Node * p, Operation && op = Operation())
1153  const noexcept(noexcept(op))
1154  {
1155  return traverse_arcs(p, op);
1156  }
1157 
1182  template <class Operation>
1183  void for_each_node(Operation & operation) const noexcept(noexcept(operation))
1184  {
1185  for (typename GT::Node_Iterator it(*const_me()); it.has_curr(); it.next_ne())
1186  operation(it.get_curr_ne());
1187  }
1188 
1190  template <class Operation>
1191  void for_each_node(Operation && operation = Operation()) const
1192  {
1193  for_each_node(operation);
1194  }
1195 
1220  template <class Operation>
1221  void for_each_arc(Operation & op) const noexcept(noexcept(op))
1222  {
1223  for (typename GT::Arc_Iterator it(*const_me()); it.has_curr(); it.next_ne())
1224  op(it.get_curr_ne());
1225  }
1226 
1228  template <class Operation>
1229  void for_each_arc(Operation && operation = Operation()) const
1230  {
1231  for_each_arc(operation);
1232  }
1233 
1267  template <class Operation>
1268  void for_each_arc(Node * p, Operation & op) const noexcept(noexcept(op))
1269  {
1270  for (typename GT::Node_Arc_Iterator it(p); it.has_curr(); it.next_ne())
1271  op(it.get_curr_ne());
1272  }
1273 
1275  template <class Operation>
1276  void for_each_arc(Node * p, Operation && op = Operation())
1277  const noexcept(noexcept(op))
1278  {
1279  for_each_arc(p, op);
1280  }
1281 
1311  template <class Operation>
1312  bool all_nodes(Operation & op) const noexcept(noexcept(op))
1313  {
1314  return traverse_nodes(op);
1315  }
1316 
1318  template <class Operation>
1319  bool all_nodes(Operation && op = Operation()) const noexcept(noexcept(op))
1320  {
1321  return all_nodes(op);
1322  }
1323 
1353  template <class Operation>
1354  bool all_arcs(Operation & op) const noexcept(noexcept(op))
1355  {
1356  return traverse_arcs(op);
1357  }
1358 
1360  template <class Operation>
1361  bool all_arcs(Operation && op = Operation()) const noexcept(noexcept(op))
1362  {
1363  return all_arcs(op);
1364  }
1365 
1398  template <class Operation>
1399  bool all_arcs(Node * p, Operation & op) const noexcept(noexcept(op))
1400  {
1401  return traverse_arcs(p, op);
1402  }
1403 
1405  template <class Operation>
1406  bool all_arcs(Node * p, Operation && op = Operation())
1407  const noexcept(noexcept(op))
1408  {
1409  return all_arcs(p, op);
1410  }
1411 
1452  template <typename T = Node_Type>
1453  auto nodes_map(std::function<T(Node *)> op) const
1454  {
1455  DynList<T> ret_val;
1456  for_each_node([&ret_val, &op] (Node * p) { ret_val.append(op(p)); });
1457  return ret_val;
1458  }
1459 
1499  template <typename T = Arc_Type>
1500  auto arcs_map(std::function<T(Arc *)> operation) const
1501  {
1502  DynList<T> ret_val;
1503  for_each_arc([&ret_val, &operation] (Arc * p)
1504  {
1505  ret_val.append(operation(p));
1506  });
1507  return ret_val;
1508  }
1509 
1550  template <typename T = Arc_Type>
1551  auto arcs_map(Node * p, std::function<T(Arc *)> operation) const
1552  {
1553  DynList<T> ret_val;
1554  for_each_arc(p, [&ret_val, &operation] (Arc * a)
1555  {
1556  ret_val.append(operation(a));
1557  });
1558  return ret_val;
1559  }
1560 
1595  template <typename T = Node_Type>
1596  T foldl_nodes(const T & init,
1597  std::function<T(const T&, Node*)> op) const
1598  {
1599  T ret = init;
1600  for_each_node([&ret, &op] (Node * p) { ret = op(ret, p); }); return ret;
1601  }
1602 
1636  template <typename T = Arc_Type>
1637  T foldl_arcs(const T & init,
1638  std::function<T(const T&, Arc*)> op) const
1639  {
1640  T ret = init;
1641  for_each_arc([&ret, &op] (Arc * p) { ret = op(ret, p); });
1642  return ret;
1643  }
1644 
1679  template <typename T = Arc_Type>
1680  T foldl_arcs(Node * p, const T & init,
1681  std::function<T(const T&, Arc*)> op) const
1682  {
1683  T ret = init;
1684  for_each_arc(p, [&ret, &op] (Arc * a) { ret = op(ret, a); });
1685  return ret;
1686  }
1687 
1709  template <class Op> auto filter_nodes(Op & op) const
1710  {
1711  DynList<Node*> ret;
1712  for_each_node([&ret, &op] (Node * p)
1713  {
1714  if (op(p))
1715  ret.append(p);
1716  });
1717  return ret;
1718  }
1719 
1721  template <class Op> auto filter_nodes(Op && op) const
1722  {
1723  return filter_nodes(op);
1724  }
1725 
1747  template <class Op> auto filter_arcs(Op & op) const
1748  {
1749  DynList<Arc*> ret;
1750  for_each_arc([&ret, &op] (Arc * a)
1751  {
1752  if (op(a))
1753  ret.append(a);
1754  });
1755  return ret;
1756  }
1757 
1759  template <class Op> auto filter_arcs(Op && op) const
1760  {
1761  return filter_arcs(op);
1762  }
1763 
1794  template <class Op> auto filter_arcs(Node * p, Op & op) const
1795  {
1796  DynList<Arc*> ret;
1797  for_each_arc(p, [&ret, &op] (Arc * a)
1798  {
1799  if (op(a))
1800  ret.append(a);
1801  });
1802  return ret;
1803  }
1804 
1806  template <class Op> auto filter_arcs(Node * p, Op && op) const
1807  {
1808  return filter_arcs(p, op);
1809  }
1810 
1829  template <class Operation>
1830  bool exists_node(Operation & op) const noexcept(noexcept(op))
1831  {
1832  return not traverse_nodes([&op] (Node * p) { return not op(p); });
1833  }
1834 
1836  template <class Operation>
1837  bool exists_node(Operation && op = Operation()) const noexcept(noexcept(op))
1838  {
1839  return exists_node(op);
1840  }
1841 
1860  template <class Operation>
1861  bool exists_arc(Operation & op) const noexcept(noexcept(op))
1862  {
1863  return not traverse_arcs([&op] (Arc * a) { return not op(a); });
1864  }
1865 
1867  template <class Operation>
1868  bool exists_arc(Operation && op = Operation()) const noexcept(noexcept(op))
1869  {
1870  return exists_arc(op);
1871  }
1872 
1895  template <class Operation>
1896  bool exists_arc(Node * p, Operation & op) const noexcept(noexcept(op))
1897  {
1898  return not traverse_arcs(p, [&op] (Arc * a) { return not op(a); });
1899  }
1900 
1902  template <class Operation>
1903  bool exists_arc(Node * p, Operation && op = Operation())
1904  const noexcept(noexcept(op))
1905  {
1906  return exists_arc(p, op);
1907  }
1908 
1925  template <class Op>
1926  Node * search_node(Op & op) const noexcept(noexcept(op))
1927  {
1928  for (typename GT::Node_Iterator it(*const_me()); it.has_curr(); it.next_ne())
1929  {
1930  auto p = it.get_curr_ne();
1931  if (op(p))
1932  return p;
1933  }
1934  return nullptr;
1935  }
1936 
1938  template <class Op>
1939  Node * search_node(Op && op) const noexcept(noexcept(op))
1940  {
1941  return search_node(op);
1942  }
1943 
1955  Node * find_node(const Node_Type & info) const noexcept
1956  {
1957  return search_node([&info] (auto p) { return p->get_info() == info; });
1958  }
1959 
1976  template <class Op>
1977  Arc * search_arc(Op & op) const noexcept(noexcept(op))
1978  {
1979  for (typename GT::Arc_Iterator it(*const_me()); it.has_curr(); it.next_ne())
1980  {
1981  auto a = it.get_curr_ne();
1982  if (op(a))
1983  return a;
1984  }
1985  return nullptr;
1986  }
1987 
1989  template <class Op>
1990  Arc * search_arc(Op && op) const noexcept(noexcept(op))
1991  {
1992  return search_arc(op);
1993  }
1994 
2006  Arc * find_arc(const Arc_Type & info) const noexcept
2007  {
2008  return search_arc([&info] (auto a) { return a->get_info() == info; });
2009  }
2010 
2029  template <class Operation>
2030  Arc * search_arc(Node * p, Operation & op) const noexcept(noexcept(op))
2031  {
2032  for (typename GT::Node_Arc_Iterator it(p); it.has_curr(); it.next_ne())
2033  {
2034  Arc * arc = it.get_curr_ne();
2035  if (op(arc))
2036  return arc;
2037  }
2038  return nullptr;
2039  }
2040 
2042  template <class Operation>
2043  Arc * search_arc(Node * p, Operation && op = Operation())
2044  const noexcept(noexcept(op))
2045  {
2046  return search_arc(p, op);
2047  }
2048 
2072  Arc * search_arc(Node * src, Node * tgt) const noexcept
2073  {
2074  for (typename GT::Node_Arc_Iterator it(src); it.has_curr(); it.next_ne())
2075  if (it.get_tgt_node_ne() == tgt)
2076  return it.get_curr_ne();
2077  return nullptr;
2078  }
2079 
2090  template <template <typename> class Container = Aleph::DynList>
2091  Container<Node*> nodes() const
2092  {
2093  Container<Node*> ret;
2094  for_each_node([&ret] (Node * p) { ret.append(p); });
2095  return ret;
2096  }
2097 
2108  template <template <typename> class Container = Aleph::DynList>
2109  Container<Arc*> arcs() const
2110  {
2111  Container<Arc*> ret;
2112  for_each_arc([&ret] (Arc * a) { ret.append(a); });
2113  return ret;
2114  }
2115 
2126  template <template <typename> class Container = Aleph::DynList>
2127  Container<Arc*> arcs(Node * p) const
2128  {
2129  Container<Arc*> ret;
2130  this->for_each_arc(p, [&ret] (Arc * a) { ret.append(a); });
2131  return ret;
2132  }
2133 
2151  auto get_node_it() const noexcept
2152  {
2153  return typename GT::Node_Iterator(*const_me());
2154  }
2155 
2173  auto get_arc_it() const noexcept
2174  {
2175  return typename GT::Arc_Iterator(*const_me());
2176  }
2177 
2196  auto get_arc_it(Node * p) const noexcept
2197  {
2198  return typename GT::Node_Arc_Iterator(p);
2199  }
2200 
2233  struct In_Filt
2234  {
2235  Node * tgt = nullptr;
2236 
2238  In_Filt(Node * __tgt = nullptr) noexcept : tgt(__tgt) { /* empty */ }
2239 
2242  bool operator () (Arc * a) const noexcept
2243  {
2244  assert(tgt);
2245  return a->tgt_node == tgt;
2246  }
2247 
2249  Node * get_node(Arc * a) const noexcept
2250  {
2251  assert(tgt);
2252  return (typename GT::Node *) a->src_node;
2253  }
2254  };
2255 
2288  struct Out_Filt
2289  {
2290  Node * src = nullptr;
2291 
2293  Out_Filt(Node * __src) noexcept : src(__src) { /* empty */ }
2294 
2297  bool operator () (Arc * a) const noexcept
2298  {
2299  assert(src);
2300  return a->src_node == src;
2301  }
2302 
2304  Node * get_node(Arc * a) const noexcept
2305  {
2306  assert(src);
2307  return (Node *) a->tgt_node;
2308  }
2309  };
2310 
2336  template <class Filter>
2338  {
2340 
2341  Filter filt;
2342  Itor it;
2343 
2344  public:
2345 
2346  using Item_Type = typename Itor::Item_Type;
2347 
2349 
2352  noexcept(noexcept(Filter(p)) and noexcept(Itor(p, filt)))
2353  : filt(p), it(p, filt)
2354  {
2355  // empty
2356  }
2357 
2358  void next_ne() noexcept { it.next_ne(); }
2359 
2362  void next() { it.next(); }
2363 
2366  void prev() { it.prev(); }
2367 
2368  void prev_ne() { it.prev_ne(); }
2369 
2371  bool has_curr() const noexcept { return it.has_curr(); }
2372 
2375  typename GT::Arc * get_curr() const { return it.get_curr(); }
2376 
2377  typename GT::Arc * get_curr_ne() const noexcept { return it.get_curr_ne(); }
2378 
2380  auto get_current_arc() const { return get_curr(); }
2381 
2382  auto get_current_arc_ne() const noexcept { return get_curr_ne(); }
2383 
2386  typename GT::Node * get_node(typename GT::Arc * a) const noexcept
2387  {
2388  return filt.get_node(a);
2389  }
2390 
2393  typename GT::Node * get_node_ne() const noexcept
2394  {
2395  return this->get_node(this->get_curr_ne());
2396  }
2397 
2399  auto get_tgt_node_ne() const noexcept { return get_node_ne(); }
2400 
2401  typename GT::Node * get_node() const
2402  {
2403  return this->get_node(this->get_curr());
2404  }
2405 
2407  auto get_tgt_node() const { return get_node(); }
2408 
2410  void reset_first() noexcept { it.reset_first(); }
2411 
2413  void reset_last() noexcept { it.reset_last(); }
2414  };
2415 
2417  template <class Filt> using Filter_Iterator = Digraph_Iterator<Filt>;
2418 
2420  using In_Iterator = Digraph_Iterator<In_Filt>;
2421 
2423  using Out_Iterator = Digraph_Iterator<Out_Filt>;
2424 
2443  In_Iterator get_in_it(Node * p) const noexcept { return In_Iterator(p); }
2444 
2463  Out_Iterator get_out_it(Node * p) const noexcept { return Out_Iterator(p); }
2464 
2475  Arc * search_directed_arc(Node * src, Node * tgt) const noexcept
2476  {
2477  for (typename GT::Out_Iterator it(src); it.has_curr(); it.next_ne())
2478  if (it.get_tgt_node() == tgt)
2479  return it.get_curr_ne();
2480  return nullptr;
2481  }
2482 
2493  DynList<Node*> in_nodes(Node * p) const
2494  {
2495  DynList<Node*> ret;
2496  for (In_Iterator it(p); it.has_curr(); it.next_ne())
2497  ret.append(it.get_node());
2498  return ret;
2499  }
2500 
2511  DynList<Node*> out_nodes(Node * p) const
2512  {
2513  DynList<Node*> ret;
2514  for (Out_Iterator it(p); it.has_curr(); it.next_ne())
2515  ret.append(it.get_node_ne());
2516  return ret;
2517  }
2518 
2528  DynList<Arc*> out_arcs(Node * p) const
2529  {
2530  DynList<Arc*> ret;
2531  for (Out_Iterator it(p); it.has_curr(); it.next_ne())
2532  ret.append(it.get_curr_ne());
2533  return ret;
2534  }
2535 
2544  DynList<Arc*> in_arcs(Node * p) const
2545  {
2546  DynList<Arc*> ret;
2547  for (In_Iterator it(p); it.has_curr(); it.next_ne())
2548  ret.append(it.get_curr_ne());
2549  return ret;
2550  }
2551 
2553  using ArcPair = tuple<Arc*, Node*>;
2554 
2567  auto in_pairs(Node * p) const
2568  {
2569  DynList<ArcPair> ret;
2570  for (In_Iterator it(p); it.has_curr(); it.next_ne())
2571  {
2572  auto a = it.get_curr_ne();
2573  ret.append(make_tuple(a, (Node*) a->get_connected_node(p)));
2574  }
2575  return ret;
2576  }
2577 
2590  auto out_pairs(Node * p) const
2591  {
2592  DynList<ArcPair> ret;
2593  for (Out_Iterator it(p); it.has_curr(); it.next_ne())
2594  {
2595  auto a = it.get_curr_ne();
2596  ret.append(make_tuple(a, (Node*) a->get_connected_node(p)));
2597  }
2598  return ret;
2599  }
2600 
2614  size_t in_degree(Node * p) const noexcept
2615  {
2616  size_t count = 0;
2617  for (In_Iterator it(p); it.has_curr(); it.next_ne())
2618  ++count;
2619  return count;
2620  }
2621 
2637  size_t out_degree(Node * p) const noexcept
2638  {
2639  size_t count = 0;
2640  for (Out_Iterator it(p); it.has_curr(); it.next_ne())
2641  ++count;
2642  return count;
2643  }
2644 
2663  template <class Itor, class Operation>
2664  bool traverse_arcs(Node * p, Operation & op) const noexcept(noexcept(op))
2665  {
2666  for (Itor it(p); it.has_curr(); it.next_ne())
2667  if (not op(it.get_curr_ne()))
2668  return false;
2669  return true;
2670  }
2671 
2673  template <class Itor, class Operation>
2674  void for_each_arc(Node * p, Operation & op) const noexcept(noexcept(op))
2675  {
2676  for (Itor it(p); it.has_curr(); it.next_ne())
2677  operation(it.get_curr_ne());
2678  }
2679 
2682  template <class Op>
2683  bool traverse_in_arcs(Node * p, Op & op) const noexcept(noexcept(op))
2684  {
2685  return traverse_arcs<In_Iterator, Op>(p, op);
2686  }
2687 
2689  template <class Op>
2690  bool traverse_in_arcs(Node * p, Op && op = Op()) const noexcept(noexcept(op))
2691  {
2692  return traverse_in_arcs(p, op);
2693  }
2694 
2696  template <class Op>
2697  void for_each_in_arc(Node * p, Op & op) const noexcept(noexcept(op))
2698  {
2699  for_each_arc(p, op);
2700  }
2701 
2702  // \overload for_each_in_arc(Node * p, Op & op)
2703  template <class Op>
2704  void for_each_in_arc(Node * p, Op && op = Op()) const noexcept(noexcept(op))
2705  {
2706  for_each_in_arc(p, op);
2707  }
2708 
2710  template <class Op>
2711  bool all_in_arcs(Node * p, Op & op) const noexcept(noexcept(op))
2712  {
2713  return traverse_in_arcs(p, [&op] (auto a) { return op(a); });
2714  }
2715 
2717  template <class Op>
2718  bool all_in_arcs(Node * p, Op && op = Op()) const noexcept(noexcept(op))
2719  {
2720  return all_in_arc(p, op);
2721  }
2722 
2725  template <class Op>
2726  bool exists_in_arc(Node * p, Op & op) const noexcept(noexcept(op))
2727  {
2728  return not traverse_in_arcs(p, [&op] (auto a) { return not op(a); });
2729  }
2730 
2732  template <class Op>
2733  bool exists_in_arc(Node * p, Op && op = Op()) const noexcept(noexcept(op))
2734  {
2735  return exists_in_arc(p, op);
2736  }
2737 
2751  template <class Op>
2752  auto search_in_arc(Node * p, Op & op) const noexcept(noexcept(op))
2753  {
2754  Arc * ret = nullptr;
2755  traverse_in_arcs(p, [&op, &ret] (auto a)
2756  {
2757  if (op(a))
2758  {
2759  ret = a;
2760  return false;
2761  }
2762  return true;
2763  });
2764  return ret;
2765  }
2766 
2768  template <class Op>
2769  auto search_in_arc(Node * p, Op && op = Op()) const noexcept(noexcept(op))
2770  {
2771  return search_in_arc(p, op);
2772  }
2773 
2782  template <typename T>
2783  auto in_arcs_map(Node * p, std::function<T(Arc*)> op)
2784  const noexcept(noexcept(op))
2785  {
2786  DynList<T> ret;
2787  for_each_in_arc(p, [&ret, &op] (auto a) { ret.append(op(a)); });
2788  return ret;
2789  }
2790 
2798  template <typename T = Arc_Type>
2799  T foldl_in_arcs(Node * p, const T & init,
2800  std::function<T(const T&, Arc*)> op)
2801  const noexcept(noexcept(op))
2802  {
2803  T ret = init;
2804  for_each_in_arc(p, [&ret, &op] (auto a) { ret = op(ret, a); });
2805  return ret;
2806  }
2807 
2815  template <class Op>
2816  DynList<Arc*> filter_in_arcs(Node * p, Op & op) const
2817  {
2818  DynList<Arc*> ret;
2819  for_each_in_arc(p, [&ret, &op] (auto a)
2820  {
2821  if (op(a))
2822  ret.append(a);
2823  });
2824  return ret;
2825  }
2826 
2828  template <class Op>
2829  auto filter_in_arcs(Node * p, Op && op = Op()) const
2830  {
2831  return filter_in_arcs(p, op);
2832  }
2833 
2836  template <class Op>
2837  bool traverse_out_arcs(Node * p, Op & op) const noexcept(noexcept(op))
2838  {
2839  return traverse_arcs(p, op);
2840  }
2841 
2843  template <class Op>
2844  bool traverse_out_arcs(Node * p, Op && op = Op())
2845  const noexcept(noexcept(op))
2846  {
2847  return traverse_out_arcs(p, op);
2848  }
2849 
2851  template <class Op>
2852  void for_each_out_arc(Node * p, Op & op) const noexcept(noexcept(op))
2853  {
2854  for_each_arc(p, op);
2855  }
2856 
2858  template <class Op>
2859  void for_each_out_arc(Node * p, Op && op = Op()) const noexcept(noexcept(op))
2860  {
2861  for_each_out_arc(p, op);
2862  }
2863 
2865  template <class Op>
2866  bool all_out_arcs(Node * p, Op & op) const noexcept(noexcept(op))
2867  {
2868  return traverse_out_arcs(p, [&op] (auto a) { return op(a); });
2869  }
2870 
2872  template <class Op>
2873  bool all_out_arcs(Node * p, Op && op = Op()) const noexcept(noexcept(op))
2874  {
2875  return all_out_arc(p, op);
2876  }
2877 
2880  template <class Op>
2881  bool exists_out_arc(Node * p, Op & op) const noexcept(noexcept(op))
2882  {
2883  return not traverse_out_arcs(p, [&op] (auto a) { return not op(a); });
2884  }
2885 
2887  template <class Op>
2888  bool exists_out_arc(Node * p, Op && op = Op()) const noexcept(noexcept(op))
2889  {
2890  return exists_out_arc(p, op);
2891  }
2892  template <class Op>
2906  auto search_out_arc(Node * p, Op & op) const noexcept(noexcept(op))
2907  {
2908  typename GT::Arc * ret = nullptr;
2909  traverse_out_arcs(p, [&op, &ret] (auto a)
2910  {
2911  if (op(a))
2912  {
2913  ret = a;
2914  return false;
2915  }
2916  return true;
2917  });
2918  return ret;
2919  }
2920 
2922  template <class Op>
2923  auto search_out_arc(Node * p, Op && op = Op()) const noexcept(noexcept(op))
2924  {
2925  return search_out_arc(p, op);
2926  }
2927 
2936  template <typename T = Arc_Type>
2937  auto out_arcs_map(Node * p, std::function<T(Arc*)> op) const
2938  {
2939  DynList<T> ret;
2940  for_each_out_arc(p, [&ret, &op] (auto a) { ret.append(op(a)); });
2941  return ret;
2942  }
2943 
2945  template <typename T = Arc_Type>
2946  T foldl_out_arcs(Node * p, const T & init,
2947  std::function<T(const T&, Arc*)> op)
2948  const noexcept(noexcept(op))
2949  {
2950  T ret = init;
2951  for_each_out_arc(p, [&ret, &op] (auto a) { ret = op(ret, a); });
2952  return ret;
2953  }
2954 
2962  template <class Op>
2963  DynList<Arc*> filter_out_arcs(Node * p, Op & op) const noexcept(noexcept(op))
2964  {
2965  DynList<Arc*> ret;
2966  for_each_out_arc(p, [&ret, &op] (auto a)
2967  {
2968  if (op(a))
2969  ret.append(a);
2970  });
2971  return ret;
2972  }
2973 
2975  template <class Op>
2976  auto filter_out_arcs(Node * p, Op && op = Op()) const noexcept(noexcept(op))
2977  {
2978  return filter_out_arcs(p, op);
2979  }
2980 };
2981 
2982 
2983 
2984 # endif // GRAPH_DRY_H
Arc * search_arc(Op &&op) const noexcept(noexcept(op))
Definition: graph-dry.H:1990
auto arcs_map(Node *p, std::function< T(Arc *)> operation) const
Definition: graph-dry.H:1551
Node * get_tgt_node_ne() const noexcept
Return the target node of current arc (if it is a directed graph)
Definition: graph-dry.H:123
Bit_Fields & get_control_bits(Node *node) const noexcept
Return a reference to control fields of node
Definition: graph-dry.H:511
bool all_in_arcs(Node *p, Op &op) const noexcept(noexcept(op))
Return true if op is true for all the incoming arcs to node p
Definition: graph-dry.H:2711
DynList< Arc * > out_arcs(Node *p) const
Definition: graph-dry.H:2528
void for_each_in_arc(typename GT::Node *p, Op op=Op()) noexcept(noexcept(op))
Definition: tpl_graph.H:2077
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
Definition: graph-dry.H:242
size_t out_degree(Node *p) const noexcept
Definition: graph-dry.H:2637
auto filter_arcs(Op &&op) const
Definition: graph-dry.H:1759
void reset_node(Node *p) const noexcept
Definition: graph-dry.H:597
void for_each_arc(Node *p, Operation &op) const noexcept(noexcept(op))
Perform operation on each arc of node p
Definition: graph-dry.H:2674
auto out_pairs(Node *p) const
Definition: graph-dry.H:2590
Node * get_src_node_ne() const noexcept
Return the sourcenode of current arc (if it is a directed graph)
Definition: graph-dry.H:117
size_t get_num_arcs(Node *node) const noexcept
Definition: graph-dry.H:498
auto in_arcs_map(Node *p, std::function< T(Arc *)> op) const noexcept(noexcept(op))
Definition: graph-dry.H:2783
Arc * insert_arc(Node *src, Node *tgt, Arc_Type &&arc_info=Arc_Type())
Definition: graph-dry.H:929
bool traverse_out_arcs(Node *p, Op &&op=Op()) const noexcept(noexcept(op))
Definition: graph-dry.H:2844
#define ARC_COUNTER(p)
Definition: aleph-graph.H:339
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Definition: graph-dry.H:488
bool all_arcs(Node *p, Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1399
auto get_arc_it() const noexcept
Definition: graph-dry.H:2173
bool is_digraph() const noexcept
Return true if the graph this is directed.
Definition: graph-dry.H:373
void reset_cookie_arcs() const noexcept
Definition: graph-dry.H:798
void reset_node_counters() const noexcept
Reset all the node counters of graph to zero.
Definition: graph-dry.H:589
Array_Graph Set_Type
The type of container on which iterate.
Definition: graph-dry.H:92
#define NODE_COOKIE(p)
Definition: aleph-graph.H:333
void reset_counter(Arc *arc) const noexcept
Reset the acr counter to zero.
Definition: graph-dry.H:609
Out_Iterator get_out_it(Node *p) const noexcept
Definition: graph-dry.H:2463
Node * get_node() const
Definition: graph-dry.H:424
Node * get_node(Arc *a) const noexcept
Return the source node of arc a (whose target is tgt)
Definition: graph-dry.H:2304
long & get_counter(Node *node) const noexcept
Get a modifiable reference to the counter of node
Definition: graph-dry.H:577
size_t degree(Node *p) const noexcept
Definition: graph-dry.H:505
T foldl_in_arcs(Node *p, const T &init, std::function< T(const T &, Arc *)> op) const noexcept(noexcept(op))
Definition: graph-dry.H:2799
GTNodeIterator(Dlink &head) noexcept
Build a iterator for all the nodes of g.
Definition: graph-dry.H:55
Node * insert_node(Node_Type &&node_info=Node_Type())
Definition: graph-dry.H:846
Node * emplace_node(Args &&... args)
Definition: graph-dry.H:872
Arc * get_curr_ne() const noexcept
Return current arc without exception.
Definition: graph-dry.H:102
GTArcIterator(Dlink &head) noexcept
Build a iterator for all the arcs of g.
Definition: graph-dry.H:97
bool exists_node(Operation &&op=Operation()) const noexcept(noexcept(op))
Definition: graph-dry.H:1837
void reset_bits(Node *node) const noexcept
Reset all the control bits of node
Definition: graph-dry.H:523
auto get_arc_it(Node *p) const noexcept
Definition: graph-dry.H:2196
Container< Node * > nodes() const
Definition: graph-dry.H:2091
bool traverse_arcs(typename GT::Node *p, Operation op=Operation()) noexcept(noexcept(op))
Definition: tpl_graph.H:2017
void for_each_arc(Node *p, Operation &&op=Operation()) const noexcept(noexcept(op))
for_each_arc(Node * p, Operation & operation)
Definition: graph-dry.H:1276
void reset_arc_counters() const noexcept
Reset all the arc counters of graph to zero.
Definition: graph-dry.H:615
Arc * search_arc(Op &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1977
Node * search_node(Op &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1926
bool all_arcs(Operation &&op=Operation()) const noexcept(noexcept(op))
Definition: graph-dry.H:1361
void for_each_out_arc(Node *p, Op &op) const noexcept(noexcept(op))
Perform operation on each incoming arc of node p
Definition: graph-dry.H:2852
bool traverse_in_arcs(typename GT::Node *p, Op op=Op()) noexcept(noexcept(op))
Definition: tpl_graph.H:2064
bool all_out_arcs(Node *p, Op &op) const noexcept(noexcept(op))
Return true if op is true for all the outcoming arcs to node p
Definition: graph-dry.H:2866
bool exists_in_arc(Node *p, Op &op) const noexcept(noexcept(op))
Definition: graph-dry.H:2726
const ArcInfo & get_info() const noexcept
Return a constant reference to the arc data.
Definition: graph-dry.H:310
Node * get_tgt_node() const
Return the target node of current arc (if it is a directed graph)
Definition: graph-dry.H:135
auto get_node_it() const noexcept
Definition: graph-dry.H:2151
Node * get_node(Arc *a) const noexcept
Return the source node of arc a
Definition: graph-dry.H:2249
void reset_bit(Node *node, int bit) const noexcept
Reset the bit of node (to zero)
Definition: graph-dry.H:517
Graph_Attr attrs
Definition: graph-dry.H:214
bool all_arcs(Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1354
bool all_arcs(Node *p, Operation &&op=Operation()) const noexcept(noexcept(op))
Definition: graph-dry.H:1406
Node * get_current_node() const
Return the current node.
Definition: graph-dry.H:67
int get_bit(Arc *arc, int bit) const noexcept
Get the control bit of arc
Definition: graph-dry.H:553
int get_bit(Node *node, int bit) const noexcept
Get the control bit of node
Definition: graph-dry.H:526
Node * insert_node(const Node_Type &node_info)
Definition: graph-dry.H:822
Arc * get_current_arc_ne() const noexcept
Return the current arc without exception.
Definition: graph-dry.H:114
bool has_curr() const noexcept
Return true is the iterator has a current arc.
Definition: graph-dry.H:2371
auto filter_out_arcs(Node *p, Op &&op=Op()) const noexcept(noexcept(op))
Definition: graph-dry.H:2976
auto filter_in_arcs(Node *p, Op &&op=Op()) const
Definition: graph-dry.H:2829
GT::Node * get_node(typename GT::Arc *a) const noexcept
Definition: graph-dry.H:2386
void reset_arc(Arc *arc) const noexcept
Definition: graph-dry.H:623
T foldl_out_arcs(Node *p, const T &init, std::function< T(const T &, Arc *)> op) const noexcept(noexcept(op))
Definition: graph-dry.H:2946
auto filter_arcs(Node *p, Op &&op) const
Definition: graph-dry.H:1806
auto out_arcs_map(Node *p, std::function< T(Arc *)> op) const
Definition: graph-dry.H:2937
Node * get_src_node() const
Return the sourcenode of current arc (if it is a directed graph)
Definition: graph-dry.H:129
bool traverse_arcs(Operation &&op=Operation()) const noexcept(noexcept(op))
Definition: graph-dry.H:1085
Node * search_node(Op &&op) const noexcept(noexcept(op))
Definition: graph-dry.H:1939
Node * get_arc() const
Definition: graph-dry.H:434
void set_digraph(bool val)
Definition: graph-dry.H:408
#define ARC_COOKIE(p)
Definition: aleph-graph.H:366
Definition: graph-dry.H:83
#define NODE_COUNTER(p)
Definition: aleph-graph.H:311
void reset_bits(Arc *arc) const noexcept
Reset all the control bits of arc
Definition: graph-dry.H:550
void * get_cookie() const noexcept
Return a constant reference to graph&#39;s cookie.
Definition: graph-dry.H:370
bool all_nodes(Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1312
void reset_bit_arcs() const noexcept
Reset all the bits for all the arcs of graph.
Definition: graph-dry.H:764
auto arcs_map(std::function< T(Arc *)> operation) const
Definition: graph-dry.H:1500
void for_each_arc(const GT &g, std::function< void(typename GT::Arc *)> operation, SA sa=SA()) noexcept(noexcept(operation) and noexcept(sa))
Definition: tpl_graph.H:1325
In_Filt(Node *__tgt=nullptr) noexcept
target node of iteration
Definition: graph-dry.H:2238
void reset_bit(Arc *arc, int bit) const noexcept
Reset the bit of arc to zero.
Definition: graph-dry.H:544
auto search_in_arc(Node *p, Op &op) const noexcept(noexcept(op))
Definition: graph-dry.H:2752
Definition: graph-dry.H:272
Digraph_Iterator< Out_Filt > Out_Iterator
Definition: graph-dry.H:2423
Definition: graph-dry.H:2337
Node * get_curr() const
Return the current node.
Definition: graph-dry.H:64
void for_each_out_arc(Node *p, Op &&op=Op()) const noexcept(noexcept(op))
Definition: graph-dry.H:2859
T foldl_arcs(Node *p, const T &init, std::function< T(const T &, Arc *)> op) const
Definition: graph-dry.H:1680
void for_each_arc(Node *p, Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1268
Definition: graph-dry.H:329
Definition: graph-dry.H:2233
Arc * search_directed_arc(Node *src, Node *tgt) const noexcept
Definition: graph-dry.H:2475
GT::Node * get_node_ne() const noexcept
Definition: graph-dry.H:2393
bool exists_node(Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1830
Node * Item_Type
The type of item that returns the iterator.
Definition: graph-dry.H:47
Definition: graph-dry.H:42
Node * get_curr_ne() const noexcept
Return the current node without exception.
Definition: graph-dry.H:58
bool all_in_arcs(Node *p, Op &&op=Op()) const noexcept(noexcept(op))
Definition: graph-dry.H:2718
Recorre condicionalmente el contenedor y ejecuta una operation mientras ésta retorne true...
void *& get_cookie(Node *node) const noexcept
Get a modifiable reference to the cookie pointer of node
Definition: graph-dry.H:565
auto filter_arcs(Op &op) const
Definition: graph-dry.H:1747
auto in_pairs(Node *p) const
Definition: graph-dry.H:2567
bool traverse_arcs(Node *p, Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1142
void next()
Definition: graph-dry.H:2362
DynList< Arc * > filter_in_arcs(Node *p, Op &op) const
Definition: graph-dry.H:2816
void for_each_node(const GT &g, std::function< void(typename GT::Node *)> operation, SN sn=SN()) noexcept(noexcept(operation) and noexcept(sn))
Definition: tpl_graph.H:1306
bool traverse_arcs(Node *p, Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:2664
Definition: graph-dry.H:206
Arc * search_arc(Node *p, Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:2030
Arc * Item_Type
The type of item that returns the iterator.
Definition: graph-dry.H:89
DynList< Node * > out_nodes(Node *p) const
Definition: graph-dry.H:2511
auto filter_nodes(Op &op) const
Definition: graph-dry.H:1709
static void map_arcs(A1 *p, A2 *q) noexcept
Definition: graph-dry.H:732
Bit_Fields & get_control_bits(Arc *arc) const noexcept
Return a reference to the control bits of arc
Definition: graph-dry.H:538
Node_Info Node_Type
The node.
Definition: graph-dry.H:233
void for_each_node(Operation &operation) const noexcept(noexcept(operation))
Definition: graph-dry.H:1183
Arc * get_current_arc() const
Return the current arc.
Definition: graph-dry.H:111
unsigned int state() const noexcept
Return the state of arc.
Definition: graph-dry.H:301
List_Graph Set_Type
The type of container on which iterate.
Definition: graph-dry.H:50
void reset_last() noexcept
Reset the iterator to last arc.
Definition: graph-dry.H:2413
Graph_Attr attrs
Please don&#39;t use.
Definition: graph-dry.H:286
auto nodes_map(std::function< T(Node *)> op) const
Definition: graph-dry.H:1453
DynList< Arc * > filter_out_arcs(Node *p, Op &op) const noexcept(noexcept(op))
Definition: graph-dry.H:2963
Container< Arc * > arcs() const
Definition: graph-dry.H:2109
tuple< __Graph_Arc *, __Graph_Node *> ArcPair
Pair of arc and node (topologically related)
Definition: graph-dry.H:2553
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Definition: graph-dry.H:447
Node * get_arc(Node *p)
Definition: graph-dry.H:444
void for_each_node(Operation &&operation=Operation()) const
Definition: graph-dry.H:1191
unsigned int state() const noexcept
Return the state&#39;s value.
Definition: graph-dry.H:248
void reset_first() noexcept
Reset the iterator to first arc.
Definition: graph-dry.H:2410
auto get_tgt_node() const
Definition: graph-dry.H:2407
void for_each_arc(Operation &&operation=Operation()) const
Definition: graph-dry.H:1229
GT::Arc * search_arc(const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept
Definition: tpl_graph.H:2381
size_t vsize() const noexcept
get_num_nodes()
Definition: graph-dry.H:414
void reset_counter_arcs() const noexcept
Reset all the counters to zero for all the arcs of graph.
Definition: graph-dry.H:776
#define NODE_BITS(p)
Definition: aleph-graph.H:305
Digraph_Iterator< Filt > Filter_Iterator
Definition: graph-dry.H:2417
bool exists_arc(Node *p, Operation &&op=Operation()) const noexcept(noexcept(op))
Definition: graph-dry.H:1903
void prev()
Definition: graph-dry.H:2366
bool traverse_arcs(Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1075
void for_each_in_arc(Node *p, Op &op) const noexcept(noexcept(op))
Perform operation on each incoming arc of node p
Definition: graph-dry.H:2697
Arc * search_arc(Node *p, Operation &&op=Operation()) const noexcept(noexcept(op))
Definition: graph-dry.H:2043
bool exists_out_arc(Node *p, Op &op) const noexcept(noexcept(op))
Definition: graph-dry.H:2881
bool all_out_arcs(Node *p, Op &&op=Op()) const noexcept(noexcept(op))
Definition: graph-dry.H:2873
bool exists_arc(Node *p, Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1896
bool traverse_in_arcs(Node *p, Op &&op=Op()) const noexcept(noexcept(op))
Definition: graph-dry.H:2690
GTArcCommon(const ArcInfo &info)
data contained in arc
Definition: graph-dry.H:290
void set_state(unsigned int s) noexcept
Set the state to value s
Definition: graph-dry.H:251
void reset_bit_nodes() const noexcept
Reset all the bits for all the nodes of graph.
Definition: graph-dry.H:758
bool all_nodes(Operation &&op=Operation()) const noexcept(noexcept(op))
Definition: graph-dry.H:1319
void *& get_cookie(Arc *arc) const noexcept
Get a modifiable reference to the cookie pointer of arc
Definition: graph-dry.H:571
bool exists_out_arc(Node *p, Op &&op=Op()) const noexcept(noexcept(op))
Definition: graph-dry.H:2888
void for_each_arc(Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1221
size_t get_num_arcs() const noexcept
Definition: graph-dry.H:494
bool traverse_arcs(Node *p, Operation &&op=Operation()) const noexcept(noexcept(op))
Definition: graph-dry.H:1152
Arc * find_arc(const Arc_Type &info) const noexcept
Definition: graph-dry.H:2006
DynList< Arc * > in_arcs(Node *p) const
Definition: graph-dry.H:2544
void reset_cookie_nodes() const noexcept
Definition: graph-dry.H:787
Arc * emplace_arc(Node *src, Node *tgt, Args &&... args)
Definition: graph-dry.H:958
static void map_nodes(N1 *p, N2 *q) noexcept
Definition: graph-dry.H:704
bool exists_arc(Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1861
GTNodeCommon() noexcept
another alias for set type
Definition: graph-dry.H:235
void reset_nodes() const
Definition: graph-dry.H:630
#define ARC_BITS(p)
Definition: aleph-graph.H:351
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Definition: graph-dry.H:453
GT::Arc * get_curr() const
Definition: graph-dry.H:2375
void set_state(unsigned int s) noexcept
Set the state of arc to value s
Definition: graph-dry.H:304
auto get_tgt_node_ne() const noexcept
Definition: graph-dry.H:2399
void *& get_cookie() noexcept
Return a modifiable reference to graph&#39;s cookie.
Definition: graph-dry.H:367
auto search_out_arc(Node *p, Op &&op=Op()) const noexcept(noexcept(op))
Definition: graph-dry.H:2923
long & get_counter(Arc *arc) const noexcept
Get a modifiable reference to the counter of arc
Definition: graph-dry.H:603
void reset_arcs() const
Definition: graph-dry.H:637
bool traverse_nodes(Operation &&op=Operation()) const noexcept(noexcept(op))
Definition: graph-dry.H:1020
size_t in_degree(Node *p) const noexcept
Definition: graph-dry.H:2614
void for_each_out_arc(typename GT::Node *p, Op op=Op()) noexcept(noexcept(op))
Definition: tpl_graph.H:2234
Definition: ahDry.H:41
Out_Filt(Node *__src) noexcept
source node of iteration
Definition: graph-dry.H:2293
Digraph_Iterator(Node *p) noexcept(noexcept(Filter(p)) and noexcept(Itor(p, filt)))
Instantiate an filtered iterator for arcs on the node p
Definition: graph-dry.H:2351
void set_bit(Node *node, int bit, int value) const noexcept
Set the control bit of node to value
Definition: graph-dry.H:532
void reset_bit_arcs(int bit) const noexcept
Reset bit to zero for all the arcs of graph.
Definition: graph-dry.H:752
Arc * insert_arc(Node *src, Node *tgt, const Arc_Type &arc_info)
Definition: graph-dry.H:899
In_Iterator get_in_it(Node *p) const noexcept
Definition: graph-dry.H:2443
const NodeInfo & get_info() const noexcept
Return a constant reference to the data contained in the node.
Definition: graph-dry.H:245
auto search_out_arc(Node *p, Op &op) const noexcept(noexcept(op))
Definition: graph-dry.H:2906
bool exists_arc(Operation &&op=Operation()) const noexcept(noexcept(op))
Definition: graph-dry.H:1868
Node * find_node(const Node_Type &info) const noexcept
Definition: graph-dry.H:1955
void reset_counter_nodes() const noexcept
Reset all the counters to zero for all the nodes of graph.
Definition: graph-dry.H:770
auto filter_nodes(Op &&op) const
Definition: graph-dry.H:1721
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
Definition: graph-dry.H:307
size_t esize() const noexcept
Return the total of arcs of graph.
Definition: graph-dry.H:508
Definition: graph-dry.H:2288
bool exists_in_arc(Node *p, Op &&op=Op()) const noexcept(noexcept(op))
Definition: graph-dry.H:2733
auto search_in_arc(Node *p, Op &&op=Op()) const noexcept(noexcept(op))
Definition: graph-dry.H:2769
bool traverse_nodes(Operation &op) const noexcept(noexcept(op))
Definition: graph-dry.H:1010
bool traverse_out_arcs(typename GT::Node *p, Op op=Op()) noexcept(noexcept(op))
Definition: tpl_graph.H:2221
T foldl_nodes(const T &init, std::function< T(const T &, Node *)> op) const
Definition: graph-dry.H:1596
size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Definition: graph-dry.H:411
auto get_current_arc() const
Definition: graph-dry.H:2380
void set_bit(Arc *arc, int bit, int value) const noexcept
Set the control bit of arc to value
Definition: graph-dry.H:559
void reset_bit_nodes(int bit) const noexcept
Reset bit to zero for all the nodes of graph.
Definition: graph-dry.H:746
Digraph_Iterator< In_Filt > In_Iterator
Definition: graph-dry.H:2420
bool traverse_out_arcs(Node *p, Op &op) const noexcept(noexcept(op))
Definition: graph-dry.H:2837
Container< Arc * > arcs(Node *p) const
Definition: graph-dry.H:2127
Arc * search_arc(Node *src, Node *tgt) const noexcept
Definition: graph-dry.H:2072
DynList< Node * > in_nodes(Node *p) const
Definition: graph-dry.H:2493
Arc * get_curr() const
Return current arc.
Definition: graph-dry.H:108
void reset_counter(Node *node) const noexcept
Reset the node counter to zero.
Definition: graph-dry.H:583
T foldl_arcs(const T &init, std::function< T(const T &, Arc *)> op) const
Definition: graph-dry.H:1637
auto filter_arcs(Node *p, Op &op) const
Definition: graph-dry.H:1794
bool traverse_in_arcs(Node *p, Op &op) const noexcept(noexcept(op))
Definition: graph-dry.H:2683

Leandro Rabindranath León