ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
IncidenceGraph.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File IncidenceGraph.h -------------------------*/
3/*--------------------------------------------------------------------------*/
52/*--------------------------------------------------------------------------*/
53/*----------------------------- DEFINITIONS --------------------------------*/
54/*--------------------------------------------------------------------------*/
55
56#ifndef __ADS_IncidenceGraph
57 #define __ADS_IncidenceGraph
58/* self-identification: #endif constant */
59
60/*--------------------------------------------------------------------------*/
61/*------------------------------ INCLUDES ----------------------------------*/
62/*--------------------------------------------------------------------------*/
63
64#include "ADS/Contract.h"
65
66#include <algorithm>
67#include <cstddef>
68#include <cstdint>
69#include <vector>
70
71/*--------------------------------------------------------------------------*/
72/*--------------------------- NAMESPACE ------------------------------------*/
73/*--------------------------------------------------------------------------*/
74
75namespace ADS
76{
77
78/*--------------------------------------------------------------------------*/
79/*------------------------- CLASS IncidenceGraph ---------------------------*/
80/*--------------------------------------------------------------------------*/
81
84{
85
86/*--------------------------------------------------------------------------*/
87 public:
90 explicit IncidenceGraph( int n = 0 );
91
93 [[nodiscard]] int n( void ) const { return( f_n ); }
94
96 [[nodiscard]] int bound( void ) const { return( f_n ); }
97
99 [[nodiscard]] int m( void ) const { return( f_m ); }
100
102 [[nodiscard]] bool directed( void ) const { return( true ); }
103
105 [[nodiscard]] bool hasNode( int u ) const {
106 return( ( u >= 0 ) && ( u < f_n ) );
107 }
108
110 [[nodiscard]] std::vector< int > V( void ) const;
111
115 void insertEdge( int i , int j );
116
132 void deleteEdge( int i , int j );
133
147 [[nodiscard]] bool hasEdge( int i , int j ) const;
148
165 [[nodiscard]] std::vector< int > adj( int i ) const;
166
170 [[nodiscard]] std::vector< int > inAdj( int i ) const;
171
174 template< class F >
175 void forEachAdj( int i , F && f ) const;
176
179 [[nodiscard]] int entry( int i , int e ) const;
180
182 [[nodiscard]] std::size_t bytes( void ) const { return( f_A.size() ); }
183
184/*--------------------------------------------------------------------------*/
185 private:
187 [[nodiscard]] int column( int i , int j ) const;
188
190 [[nodiscard]] int find( int e , std::int8_t v ) const;
191
193 [[nodiscard]] bool columnOk( int e ) const;
194
195 int f_n;
196 int f_m = 0;
197 std::vector< std::int8_t > f_A;
198
199 }; // end( class IncidenceGraph )
200
201/*--------------------------------------------------------------------------*/
202
203} // end( namespace ADS )
204
205/*--------------------------------------------------------------------------*/
206/*-------------------------- IMPLEMENTATION --------------------------------*/
207/*--------------------------------------------------------------------------*/
208
209#include "ADS/graph/impl/IncidenceGraph.tpp"
210
211/*--------------------------------------------------------------------------*/
212
213#endif /* IncidenceGraph.h included */
214
215/*--------------------------------------------------------------------------*/
216/*------------------------ End File IncidenceGraph.h -----------------------*/
217/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
bool hasNode(int u) const
whether is a node
Definition IncidenceGraph.h:105
std::vector< int > inAdj(int i) const
the sources of the edges into , in the order of the columns, time
void insertEdge(int i, int j)
adds the edge as a new column, amortized time
std::vector< int > V(void) const
the nodes,
int bound(void) const
the names of the nodes are in
Definition IncidenceGraph.h:96
bool hasEdge(int i, int j) const
whether is an edge, time
int m(void) const
the number of edges, the columns
Definition IncidenceGraph.h:99
int n(void) const
the number of nodes
Definition IncidenceGraph.h:93
void forEachAdj(int i, F &&f) const
on the targets of the edges out of
std::vector< int > adj(int i) const
the targets of the edges out of , in the order of the columns, time
bool directed(void) const
always oriented
Definition IncidenceGraph.h:102
int entry(int i, int e) const
the entry
IncidenceGraph(int n=0)
the graph of nodes and no edge
std::size_t bytes(void) const
the bytes of the matrix,
Definition IncidenceGraph.h:182
void deleteEdge(int i, int j)
removes the edge , if it is there, the last column copied in its place, time
Definition ADT.h:96