ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
GraphBuilder.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File GraphBuilder.h --------------------------*/
3/*--------------------------------------------------------------------------*/
38/*--------------------------------------------------------------------------*/
39/*----------------------------- DEFINITIONS --------------------------------*/
40/*--------------------------------------------------------------------------*/
41
42#ifndef __ADS_GraphBuilder
43 #define __ADS_GraphBuilder
44/* self-identification: #endif constant */
45
46/*--------------------------------------------------------------------------*/
47/*------------------------------ INCLUDES ----------------------------------*/
48/*--------------------------------------------------------------------------*/
49
50#include "ADS/Contract.h"
53
54#include <cstddef>
55#include <tuple>
56#include <variant>
57#include <vector>
58
59/*--------------------------------------------------------------------------*/
60/*--------------------------- NAMESPACE ------------------------------------*/
61/*--------------------------------------------------------------------------*/
62
63namespace ADS
64{
65
66/*--------------------------------------------------------------------------*/
67/*--------------------------- CLASS GraphBuilder ---------------------------*/
68/*--------------------------------------------------------------------------*/
69
72template< class W = std::monostate >
74{
75
76/*--------------------------------------------------------------------------*/
77 public:
78 using Weight = W;
79
81 using Edge = std::tuple< int , int , W >;
82
85 explicit GraphBuilder( int n = 0 , bool directed = true );
86
88 [[nodiscard]] bool directed( void ) const { return( f_directed ); }
89
91 [[nodiscard]] int n( void ) const { return( f_n ); }
92
94 [[nodiscard]] int m( void ) const { return( int( f_E.size() ) ); }
95
97 [[nodiscard]] const std::vector< Edge > & edges( void ) const {
98 return( f_E );
99 }
100
102 void reserve( std::size_t m ) { f_E.reserve( m ); }
103
105 int addNode( void ) { return( f_n++ ); }
106
111 void addEdge( int u , int v , const W & w = W() );
112
124 [[nodiscard]] StaticGraph< W > toStaticGraph( void ) const;
125
136 [[nodiscard]] ArrayGraph< W > toArrayGraph( void ) const;
137
138/*--------------------------------------------------------------------------*/
139 private:
140 bool f_directed;
141 int f_n;
142 std::vector< Edge > f_E;
143
144 }; // end( class GraphBuilder )
145
146/*--------------------------------------------------------------------------*/
147
148} // end( namespace ADS )
149
150/*--------------------------------------------------------------------------*/
151/*-------------------------- IMPLEMENTATION --------------------------------*/
152/*--------------------------------------------------------------------------*/
153
154#include "ADS/graph/impl/GraphBuilder.tpp"
155
156/*--------------------------------------------------------------------------*/
157
158#endif /* GraphBuilder.h included */
159
160/*--------------------------------------------------------------------------*/
161/*------------------------ End File GraphBuilder.h -------------------------*/
162/*--------------------------------------------------------------------------*/
The static GRAPH with vectors of adjacency of section 9.4 [see Graph.h]: the adjacent nodes of all th...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
A static GRAPH for the engineered algorithms, beyond the book [see Graph.h]: the compressed sparse ro...
a static graph with vectors of adjacency, all in one vector
Definition ArrayGraph.h:62
W Weight
the type of the weights
Definition GraphBuilder.h:78
GraphBuilder(int n=0, bool directed=true)
the builder of the nodes and of no edge
int addNode(void)
a new node, the next name
Definition GraphBuilder.h:105
int m(void) const
the number of edges, an unoriented one counted once
Definition GraphBuilder.h:94
int n(void) const
the number of nodes
Definition GraphBuilder.h:91
void reserve(std::size_t m)
room for edges, so that the next insertions do not move them
Definition GraphBuilder.h:102
void addEdge(int u, int v, const W &w=W())
the edge , or if unoriented, of weight , after those already there, even if parallel to one of them
bool directed(void) const
whether the graph is oriented
Definition GraphBuilder.h:88
const std::vector< Edge > & edges(void) const
the edges, in the order in which they were added
Definition GraphBuilder.h:97
ArrayGraph< W > toArrayGraph(void) const
the graph in compressed rows, each row in the order of insertion
std::tuple< int, int, W > Edge
an edge of weight
Definition GraphBuilder.h:81
StaticGraph< W > toStaticGraph(void) const
the graph in compressed rows, each row sorted by head
a static graph in compressed sparse rows, the arcs of each node sorted by head, their heads and their...
Definition StaticGraph.h:275
Definition ADT.h:96