fennec
Loading...
Searching...
No Matches
fennec::graph< VertexT, EdgeT >

Graph Data Structure, describes sets of arbitrarily connected vertices. More...

#include <graph.h>

Detailed Description

template<typename VertexT, typename EdgeT = empty_t>
struct fennec::graph< VertexT, EdgeT >
Property Value
stable
dynamic
homogenous
distinct
ordered
space \(O(N)\)
linear
access \(O(1)\)
find \(O(1)\)
insertion \(O(1)\)
deletion \(O(N)\)

Graphs contain vertices and edges. Graphs are either directed or undirected. This structure allows the creation of both directed and undirected edges. As far as what that means; a directed graph means that edges have direction, where there are edges that are "to" and "from," rather than "between" which is used in undirected graphs.

An undirected graph is connected if there is a path between every pair of vertices in the graph.

A directed graph is weakly connected if replacing all of its directed edges with undirected edges would produce a connected graph. We will call this "disjointed"

A directed graph is semi-connected if there is a directed path p for uv or vu for every pair of vertices u, v. We will call this "unilateral"

A directed graph is strongly-connected if there is a directed path p for uv and vu for every pair of vertices u, v. We will call this "connected"

Template Parameters
VertexTThe type associated with each vertex
EdgeTThe type associated with each edge

Public Types

using edge_t = EdgeT
 Alias for the edge type.
 
using vertex_t = VertexT
 Alias for the vertex type.
 
using vertex_pool_t = object_pool< vertex_t >
 Alias for a pool of vertices.
 
using edge_map_t = dynarray< map< size_t, size_t > >
 Alias for edge mapping.
 
using edge_pool_t = object_pool< edge_t >
 Alias for a pool of edges.
 

Public Member Functions

Constructors & Destructor
constexpr graph ()=default
 Default Constructor, initializes empty graph.
 
constexpr ~graph ()=default
 Destructor.
 
Assignment Operators
constexpr graphoperator= (const graph &g)=default
 Copy Assignment Operator.
 
constexpr graphoperator= (graph &&g)=default
 Move Assignment Operator.
 
Properties
constexpr size_t num_vertices () const
 
constexpr size_t num_edges () const
 
constexpr size_t capacity () const
 
constexpr bool empty () const
 
constexpr bool exists (size_t a, size_t b) const
 Checks if there exists an edge e that starts from a and ends at b
 
constexpr bool is_symmetric (size_t a, size_t b) const
 Checks if there exists an edge e0 that starts from a and ends at b and e1 that starts from b and ends at a
 
constexpr bool is_undirected (size_t a, size_t b) const
 Checks if there exists an edge e between a and b
 
Access
constexpr vertex_toperator[] (size_t vertex)
 vertex Access Operator
 
constexpr const vertex_toperator[] (size_t vertex) const
 vertex Const Access Operator
 
constexpr edge_toperator[] (size_t a, size_t b)
 edge Access Operator
 
constexpr const edge_toperator[] (size_t a, size_t b) const
 edge Const Access Operator
 
list< size_toutgoing (size_t vertex)
 Getter for a list of vertices x that vertex has an edge to x...
 
list< size_tincoming (size_t vertex)
 Getter for a list of vertices x that vertex has an edge from x...
 
list< size_tsymmetric (size_t vertex)
 Getter for a list of vertices x that vertex has an edge to and from x...
 
list< size_tundirected (size_t vertex)
 Getter for a list of vertices x that vertex has an edge to and from x... and share the same value.
 
const auto * edges (size_t vertex)
 Getter for the internal storage of mapped edges from this vertex. Use this when you want to iterate over edges that start from this vertex.
 
Modifiers
constexpr size_t insert (vertex_t &&vertex)
 Move a new vertex into the graph.
 
constexpr size_t insert (const vertex_t &vertex)
 Copy a new vertex into the graph.
 
template<typename... ArgsT>
constexpr size_t emplace (ArgsT &&...args)
 Construct a new vertex in the graph.
 
constexpr void erase (size_t vertex)
 Erase a vertex from the graph.
 
template<typename... ArgsT>
constexpr void make_edge (size_t a, size_t b, ArgsT &&...args)
 Form an edge from vertex a to vertex b
 
template<typename... ArgsT>
constexpr void make_edge2 (size_t a, size_t b, ArgsT &&...args)
 Form an undirected edge between vertex a and vertex b
 
