Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_sgraph_test.cc
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
33
38#include <gtest/gtest.h>
39#include <tpl_sgraph.H>
40#include <string>
41#include <vector>
42
43using namespace Aleph;
44
45namespace
46{
47 // Type aliases for common graph types
51}
52
53// =============================================================================
54// Graph_Snode Tests
55// =============================================================================
56
63
65{
66 Graph_Snode<int> node(42);
67 EXPECT_EQ(node.get_info(), 42);
68 EXPECT_EQ(node.num_arcs, 0u);
70}
71
73{
76 EXPECT_EQ(node2.get_info(), 42);
77 EXPECT_EQ(node2.num_arcs, 0u);
78}
79
81{
82 Graph_Snode<std::string> node1(std::string("test"));
84 EXPECT_EQ(node2.get_info(), "test");
85}
86
94
96{
97 Graph_Snode<int> node(42);
98 node = node;
99 EXPECT_EQ(node.get_info(), 42);
100}
101
108
109// =============================================================================
110// Graph_Sarc Tests
111// =============================================================================
112
114{
115 Graph_Sarc<int> arc;
116 EXPECT_EQ(arc.get_info(), 0); // Default int value
117}
118
120{
121 Graph_Sarc<int> arc(100);
122 EXPECT_EQ(arc.get_info(), 100);
123}
124
126{
127 Graph_Sarc<std::string> arc1(std::string("edge"));
128 Graph_Sarc<std::string> arc2(arc1);
129 EXPECT_EQ(arc2.get_info(), "edge");
130}
131
133{
134 Graph_Sarc<int> arc1(42);
135 Graph_Sarc<int> arc2(100);
136 arc2 = arc1;
137 EXPECT_EQ(arc2.get_info(), 42);
138}
139
141{
142 Graph_Sarc<int> arc(42);
143 arc = arc;
144 EXPECT_EQ(arc.get_info(), 42);
145}
146
155
156// =============================================================================
157// List_SGraph Basic Operations
158// =============================================================================
159
161{
162 IntGraph g;
163 EXPECT_EQ(g.vsize(), 0u);
164 EXPECT_EQ(g.esize(), 0u);
166}
167
169{
170 IntGraph g;
171 auto n1 = g.insert_node(1);
172 auto n2 = g.insert_node(2);
173 auto n3 = g.insert_node(3);
174
175 EXPECT_EQ(g.vsize(), 3u);
176 EXPECT_EQ(n1->get_info(), 1);
177 EXPECT_EQ(n2->get_info(), 2);
178 EXPECT_EQ(n3->get_info(), 3);
179}
180
182{
183 IntGraph g;
184 auto n1 = g.insert_node(1);
185 auto n2 = g.insert_node(2);
186
187 auto arc = g.insert_arc(n1, n2, 10);
188
189 EXPECT_EQ(g.esize(), 1u);
190 EXPECT_EQ(arc->get_info(), 10);
191 EXPECT_EQ(g.get_src_node(arc), n1);
192 EXPECT_EQ(g.get_tgt_node(arc), n2);
193}
194
196{
197 IntGraph g;
198 auto n1 = g.insert_node(1);
199 auto n2 = g.insert_node(2);
200
201 g.insert_arc(n1, n2, 10);
202
203 // In undirected graph, arc appears in both nodes' adjacency lists
204 EXPECT_EQ(n1->num_arcs, 1u);
205 EXPECT_EQ(n2->num_arcs, 1u);
206}
207
209{
210 IntGraph g;
211 auto n1 = g.insert_node(1);
212 auto n2 = g.insert_node(2);
213 auto arc = g.insert_arc(n1, n2, 10);
214
215 EXPECT_EQ(g.esize(), 1u);
216 g.remove_arc(arc);
217 EXPECT_EQ(g.esize(), 0u);
218 EXPECT_EQ(n1->num_arcs, 0u);
219 EXPECT_EQ(n2->num_arcs, 0u);
220}
221
223{
224 IntGraph g;
225 auto n1 = g.insert_node(1);
226 auto n2 = g.insert_node(2);
227 auto n3 = g.insert_node(3);
228
229 g.insert_arc(n1, n2, 12);
230 g.insert_arc(n2, n3, 23);
231
232 EXPECT_EQ(g.vsize(), 3u);
233 EXPECT_EQ(g.esize(), 2u);
234
235 g.remove_node(n2);
236
237 EXPECT_EQ(g.vsize(), 2u);
238 EXPECT_EQ(g.esize(), 0u); // All arcs connected to n2 removed
239}
240
242{
243 IntGraph g;
244 auto n1 = g.insert_node(1);
245 auto n2 = g.insert_node(2);
246 auto n3 = g.insert_node(3);
247 auto n4 = g.insert_node(4);
248
249 g.insert_arc(n1, n2, 12);
250 g.insert_arc(n1, n3, 13);
251 g.insert_arc(n1, n4, 14);
252 g.insert_arc(n2, n3, 23);
253 g.insert_arc(n3, n4, 34);
254
255 EXPECT_EQ(g.esize(), 5u);
256 EXPECT_EQ(n1->num_arcs, 3u); // n1 connected to n2, n3, n4
257}
258
259// =============================================================================
260// List_SDigraph Tests
261// =============================================================================
262
264{
265 IntDigraph g;
266 EXPECT_TRUE(g.is_digraph());
267}
268
270{
271 IntDigraph g;
272 auto n1 = g.insert_node(1);
273 auto n2 = g.insert_node(2);
274
275 g.insert_arc(n1, n2, 10);
276
277 // In directed graph, arc only appears in source node's adjacency list
278 EXPECT_EQ(n1->num_arcs, 1u);
279 EXPECT_EQ(n2->num_arcs, 0u);
280}
281
283{
284 IntDigraph g;
285 auto n1 = g.insert_node(1);
286 auto n2 = g.insert_node(2);
287
288 g.insert_arc(n1, n2, 12);
289 g.insert_arc(n2, n1, 21);
290
291 EXPECT_EQ(g.esize(), 2u);
292 EXPECT_EQ(n1->num_arcs, 1u);
293 EXPECT_EQ(n2->num_arcs, 1u);
294}
295
296// =============================================================================
297// Iterator Tests
298// =============================================================================
299
301{
302 IntGraph g;
303 g.insert_node(1);
304 g.insert_node(2);
305 g.insert_node(3);
306
307 int count = 0;
308 int sum = 0;
309 for (IntGraph::Node_Iterator it(g); it.has_curr(); it.next())
310 {
311 sum += it.get_curr()->get_info();
312 ++count;
313 }
314
315 EXPECT_EQ(count, 3);
316 EXPECT_EQ(sum, 6); // 1 + 2 + 3
317}
318
320{
321 IntGraph g;
322 auto n1 = g.insert_node(1);
323 auto n2 = g.insert_node(2);
324 auto n3 = g.insert_node(3);
325
326 g.insert_arc(n1, n2, 10);
327 g.insert_arc(n2, n3, 20);
328
329 int count = 0;
330 int sum = 0;
331 for (IntGraph::Arc_Iterator it(g); it.has_curr(); it.next())
332 {
333 sum += it.get_curr()->get_info();
334 ++count;
335 }
336
337 EXPECT_EQ(count, 2);
338 EXPECT_EQ(sum, 30); // 10 + 20
339}
340
342{
343 IntGraph g;
344 auto n1 = g.insert_node(1);
345 auto n2 = g.insert_node(2);
346 auto n3 = g.insert_node(3);
347 auto n4 = g.insert_node(4);
348
349 g.insert_arc(n1, n2, 12);
350 g.insert_arc(n1, n3, 13);
351 g.insert_arc(n1, n4, 14);
352
353 int count = 0;
354 int sum = 0;
355 for (IntGraph::Node_Arc_Iterator it(n1); it.has_curr(); it.next())
356 {
357 sum += it.get_curr()->get_info();
358 ++count;
359 }
360
361 EXPECT_EQ(count, 3);
362 EXPECT_EQ(sum, 39); // 12 + 13 + 14
363}
364
366{
367 IntGraph g;
368 auto n1 = g.insert_node(1);
369 auto n2 = g.insert_node(2);
370 auto n3 = g.insert_node(3);
371
372 g.insert_arc(n1, n2, 12);
373 g.insert_arc(n1, n3, 13);
374
375 std::vector<int> targets;
376 for (IntGraph::Node_Arc_Iterator it(n1); it.has_curr(); it.next())
377 {
378 targets.push_back(it.get_tgt_node()->get_info());
379 }
380
381 EXPECT_EQ(targets.size(), 2u);
382 // Order may vary, just check both are present
383 EXPECT_TRUE(std::find(targets.begin(), targets.end(), 2) != targets.end());
384 EXPECT_TRUE(std::find(targets.begin(), targets.end(), 3) != targets.end());
385}
386
388{
389 IntDigraph g;
390 auto n1 = g.insert_node(1);
391 auto n2 = g.insert_node(2);
392
393 g.insert_arc(n1, n2, 12);
394
395 IntDigraph::Arc_Iterator it(g);
396 EXPECT_TRUE(it.has_curr());
397 EXPECT_EQ(it.get_src_node()->get_info(), 1);
398 EXPECT_EQ(it.get_tgt_node()->get_info(), 2);
399}
400
401// =============================================================================
402// Copy and Move Semantics
403// =============================================================================
404
406{
407 IntGraph g1;
408 auto n1 = g1.insert_node(1);
409 auto n2 = g1.insert_node(2);
410 g1.insert_arc(n1, n2, 10);
411
412 IntGraph g2(g1);
413
414 EXPECT_EQ(g2.vsize(), 2u);
415 EXPECT_EQ(g2.esize(), 1u);
416}
417
419{
420 IntGraph g1;
421 g1.insert_node(1);
422 g1.insert_node(2);
423
424 IntGraph g2(std::move(g1));
425
426 EXPECT_EQ(g2.vsize(), 2u);
427 EXPECT_EQ(g1.vsize(), 0u); // Moved-from state
428}
429
431{
432 IntGraph g1;
433 auto n1 = g1.insert_node(1);
434 auto n2 = g1.insert_node(2);
435 g1.insert_arc(n1, n2, 10);
436
437 IntGraph g2;
438 g2 = g1;
439
440 EXPECT_EQ(g2.vsize(), 2u);
441 EXPECT_EQ(g2.esize(), 1u);
442}
443
445{
446 IntGraph g;
447 g.insert_node(1);
448 g.insert_node(2);
449
450 g = g;
451
452 EXPECT_EQ(g.vsize(), 2u);
453}
454
456{
457 IntGraph g1;
458 g1.insert_node(1);
459 g1.insert_node(2);
460
461 IntGraph g2;
462 g2 = std::move(g1);
463
464 EXPECT_EQ(g2.vsize(), 2u);
465 EXPECT_EQ(g1.vsize(), 0u);
466}
467
469{
471 auto n1 = g1.insert_node(1);
472 auto n2 = g1.insert_node(2);
473 g1.insert_arc(n1, n2, 10);
474
476
477 EXPECT_EQ(g2.vsize(), 2u);
478 EXPECT_EQ(g2.esize(), 1u);
479 EXPECT_TRUE(g2.is_digraph());
480}
481
483{
485 g1.insert_node(1);
486 g1.insert_node(2);
487
488 IntDigraph g2(std::move(g1));
489
490 EXPECT_EQ(g2.vsize(), 2u);
491 EXPECT_TRUE(g2.is_digraph());
492}
493
495{
497 auto n1 = g1.insert_node(1);
498 auto n2 = g1.insert_node(2);
499 g1.insert_arc(n1, n2, 10);
500
502 g2 = g1;
503
504 EXPECT_EQ(g2.vsize(), 2u);
505 EXPECT_EQ(g2.esize(), 1u);
506 EXPECT_TRUE(g2.is_digraph());
507}
508
510{
512 g1.insert_node(1);
513 g1.insert_node(2);
514
516 g2 = std::move(g1);
517
518 EXPECT_EQ(g2.vsize(), 2u);
519 EXPECT_TRUE(g2.is_digraph());
520}
521
522// =============================================================================
523// Stress Tests
524// =============================================================================
525
527{
528 IntGraph g;
529 constexpr int N = 100;
530
531 // Insert N nodes
532 std::vector<IntGraph::Node*> nodes;
533 for (int i = 0; i < N; ++i)
534 nodes.push_back(g.insert_node(i));
535
536 EXPECT_EQ(g.vsize(), static_cast<size_t>(N));
537
538 // Create a complete graph (N*(N-1)/2 edges)
539 for (int i = 0; i < N; ++i)
540 for (int j = i + 1; j < N; ++j)
541 g.insert_arc(nodes[i], nodes[j], i * N + j);
542
543 EXPECT_EQ(g.esize(), static_cast<size_t>(N * (N - 1) / 2));
544}
545
547{
548 IntDigraph g;
549 constexpr int N = 50;
550
551 std::vector<IntDigraph::Node*> nodes;
552 for (int i = 0; i < N; ++i)
553 nodes.push_back(g.insert_node(i));
554
555 // Create complete digraph (N*(N-1) edges)
556 for (int i = 0; i < N; ++i)
557 for (int j = 0; j < N; ++j)
558 if (i != j)
559 g.insert_arc(nodes[i], nodes[j], i * N + j);
560
561 EXPECT_EQ(g.esize(), static_cast<size_t>(N * (N - 1)));
562}
563
564// =============================================================================
565// Edge Cases
566// =============================================================================
567
569{
570 IntGraph g;
571 auto n1 = g.insert_node(1);
572
573 auto arc = g.insert_arc(n1, n1, 11);
574
575 EXPECT_EQ(g.esize(), 1u);
576 EXPECT_EQ(n1->num_arcs, 1u); // Self-loop counted once in undirected
577 EXPECT_EQ(g.get_src_node(arc), n1);
578 EXPECT_EQ(g.get_tgt_node(arc), n1);
579}
580
582{
583 IntDigraph g;
584 auto n1 = g.insert_node(1);
585
586 auto arc = g.insert_arc(n1, n1, 11);
587
588 EXPECT_EQ(g.esize(), 1u);
589 EXPECT_EQ(n1->num_arcs, 1u);
590 EXPECT_EQ(g.get_src_node(arc), n1);
591 EXPECT_EQ(g.get_tgt_node(arc), n1);
592}
593
595{
596 IntGraph g;
597
598 int node_count = 0;
599 for (IntGraph::Node_Iterator it(g); it.has_curr(); it.next())
600 ++node_count;
601 EXPECT_EQ(node_count, 0);
602
603 int arc_count = 0;
604 for (IntGraph::Arc_Iterator it(g); it.has_curr(); it.next())
605 ++arc_count;
607}
608
610{
611 IntGraph g;
612 auto n1 = g.insert_node(1);
613 auto n2 = g.insert_node(2);
614 auto arc = g.insert_arc(n1, n2, 10);
615
616 EXPECT_NE(g.get_first_node(), nullptr);
617 EXPECT_NE(g.get_first_arc(), nullptr);
618 EXPECT_EQ(g.get_first_arc(n1), arc);
619}
620
622{
623 IntGraph g;
624 auto n1 = g.insert_node(1);
625
626 EXPECT_THROW(g.get_first_arc(n1), std::range_error);
627}
628
630{
631 IntGraph g;
632 auto n1 = g.insert_node(1);
633 auto n2 = g.insert_node(2);
634 g.insert_arc(n1, n2, 10);
635
636 g.remove_node(n1);
637 g.remove_node(n2);
638
639 EXPECT_EQ(g.vsize(), 0u);
640 EXPECT_EQ(g.esize(), 0u);
641}
642
644{
645 IntGraph g1;
646 g1.insert_node(1);
647 g1.insert_node(2);
648
649 IntGraph g2;
650 g2.insert_node(10);
651
652 g1.swap(g2);
653
654 EXPECT_EQ(g1.vsize(), 1u);
655 EXPECT_EQ(g2.vsize(), 2u);
656}
657
658// =============================================================================
659// String Data Type Tests
660// =============================================================================
661
663{
664 StringGraph g;
665 auto n1 = g.insert_node(std::string("node1"));
666 auto n2 = g.insert_node(std::string("node2"));
667
668 g.insert_arc(n1, n2, std::string("edge"));
669
670 EXPECT_EQ(n1->get_info(), "node1");
671 EXPECT_EQ(n2->get_info(), "node2");
672}
673
674// =============================================================================
675// Iterator Method Tests
676// =============================================================================
677
679{
680 IntGraph g;
681 g.insert_node(42);
682
683 IntGraph::Node_Iterator it(g);
684 EXPECT_TRUE(it.has_curr());
685 EXPECT_EQ(it.get_current_node()->get_info(), 42);
686 EXPECT_EQ(it.get_current_node_ne()->get_info(), 42);
687}
688
690{
691 IntGraph g;
692 auto n1 = g.insert_node(1);
693 auto n2 = g.insert_node(2);
694 g.insert_arc(n1, n2, 100);
695
696 IntGraph::Node_Arc_Iterator it(n1);
697 EXPECT_TRUE(it.has_curr());
698 EXPECT_EQ(it.get_current_arc()->get_info(), 100);
699 EXPECT_EQ(it.get_current_arc_ne()->get_info(), 100);
700}
701
703{
704 IntGraph g;
705 auto n1 = g.insert_node(1);
706 auto n2 = g.insert_node(2);
707 g.insert_arc(n1, n2, 100);
708
709 IntGraph::Arc_Iterator it(g);
710 EXPECT_TRUE(it.has_curr());
711 EXPECT_EQ(it.get_current_arc()->get_info(), 100);
712 EXPECT_EQ(it.get_current_arc_ne()->get_info(), 100);
713}
714
715// =============================================================================
716// Multiple Operations Test
717// =============================================================================
718
720{
721 IntGraph g;
722
723 // Build a graph
724 auto n1 = g.insert_node(1);
725 auto n2 = g.insert_node(2);
726 auto n3 = g.insert_node(3);
727 auto n4 = g.insert_node(4);
728
729 auto a12 = g.insert_arc(n1, n2, 12);
730 g.insert_arc(n2, n3, 23);
731 g.insert_arc(n3, n4, 34);
732 g.insert_arc(n4, n1, 41);
733
734 EXPECT_EQ(g.vsize(), 4u);
735 EXPECT_EQ(g.esize(), 4u);
736
737 // Remove one arc
738 g.remove_arc(a12);
739 EXPECT_EQ(g.esize(), 3u);
740
741 // Remove one node (should remove 2 arcs: 41 and 34)
742 g.remove_node(n4);
743 EXPECT_EQ(g.vsize(), 3u);
744 EXPECT_EQ(g.esize(), 1u); // Only 23 remains
745
746 // Copy the graph
747 IntGraph g2(g);
748 EXPECT_EQ(g2.vsize(), 3u);
749 EXPECT_EQ(g2.esize(), 1u);
750}
751
752// =============================================================================
753// Digraph Template Wrapper Tests
754// =============================================================================
755
756// These tests validate the generic Digraph<BaseGraph> template wrapper
757// that was introduced to reduce code duplication across digraph implementations.
758
760{
761 // Verify that List_SDigraph is actually a Digraph<List_SGraph<...>>
762 IntDigraph dg;
763
764 // Should inherit all base graph functionality
765 auto n1 = dg.insert_node(1);
766 auto n2 = dg.insert_node(2);
767 auto arc = dg.insert_arc(n1, n2, 100);
768
769 EXPECT_EQ(dg.vsize(), 2u);
770 EXPECT_EQ(dg.esize(), 1u);
771 EXPECT_TRUE(dg.is_digraph());
772 EXPECT_EQ(dg.get_src_node(arc), n1);
773 EXPECT_EQ(dg.get_tgt_node(arc), n2);
774}
775
777{
779 dg1.insert_node(1);
780 dg1.insert_node(2);
781
782 // Copy construction should preserve digraph flag
784 EXPECT_TRUE(dg2.is_digraph());
785 EXPECT_EQ(dg2.vsize(), 2u);
786}
787
789{
791 dg1.insert_node(1);
792 dg1.insert_node(2);
793
794 // Move construction should preserve digraph flag
795 IntDigraph dg2(std::move(dg1));
796 EXPECT_TRUE(dg2.is_digraph());
797 EXPECT_EQ(dg2.vsize(), 2u);
798}
799
801{
803 dg1.insert_node(1);
804
806 dg2.insert_node(10);
807 dg2.insert_node(20);
808
809 dg2 = dg1;
810 EXPECT_TRUE(dg2.is_digraph());
811 EXPECT_EQ(dg2.vsize(), 1u);
812}
813
815{
817 dg1.insert_node(1);
818
820 dg2.insert_node(10);
821
822 dg2 = std::move(dg1);
823 EXPECT_TRUE(dg2.is_digraph());
824 EXPECT_EQ(dg2.vsize(), 1u);
825}
826
828{
829 IntDigraph dg;
830 auto n1 = dg.insert_node(1);
831 auto n2 = dg.insert_node(2);
832 dg.insert_arc(n1, n2, 100);
833
834 dg = dg; // Self-assignment should be safe
835
836 EXPECT_TRUE(dg.is_digraph());
837 EXPECT_EQ(dg.vsize(), 2u);
838 EXPECT_EQ(dg.esize(), 1u);
839}
840
842{
843 IntDigraph dg;
844 auto n1 = dg.insert_node(1);
845 auto n2 = dg.insert_node(2);
846 dg.insert_arc(n1, n2, 100); // n1 -> n2
847
848 // In a digraph, arc should only be visible from source node
849 EXPECT_EQ(n1->num_arcs, 1u); // Source has the arc
850 // Note: In digraph mode, target node doesn't have the arc in its adjacency list
851}
852
853// =============================================================================
854// C++20 Concepts Tests
855// =============================================================================
856
857// Compile-time verification that List_SGraph iterators satisfy concepts
859 "List_SGraph::Node_Iterator must satisfy BasicGraphIterator");
861 "List_SGraph::Arc_Iterator must satisfy BasicGraphIterator");
863 "List_SGraph::Node_Iterator must satisfy GraphNodeIterator");
865 "List_SGraph::Arc_Iterator must satisfy GraphArcIterator");
866
868{
869 IntGraph g;
870 auto n1 = g.insert_node(1);
871 auto n2 = g.insert_node(2);
872 g.insert_arc(n1, n2, 10);
873
874 // Verify node iterator works per concept
875 auto nit = g.get_node_it();
876 EXPECT_TRUE(nit.has_curr());
877 EXPECT_NE(nit.get_curr(), nullptr);
878
879 // Verify arc iterator works per concept
880 auto ait = g.get_arc_it();
881 EXPECT_TRUE(ait.has_curr());
882 EXPECT_NE(ait.get_curr(), nullptr);
883}
Generic directed graph (digraph) wrapper template.
Definition graph-dry.H:3848
DynList & swap(DynList &l) noexcept
Swap this with l.
Definition htlist.H:1448
Arc for graphs implemented with simple adjacency lists.
Definition tpl_sgraph.H:197
constexpr bool is_empty() const noexcept
Return true if list is empty.
Definition htlist.H:523
size_t size() const noexcept
Count the number of elements of the list.
Definition htlist.H:1319
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
virtual void remove_node(Node *node) noexcept
Remove a node from the graph and free its memory.
Definition tpl_graph.H:543
virtual void remove_arc(Arc *arc) noexcept
Remove an arc from the graph and free it.
Definition tpl_graph.H:649
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Definition tpl_graph.H:604
Graph class implemented with singly-linked adjacency lists.
Definition tpl_sgraph.H:274
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
Definition graph-dry.H:595
void * tgt_node
Please don't use.
Definition graph-dry.H:534
void * src_node
Definition graph-dry.H:533
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
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
Definition graph-dry.H:2802
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Definition graph-dry.H:731
bool is_digraph() const noexcept
Return true if the graph this is directed.
Definition graph-dry.H:657
constexpr size_t vsize() const noexcept
Definition graph-dry.H:698
size_t esize() const noexcept
Return the total of arcs of graph.
Definition graph-dry.H:792
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
Definition graph-dry.H:2780
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Definition graph-dry.H:737
iterator end() noexcept
Return an STL-compatible end iterator.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
Concept for basic graph iterators.
Definition graph-dry.H:152
Concept for graph arc iterators.
Definition graph-dry.H:210
Concept for graph node iterators.
Definition graph-dry.H:191
Concept for node adjacency iterators.
Definition graph-dry.H:234
#define TEST(name)
#define N
Definition fib.C:294
DynArray< Graph::Node * > nodes
Definition graphpic.C:406
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Node for graphs implemented with simple adjacency lists.
Definition tpl_sgraph.H:93
DynList< void * > arc_list
Adjacency list of arcs incident to this node.
Definition tpl_sgraph.H:97
Simple graph implementation with adjacency lists.