Bridges-C++  3.1.1
Bridges(C++API)
Classes | Public Member Functions | List of all members
bridges::datastructure::GraphAdjList< K, E1, E2 > Class Template Reference

#include <Element.h>

Inheritance diagram for bridges::datastructure::GraphAdjList< K, E1, E2 >:
bridges::datastructure::DataStructure

Detailed Description

template<typename K, typename E1 = K, typename E2 = E1>
class bridges::datastructure::GraphAdjList< K, E1, E2 >

This class provides methods to represent adjacency list based graphs.

The class is simply a wrapper around the C++ STL unordered_map class and thus derives all its operations from it.

Parameters
Kused as an index to retrieve vertices,
E1data type used to store vertex specific information,
E2data type used to store edge specific information
Author
Kalpathi Subramanian
Date
Last modified 4/22/18, 7/12/19

There is a tutorial about Graph Adjacency List : http://bridgesuncc.github.io/tutorials/Graph_AL.html

Classes

class  constVertexElementSet_listhelper
 This is a helper class to return sets of vertices ina way that are iterable with range for loops. Students should not have to use this directly. More...
 
class  KeySet_helper
 This is a helper class to return sets of vertices ina way that are iterable with range for loops. Students should not have to use this directly. More...
 
class  VertexElementSet_listhelper
 This is a helper class to return sets of vertices in a way that are iterable with range for loops. Students should have to use this directly. More...
 

Public Member Functions

 GraphAdjList ()=default
 
 GraphAdjList (GraphAdjList &&gr)=default
 
virtual ~GraphAdjList () override
 
virtual const string getDStype () const override
 
void addVertex (const K &k, const E1 &e=E1())
 
void addEdge (const K &src, const K &dest, const E2 &data=E2())
 add an edge with data. More...
 
const E1 & getVertexData (const K &src) &
 
void setVertexData (const K &vertID, E1 const &data)
 
E2 & getEdgeData (const K &src, const K &dest)
 
E2 const & getEdgeData (const K &src, const K &dest) const
 
void setEdgeData (const K &src, const K &dest, E2 &data)
 
unordered_map< K, Element< E1 > * > * getVertices ()
 
const unordered_map< K, Element< E1 > * > * getVertices () const
 
const Element< E1 > * getVertex (const K &key) const
 
Element< E1 > * getVertex (const K &key)
 
const unordered_map< K, SLelement< Edge< K, E2 > > * > & getAdjacencyList () const
 
SLelement< Edge< K, E2 > > * getAdjacencyList (const K &k)
 
const SLelement< Edge< K, E2 > > * getAdjacencyList (const K &k) const
 
ElementVisualizergetVisualizer (const K &k)
 
LinkVisualizergetLinkVisualizer (const K &k1, const K &k2)
 
void forceLargeVisualization (bool f)
 
void forceSmallVisualization (bool f)
 
KeySet_helper keySet () const
 
SLelement< Edge< K, E2 > >::SLelement_listhelper outgoingEdgeSetOf (K const &k)
 
SLelement< Edge< K, E2 > >::SLelement_constlisthelper outgoingEdgeSetOf (K const &k) const
 
VertexElementSet_listhelper vertexSet ()
 returns a set of vertices (Element<E>) that conforms to STL list interface. That means we can use range for More...
 
constVertexElementSet_listhelper vertexSet () const
 returns a set of vertices (Element<E>) that conforms to STL list interface. That means we can use range for More...
 
- Public Member Functions inherited from bridges::datastructure::DataStructure
virtual ~DataStructure ()=default
 

Constructor & Destructor Documentation

◆ GraphAdjList() [1/2]

template<typename K, typename E1 = K, typename E2 = E1>
bridges::datastructure::GraphAdjList< K, E1, E2 >::GraphAdjList ( )
default

◆ GraphAdjList() [2/2]

template<typename K, typename E1 = K, typename E2 = E1>
bridges::datastructure::GraphAdjList< K, E1, E2 >::GraphAdjList ( GraphAdjList< K, E1, E2 > &&  gr)
default

◆ ~GraphAdjList()

template<typename K, typename E1 = K, typename E2 = E1>
virtual bridges::datastructure::GraphAdjList< K, E1, E2 >::~GraphAdjList ( )
inlineoverridevirtual

Member Function Documentation