constexpr void cut_edge (size_t a, size_t b)
 Disconnect an edge from vertex a to vertex b
 
constexpr void cut_edge2 (size_t a, size_t b)
 Disconnect both directed edges between vertices a and b
 
void cut (size_t n)
 Break all edges to and from n
 
void clear ()
 Clear the graph, destructing all vertices and edges.
 

Static Public Attributes

static constexpr size_t npos = -1
 Constant for a non-existent vertex.
 

Member Function Documentation

◆ operator=() [1/2]

template<typename VertexT , typename EdgeT = empty_t>
constexpr graph & fennec::graph< VertexT, EdgeT >::operator= ( const graph< VertexT, EdgeT > &  g)
constexprdefault
Parameters
gThe graph to copy
Returns
A reference to this after assigning g

◆ operator=() [2/2]

template<typename VertexT , typename EdgeT = empty_t>
constexpr graph & fennec::graph< VertexT, EdgeT >::operator= ( graph< VertexT, EdgeT > &&  g)
constexprdefault
Parameters
gThe graph to copy
Returns
A reference to this after assigning g

◆ num_vertices()

template<typename VertexT , typename EdgeT = empty_t>
constexpr size_t fennec::graph< VertexT, EdgeT >::num_vertices ( ) const
inlineconstexpr
Returns
The number of vertices in the graph

◆ num_edges()

template<typename VertexT , typename EdgeT = empty_t>
constexpr size_t fennec::graph< VertexT, EdgeT >::num_edges ( ) const
inlineconstexpr
Returns
The number of edges in the graph

◆ capacity()

template<typename VertexT , typename EdgeT = empty_t>
constexpr size_t fennec::graph< VertexT, EdgeT >::capacity ( ) const
inlineconstexpr
Returns
The capacity of the vertex pool

◆ empty()

template<typename VertexT , typename EdgeT = empty_t>
constexpr bool fennec::graph< VertexT, EdgeT >::empty ( ) const
inlineconstexpr
Returns
true when there are no vertices in the graph, false otherwise

◆ exists()

template<typename VertexT , typename EdgeT = empty_t>
constexpr bool fennec::graph< VertexT, EdgeT >::exists ( size_t  a,
size_t  b 
) const
inlineconstexpr
Parameters
aThe first vertex
bThe second vertex
Returns
true if the edge exists, false otherwise

◆ is_symmetric()

template<typename VertexT , typename EdgeT = empty_t>
constexpr bool fennec::graph< VertexT, EdgeT >::is_symmetric ( size_t  a,
size_t  b 
) const
inlineconstexpr
Parameters
aThe first vertex
bThe second vertex
Returns
true if both edges exist, false otherwise

◆ is_undirected()

template<typename VertexT , typename EdgeT = empty_t>
constexpr bool fennec::graph< VertexT, EdgeT >::is_undirected ( size_t  a,
size_t  b 
) const
inlineconstexpr
Parameters
aThe first vertex
bThe second vertex
Returns
true if both edges exist, false otherwise

◆ operator[]() [1/4]

template<typename VertexT , typename EdgeT = empty_t>
constexpr vertex_t & fennec::graph< VertexT, EdgeT >::operator[] ( size_t  vertex)
inlineconstexpr
Parameters
vertexThe id of the vertex
Returns
A reference to the value stored in the vertex

◆ operator[]() [2/4]

template<typename VertexT , typename EdgeT = empty_t>
constexpr const vertex_t & fennec::graph< VertexT, EdgeT >::operator[] ( size_t  vertex) const
inlineconstexpr
Parameters
vertexThe id of the vertex
Returns
A reference to the value stored in the vertex

◆ operator[]() [3/4]

template<typename VertexT , typename EdgeT = empty_t>
constexpr edge_t * fennec::graph< VertexT, EdgeT >::operator[] ( size_t  a,
size_t  b 
)
inlineconstexpr
Parameters
aThe id of the first vertex
bThe id of the second vertex
Returns
A pointer to the value stored in the edge, nullptr if not found

◆ operator[]() [4/4]

template<typename VertexT , typename EdgeT = empty_t>
constexpr const edge_t * fennec::graph< VertexT, EdgeT >::operator[] ( size_t  a,
size_t  b 
) const
inlineconstexpr
Parameters
aThe id of the first vertex
bThe id of the second vertex
Returns
A const-qualified pointer to the value stored in the edge, nullptr if not found

◆ outgoing()

