90concept Graph =
requires(
const G g ,
int u )
92 { g.n() } -> std::convertible_to< int >;
93 { g.bound() } -> std::convertible_to< int >;
94 { g.directed() } -> std::same_as< bool >;
95 { g.hasNode( u ) } -> std::same_as< bool >;
96 { g.V() } -> std::same_as< std::vector< int > >;
97 { g.adj( u ) } -> std::same_as< std::vector< int > >;
98 g.forEachAdj( u , [](
int ) { } );
105 { g.insertNode() } -> std::same_as< int >;
106 g.insertEdge( u , v );
108 g.deleteEdge( u , v );
126 [[nodiscard]]
int n(
void )
const {
return(
f_n ); }
129 [[nodiscard]]
int m(
void )
const {
return(
f_m ); }
132 [[nodiscard]]
int bound(
void )
const {
return(
int(
f_alive.size() ) ); }
138 [[nodiscard]] std::vector< int >
V(
void )
const;
142 [[nodiscard]]
const T &
label(
int u )
const;
158 static std::size_t
size(
const auto & o ) {
return( o.f_alive.size() ); }
160 static bool occupied(
const auto & o , std::size_t i ) {
161 return( o.f_alive[ i ] );
164 static int read(
const auto & , std::size_t i ) {
return(
int( i ) ); }
168 [[nodiscard]]
auto nodes(
void )
const {
171 std::ranges::subrange( It(
this , 0 ) , It(
this ,
f_alive.size() ) ) );
186 void edge(
int u ,
int v )
const;
221std::vector< std::vector< int > >
incidence(
const G & g );
239inline std::vector< int >
261 static constexpr bool byArcHeads =
requires(
const G & h ) {
262 { h.offsets() } -> std::convertible_to< const int * >;
267 template<
bool A ,
class =
void >
270 using type =
const int *;
273 struct Heads< true , V >
275 using type =
decltype( std::declval< const G & >().arcHeads() );
280 static constexpr bool direct = byArcHeads ||
requires(
const G & h ) {
281 { h.offsets() } -> std::convertible_to< const int * >;
282 { h.heads() } -> std::convertible_to< const int * >;
287 explicit Rows(
const G & g ) {
288 if constexpr( byArcHeads ) {
292 else if constexpr( direct ) {
297 const int n = g.bound();
298 f_off.assign( std::size_t( n ) + 1 , 0 );
299 for(
int u = 0 ; u < n ; ++u ) {
300 f_off[ u ] = f_head.size();
302 g.forEachAdj( u , [ & ](
int v ) { f_head.push_back( v ); } );
304 f_off[ n ] = f_head.size();
309 [[nodiscard]] std::size_t first(
int u )
const {
310 if constexpr( direct )
311 return( std::size_t( f_o[ u ] ) );
313 return( f_off[ u ] );
317 [[nodiscard]] std::size_t last(
int u )
const {
return( first( u + 1 ) ); }
320 [[nodiscard]]
int head( std::size_t i )
const {
321 if constexpr( ! direct )
322 return( f_head[ i ] );
328 const int * f_o =
nullptr;
330 typename Heads< byArcHeads >::type f_h{};
331 std::vector< std::size_t > f_off;
332 std::vector< int > f_head;
346#include "ADS/graph/impl/Graph.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The iterators that the containers of the library have in common, beyond the book: they give a contain...
The LIST of the book: a SEQUENCE [see ADT.h] realized as a bidirectional circular list of cells with ...
GraphNodes(int n, bool directed)
bool nodesCounted(void) const
n() counts the names in use, and each has a label
void edge(int u, int v) const
and must be two distinct nodes
int f_n
the number of nodes
Definition Graph.h:194
bool f_directed
oriented or not
Definition Graph.h:191
void setLabel(int u, const T &t)
the label of the node becomes
std::vector< bool > f_alive
whether a name is a node
Definition Graph.h:192
std::vector< int > V(void) const
the set of the nodes, in increasing order
const T & label(int u) const
the label of the node
std::vector< T > f_label
the labels
Definition Graph.h:193
int bound(void) const
the names of the nodes are in
Definition Graph.h:132
int f_m
the number of edges
Definition Graph.h:195
int check(int u) const
, which must be a node
int m(void) const
the number of edges, an unoriented one counted once
Definition Graph.h:129
int n(void) const
the number of nodes, the G.n of the book
Definition Graph.h:126
bool hasNode(int u) const
whether is a node
auto nodes(void) const
the nodes in increasing order, bidirectional
Definition Graph.h:168
int addNode(const T &t)
a new node of label , and its name
bool directed(void) const
whether the graph is oriented
Definition Graph.h:123
a bidirectional iterator on the occupied places of the table O, by the policy P with the static funct...
Definition Iterators.h:691
a GRAPH with the insertions and the deletions of its specification
Definition Graph.h:103
GRAPH (section 9.2), as far as the visits need it: the nodes, the adjacent nodes of a node,...
Definition Graph.h:90
std::vector< std::vector< int > > incidence(const G &g)
the matrix of incidence nodes-edges, the edges in the order of V() and of adj(), an unoriented one wh...
std::vector< int > adjFromIncidence(const std::vector< std::vector< int > > &B, int u, bool directed)
the adjacent nodes of from the matrix of incidence of a graph, oriented or not, in the order of the...
the names in use, for SlotIterator
Definition Graph.h:156
static int read(const auto &, std::size_t i)
the node of the name
Definition Graph.h:164
static bool occupied(const auto &o, std::size_t i)
whether the name is in use
Definition Graph.h:160
static std::size_t size(const auto &o)
the number of the names
Definition Graph.h:158