|
| | ArrayGraph (int n, const std::vector< std::tuple< int, int, W > > &E, bool directed=true) |
| | the graph of the nodes \( 0 , \ldots , n - 1 \) and of the given edges; an unoriented edge \( [ u , v ] \) is given once
|
| template<Graph G> |
| | ArrayGraph (const G &g) |
| | the copy of any graph, with the nodes 0 , ... , g.bound() - 1: the names that are not nodes of g, deleted ones, become isolated nodes, so that each node keeps its name
|
| 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
|
| int | arcs (void) const |
| | the number of arcs, 2 m() if the graph is unoriented, as in StaticGraph
|
| int | bound (void) const |
| | the names of the nodes, \( [ 0 , \mathrm{bound}() ) = [ 0 , n ) \)
|
| bool | hasNode (int u) const |
| | whether \( u \) is a node
|
| std::vector< int > | V (void) const |
| | the set of the nodes, in increasing order
|
| std::vector< int > | adj (int u) const |
| template<class F> |
| void | forEachAdj (int u, F &&f) const |
| template<class F> |
| void | forEachEdge (int u, F &&f) const |
| std::optional< W > | weight (int u, int v) const |
| | the weight of \( ( u , v ) \), nothing if there is no such edge, in \( O( |\mathrm{adj}( u )| ) \)
|
| bool | setWeight (int u, int v, const W &w) |
| | the weight of \( ( u , v ) \) set to \( w \) (of both its arcs if unoriented), in \( O( |\mathrm{adj}( u )| + |\mathrm{adj}( v )| )
\); false if there is no such edge
|
| auto | nodes (void) const |
| | the nodes, \( 0 , \ldots , n - 1 \), random access
|
| std::span< const int > | neighbors (int u) const |
| | the nodes adjacent to \( u \), contiguous in the array of the edges
|
| const int * | offsets (void) const |
| | the offsets of the rows, \( n + 1 \) of them: the adjacent nodes of \( u \) are the places from offsets()[ u ] to offsets()[ u + 1 ] of heads(), and their weights the same places of weightData() (the arrays that the adapters to other libraries read in place)
|
| const int * | heads (void) const |
| | the adjacent nodes, row by row
|
| const W * | weightData (void) const |
| | the weights, in the places of heads()
|
| const int * | arcHeads (void) const |
| | the heads of all the arcs read in place, heads(), as in StaticGraph
|
| const W * | arcWeights (void) const |
| | the weights of all the arcs read in place, weightData(), as in StaticGraph
|
template<class W = std::monostate>
class ADS::ArrayGraph< W >
a static graph with vectors of adjacency, all in one vector
template<class W = std::monostate>
| ADS::ArrayGraph< W >::ArrayGraph |
( |
int | n, |
|
|
const std::vector< std::tuple< int, int, W > > & | E, |
|
|
bool | directed = true ) |
the graph of the nodes \( 0 , \ldots , n - 1 \) and of the given edges; an unoriented edge \( [ u , v ] \) is given once
In pseudocode (section 9.4), the offsets by counting:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{build}( n , E )\quad \triangleright
\ \text{the adjacent nodes of } u \text{ in } [ \mathit{off}[ u ] ,
\mathit{off}[ u + 1 ] ) \cr
2 & \quad \mathit{off}[ u + 1 ] \gets \text{the degree of } u
\text{ in } E \text{ for each node } u\quad \triangleright
\ \text{both ends if unoriented} \cr
3 & \quad \text{make } \mathit{off} \text{ its own prefix sums};
\ \mathit{off}[ 0 ] = 0 \cr
4 & \quad \textbf{foreach}\ ( u , v ) \in E\ \textbf{do}\ \text{write }
v \text{ in the first free place of the range of } u \cr
& \qquad \text{(and } u \text{ in that of } v \text{ if unoriented)}
\cr
5 & \quad \textbf{return}\ ( \mathit{off} ,
\text{the vector of the adjacent nodes} )
\end{array}}
\]
- Precondition
- \( n \ge 0 \), and each edge joins two distinct nodes
template<class W = std::monostate>
template<Graph G>
the copy of any graph, with the nodes 0 , ... , g.bound() - 1: the names that are not nodes of g, deleted ones, become isolated nodes, so that each node keeps its name