ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::GraphBuilder< W > Class Template Reference

the nodes and the edges of a graph collected one at a time, then frozen into a StaticGraph or an ArrayGraph More...

#include <ADS/graph/GraphBuilder.h>

Public types

using Weight = W
 the type of the weights
using Edge = std::tuple< int , int , W >
 an edge \( ( u , v ) \) of weight \( w \)

Public member functions

 GraphBuilder (int n=0, bool directed=true)
 the builder of the nodes \( 0 , \ldots , n - 1 \) and of no edge
bool directed (void) const
 whether the graph is oriented
int n (void) const
 the number of nodes
int m (void) const
 the number of edges, an unoriented one counted once
const std::vector< Edge > & edges (void) const
 the edges, in the order in which they were added
void reserve (std::size_t m)
 room for \( m \) edges, so that the next insertions do not move them
int addNode (void)
 a new node, the next name
void addEdge (int u, int v, const W &w=W())
 the edge \( ( u , v ) \), or \( [ u , v ] \) if unoriented, of weight \( w \), after those already there, even if parallel to one of them
StaticGraph< W > toStaticGraph (void) const
 the graph in compressed rows, each row sorted by head
ArrayGraph< W > toArrayGraph (void) const
 the graph in compressed rows, each row in the order of insertion

Detailed description

template<class W = std::monostate>
class ADS::GraphBuilder< W >

the nodes and the edges of a graph collected one at a time, then frozen into a StaticGraph or an ArrayGraph

Member typedef documentation

◆ Edge

template<class W = std::monostate>
using ADS::GraphBuilder< W >::Edge = std::tuple< int , int , W >

an edge \( ( u , v ) \) of weight \( w \)

◆ Weight

template<class W = std::monostate>
using ADS::GraphBuilder< W >::Weight = W

the type of the weights

Constructor and destructor documentation

◆ GraphBuilder()

template<class W = std::monostate>
ADS::GraphBuilder< W >::GraphBuilder ( int n = 0,
bool directed = true )
explicit

the builder of the nodes \( 0 , \ldots , n - 1 \) and of no edge

Precondition
\( n \ge 0 \)

Member function documentation

◆ addEdge()

template<class W = std::monostate>
void ADS::GraphBuilder< W >::addEdge ( int u,
int v,
const W & w = W() )

the edge \( ( u , v ) \), or \( [ u , v ] \) if unoriented, of weight \( w \), after those already there, even if parallel to one of them

Precondition
\( u \) and \( v \) are two distinct nodes, fewer than \( 2^{31} - 1 \) edges

◆ addNode()

template<class W = std::monostate>
int ADS::GraphBuilder< W >::addNode ( void )
inline

a new node, the next name

◆ directed()

template<class W = std::monostate>
bool ADS::GraphBuilder< W >::directed ( void ) const
inlinenodiscard

whether the graph is oriented

◆ edges()

template<class W = std::monostate>
const std::vector< Edge > & ADS::GraphBuilder< W >::edges ( void ) const
inlinenodiscard

the edges, in the order in which they were added

◆ m()

template<class W = std::monostate>
int ADS::GraphBuilder< W >::m ( void ) const
inlinenodiscard

the number of edges, an unoriented one counted once

◆ n()

template<class W = std::monostate>
int ADS::GraphBuilder< W >::n ( void ) const
inlinenodiscard

the number of nodes

◆ reserve()

template<class W = std::monostate>
void ADS::GraphBuilder< W >::reserve ( std::size_t m)
inline

room for \( m \) edges, so that the next insertions do not move them

◆ toArrayGraph()

template<class W = std::monostate>
ArrayGraph< W > ADS::GraphBuilder< W >::toArrayGraph ( void ) const
nodiscard

the graph in compressed rows, each row in the order of insertion

In pseudocode:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{toArrayGraph}() \cr 2 & \quad \textbf{return}\ \mathrm{ArrayGraph}( n , E )\quad \triangleright\ \text{one stable pass of counting sort by tail} \end{array}} \]

◆ toStaticGraph()

template<class W = std::monostate>
StaticGraph< W > ADS::GraphBuilder< W >::toStaticGraph ( void ) const
nodiscard

the graph in compressed rows, each row sorted by head

In pseudocode:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{toStaticGraph}() \cr 2 & \quad \textbf{return}\ \mathrm{StaticGraph}( n , E )\quad \triangleright\ \text{two passes of counting sort, by head and by } \text{tail} \end{array}} \]


The documentation for this class was generated from the following file: