Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_matgraph.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
65#ifndef TPL_MAT_GRAPH_H
66#define TPL_MAT_GRAPH_H
67
68#include <tpl_graph.H>
69#include <tpl_sort_utils.H>
70#include <ah-errors.H>
71
72namespace Aleph
73{
74
75// =============================================================================
76// Internal Helper Functions
77// =============================================================================
78
79namespace matgraph_detail
80{
81
90template <typename GT>
91[[nodiscard]] inline typename GT::Node*
93{
94 ah_out_of_range_error_if(i < 0 or static_cast<size_t>(i) >= nodes.size())
95 << "Node index " << i << " out of range [0, " << nodes.size() << ")";
96 return nodes.access(i);
97}
98
107template <typename GT>
108[[nodiscard]] inline typename GT::Node*
110{
111 ah_out_of_range_error_if(i < 0 or static_cast<size_t>(i) >= nodes.size())
112 << "Node index " << i << " out of range [0, " << nodes.size() << ")";
113 return nodes.access(i);
114}
115
124template <typename GT>
125[[nodiscard]] inline long
127{
128 return Aleph::binary_search(nodes, p, 0, n - 1);
129}
130
139[[nodiscard]] inline long
140index_array(long i, long j, long n) noexcept
141{
142 return i + j * n;
143}
144
153[[nodiscard]] inline long
154checked_index_array(long i, long j, long n)
155{
157 << "Matrix index (" << i << ", " << j << ") out of range [0, " << n << ")";
158 return index_array(i, j, n);
159}
160
170template <typename Entry>
171[[nodiscard]] inline Entry*
172read_matrix(const DynArray<Entry>& mat, long i, long j, long n)
173{
174 const long index = checked_index_array(i, j, n);
175 if (not mat.exist(index))
176 return nullptr;
177 return &const_cast<Entry&>(mat.access(index));
178}
179
189template <typename Entry>
190inline void
191write_matrix(DynArray<Entry>& mat, long i, long j, long n, const Entry& entry)
192{
193 mat[checked_index_array(i, j, n)] = entry;
194}
195
196} // namespace matgraph_detail
197
198
199// =============================================================================
200// Map_Matrix_Graph - Mapped Adjacency Matrix
201// =============================================================================
202
247template <class GT, class SA = Dft_Show_Arc<GT>>
249{
250public:
252 using Graph_Type = GT;
253
255 using Node_Type = typename GT::Node_Type;
256
258 using Arc_Type = typename GT::Arc_Type;
259
261 using Node = typename GT::Node;
262
264 using Arc = typename GT::Arc;
265
266private:
268 {
269 Arc* arc = nullptr;
270 Mat_Entry() = default;
271 explicit Mat_Entry(Arc* a) : arc(a) {}
272 };
273
275 GT* lgraph = nullptr;
276 mutable size_t num_nodes = 0;
279
280public:
288 void copy_list_graph(GT& g);
289
298 {
300 }
301
309 : lgraph(&g), num_nodes(g.get_num_nodes()), sa(__sa)
310 {
312 }
313
320
323
326
334 {
335 return matgraph_detail::get_node<GT>(nodes, i);
336 }
337
344 [[nodiscard]] long operator()(Node* node) const
345 {
346 return matgraph_detail::node_index<GT>(nodes, num_nodes, node);
347 }
348
356 [[nodiscard]] Arc* operator()(Node* src_node, Node* tgt_node) const
357 {
358 Mat_Entry* entry = matgraph_detail::read_matrix<Mat_Entry>(
359 mat,
360 matgraph_detail::node_index<GT>(nodes, num_nodes, src_node),
361 matgraph_detail::node_index<GT>(nodes, num_nodes, tgt_node),
362 num_nodes);
363 return entry ? entry->arc : nullptr;
364 }
365
374 [[nodiscard]] Arc* operator()(long i, long j) const
375 {
376 Mat_Entry* entry = matgraph_detail::read_matrix<Mat_Entry>(mat, i, j, num_nodes);
377 return entry ? entry->arc : nullptr;
378 }
379
382
384 [[nodiscard]] const GT& get_list_graph() const noexcept { return *lgraph; }
385
388};
389
390// Implementation
391
392template <class GT, class SA>
395{
396 if (this != &other)
397 copy_list_graph(*other.lgraph);
398 return *this;
399}
400
401template <class GT, class SA>
404{
405 copy_list_graph(g);
406 return *this;
407}
408
409template <class GT, class SA>
410void
412{
413 lgraph = &g;
415 nodes.cut();
416 mat.cut();
417
418 // Copy nodes to array
419 long i = 0;
420 for (typename GT::Node_Iterator it(g); it.has_curr(); it.next_ne(), ++i)
421 nodes[i] = it.get_current_node_ne();
422
423 // Sort for binary search
425
426 // Copy arcs to matrix
427 for (typename GT::Node_Iterator nit(g); nit.has_curr(); nit.next_ne())
428 {
429 Node* src = nit.get_current_node_ne();
430 const long src_idx = matgraph_detail::node_index<GT>(nodes, num_nodes, src);
431
432 for (Node_Arc_Iterator<GT, SA> ait(src, sa); ait.has_curr(); ait.next_ne())
433 {
434 Arc* arc = ait.get_current_arc_ne();
435 Node* tgt = g.get_connected_node(arc, src);
436 const long tgt_idx = matgraph_detail::node_index<GT>(nodes, num_nodes, tgt);
437 matgraph_detail::write_matrix<Mat_Entry>(mat, src_idx, tgt_idx, num_nodes, Mat_Entry(arc));
438 }
439 }
440}
441
442
443// =============================================================================
444// Matrix_Graph - Attribute-Copying Adjacency Matrix
445// =============================================================================
446
486template <typename GT, class SA = Dft_Show_Arc<GT>>
488{
489public:
491 using Graph_Type = GT;
492
494 using Node_Type = typename GT::Node_Type;
495
497 using Arc_Type = typename GT::Arc_Type;
498
500 using Node = typename GT::Node;
501
503 using Arc = typename GT::Arc;
504
505private:
508 mutable size_t n = 0;
511
513 {
514 if (this == &other)
515 return;
516
517 n = other.n;
518 Null_Value = other.Null_Value;
519 nodes.cut();
520 arcs.cut();
522
523 for (size_t i = 0; i < n; ++i)
524 {
525 nodes[i] = other.nodes[i];
526 for (size_t j = 0; j < n; ++j)
527 {
528 const long idx = matgraph_detail::index_array(i, j, n);
529 if (other.arcs.exist(idx))
530 arcs.touch(idx) = other.arcs.access(idx);
531 }
532 }
533 }
534
535 void copy(GT& g)
536 {
537 n = g.get_num_nodes();
539
540 long i = 0;
541 for (typename GT::Node_Iterator it(g); it.has_curr(); it.next_ne(), ++i)
542 ptr[i] = it.get_current_node_ne();
543
544 quicksort(ptr);
546
547 for (size_t idx = 0; idx < n; ++idx)
548 {
549 typename GT::Node* src = ptr[idx];
550 nodes[idx] = src->get_info();
551 for (Node_Arc_Iterator<GT, SA> it(src, sa); it.has_curr(); it.next_ne())
552 {
553 typename GT::Arc* arc = it.get_current_arc_ne();
554 typename GT::Node* tgt = it.get_tgt_node();
555 const long j = matgraph_detail::node_index<GT>(ptr, n, tgt);
556 arcs[matgraph_detail::index_array(idx, j, n)] = arc->get_info();
557 }
558 }
559 }
560
561public:
563 [[nodiscard]] size_t get_num_nodes() const noexcept { return n; }
564
567
575 Matrix_Graph(GT& g, const Arc_Type& null, SA&& __sa = SA())
576 : Null_Value(null), sa(std::move(__sa))
577 {
578 copy(g);
579 }
580
581 Matrix_Graph(GT& g, const Arc_Type& null, SA& __sa)
582 : Null_Value(null), sa(__sa)
583 {
584 copy(g);
585 }
586
589
592 {
593 copy(other);
594 return *this;
595 }
596
599 {
600 copy(g);
601 return *this;
602 }
603
611 [[nodiscard]] const Arc_Type& operator()(long i, long j) const
612 {
613 const long idx = matgraph_detail::checked_index_array(i, j, n);
614 return arcs.exist(idx) ? arcs.access(idx) : Null_Value;
615 }
616
623 [[nodiscard]] Node_Type& operator()(long i) const
624 {
625 ah_out_of_range_error_if(i < 0 or static_cast<size_t>(i) >= n)
626 << "Node index " << i << " out of range";
627 return const_cast<Node_Type&>(nodes.access(i));
628 }
629
636 [[nodiscard]] Arc_Type& operator()(long i, long j)
637 {
639 }
640};
641
642
643// =============================================================================
644// Ady_Mat - Auxiliary Adjacency Matrix
645// =============================================================================
646
691template <class GT, typename __Entry_Type, class SA = Dft_Show_Arc<GT>>
693{
694public:
696 using Graph_Type = GT;
697
700
702 using Node_Type = typename GT::Node_Type;
703
705 using Arc_Type = typename GT::Arc_Type;
706
708 using Node = typename GT::Node;
709
711 using Arc = typename GT::Arc;
712
713private:
714 GT* lgraph = nullptr;
717 mutable size_t num_nodes = 0;
719
720 void test_same_graph(const Ady_Mat& other) const
721 {
723 << "Matrices refer to different graphs";
724 }
725
726 void copy_nodes(GT& g)
727 {
728 lgraph = &g;
730 nodes.cut();
731
732 long i = 0;
733 for (typename GT::Node_Iterator it(g); it.has_curr(); it.next_ne(), ++i)
734 nodes[i] = it.get_current_node_ne();
735
737 }
738
740 {
741 if (this == &other)
742 return *this;
743
745 Null_Value = other.Null_Value;
746 copy_nodes(*other.lgraph);
747 return *this;
748 }
749
750public:
758 {
759 return matgraph_detail::get_node<GT>(nodes, i);
760 }
761
768 [[nodiscard]] Node* operator()(long i) const
769 {
770 return matgraph_detail::get_node<GT>(nodes, i);
771 }
772
779 [[nodiscard]] long operator()(Node* node) const
780 {
781 return matgraph_detail::node_index<GT>(nodes, num_nodes, node);
782 }
783
791 [[nodiscard]] Entry_Type& operator()(long i, long j)
792 {
794 }
795
803 [[nodiscard]] const Entry_Type& operator()(long i, long j) const
804 {
805 const long index = matgraph_detail::checked_index_array(i, j, num_nodes);
806 return mat.exist(index) ? mat.access(index) : Null_Value;
807 }
808
817 {
818 return (*this)(matgraph_detail::node_index<GT>(nodes, num_nodes, src),
819 matgraph_detail::node_index<GT>(nodes, num_nodes, tgt));
820 }
821
829 [[nodiscard]] const Entry_Type& operator()(Node* src, Node* tgt) const
830 {
831 return (*this)(matgraph_detail::node_index<GT>(nodes, num_nodes, src),
832 matgraph_detail::node_index<GT>(nodes, num_nodes, tgt));
833 }
834
837
839 [[nodiscard]] const GT& get_list_graph() const noexcept { return *lgraph; }
840
843
846
856 explicit Ady_Mat(GT& g)
857 : lgraph(&g), num_nodes(g.get_num_nodes())
858 {
859 copy_nodes(g);
860 }
861
868 Ady_Mat(GT& g, const Entry_Type& null)
869 : lgraph(&g), num_nodes(g.get_num_nodes()), Null_Value(null)
870 {
871 copy_nodes(g);
872 }
873
875 void set_null_value(const Entry_Type& null) noexcept { Null_Value = null; }
876
879
882
899 template <class Operation>
901
913 template <class Operation>
914 void operate_all_arcs_list_graph(void* ptr);
915
928 template <class Operation>
930
936 template <class Operation>
937 void operate_all_arcs_matrix(void* ptr);
938};
939
940// Implementation of operate_* methods
941
942template <class GT, typename __Entry_Type, class SA>
943template <class Operation>
944void
946{
947 for (typename GT::Node_Iterator nit(*lgraph); nit.has_curr(); nit.next_ne())
948 {
949 Node* src = nit.get_current_node_ne();
950 const long src_idx = matgraph_detail::node_index<Graph_Type>(nodes, num_nodes, src);
951
952 for (Node_Arc_Iterator<GT, SA> at(src); at.has_curr(); at.next_ne())
953 {
954 Arc* arc = at.get_current_arc_ne();
955 Node* tgt = at.get_tgt_node();
956 const long tgt_idx =
957 matgraph_detail::node_index<Graph_Type>(nodes, num_nodes, tgt);
958 Entry_Type& entry =
960 Operation()(*this, arc, src_idx, tgt_idx, entry);
961 }
962 }
963}
964
965template <class GT, typename __Entry_Type, class SA>
966template <class Operation>
967void
969{
970 for (typename GT::Node_Iterator nit(*lgraph); nit.has_curr(); nit.next_ne())
971 {
972 Node* src = nit.get_current_node_ne();
973 const long src_idx = matgraph_detail::node_index<Graph_Type>(nodes, num_nodes, src);
974
975 for (Node_Arc_Iterator<GT, SA> at(src); at.has_curr(); at.next_ne())
976 {
977 Arc* arc = at.get_current_arc_ne();
978 Node* tgt = lgraph->get_tgt_node(arc);
979 const long tgt_idx = matgraph_detail::node_index<Graph_Type>(nodes, num_nodes, tgt);
980 Entry_Type& entry =
982 Operation()(*this, arc, src_idx, tgt_idx, entry, ptr);
983 }
984 }
985}
986
987template <class GT, typename __Entry_Type, class SA>
988template <class Operation>
989void
991{
992 const long n = num_nodes;
993 for (long s = 0; s < n; ++s)
994 {
995 Node* src_node = matgraph_detail::get_node<GT>(nodes, s);
996 for (long t = 0; t < n; ++t)
997 {
998 Node* tgt_node = matgraph_detail::get_node<GT>(nodes, t);
1000 Operation()(*this, src_node, tgt_node, s, t, entry);
1001 }
1002 }
1003}
1004
1005template <class GT, typename __Entry_Type, class SA>
1006template <class Operation>
1007void
1009{
1010 const long n = num_nodes;
1011 for (long s = 0; s < n; ++s)
1012 {
1013 Node* src_node = matgraph_detail::get_node<GT>(nodes, s);
1014 for (long t = 0; t < n; ++t)
1015 {
1016 Node* tgt_node = matgraph_detail::get_node<GT>(nodes, t);
1018 Operation()(*this, src_node, tgt_node, s, t, entry, ptr);
1019 }
1020 }
1021}
1022
1023
1024// =============================================================================
1025// Bit_Mat_Graph - Bit Matrix for Connectivity
1026// =============================================================================
1027
1066template <class GT, class SA = Dft_Show_Arc<GT>>
1068{
1069public:
1072
1074 using Node = typename GT::Node;
1075
1077 using Arc = typename GT::Arc;
1078
1079private:
1081 GT* lgraph = nullptr;
1083 mutable size_t n = 0;
1084
1086 {
1087 n = g.get_num_nodes();
1088 nodes.cut();
1089
1090 long i = 0;
1091 for (typename GT::Node_Iterator it(g); it.has_curr(); it.next_ne())
1092 nodes[i++] = static_cast<typename GT::Node*>(it.get_current_node_ne());
1093
1095
1096 for (typename GT::Node_Iterator it(g); it.has_curr(); it.next_ne())
1097 {
1098 typename GT::Node* src = it.get_current_node_ne();
1099 const size_t src_idx = matgraph_detail::node_index<Graph_Type>(nodes, n, src);
1100
1101 for (Node_Arc_Iterator<GT, SA> jt(src); jt.has_curr(); jt.next_ne())
1102 {
1103 typename GT::Node* tgt = jt.get_tgt_node_ne();
1104 const size_t tgt_idx = matgraph_detail::node_index<Graph_Type>(nodes, n, tgt);
1106 }
1107 }
1108 }
1109
1111 struct Proxy
1112 {
1114 const size_t bit_index;
1115
1116 Proxy(Bit_Mat_Graph& bitmat, long i, long j)
1118 bit_index(matgraph_detail::index_array(i, j, bitmat.n))
1119 {}
1120
1122 {
1123 bit_array[bit_index] = other.bit_array[other.bit_index];
1124 return *this;
1125 }
1126
1127 Proxy& operator=(int value)
1128 {
1129 bit_array[bit_index] = value;
1130 return *this;
1131 }
1132
1133 operator int() const { return bit_array[bit_index]; }
1134 };
1135
1136public:
1138 [[nodiscard]] size_t get_num_nodes() const noexcept { return n; }
1139
1141 Bit_Mat_Graph() = default;
1142
1147 explicit Bit_Mat_Graph(GT& g)
1149 {
1150 copy_list_graph(g);
1151 }
1152
1158
1163 explicit Bit_Mat_Graph(size_t dim)
1164 : bit_array(dim * dim), nodes(dim), n(dim)
1165 {}
1166
1172 {
1173 const size_t new_n = g.get_num_nodes();
1175 lgraph = &g;
1176 copy_list_graph(g);
1177 }
1178
1181
1184
1187 {
1188 if (this != &other)
1189 {
1190 lgraph = other.lgraph;
1191 bit_array = other.bit_array;
1192 nodes = other.nodes;
1193 n = other.n;
1194 }
1195 return *this;
1196 }
1197
1200 {
1201 if (&g != lgraph)
1202 set_list_graph(g);
1203 return *this;
1204 }
1205
1214 {
1215 ah_domain_error_if(lgraph == nullptr)
1216 << "No graph associated with bit matrix";
1217 return matgraph_detail::get_node<GT>(nodes, i);
1218 }
1219
1226 [[nodiscard]] long operator()(Node* node) const
1227 {
1228 ah_domain_error_if(lgraph == nullptr)
1229 << "No graph associated with bit matrix";
1230 return matgraph_detail::node_index<GT>(nodes, n, node);
1231 }
1232
1234 Proxy operator()(long i, long j)
1235 {
1236 return Proxy(*this, i, j);
1237 }
1238
1240 Proxy operator()(long i, long j) const
1241 {
1242 return Proxy(const_cast<Bit_Mat_Graph&>(*this), i, j);
1243 }
1244
1246 Proxy operator()(Node* src_node, Node* tgt_node)
1247 {
1248 ah_domain_error_if(lgraph == nullptr)
1249 << "No graph associated with bit matrix";
1250 return Proxy(*this,
1251 matgraph_detail::node_index<GT>(nodes, n, src_node),
1252 matgraph_detail::node_index<GT>(nodes, n, tgt_node));
1253 }
1254
1256 Proxy operator()(Node* src_node, Node* tgt_node) const
1257 {
1258 ah_domain_error_if(lgraph == nullptr)
1259 << "No graph associated with bit matrix";
1260 return Proxy(const_cast<Bit_Mat_Graph&>(*this),
1261 matgraph_detail::node_index<GT>(nodes, n, src_node),
1262 matgraph_detail::node_index<GT>(nodes, n, tgt_node));
1263 }
1264};
1265
1266
1267// =============================================================================
1268// Legacy Helper Functions (for backward compatibility)
1269// =============================================================================
1270
1272
1273template <typename GT>
1274[[nodiscard]] inline typename GT::Node*
1275get_node(DynArray<typename GT::Node*>& nodes, long i)
1276{
1277 return matgraph_detail::get_node<GT>(nodes, i);
1278}
1279
1280template <typename GT>
1281[[nodiscard]] inline long
1282node_index(const DynArray<typename GT::Node*>& nodes, long n, typename GT::Node* p)
1283{
1284 return matgraph_detail::node_index<GT>(nodes, n, p);
1285}
1286
1287[[nodiscard]] inline long
1288index_array(long i, long j, long n)
1289{
1290 return matgraph_detail::index_array(i, j, n);
1291}
1292
1293template <typename Entry>
1294[[nodiscard]] inline Entry*
1295read_matrix(const DynArray<Entry>& mat, long i, long j, long n)
1296{
1297 return matgraph_detail::read_matrix(mat, i, j, n);
1298}
1299
1300template <typename Entry>
1301inline void
1302write_matrix(DynArray<Entry>& mat, long i, long j, long n, const Entry& entry)
1303{
1304 matgraph_detail::write_matrix(mat, i, j, n, entry);
1305}
1306
1308
1309} // end namespace Aleph
1310
1311#endif // TPL_MAT_GRAPH_H
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
Definition ah-errors.H:579
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Definition ah-errors.H:522
int num_nodes
Definition btreepic.C:410
Auxiliary adjacency matrix with custom entry type.
Entry_Type & operator()(Node *src, Node *tgt)
Access entry by node pointers (modifiable).
void operate_all_arcs_list_graph()
Apply operation to all arcs from the graph.
typename GT::Node_Type Node_Type
Node attribute type from graph.
Ady_Mat(GT &g)
Construct from graph without null value.
const Entry_Type & operator()(Node *src, Node *tgt) const
Access entry by node pointers (const).
const GT & get_list_graph() const noexcept
Get const reference to underlying graph.
long operator()(Node *node) const
Get index of node.
Entry_Type & operator()(long i, long j)
Access entry by indices (modifiable).
typename GT::Node Node
Node type from graph.
typename GT::Arc_Type Arc_Type
Arc attribute type from graph.
Node * operator()(long i)
Get node pointer by index.
Ady_Mat(Ady_Mat &other)
Copy constructor.
DynArray< Node * > nodes
void copy_nodes(GT &g)
void set_null_value(const Entry_Type &null) noexcept
Set the null value.
typename GT::Arc Arc
Arc type from graph.
size_t get_num_nodes() const noexcept
Get number of nodes (matrix dimension)
void operate_all_arcs_matrix()
Apply operation to all matrix entries.
Entry_Type Null_Value
Ady_Mat(GT &g, const Entry_Type &null)
Construct from graph with null value.
Ady_Mat & copy(Ady_Mat &other)
Ady_Mat & operator=(Ady_Mat &other)
Copy assignment.
const Entry_Type & null_value() const noexcept
Get the null value.
void test_same_graph(const Ady_Mat &other) const
GT & get_list_graph() noexcept
Get reference to underlying graph.
Node * operator()(long i) const
Get node pointer by index (const).
DynArray< Entry_Type > mat
const Entry_Type & operator()(long i, long j) const
Access entry by indices (const).
__Entry_Type Entry_Type
Entry type stored in matrix.
Contiguous array of bits.
Definition bitArray.H:189
void set_size(const size_t sz)
Resets the dimension of the array.
Definition bitArray.H:337
Bit matrix for graph connectivity.
long operator()(Node *node) const
Get index of node.
DynArray< typename GT::Node * > nodes
Proxy operator()(Node *src_node, Node *tgt_node) const
Access bit by node pointers (const)
Proxy operator()(long i, long j) const
Access bit by indices (const)
const GT * get_list_graph() const noexcept
Get pointer to associated graph (const)
Bit_Mat_Graph()=default
Default constructor (empty matrix)
typename GT::Arc Arc
Arc type.
size_t get_num_nodes() const noexcept
Get number of nodes (matrix dimension)
Proxy operator()(long i, long j)
Access bit by indices.
void copy_list_graph(GT &g)
Bit_Mat_Graph & operator=(GT &g)
Assign from graph.
Bit_Mat_Graph(GT &g)
Construct from graph.
Bit_Mat_Graph & operator=(const Bit_Mat_Graph &other)
Copy assignment.
Node * operator()(long i)
Get node by index.
GT * get_list_graph() noexcept
Get pointer to associated graph (nullptr if none)
typename GT::Node Node
Node type.
void set_list_graph(GT &g)
Associate with a graph.
Bit_Mat_Graph(const Bit_Mat_Graph &other)
Copy constructor.
Bit_Mat_Graph(size_t dim)
Construct with dimension only.
Proxy operator()(Node *src_node, Node *tgt_node)
Access bit by node pointers.
void cut(const size_t new_dim=0)
Cut the array to a new dimension; that is, it reduces the dimension of array and frees the remaining ...
void set_default_initial_value(const T &value) noexcept
Set the default value.
T & touch(const size_t i)
Touch the entry i.
T & access(const size_t i) const noexcept
Fast access without checking allocation and bound_min_clock checking.
bool exist(const size_t i) const
Return true if the i-th entry is accessible.
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
size_t size() const noexcept
Count the number of elements of the list.
Definition htlist.H:1319
typename Node::Node_Type Node_Type
The arc class type.
Definition tpl_graph.H:436
Graph_Arc< int > Arc
The node class type.
Definition tpl_graph.H:433
typename Arc::Arc_Type Arc_Type
The type of data stored in the arc.
Definition tpl_graph.H:439
Adjacency matrix mapped to an adjacency list graph.
DynArray< Node * > nodes
typename GT::Node_Type Node_Type
Node attribute type from the graph.
const GT & get_list_graph() const noexcept
Get reference to underlying graph (const)
Map_Matrix_Graph(Map_Matrix_Graph &other)
Copy constructor.
typename GT::Node Node
Node type from the graph.
GT & get_list_graph() noexcept
Get reference to underlying graph.
Node * operator()(long i)
Get node pointer by index.
long operator()(Node *node) const
Get index of node.
Map_Matrix_Graph & operator=(Map_Matrix_Graph &other)
Copy assignment.
Map_Matrix_Graph(GT &g, SA &&__sa=SA())
Construct from adjacency list graph.
DynArray< Mat_Entry > mat
typename GT::Arc_Type Arc_Type
Arc attribute type from the graph.
Arc * operator()(Node *src_node, Node *tgt_node) const
Get arc by node pointers.
Arc * operator()(long i, long j) const
Get arc by indices.
typename GT::Arc Arc
Arc type from the graph.
Map_Matrix_Graph(GT &g, SA &__sa)
Construct from adjacency list graph.
void copy_list_graph(GT &g)
Copy graph structure to matrix.
size_t get_num_nodes() const noexcept
Get number of nodes (matrix dimension)
Adjacency matrix storing copies of graph attributes.
Matrix_Graph(Matrix_Graph &other)
Copy constructor.
typename GT::Node_Type Node_Type
Node attribute type.
DynArray< Arc_Type > arcs
Matrix_Graph & operator=(Matrix_Graph &other)
Copy assignment.
void copy(Matrix_Graph &other)
Matrix_Graph(GT &g, const Arc_Type &null, SA &&__sa=SA())
Construct from graph with null value.
typename GT::Arc Arc
Arc type.
Matrix_Graph(GT &g, const Arc_Type &null, SA &__sa)
typename GT::Node Node
Node type.
const Arc_Type & null_value() const noexcept
Get the null value indicating no arc.
Node_Type & operator()(long i) const
Get node attribute by index.
typename GT::Arc_Type Arc_Type
Arc attribute type.
Matrix_Graph & operator=(GT &g)
Assign from graph.
size_t get_num_nodes() const noexcept
Get number of nodes (matrix dimension)
const Arc_Type & operator()(long i, long j) const
Get arc attribute by indices (const).
DynArray< Node_Type > nodes
Arc_Type & operator()(long i, long j)
Get/set arc attribute by indices.
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
Definition graph-dry.H:595
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
Definition graph-dry.H:494
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Definition graph-dry.H:695
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
Definition graph-dry.H:772
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Definition graph-dry.H:737
List_Graph< Graph_Node< int >, Graph_Arc< int > > GT
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_dim_function > > dim(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Definition gmpfrxx.h:4052
DynArray< Graph::Node * > nodes
Definition graphpic.C:406
long node_index(const DynArray< typename GT::Node * > &nodes, long n, typename GT::Node *p)
Find index of node in sorted array using binary search.
GT::Node * get_node(DynArray< typename GT::Node * > &nodes, long i)
Get node pointer from sorted node array by index.
long index_array(long i, long j, long n) noexcept
Convert 2D matrix indices to 1D array index.
long checked_index_array(long i, long j, long n)
Validate and convert indices to linear index.
void write_matrix(DynArray< Entry > &mat, long i, long j, long n, const Entry &entry)
Write entry to matrix.
Entry * read_matrix(const DynArray< Entry > &mat, long i, long j, long n)
Read matrix entry if it exists.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
void quicksort(T *a, const long l, const long r, const Compare &cmp=Compare())
Sort an array using iterative quicksort with optimizations.
bool binary_search(Itor beg, Itor end, const T &value)
Binary search for a value.
Definition ahAlgo.H:1284
DynList< T > maps(const C &c, Op op)
Classic map operation.
STL namespace.
Proxy for bit access.
Proxy & operator=(const Proxy &other)
Proxy(Bit_Mat_Graph &bitmat, long i, long j)
Proxy & operator=(int value)
Arc of graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:222
Mat_Entry(Arc *a)
Arc * arc
Mat_Entry()=default
Filtered iterator of adjacent arcs of a node.
Definition tpl_graph.H:1119
Generic graph and digraph implementations.
Comprehensive sorting algorithms and search utilities for Aleph-w.