template<typename VertexT , typename EdgeT = empty_t>
list< size_t > fennec::graph< VertexT, EdgeT >::outgoing ( size_t  vertex)
inline
Parameters
vertexThe id of the vertex
Returns
A list containing all vertices x with edges from vertex to x...

◆ incoming()

template<typename VertexT , typename EdgeT = empty_t>
list< size_t > fennec::graph< VertexT, EdgeT >::incoming ( size_t  vertex)
inline
Parameters
vertexThe id of the vertex
Returns
A list containing all vertices x with edges from x... to vertex

◆ symmetric()

template<typename VertexT , typename EdgeT = empty_t>
list< size_t > fennec::graph< VertexT, EdgeT >::symmetric ( size_t  vertex)
inline
Parameters
vertexThe id of the vertex
Returns
A list containing all vertices x that have symmetric edges with vertex

◆ undirected()

template<typename VertexT , typename EdgeT = empty_t>
list< size_t > fennec::graph< VertexT, EdgeT >::undirected ( size_t  vertex)
inline

"Joined" edges may also be referred to as "undirected." A joined, or undirected, edge may be turned into a directed edge by changing the weight object associated with the edge, or by removing one of the sub-edges.

Parameters
vertexThe id of the vertex
Returns
A list containing all vertices x that have symmetric edges with vertex

◆ edges()

template<typename VertexT , typename EdgeT = empty_t>
const auto * fennec::graph< VertexT, EdgeT >::edges ( size_t  vertex)
inline
Parameters
vertexThe id of the vertex
Returns
A pointer to a map containing edges mapped from this vertex

◆ insert() [1/2]

template<typename VertexT , typename EdgeT = empty_t>
constexpr size_t fennec::graph< VertexT, EdgeT >::insert ( vertex_t &&  vertex)
inlineconstexpr
Parameters
vertexThe vertex to move into the graph
Returns
The id of the new vertex

◆ insert() [2/2]

template<typename VertexT , typename EdgeT = empty_t>
constexpr size_t fennec::graph< VertexT, EdgeT >::insert ( const vertex_t vertex)
inlineconstexpr
Parameters
vertexThe vertex to copy into the graph
Returns
The id of the new vertex

◆ emplace()

template<typename VertexT , typename EdgeT = empty_t>
template<typename... ArgsT>
constexpr size_t fennec::graph< VertexT, EdgeT >::emplace ( ArgsT &&...  args)
inlineconstexpr
Template Parameters
ArgsTThe types of the arguments
Parameters
argsThe arguments to construct the vertex with
Returns
The id of the new vertex

◆ erase()

template<typename VertexT , typename EdgeT = empty_t>
constexpr void fennec::graph< VertexT, EdgeT >::erase ( size_t  vertex)
inlineconstexpr
Parameters
vertexThe id of the vertex to erase

◆ make_edge()

template<typename VertexT , typename EdgeT = empty_t>
template<typename... ArgsT>
constexpr void fennec::graph< VertexT, EdgeT >::make_edge ( size_t  a,
size_t  b,
ArgsT &&...  args 
)
inlineconstexpr
Template Parameters
ArgsTThe argument types
Parameters
aThe first vertex id
bThe second vertex id
argsThe arguments to construct the edge with

◆ make_edge2()

template<typename VertexT , typename EdgeT = empty_t>
template<typename... ArgsT>
constexpr void fennec::graph< VertexT, EdgeT >::make_edge2 ( size_t  a,
size_t  b,
ArgsT &&...  args 
)
inlineconstexpr
Template Parameters
ArgsTThe argument types
Parameters
aThe first vertex id
bThe second vertex id
argsThe arguments to construct the edge with

◆ cut_edge()

template<typename VertexT , typename EdgeT = empty_t>
constexpr void fennec::graph< VertexT, EdgeT >::cut_edge ( size_t  a,
size_t  b 
)
inlineconstexpr
Parameters
aThe first vertex id
bThe second vertex id

◆ cut_edge2()

template<typename VertexT , typename EdgeT = empty_t>
constexpr void fennec::graph< VertexT, EdgeT >::cut_edge2 ( size_t  a,
size_t  b 
)
inlineconstexpr
Parameters
aThe first vertex id
bThe second vertex id

◆ cut()

template<typename VertexT , typename EdgeT = empty_t>
void fennec::graph< VertexT, EdgeT >::cut ( size_t  n)
inline
Parameters
nThe vertex id

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