|
ADS
Algorithms and Data Structures
|
a static graph in compressed sparse rows, the arcs of each node sorted by head, their heads and their weights in two arrays or, with ArcLayout::Interleaved, in one array of pairs More...
#include <ADS/graph/StaticGraph.h>
Public types | |
| using | Weight = W |
| the type of the weights | |
| using | Arc = std::conditional_t< weighted , WeightedArc< W > , int > |
| an arc: its head, and its weight if the graph is weighted | |
| using | ArcCursor |
| the cursor of the arcs: a pointer to the heads if the graph is unweighted, to the pairs if interleaved | |
| using | ArcRange |
| the arcs of a row, random access | |
| using | HeadArray |
| the heads of the arcs read in place by their places: a pointer, or the heads of the pairs if interleaved | |
| using | WeightArray |
| the weights of the arcs read in place by their places | |
Public member functions | |
| StaticGraph (void) | |
| the graph with no node | |
| StaticGraph (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 | |
| StaticGraph (int n, const std::vector< std::pair< int, int > > &E, bool directed=true) | |
| the unweighted graph of the nodes \( 0 , \ldots , n - 1 \) and of the edges \( E \) | |
| template<Graph G> | |
| StaticGraph (const G &g) | |
| the copy of any graph, the names that are not nodes of \( g \) becoming isolated nodes | |
| 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 | |
| int | bound (void) const |
| bool | hasNode (int u) const |
| int | degree (int u) const |
| std::vector< int > | V (void) const |
| std::vector< int > | adj (int u) const |
| template<class F> | |
| void | forEachAdj (int u, F &&f) const |
| template<class F> requires ( weighted ) | |
| void | forEachEdge (int u, F &&f) const |
| \( f( v , w ) \) on each arc \( ( u , v ) \) of weight \( w \) | |
| std::optional< W > | weight (int u, int v) const |
| the weight of the first arc \( ( u , v ) \), nothing if there is none, by a binary search of the row of \( u \), in \( O( \log |\mathrm{adj}( u )| ) \) | |
| bool | setWeight (int u, int v, const W &w) |
| the weight of the first arc \( ( u , v ) \) set to \( w \), and that of the first arc \( ( v , u ) \) if the graph is unoriented, in \( O( \log |\mathrm{adj}( u )| + \log |\mathrm{adj}( v )| ) \); false if there is no such arc | |
| ArcRange | out (int u) const |
| the arcs out of \( u \), contiguous, random access: on a weighted graph the WeightedArc values made from heads() and weightData(), or the pairs if interleaved | |
| const int * | offsets (void) const |
| the offsets of the rows: the arcs of u are those in the places [ offsets()[ u ] , offsets()[ u + 1 ] ) of arcData(), of heads() and of weightData(), \( n + 1 \) of them | |
| const int * | heads (void) const |
| the heads of all the arcs, row by row, arcs() of them, an array of the separate layout | |
| const W * | weightData (void) const |
| the weights of all the arcs, in the places of heads(), an array of the separate layout | |
| HeadArray | arcHeads (void) const |
| the heads of all the arcs read in place, in either layout: heads(), or the heads of the pairs | |
| WeightArray | arcWeights (void) const |
| the weights of all the arcs read in place, in either layout | |
| ArcCursor | arcData (void) const |
| all the arcs, row by row: the cursor at the first, whose place \( k \) is the arc \( k \) (the pointer heads() if the graph is unweighted, the pointer to the pairs if interleaved) | |
| StaticGraph | transpose (void) const |
| the graph with each arc reversed (the same graph if unoriented) | |
| StaticGraph | relabel (const std::vector< int > &p) const |
| the same graph with the node \( u \) renamed \( p[ u ] \) | |
| auto | nodes (void) const |
| the nodes, \( 0 , \ldots , n - 1 \), random access | |
| template<class A> | |
| void | persist (A &a) |
| the members written to, or read from, the archive \( a \) [see Persistence.h] | |
Static public member functions | |
| static int | head (const Arc &a) |
| the head of an arc | |
| static constexpr std::uint64_t | persistTag (void) |
| the type of the weights, in a file | |
Static public attributes | |
| static constexpr bool | weighted = ! std::is_same_v< W , std::monostate > |
| whether the arcs have a weight | |
| static constexpr ArcLayout | layout = L |
| the layout of the arcs | |
| static constexpr bool | interleaved |
| whether the arcs are the pairs of one array (never if unweighted) | |
| static constexpr std::string_view | persistName = "StaticGraph" |
| the name of the structure in a file [see Persistence.h] | |
a static graph in compressed sparse rows, the arcs of each node sorted by head, their heads and their weights in two arrays or, with ArcLayout::Interleaved, in one array of pairs
| using ADS::StaticGraph< W, L >::Arc = std::conditional_t< weighted , WeightedArc< W > , int > |
an arc: its head, and its weight if the graph is weighted
| using ADS::StaticGraph< W, L >::ArcCursor |
the cursor of the arcs: a pointer to the heads if the graph is unweighted, to the pairs if interleaved
| using ADS::StaticGraph< W, L >::ArcRange |
the arcs of a row, random access
| using ADS::StaticGraph< W, L >::HeadArray |
the heads of the arcs read in place by their places: a pointer, or the heads of the pairs if interleaved
| using ADS::StaticGraph< W, L >::Weight = W |
the type of the weights
| using ADS::StaticGraph< W, L >::WeightArray |
the weights of the arcs read in place by their places
|
inline |
the graph with no node
| ADS::StaticGraph< W, L >::StaticGraph | ( | 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 (two passes of counting sort, the second stable, so that the heads of each row come sorted):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{build}( n , E ) \cr 2 & \quad A \gets \text{the arcs of } E \text{ , both } ( u , v ) \text{ } \text{and } ( v , u ) \text{ if unoriented} \cr 3 & \quad A \gets \text{the arcs of } A \text{ sorted by head, by } \text{counting} \cr 4 & \quad \textbf{foreach}\ ( u , v ) \in A\ \textbf{do}\ \mathit{off}[ u + 1 ] \gets \mathit{off}[ u + 1 ] + 1 \cr 5 & \quad \textbf{for}\ u \gets 1\ \textbf{to}\ n\ \textbf{do} \ \mathit{off}[ u ] \gets \mathit{off}[ u ] + \mathit{off}[ u - 1 ] \cr 6 & \quad \textbf{foreach}\ ( u , v , w ) \in A \text{ in order } \ \textbf{do}\ p \gets \mathit{next}[ u ];\ \mathit{next}[ u ] \gets p + 1\quad \triangleright\ \mathit{next}[ u ] \text{ starts } \text{at } \mathit{off}[ u ] \cr 7 & \qquad \mathit{head}[ p ] \gets v;\ \mathit{weight}[ p ] \gets w \cr 8 & \quad \textbf{return}\ ( \mathit{off} , \mathit{head} , \mathit{weight} ) \end{array}} \]
| ADS::StaticGraph< W, L >::StaticGraph | ( | int | n, |
| const std::vector< std::pair< int, int > > & | E, | ||
| bool | directed = true ) |
the unweighted graph of the nodes \( 0 , \ldots , n - 1 \) and of the edges \( E \)
|
explicit |
the copy of any graph, the names that are not nodes of \( g \) becoming isolated nodes
|
nodiscard |
|
inlinenodiscard |
all the arcs, row by row: the cursor at the first, whose place \( k \) is the arc \( k \) (the pointer heads() if the graph is unweighted, the pointer to the pairs if interleaved)
|
inlinenodiscard |
the heads of all the arcs read in place, in either layout: heads(), or the heads of the pairs
|
inlinenodiscard |
the number of arcs, 2 m() if the graph is unoriented
|
inlinenodiscard |
the weights of all the arcs read in place, in either layout
|
inlinenodiscard |
|
nodiscard |
|
inlinenodiscard |
whether the graph is oriented
| void ADS::StaticGraph< W, L >::forEachAdj | ( | int | u, |
| F && | f ) const |
| void ADS::StaticGraph< W, L >::forEachEdge | ( | int | u, |
| F && | f ) const |
\( f( v , w ) \) on each arc \( ( u , v ) \) of weight \( w \)
|
inlinenodiscard |
|
inlinestatic |
the head of an arc
|
inlinenodiscard |
the heads of all the arcs, row by row, arcs() of them, an array of the separate layout
|
inlinenodiscard |
the number of edges, an unoriented one counted once
|
inlinenodiscard |
the number of nodes
|
inlinenodiscard |
the nodes, \( 0 , \ldots , n - 1 \), random access
|
inlinenodiscard |
the offsets of the rows: the arcs of u are those in the places [ offsets()[ u ] , offsets()[ u + 1 ] ) of arcData(), of heads() and of weightData(), \( n + 1 \) of them
|
nodiscard |
the arcs out of \( u \), contiguous, random access: on a weighted graph the WeightedArc values made from heads() and weightData(), or the pairs if interleaved
| void ADS::StaticGraph< W, L >::persist | ( | A & | a | ) |
the members written to, or read from, the archive \( a \) [see Persistence.h]
|
inlinestaticnodiscardconstexpr |
the type of the weights, in a file
|
nodiscard |
the same graph with the node \( u \) renamed \( p[ u ] \)
In pseudocode:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{relabel}( p ) \cr 2 & \quad \textbf{return}\ \mathrm{build}( n , \text{the arcs } ( p[ u ] , p[ v ] ) \text{ for each arc } ( u , v ) ) \end{array}} \]
| bool ADS::StaticGraph< W, L >::setWeight | ( | int | u, |
| int | v, | ||
| const W & | w ) |
the weight of the first arc \( ( u , v ) \) set to \( w \), and that of the first arc \( ( v , u ) \) if the graph is unoriented, in \( O( \log |\mathrm{adj}( u )| + \log |\mathrm{adj}( v )| ) \); false if there is no such arc
|
nodiscard |
the graph with each arc reversed (the same graph if unoriented)
In pseudocode:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{transpose}() \cr 2 & \quad \textbf{return}\ \mathrm{build}( n , \text{the arcs } ( v , u ) \text{ for each arc } ( u , v ) ) \end{array}} \]
|
nodiscard |
|
nodiscard |
the weight of the first arc \( ( u , v ) \), nothing if there is none, by a binary search of the row of \( u \), in \( O( \log |\mathrm{adj}( u )| ) \)
|
inlinenodiscard |
the weights of all the arcs, in the places of heads(), an array of the separate layout
|
staticconstexpr |
whether the arcs are the pairs of one array (never if unweighted)
|
staticconstexpr |
the layout of the arcs
|
staticconstexpr |
the name of the structure in a file [see Persistence.h]
|
staticconstexpr |
whether the arcs have a weight