Easy_rider
 
Loading...
Searching...
No Matches
Graph< T, U > Class Template Reference

A templated graph storing nodes of type T and edges of type U. More...

#include <Graph.h>

Public Types

enum class  AddEdgeResult { Success , AlreadyExists , Crosses }
 Result of attempting to insert an edge with checks. More...
 

Public Member Functions

 Graph ()=default
 Default-constructs an empty graph.
 
void addNode (const T &node)
 Add a node to the graph.
 
void addEdge (const U &edge)
 Add an edge to the graph without checking for duplicates.
 
AddEdgeResult addEdgeIfNotExists (const U &edge)
 Attempt to add a directed edge, rejecting duplicates or crossings.
 
std::vector< T > getNodes () const
 Retrieve all nodes in the graph.
 
std::vector< U > getEdges () const
 Retrieve all edges in the graph.
 

Detailed Description

template<NodeConcept T, typename U>
requires EdgeConcept<U, T>
class Graph< T, U >

A templated graph storing nodes of type T and edges of type U.

Template Parameters
TA Node type satisfying NodeConcept.
UAn Edge type satisfying EdgeConcept<U,T>.

Member Enumeration Documentation

◆ AddEdgeResult

template<NodeConcept T, typename U >
enum class Graph::AddEdgeResult
strong

Result of attempting to insert an edge with checks.

Enumerator
Success 

Edge was inserted.

AlreadyExists 

Duplicate edge.

Crosses 

Would cross/overlap an existing edge.

Member Function Documentation

◆ addEdge()

template<NodeConcept T, typename U >
void Graph< T, U >::addEdge ( const U &  edge)
inline

Add an edge to the graph without checking for duplicates.

Parameters
edgeThe edge to add.

◆ addEdgeIfNotExists()

template<NodeConcept T, typename U >
AddEdgeResult Graph< T, U >::addEdgeIfNotExists ( const U &  edge)
inline

Attempt to add a directed edge, rejecting duplicates or crossings.

Parameters
edgeThe edge to add.
Returns

◆ addNode()

template<NodeConcept T, typename U >
void Graph< T, U >::addNode ( const T &  node)
inline

Add a node to the graph.

Parameters
nodeThe node to add.

◆ getEdges()

template<NodeConcept T, typename U >
std::vector< U > Graph< T, U >::getEdges ( ) const
inline

Retrieve all edges in the graph.

Returns
A vector of edges.

◆ getNodes()

template<NodeConcept T, typename U >
std::vector< T > Graph< T, U >::getNodes ( ) const
inline

Retrieve all nodes in the graph.

Returns
A vector of nodes.

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