|
| | MatrixGraph (int n=0, bool directed=true) |
| | the graph of the nodes \( 0 , \ldots , n - 1 \), with no edge
|
| int | insertNode (const T &t=T()) |
| | a new node, a new row and a new column, \( O( n ) \) time
|
| void | insertEdge (int u, int v, const W &w=W()) |
| | the edge \( ( u , v ) \), or \( [ u , v ] \), of weight \( w \), \( O( 1 ) \) time; only the weight changes if it is there
|
| void | deleteEdge (int u, int v) |
| void | deleteNode (int u) |
| | removes the node \( u \) and its edges, \( \Theta( n ) \) time
|
| bool | hasEdge (int u, int v) const |
| | \( O( 1 ) \) time
|
| std::optional< W > | weight (int u, int v) const |
| | the weight of \( ( u , v ) \), nothing (the infinity of the book) if there is no such edge
|
| std::vector< int > | adj (int u) const |
| | the set of the nodes adjacent to \( u \), in increasing order, \( \Theta( n ) \) time
|
| std::vector< int > | inAdj (int u) const |
| | the nodes with an edge to \( u \), in increasing order, the column of \( u \), \( \Theta( n ) \) time (the inEdges( i ) of the AdjacencyMatrix of section 12.1 of Morin's book)
|
| template<class F> |
| void | forEachAdj (int u, F &&f) const |
| template<class F> |
| void | forEachEdge (int u, F &&f) const |
| auto | neighbors (int u) const |
| | the nodes adjacent to \( u \) in increasing order, bidirectional
|
| bool | directed (void) const |
| | whether the graph is oriented
|
| int | n (void) const |
| | the number of nodes, the G.n of the book
|
| int | m (void) const |
| | the number of edges, an unoriented one counted once
|
| int | bound (void) const |
| | the names of the nodes are in \( [ 0 , \mathrm{bound}() ) \)
|
| bool | hasNode (int u) const |
| | whether \( u \) is a node
|
| std::vector< int > | V (void) const |
| | the set of the nodes, in increasing order
|
| const std::monostate & | label (int u) const |
| | the label of the node \( u \)
|
| void | setLabel (int u, const std::monostate &t) |
| | the label of the node \( u \) becomes \( t \)
|
| auto | nodes (void) const |
| | the nodes in increasing order, bidirectional
|
|
| | GraphNodes (int n, bool directed) |
| int | addNode (const std::monostate &t) |
| | a new node of label \( t \), and its name
|
| int | check (int u) const |
| | \( u \), which must be a node
|
| void | edge (int u, int v) const |
| | \( u \) and \( v \) must be two distinct nodes
|
| bool | nodesCounted (void) const |
| | n() counts the names in use, and each has a label
|
| bool | f_directed |
| | oriented or not
|
| std::vector< bool > | f_alive |
| | whether a name is a node
|
| std::vector< std::monostate > | f_label |
| | the labels
|
| int | f_n |
| | the number of nodes
|
| int | f_m |
| | the number of edges
|
template<class W = std::monostate, class T = std::monostate>
class ADS::MatrixGraph< W, T >
a graph with an adjacency matrix
template<class W = std::monostate, class T = std::monostate>
the nodes with an edge to \( u \), in increasing order, the column of \( u \), \( \Theta( n ) \) time (the inEdges( i ) of the AdjacencyMatrix of section 12.1 of Morin's book)
In pseudocode (section 12.1 of Morin's book), \( M \) the matrix:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{inAdj}( u ) \cr
2 & \quad L \gets () \cr
3 & \quad \textbf{for}\ v \gets 0\ \textbf{to}\ \mathrm{bound}() - 1
\ \textbf{do} \cr
4 & \qquad \textbf{if}\ M[ v ][ u ] \ne \textbf{nil}\ \textbf{then}
\ L \gets L \cdot ( v ) \cr
5 & \quad \textbf{return}\ L
\end{array}}
\]
- Precondition
- \( u \) is a node
template<class W = std::monostate, class T = std::monostate>
the edge \( ( u , v ) \), or \( [ u , v ] \), of weight \( w \), \( O( 1 ) \) time; only the weight changes if it is there
In pseudocode (section 9.3), \( M \) the matrix:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{insertEdge}( u , v , w )\quad
\triangleright\ \textbf{nil} \text{ marks no edge} \cr
2 & \quad m \gets m + [ M[ u ][ v ] = \textbf{nil} ];\ M[ u ][ v ] \gets
w \cr
3 & \quad \textbf{if}\ G \text{ is unoriented}\ \textbf{then}\ M[ v ][ u
] \gets w\quad \triangleright\ \text{a symmetric matrix}
\end{array}}
\]
- Precondition
- \( u \) and \( v \) are distinct nodes
- Postcondition
- hasEdge( u , v )