◆ addEdge()

template<typename K, typename E1 = K, typename E2 = E1>
void bridges::datastructure::GraphAdjList< K, E1, E2 >::addEdge ( const K &  src,
const K &  dest,
const E2 &  data = E2() 
)
inline

add an edge with data.

Note that this function adds the edge regardless of the contents of the adjacency list; its the user's responsibility to ensure there are no duplicates and ensure consistency.

Parameters
srcThe key of the source Vertex
destThe key of the destination Vertex
dataThe edge data
Exceptions
out_of_rangeIf "src" or "dest" is non-existent within this graph
bad_allocIf allocation of a graph adjacency list item failed

◆ addVertex()

template<typename K, typename E1 = K, typename E2 = E1>
void bridges::datastructure::GraphAdjList< K, E1, E2 >::addVertex ( const K &  k,
const E1 &  e = E1() 
)
inline

Adds a vertex of key "k" and value "e" to the graph, and initializes its adjacency list; If this key already exists then this will not create a new vertex.

Parameters
kThe vertex key
eThe vertex data

◆ forceLargeVisualization()

template<typename K, typename E1 = K, typename E2 = E1>
void bridges::datastructure::GraphAdjList< K, E1, E2 >::forceLargeVisualization ( bool  f)
inline

◆ forceSmallVisualization()

template<typename K, typename E1 = K, typename E2 = E1>
void bridges::datastructure::GraphAdjList< K, E1, E2 >::forceSmallVisualization ( bool  f)
inline

◆ getAdjacencyList() [1/3]

template<typename K, typename E1 = K, typename E2 = E1>
const unordered_map<K, SLelement<Edge<K, E2> >*>& bridges::datastructure::GraphAdjList< K, E1, E2 >::getAdjacencyList ( ) const
inline

Return the adjacency list

Returns
The adjacency list of the graph

◆ getAdjacencyList() [2/3]

template<typename K, typename E1 = K, typename E2 = E1>
SLelement<Edge<K, E2> >* bridges::datastructure::GraphAdjList< K, E1, E2 >::getAdjacencyList ( const K &  k)
inline

Returns adjacency list of a vertex with name k

Parameters
kThe key of the source vertex
Exceptions
out_of_rangeIf key is non-existent within this graph
Returns
The adjacency list of key "k"

◆ getAdjacencyList() [3/3]

template<typename K, typename E1 = K, typename E2 = E1>
const SLelement<Edge<K, E2> >* bridges::datastructure::GraphAdjList< K, E1, E2 >::getAdjacencyList ( const K &  k) const
inline

Returns adjacency list of a vertex with name k - const version

Parameters
kThe key of the source vertex
Exceptions
out_of_rangeIf key is non-existent within this graph
Returns
The adjacency list of key "k"

◆ getDStype()

template<typename K, typename E1 = K, typename E2 = E1>
virtual const string bridges::datastructure::GraphAdjList< K, E1, E2 >::getDStype ( ) const
inlineoverridevirtual
Returns
The string representation of this data structure type

Implements bridges::datastructure::DataStructure.

◆ getEdgeData() [1/2]

template<typename K, typename E1 = K, typename E2 = E1>
E2& bridges::datastructure::GraphAdjList< K, E1, E2 >::getEdgeData ( const K &  src,
const K &  dest 
)
inline

Gets edge data for the edge from "src" to "dest"

Parameters
srcThe key of the source Vertex
destThe key of the destination Vertex
Returns
edge specific data

◆ getEdgeData() [2/2]

template<typename K, typename E1 = K, typename E2 = E1>
E2 const& bridges::datastructure::GraphAdjList< K, E1, E2 >::getEdgeData ( const K &  src,
const K &  dest 
) const
inline

Gets edge data for the edge from "src" to "dest" - const version

Parameters
srcThe key of the source Vertex
destThe key of the destination Vertex
Returns
edge specific data

◆ getLinkVisualizer()

template<typename K, typename E1 = K, typename E2 = E1>
LinkVisualizer* bridges::datastructure::GraphAdjList< K, E1, E2 >::getLinkVisualizer ( const K &  k1,
const K &  k2 
)
inline

Returns the link visualizer corresponding to two graph nodes with an existing link; error returned if no link exists.

Parameters
k1The key of the link source vertex
k2The key of the link destination vertex
Returns
the visualizer that controls the attributes of this link

