cgrapht 1.0.0
A modern C++20 header-only graph library
Loading...
Searching...
No Matches
cgrapht::DirectedGraph< V, E > Class Template Reference

Directed graph with hashed vertex and edge ids. More...

#include <graph.hpp>

Public Member Functions

Result< std::size_t, ErrorTypeadd_vertex (const V &v)
 Add a vertex to the graph.
 
Result< std::size_t, ErrorTypedelete_vertex (std::size_t vertex_id)
 Delete a vertex if it has no incident edges.
 
Result< std::size_t, ErrorTypeadd_edge (std::size_t from_id, std::size_t to_id, const E &e)
 Add a directed edge between two vertices.
 
Result< std::size_t, ErrorTypedelete_edge (std::size_t edge_id)
 Delete an edge by id.
 
Result< V, ErrorTypeget_vertex (std::size_t id) const
 Fetch a vertex payload by id.
 
Result< Edge< E >, ErrorTypeget_edge (std::size_t id) const
 Fetch an edge record by id.
 
Result< std::unordered_set< std::size_t >, ErrorTypeget_children (std::size_t vertex_id) const
 Get adjacent children (outgoing neighbors).
 
Result< std::unordered_set< std::size_t >, ErrorTypeget_parents (std::size_t vertex_id) const
 Get adjacent parents (incoming neighbors).
 
Result< std::unordered_set< std::size_t >, ErrorTypeget_neighbours (std::size_t vertex_id) const
 Get all adjacent neighbors (incoming or outgoing).
 
Result< std::unordered_set< std::size_t >, ErrorTypeget_outgoing_edges (std::size_t vertex_id) const
 Get outgoing edge ids for a vertex.
 
Result< std::unordered_set< std::size_t >, ErrorTypeget_incoming_edges (std::size_t vertex_id) const
 Get incoming edge ids for a vertex.
 
std::ranges::forward_range auto get_vertices () const &
 View of all vertex payloads.
 
std::ranges::forward_range auto get_edges () const &
 View of all edge records.
 

Detailed Description

template<Hashable V, Hashable E>
class cgrapht::DirectedGraph< V, E >

Directed graph with hashed vertex and edge ids.

Template Parameters
VVertex payload type.
EEdge payload type.
Note
Both V and E must be hashable types.

Definition at line 63 of file graph.hpp.

Member Function Documentation

◆ add_edge()

template<Hashable V, Hashable E>
Result< std::size_t, ErrorType > cgrapht::DirectedGraph< V, E >::add_edge ( std::size_t  from_id,
std::size_t  to_id,
const E &  e 
)

Add a directed edge between two vertices.

Parameters
from_idSource vertex id.
to_idDestination vertex id.
eEdge payload.
Returns
Result containing the edge id or an error.

Definition at line 177 of file graph.hpp.

References cgrapht::ABSENT_VERTEX, cgrapht::EDGE_ALREADY_EXISTS, cgrapht::Result< SUCCESS, ERROR >::error(), cgrapht::Edge< E >::from_id, and cgrapht::Result< SUCCESS, ERROR >::success().

◆ add_vertex()

template<Hashable V, Hashable E>
Result< std::size_t, ErrorType > cgrapht::DirectedGraph< V, E >::add_vertex ( const V &  v)

Add a vertex to the graph.

Parameters
vVertex payload.
Returns
Result containing the vertex id or an error.

Definition at line 156 of file graph.hpp.

References cgrapht::Result< SUCCESS, ERROR >::success().

◆ delete_edge()

template<Hashable V, Hashable E>
Result< std::size_t, ErrorType > cgrapht::DirectedGraph< V, E >::delete_edge ( std::size_t  edge_id)

Delete an edge by id.

Parameters
edge_idEdge id.
Returns
Result containing the deleted edge id or an error.

Definition at line 195 of file graph.hpp.

References cgrapht::ABSENT_EDGE, cgrapht::Result< SUCCESS, ERROR >::error(), and cgrapht::Result< SUCCESS, ERROR >::success().

◆ delete_vertex()

template<Hashable V, Hashable E>
Result< std::size_t, ErrorType > cgrapht::DirectedGraph< V, E >::delete_vertex ( std::size_t  vertex_id)

