ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::IncidenceGraph Class Reference

an oriented graph on its matrix of incidence, kept by columns More...

#include <ADS/graph/IncidenceGraph.h>

Public member functions

 IncidenceGraph (int n=0)
 the graph of \( n \) nodes and no edge
int n (void) const
 the number of nodes
int bound (void) const
 the names of the nodes are in \( [ 0 , n ) \)
int m (void) const
 the number of edges, the columns
bool directed (void) const
 always oriented
bool hasNode (int u) const
 whether \( u \) is a node
std::vector< int > V (void) const
 the nodes, \( 0 , \ldots , n - 1 \)
void insertEdge (int i, int j)
 adds the edge \( ( i , j ) \) as a new column, \( O( n ) \) amortized time
void deleteEdge (int i, int j)
 removes the edge \( ( i , j ) \), if it is there, the last column copied in its place, \( O( m + n ) \) time
bool hasEdge (int i, int j) const
 whether \( ( i , j ) \) is an edge, \( O( m ) \) time
std::vector< int > adj (int i) const
 the targets of the edges out of \( i \), in the order of the columns, \( O( m + n \deg^+( i ) ) \) time
std::vector< int > inAdj (int i) const
 the sources of the edges into \( i \), in the order of the columns, \( O( m + n \deg^-( i ) ) \) time
template<class F>
void forEachAdj (int i, F &&f) const
 \( f( j ) \) on the targets of the edges out of \( i \)
int entry (int i, int e) const
 the entry \( A_{i,e} \)
std::size_t bytes (void) const
 the bytes of the matrix, \( n m \)

Detailed description

an oriented graph on its matrix of incidence, kept by columns

Constructor and destructor documentation

◆ IncidenceGraph()

ADS::IncidenceGraph::IncidenceGraph ( int n = 0)
explicit

the graph of \( n \) nodes and no edge

Precondition
\( n \ge 0 \)

Member function documentation

◆ adj()

std::vector< int > ADS::IncidenceGraph::adj ( int i) const
nodiscard

the targets of the edges out of \( i \), in the order of the columns, \( O( m + n \deg^+( i ) ) \) time

In pseudocode (exercise 12.2 of Morin's book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{adj}( i ) \cr 2 & \quad L \gets () \cr 3 & \quad \textbf{for}\ e \gets 0\ \textbf{to}\ m - 1 \ \textbf{with}\ A_{i,e} = -1\ \textbf{do} \cr 4 & \qquad L \gets L \cdot ( \text{the } j \text{ with } A_{j,e} = +1 ) \cr 5 & \quad \textbf{return}\ L \end{array}} \]

Precondition
\( i \) is a node

◆ bound()

int ADS::IncidenceGraph::bound ( void ) const
inlinenodiscard

the names of the nodes are in \( [ 0 , n ) \)

◆ bytes()

std::size_t ADS::IncidenceGraph::bytes ( void ) const
inlinenodiscard

the bytes of the matrix, \( n m \)

◆ deleteEdge()

void ADS::IncidenceGraph::deleteEdge ( int i,
int j )

removes the edge \( ( i , j ) \), if it is there, the last column copied in its place, \( O( m + n ) \) time

In pseudocode, \( A_{\cdot,e} \) the column of the edge \( e \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{deleteEdge}( i , j ) \cr 2 & \quad e \gets \text{the first column with } A_{i,e} = -1 \text{ and } A_{j,e} = +1 \text{, or } m \cr 3 & \quad \textbf{if}\ e = m\ \textbf{then return} \cr 4 & \quad A_{\cdot,e} \gets A_{\cdot,m-1};\ \text{drop the column } m - 1;\ m \gets m - 1 \end{array}} \]

Precondition
\( i \) and \( j \) are distinct nodes

◆ directed()

bool ADS::IncidenceGraph::directed ( void ) const
inlinenodiscard

always oriented

◆ entry()

int ADS::IncidenceGraph::entry ( int i,
int e ) const
nodiscard

the entry \( A_{i,e} \)

Precondition
\( i \) is a node, \( 0 \le e < m \)

◆ forEachAdj()

template<class F>
void ADS::IncidenceGraph::forEachAdj ( int i,
F && f ) const

\( f( j ) \) on the targets of the edges out of \( i \)

Precondition
\( i \) is a node

◆ hasEdge()

bool ADS::IncidenceGraph::hasEdge ( int i,
int j ) const
nodiscard

whether \( ( i , j ) \) is an edge, \( O( m ) \) time

In pseudocode (exercise 12.2 of Morin's book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{hasEdge}( i , j ) \cr 2 & \quad \textbf{for}\ e \gets 0\ \textbf{to}\ m - 1\ \textbf{do} \cr 3 & \qquad \textbf{if}\ A_{i,e} = -1\ \textbf{and}\ A_{j,e} = +1 \ \textbf{then return true} \cr 4 & \quad \textbf{return false} \end{array}} \]

Precondition
\( i \) and \( j \) are nodes

◆ hasNode()

bool ADS::IncidenceGraph::hasNode ( int u) const
inlinenodiscard

whether \( u \) is a node

◆ inAdj()

std::vector< int > ADS::IncidenceGraph::inAdj ( int i) const
nodiscard

the sources of the edges into \( i \), in the order of the columns, \( O( m + n \deg^-( i ) ) \) time

Precondition
\( i \) is a node

◆ insertEdge()

void ADS::IncidenceGraph::insertEdge ( int i,
int j )

adds the edge \( ( i , j ) \) as a new column, \( O( n ) \) amortized time

Precondition
\( i \) and \( j \) are distinct nodes

◆ m()

int ADS::IncidenceGraph::m ( void ) const
inlinenodiscard

the number of edges, the columns

◆ n()

int ADS::IncidenceGraph::n ( void ) const
inlinenodiscard

the number of nodes

◆ V()

std::vector< int > ADS::IncidenceGraph::V ( void ) const
nodiscard

the nodes, \( 0 , \ldots , n - 1 \)


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