◆ getVertex() [1/2]

template<typename K, typename E1 = K, typename E2 = E1>
const Element<E1>* bridges::datastructure::GraphAdjList< K, E1, E2 >::getVertex ( const K &  key) const
inline

Return the vertex corresponding to a key

Returns
the requested vertex of this graph or nullptr if not found

◆ getVertex() [2/2]

template<typename K, typename E1 = K, typename E2 = E1>
Element<E1>* bridges::datastructure::GraphAdjList< K, E1, E2 >::getVertex ( const K &  key)
inline

Return the requested vertex corresponding to a key - non-const version

Returns
the requested vertex of this graph or nullptr if not found

◆ getVertexData()

template<typename K, typename E1 = K, typename E2 = E1>
const E1& bridges::datastructure::GraphAdjList< K, E1, E2 >::getVertexData ( const K &  src) &
inline

Gets vertex data for a graph vertex

Parameters
srcThe key of the source vertex
Returns
E1 vertex specific data

◆ getVertices() [1/2]

template<typename K, typename E1 = K, typename E2 = E1>
unordered_map<K, Element<E1>*>* bridges::datastructure::GraphAdjList< K, E1, E2 >::getVertices ( )
inline

Return the graph nodes

Returns
The vertex list of this graph

◆ getVertices() [2/2]

template<typename K, typename E1 = K, typename E2 = E1>
const unordered_map<K, Element<E1>*>* bridges::datastructure::GraphAdjList< K, E1, E2 >::getVertices ( ) const
inline

Return the graph nodes - const version

Returns
The vertex list of this graph

◆ getVisualizer()

template<typename K, typename E1 = K, typename E2 = E1>
ElementVisualizer* bridges::datastructure::GraphAdjList< K, E1, E2 >::getVisualizer ( const K &  k)
inline

Returns the visualizer corresponding to a graph vertex; convenient method to set attributes of the graph vertex

Parameters
kThe key of the graph vertex
Returns
the visualizer that controls the attributes of this node

◆ keySet()

template<typename K, typename E1 = K, typename E2 = E1>
KeySet_helper bridges::datastructure::GraphAdjList< K, E1, E2 >::keySet ( ) const
inline

returns a set of all keys (read only) that conforms to STL list interface. That means we can use range for

◆ outgoingEdgeSetOf() [1/2]

template<typename K, typename E1 = K, typename E2 = E1>
SLelement<Edge<K, E2> >::SLelement_listhelper bridges::datastructure::GraphAdjList< K, E1, E2 >::outgoingEdgeSetOf ( K const &  k)
inline

◆ outgoingEdgeSetOf() [2/2]

template<typename K, typename E1 = K, typename E2 = E1>
SLelement<Edge<K, E2> >::SLelement_constlisthelper bridges::datastructure::GraphAdjList< K, E1, E2 >::outgoingEdgeSetOf ( K const &  k) const
inline

◆ setEdgeData()

template<typename K, typename E1 = K, typename E2 = E1>
void bridges::datastructure::GraphAdjList< K, E1, E2 >::setEdgeData ( const K &  src,
const K &  dest,
E2 &  data 
)
inline

Loads edge specific information for the edge from "src" to "dest"

Parameters
srcThe key of the source Vertex
destThe key of the destination Vertex
dataedge data

◆ setVertexData()

template<typename K, typename E1 = K, typename E2 = E1>
void bridges::datastructure::GraphAdjList< K, E1, E2 >::setVertexData ( const K &  vertID,
E1 const &  data 
)
inline

Loads vertex specific information for a graph vertex

Parameters
vertIDThe key of Vertex
datadata to set

◆ vertexSet() [1/2]

template<typename K, typename E1 = K, typename E2 = E1>
VertexElementSet_listhelper bridges::datastructure::GraphAdjList< K, E1, E2 >::vertexSet ( )
inline

returns a set of vertices (Element<E>) that conforms to STL list interface. That means we can use range for

◆ vertexSet() [2/2]

template<typename K, typename E1 = K, typename E2 = E1>
constVertexElementSet_listhelper bridges::datastructure::GraphAdjList< K, E1, E2 >::vertexSet ( ) const
inline

returns a set of vertices (Element<E>) that conforms to STL list interface. That means we can use range for


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