Delete a vertex if it has no incident edges.

Parameters
vertex_idVertex id.
Returns
Result containing the deleted vertex id or an error.

Definition at line 165 of file graph.hpp.

References cgrapht::ABSENT_VERTEX, cgrapht::Result< SUCCESS, ERROR >::error(), cgrapht::Result< SUCCESS, ERROR >::success(), and cgrapht::VERTEX_NOT_FREE.

◆ get_children()

template<Hashable V, Hashable E>
Result< std::unordered_set< std::size_t >, ErrorType > cgrapht::DirectedGraph< V, E >::get_children ( std::size_t  vertex_id) const

Get adjacent children (outgoing neighbors).

Parameters
vertex_idVertex id.
Returns
Result containing a set of vertex ids or an error.

Definition at line 220 of file graph.hpp.

References cgrapht::ABSENT_VERTEX.

◆ get_edge()

template<Hashable V, Hashable E>
Result< Edge< E >, ErrorType > cgrapht::DirectedGraph< V, E >::get_edge ( std::size_t  id) const

Fetch an edge record by id.

Parameters
idEdge id.
Returns
Result containing the edge or an error.

Definition at line 213 of file graph.hpp.

References cgrapht::ABSENT_EDGE.

◆ get_edges()

template<Hashable V, Hashable E>
std::ranges::forward_range auto cgrapht::DirectedGraph< V, E >::get_edges ( ) const &
inline

View of all edge records.

Returns
Forward range of edges.

Definition at line 151 of file graph.hpp.

◆ get_incoming_edges()

template<Hashable V, Hashable E>
Result< std::unordered_set< std::size_t >, ErrorType > cgrapht::DirectedGraph< V, E >::get_incoming_edges ( std::size_t  vertex_id) const

Get incoming edge ids for a vertex.

Parameters
vertex_idVertex id.
Returns
Result containing a set of edge ids or an error.

Definition at line 273 of file graph.hpp.

References cgrapht::ABSENT_VERTEX.

◆ get_neighbours()

template<Hashable V, Hashable E>
Result< std::unordered_set< std::size_t >, ErrorType > cgrapht::DirectedGraph< V, E >::get_neighbours ( std::size_t  vertex_id) const

Get all adjacent neighbors (incoming or outgoing).

Parameters
vertex_idVertex id.
Returns
Result containing a set of vertex ids or an error.

Definition at line 244 of file graph.hpp.

References cgrapht::ABSENT_VERTEX.

◆ get_outgoing_edges()

template<Hashable V, Hashable E>
Result< std::unordered_set< std::size_t >, ErrorType > cgrapht::DirectedGraph< V, E >::get_outgoing_edges ( std::size_t  vertex_id) const

Get outgoing edge ids for a vertex.

Parameters
vertex_idVertex id.
Returns
Result containing a set of edge ids or an error.

Definition at line 265 of file graph.hpp.

References cgrapht::ABSENT_VERTEX.

◆ get_parents()

template<Hashable V, Hashable E>
Result< std::unordered_set< std::size_t >, ErrorType > cgrapht::DirectedGraph< V, E >::get_parents ( std::size_t  vertex_id) const

Get adjacent parents (incoming neighbors).

Parameters
vertex_idVertex id.
Returns
Result containing a set of vertex ids or an error.

Definition at line 232 of file graph.hpp.

References cgrapht::ABSENT_VERTEX.

◆ get_vertex()

template<Hashable V, Hashable E>
Result< V, ErrorType > cgrapht::DirectedGraph< V, E >::get_vertex ( std::size_t  id) const

Fetch a vertex payload by id.

Parameters
idVertex id.
Returns
Result containing the vertex or an error.

Definition at line 206 of file graph.hpp.

References cgrapht::ABSENT_VERTEX, cgrapht::Result< SUCCESS, ERROR >::error(), and cgrapht::Result< SUCCESS, ERROR >::success().

◆ get_vertices()

template<Hashable V, Hashable E>
std::ranges::forward_range auto cgrapht::DirectedGraph< V, E >::get_vertices ( ) const &
inline

View of all vertex payloads.

Returns
Forward range of vertices.

Definition at line 143 of file graph.hpp.


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