ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
PointerGraph.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File PointerGraph.h ---------------------------*/
3/*--------------------------------------------------------------------------*/
31/*--------------------------------------------------------------------------*/
32/*----------------------------- DEFINITIONS --------------------------------*/
33/*--------------------------------------------------------------------------*/
34
35#ifndef __ADS_PointerGraph
36 #define __ADS_PointerGraph
37/* self-identification: #endif constant */
38
39/*--------------------------------------------------------------------------*/
40/*------------------------------ INCLUDES ----------------------------------*/
41/*--------------------------------------------------------------------------*/
42
43#include "ADS/Contract.h"
44
45#include <algorithm>
46#include <list>
47#include <queue>
48#include <utility>
49#include <vector>
50
51/*--------------------------------------------------------------------------*/
52/*--------------------------- NAMESPACE ------------------------------------*/
53/*--------------------------------------------------------------------------*/
54
55namespace ADS
56{
57
58/*--------------------------------------------------------------------------*/
59/*--------------------------- CLASS PointerGraph ---------------------------*/
60/*--------------------------------------------------------------------------*/
61
63template< class T , class W = int >
65{
66
67/*--------------------------------------------------------------------------*/
68 public:
69 struct Node;
70
72 struct Edge
73 {
74 Node * to;
76 };
77
79 struct Node
80 {
82 int degree = 0;
83 bool seen = false;
84 std::list< Edge > out;
85 };
86
88 PointerGraph( void ) = default;
90 PointerGraph( const PointerGraph & ) = delete;
92 PointerGraph & operator=( const PointerGraph & ) = delete;
93
95 [[nodiscard]] int n( void ) const { return( int( f_V.size() ) ); }
96
98 Node * insertNode( const T & t );
99
101 [[nodiscard]] Node * find( const T & t );
102
104 [[nodiscard]] bool hasEdge( const Node * u , const Node * v ) const;
105
109 void insertEdge( Node * u , Node * v , const W & w = W() );
110
113 void deleteEdge( Node * u , Node * v );
114
117 bool deleteNode( Node * u );
118
132
135 [[nodiscard]] std::vector< Node * > adjacent( const Node * u ) const;
136
151 template< class F >
152 void dfs( Node * r , F && f );
153
170 template< class F >
171 void bfs( Node * r , F && f );
172
173/*--------------------------------------------------------------------------*/
174 private:
175 void clear( void );
176
178 [[nodiscard]] bool owns( const Node * u ) const;
179
181 [[nodiscard]] bool consistent( void ) const;
182
183 std::list< Node > f_V;
184
185 }; // end( class PointerGraph )
186
187/*--------------------------------------------------------------------------*/
188
189} // end( namespace ADS )
190
191/*--------------------------------------------------------------------------*/
192/*-------------------------- IMPLEMENTATION --------------------------------*/
193/*--------------------------------------------------------------------------*/
194
195#include "ADS/graph/impl/PointerGraph.tpp"
196
197/*--------------------------------------------------------------------------*/
198
199#endif /* PointerGraph.h included */
200
201/*--------------------------------------------------------------------------*/
202/*------------------------ End File PointerGraph.h -------------------------*/
203/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
void deleteEdge(Node *u, Node *v)
void forceDeleteNode(Node *u)
deletes the edges of and then
Node * find(const T &t)
the first node of label , nullptr if none
std::vector< Node * > adjacent(const Node *u) const
the nodes adjacent to
void dfs(Node *r, F &&f)
the depth first visit from , on each node reached
PointerGraph & operator=(const PointerGraph &)=delete
no copy, since the nodes are linked by pointers
PointerGraph(const PointerGraph &)=delete
no copy, since the nodes are linked by pointers
bool hasEdge(const Node *u, const Node *v) const
PointerGraph(void)=default
the empty graph
void bfs(Node *r, F &&f)
the breadth first visit from
Node * insertNode(const T &t)
a new isolated node of label
int n(void) const
the number of nodes
Definition PointerGraph.h:95
void insertEdge(Node *u, Node *v, const W &w=W())
the edge of weight , if not there
bool deleteNode(Node *u)
deletes if isolated; false otherwise
Definition ADT.h:96
an edge, to its other end
Definition PointerGraph.h:73
Node * to
the other end
Definition PointerGraph.h:74
W weight
the weight
Definition PointerGraph.h:75
a node
Definition PointerGraph.h:80
bool seen
the flag of the visits
Definition PointerGraph.h:83
T label
the label
Definition PointerGraph.h:81
std::list< Edge > out
the edges that leave it
Definition PointerGraph.h:84
int degree
the edges that enter or leave it
Definition PointerGraph.h:82