andres::graph
Public Types | Public Member Functions | List of all members
andres::graph::Graph< VISITOR > Class Template Reference

Undirected graph, implemented as an adjacency list. More...

#include <graph.hxx>

Public Types

typedef VISITOR Visitor
typedef detail::VertexIterator VertexIterator
typedef detail::EdgeIterator EdgeIterator
typedef
detail::Adjacencies::const_iterator 
AdjacencyIterator
typedef
AdjacencyIterator::value_type 
AdjacencyType

Public Member Functions

 Graph (const Visitor &=Visitor())
 Construct an undirected graph.
 Graph (const std::size_t, const Visitor &=Visitor())
 Construct an undirected graph with an initial number of vertices.
void assign (const Visitor &=Visitor())
 Clear an undirected graph.
void assign (const std::size_t, const Visitor &=Visitor())
 Clear an undirected graph with an initial number of vertices.
void reserveVertices (const std::size_t)
 Reserve memory for at least the given total number of vertices.
void reserveEdges (const std::size_t)
 Reserve memory for at least the given total number of edges.
VertexIterator verticesFromVertexBegin (const std::size_t) const
 Get an iterator to the beginning of the sequence of vertices reachable from a given vertex via a single edge.
VertexIterator verticesFromVertexEnd (const std::size_t) const
 Get an iterator to the end of the sequence of vertices reachable from a given vertex via a single edge.
VertexIterator verticesToVertexBegin (const std::size_t) const
 Get an iterator to the beginning of the sequence of vertices from which a given vertex is reachable via a single edge.
VertexIterator verticesToVertexEnd (const std::size_t) const
 Get an iterator to the end of the sequence of vertices from which a given vertex is reachable via a single edge.
EdgeIterator edgesFromVertexBegin (const std::size_t) const
 Get an iterator to the beginning of the sequence of edges that originate from a given vertex.
EdgeIterator edgesFromVertexEnd (const std::size_t) const
 Get an iterator to the end of the sequence of edges that originate from a given vertex.
EdgeIterator edgesToVertexBegin (const std::size_t) const
 Get an iterator to the beginning of the sequence of edges that are incident to a given vertex.
EdgeIterator edgesToVertexEnd (const std::size_t) const
 Get an iterator to the end of the sequence of edges that are incident to a given vertex.
AdjacencyIterator adjacenciesFromVertexBegin (const std::size_t) const
 Get an iterator to the beginning of the sequence of adjacencies that originate from a given vertex.
AdjacencyIterator adjacenciesFromVertexEnd (const std::size_t) const
 Get an iterator to the end of the sequence of adjacencies that originate from a given vertex.
AdjacencyIterator adjacenciesToVertexBegin (const std::size_t) const
 Get an iterator to the beginning of the sequence of adjacencies incident to a given vertex.
AdjacencyIterator adjacenciesToVertexEnd (const std::size_t) const
 Get an iterator to the end of the sequence of adjacencies incident to a given vertex.
std::size_t numberOfVertices () const
 Get the number of vertices.
std::size_t numberOfEdges () const
 Get the number of edges.
std::size_t numberOfEdgesFromVertex (const std::size_t) const
 Get the number of edges that originate from a given vertex.
std::size_t numberOfEdgesToVertex (const std::size_t) const
 Get the number of edges that are incident to a given vertex.
std::size_t vertexOfEdge (const std::size_t, const std::size_t) const
 Get the integer index of a vertex of an edge.
std::size_t edgeFromVertex (const std::size_t, const std::size_t) const
 Get the integer index of an edge that originates from a given vertex.
std::size_t edgeToVertex (const std::size_t, const std::size_t) const
 Get the integer index of an edge that is incident to a given vertex.
std::size_t vertexFromVertex (const std::size_t, const std::size_t) const
 Get the integer index of a vertex reachable from a given vertex via a single edge.
std::size_t vertexToVertex (const std::size_t, const std::size_t) const
 Get the integer index of a vertex from which a given vertex is reachable via a single edge.
const AdjacencyTypeadjacencyFromVertex (const std::size_t, const std::size_t) const
 Get the j-th adjacency from a vertex.
const AdjacencyTypeadjacencyToVertex (const std::size_t, const std::size_t) const
 Get the j-th adjacency to a vertex.
std::pair< bool, std::size_t > findEdge (const std::size_t, const std::size_t) const
 Search for an edge (in logarithmic time).
bool multipleEdgesEnabled () const
 Indicate if multiple edges are enabled.
std::size_t insertVertex ()
 Insert an additional vertex.
std::size_t insertVertices (const std::size_t)
 Insert additional vertices.
std::size_t insertEdge (const std::size_t, const std::size_t)
 Insert an additional edge.
void eraseVertex (const std::size_t)
 Erase a vertex and all edges connecting this vertex.
void eraseEdge (const std::size_t)
 Erase an edge.
bool & multipleEdgesEnabled ()
 Indicate if multiple edges are enabled.

Detailed Description

template<typename VISITOR = IdleGraphVisitor<std::size_t>>
class andres::graph::Graph< VISITOR >

Undirected graph, implemented as an adjacency list.

Definition at line 27 of file graph.hxx.

Member Typedef Documentation

template<typename VISITOR = IdleGraphVisitor<std::size_t>>
typedef detail::Adjacencies::const_iterator andres::graph::Graph< VISITOR >::AdjacencyIterator

Definition at line 32 of file graph.hxx.

template<typename VISITOR = IdleGraphVisitor<std::size_t>>
typedef AdjacencyIterator::value_type andres::graph::Graph< VISITOR >::AdjacencyType

Definition at line 33 of file graph.hxx.

template<typename VISITOR = IdleGraphVisitor<std::size_t>>
typedef detail::EdgeIterator andres::graph::Graph< VISITOR >::EdgeIterator

Definition at line 31 of file graph.hxx.

template<typename VISITOR = IdleGraphVisitor<std::size_t>>
typedef detail::VertexIterator andres::graph::Graph< VISITOR >::VertexIterator

Definition at line 30 of file graph.hxx.

template<typename VISITOR = IdleGraphVisitor<std::size_t>>
typedef VISITOR andres::graph::Graph< VISITOR >::Visitor

Definition at line 29 of file graph.hxx.

Constructor & Destructor Documentation

template<typename VISITOR >
andres::graph::Graph< VISITOR >::Graph ( const Visitor visitor = Visitor())
inline

Construct an undirected graph.

Parameters
visitorVisitor to follow changes of integer indices of vertices and edges.

Definition at line 99 of file graph.hxx.

template<typename VISITOR >
andres::graph::Graph< VISITOR >::Graph ( const std::size_t  numberOfVertices,
const Visitor visitor = Visitor() 
)
inline

Construct an undirected graph with an initial number of vertices.

Parameters
numberOfVerticesNumber of vertices.
visitorVisitor to follow changes of integer indices of vertices and edges.

Definition at line 115 of file graph.hxx.

Member Function Documentation

template<typename VISITOR >
Graph< VISITOR >::AdjacencyIterator andres::graph::Graph< VISITOR >::adjacenciesFromVertexBegin ( const std::size_t  vertex) const
inline

Get an iterator to the beginning of the sequence of adjacencies that originate from a given vertex.

Parameters
vertexInteger index of the vertex.
Returns
AdjacencyIterator.
See Also
adjacenciesFromVertexEnd()

Definition at line 571 of file graph.hxx.

template<typename VISITOR >
Graph< VISITOR >::AdjacencyIterator andres::graph::Graph< VISITOR >::adjacenciesFromVertexEnd ( const std::size_t  vertex) const
inline

Get an iterator to the end of the sequence of adjacencies that originate from a given vertex.

Parameters
vertexInteger index of the vertex.
Returns
AdjacencyIterator.
See Also
adjacenciesFromVertexBegin()

Definition at line 586 of file graph.hxx.

template<typename VISITOR >
Graph< VISITOR >::AdjacencyIterator andres::graph::Graph< VISITOR >::adjacenciesToVertexBegin ( const std::size_t  vertex) const
inline

Get an iterator to the beginning of the sequence of adjacencies incident to a given vertex.

Parameters
vertexInteger index of the vertex.
Returns
AdjacencyIterator.
See Also
adjacenciesToVertexEnd()

Definition at line 601 of file graph.hxx.

template<typename VISITOR >
Graph< VISITOR >::AdjacencyIterator andres::graph::Graph< VISITOR >::adjacenciesToVertexEnd ( const std::size_t  vertex) const
inline

Get an iterator to the end of the sequence of adjacencies incident to a given vertex.

Parameters
vertexInteger index of the vertex.
Returns
AdjacencyIterator.
See Also
adjacenciesToVertexBegin()

Definition at line 616 of file graph.hxx.

template<typename VISITOR >
const Graph< VISITOR >::AdjacencyType & andres::graph::Graph< VISITOR >::adjacencyFromVertex ( const std::size_t  vertex,
const std::size_t  j 
) const
inline

Get the j-th adjacency from a vertex.

Parameters
vertexVertex.
jNumber of the adjacency.

Definition at line 653 of file graph.hxx.

template<typename VISITOR >
const Graph< VISITOR >::AdjacencyType & andres::graph::Graph< VISITOR >::adjacencyToVertex ( const std::size_t  vertex,
const std::size_t  j 
) const
inline

Get the j-th adjacency to a vertex.

Parameters
vertexVertex.
jNumber of the adjacency.

Definition at line 667 of file graph.hxx.

template<typename VISITOR >
void andres::graph::Graph< VISITOR >::assign ( const Visitor visitor = Visitor())
inline

Clear an undirected graph.

Parameters
visitorVisitor to follow changes of integer indices of vertices and edges.

Definition at line 133 of file graph.hxx.

template<typename VISITOR >
void andres::graph::Graph< VISITOR >::assign ( const std::size_t  numberOfVertices,
const Visitor visitor = Visitor() 
)
inline

Clear an undirected graph with an initial number of vertices.

Parameters
numberOfVerticesNumber of vertices.
visitorVisitor to follow changes of integer indices of vertices and edges.

Definition at line 149 of file graph.hxx.

template<typename VISITOR >
std::size_t andres::graph::Graph< VISITOR >::edgeFromVertex ( const std::size_t  vertex,
const std::size_t  j 
) const
inline

Get the integer index of an edge that originates from a given vertex.

Parameters
vertexInteger index of a vertex.
jNumber of the edge; between 0 and numberOfEdgesFromVertex(vertex) - 1.
See Also
numberOfEdgesFromVertex()

Definition at line 230 of file graph.hxx.

template<typename VISITOR >
Graph< VISITOR >::EdgeIterator andres::graph::Graph< VISITOR >::edgesFromVertexBegin ( const std::size_t  vertex) const
inline

Get an iterator to the beginning of the sequence of edges that originate from a given vertex.

Parameters
vertexInteger index of the vertex.
Returns
EdgeIterator.
See Also
edgesFromVertexEnd()

Definition at line 511 of file graph.hxx.

template<typename VISITOR >
Graph< VISITOR >::EdgeIterator andres::graph::Graph< VISITOR >::edgesFromVertexEnd ( const std::size_t  vertex) const
inline

Get an iterator to the end of the sequence of edges that originate from a given vertex.

Parameters
vertexInteger index of the vertex.
Returns
EdgeIterator.
See Also
edgesFromVertexBegin()

Definition at line 526 of file graph.hxx.

template<typename VISITOR >
Graph< VISITOR >::EdgeIterator andres::graph::Graph< VISITOR >::edgesToVertexBegin ( const std::size_t  vertex) const
inline

Get an iterator to the beginning of the sequence of edges that are incident to a given vertex.

Parameters
vertexInteger index of the vertex.
Returns
EdgeIterator.
See Also
edgesToVertexEnd()

Definition at line 541 of file graph.hxx.

template<typename VISITOR >
Graph< VISITOR >::EdgeIterator andres::graph::Graph< VISITOR >::edgesToVertexEnd ( const std::size_t  vertex) const
inline

Get an iterator to the end of the sequence of edges that are incident to a given vertex.

Parameters
vertexInteger index of the vertex.
Returns
EdgeIterator.
See Also
edgesToVertexBegin()

Definition at line 556 of file graph.hxx.

template<typename VISITOR >
std::size_t andres::graph::Graph< VISITOR >::edgeToVertex ( const std::size_t  vertex,
const std::size_t  j 
) const
inline

Get the integer index of an edge that is incident to a given vertex.

Parameters
vertexInteger index of a vertex.
jNumber of the edge; between 0 and numberOfEdgesFromVertex(vertex) - 1.
See Also
numberOfEdgesToVertex()

Definition at line 246 of file graph.hxx.

template<typename VISITOR >
void andres::graph::Graph< VISITOR >::eraseEdge ( const std::size_t  edgeIndex)
inline

Erase an edge.

Parameters
edgeIndexInteger index of the edge to be erased.

Definition at line 421 of file graph.hxx.

template<typename VISITOR >
void andres::graph::Graph< VISITOR >::eraseVertex ( const std::size_t  vertexIndex)

Erase a vertex and all edges connecting this vertex.

Parameters
vertexIndexInteger index of the vertex to be erased.

Definition at line 357 of file graph.hxx.

template<typename VISITOR >
std::pair< bool, std::size_t > andres::graph::Graph< VISITOR >::findEdge ( const std::size_t  vertex0,
const std::size_t  vertex1 
) const
inline

Search for an edge (in logarithmic time).

Parameters
vertex0first vertex of the edge.
vertex1second vertex of the edge.
Returns
if an edge from vertex0 to vertex1 exists, pair.first is true and pair.second is the index of such an edge. if no edge from vertex0 to vertex1 exists, pair.first is false and pair.second is undefined.

Definition at line 684 of file graph.hxx.

template<typename VISITOR >
std::size_t andres::graph::Graph< VISITOR >::insertEdge ( const std::size_t  vertexIndex0,
const std::size_t  vertexIndex1 
)
inline

Insert an additional edge.

Parameters
vertexIndex0Integer index of the first vertex in the edge.
vertexIndex1Integer index of the second vertex in the edge.
Returns
Integer index of the newly inserted edge.

Definition at line 325 of file graph.hxx.

template<typename VISITOR >
std::size_t andres::graph::Graph< VISITOR >::insertVertex ( )
inline

Insert an additional vertex.

Returns
Integer index of the newly inserted vertex.
See Also
insertVertices()

Definition at line 293 of file graph.hxx.

template<typename VISITOR >
std::size_t andres::graph::Graph< VISITOR >::insertVertices ( const std::size_t  number)
inline

Insert additional vertices.

Parameters
numberNumber of new vertices to be inserted.
Returns
Integer index of the first newly inserted vertex.
See Also
insertVertex()

Definition at line 308 of file graph.hxx.

template<typename VISITOR >
bool andres::graph::Graph< VISITOR >::multipleEdgesEnabled ( ) const
inline

Indicate if multiple edges are enabled.

Returns
true if multiple edges are enabled, false otherwise.

Definition at line 718 of file graph.hxx.

template<typename VISITOR >
bool & andres::graph::Graph< VISITOR >::multipleEdgesEnabled ( )
inline

Indicate if multiple edges are enabled.

Enable multiple edges like this: graph.multipleEdgesEnabled() = true;

Returns
reference the a Boolean flag.

Definition at line 730 of file graph.hxx.

template<typename VISITOR >
std::size_t andres::graph::Graph< VISITOR >::numberOfEdges ( ) const
inline

Get the number of edges.

Definition at line 173 of file graph.hxx.

template<typename VISITOR >
std::size_t andres::graph::Graph< VISITOR >::numberOfEdgesFromVertex ( const std::size_t  vertex) const
inline

Get the number of edges that originate from a given vertex.

Parameters
vertexInteger index of a vertex.
See Also
edgeFromVertex()

Definition at line 185 of file graph.hxx.

template<typename VISITOR >
std::size_t andres::graph::Graph< VISITOR >::numberOfEdgesToVertex ( const std::size_t  vertex) const
inline

Get the number of edges that are incident to a given vertex.

Parameters
vertexInteger index of a vertex.
See Also
edgeToVertex()

Definition at line 199 of file graph.hxx.

template<typename VISITOR >
std::size_t andres::graph::Graph< VISITOR >::numberOfVertices ( ) const
inline

Get the number of vertices.

Definition at line 165 of file graph.hxx.

template<typename VISITOR >
void andres::graph::Graph< VISITOR >::reserveEdges ( const std::size_t  number)
inline

Reserve memory for at least the given total number of edges.

Parameters
numberTotal number of edges.

Definition at line 640 of file graph.hxx.

template<typename VISITOR >
void andres::graph::Graph< VISITOR >::reserveVertices ( const std::size_t  number)
inline

Reserve memory for at least the given total number of vertices.

Parameters
numberTotal number of vertices.

Definition at line 628 of file graph.hxx.

template<typename VISITOR >
std::size_t andres::graph::Graph< VISITOR >::vertexFromVertex ( const std::size_t  vertex,
const std::size_t  j 
) const
inline

Get the integer index of a vertex reachable from a given vertex via a single edge.

Parameters
vertexInteger index of a vertex.
jNumber of the vertex; between 0 and numberOfEdgesFromVertex(vertex) - 1.
See Also
numberOfEdgesFromVertex()

Definition at line 262 of file graph.hxx.

template<typename VISITOR >
std::size_t andres::graph::Graph< VISITOR >::vertexOfEdge ( const std::size_t  edge,
const std::size_t  j 
) const
inline

Get the integer index of a vertex of an edge.

Parameters
edgeInteger index of an edge.
jNumber of the vertex in the edge; either 0 or 1.

Definition at line 212 of file graph.hxx.

template<typename VISITOR >
std::size_t andres::graph::Graph< VISITOR >::vertexToVertex ( const std::size_t  vertex,
const std::size_t  j 
) const
inline

Get the integer index of a vertex from which a given vertex is reachable via a single edge.

Parameters
vertexInteger index of a vertex.
jNumber of the vertex; between 0 and numberOfEdgesFromVertex(vertex) - 1.
See Also
numberOfEdgesFromVertex()

Definition at line 278 of file graph.hxx.

template<typename VISITOR >
Graph< VISITOR >::VertexIterator andres::graph::Graph< VISITOR >::verticesFromVertexBegin ( const std::size_t  vertex) const
inline

Get an iterator to the beginning of the sequence of vertices reachable from a given vertex via a single edge.

Parameters
vertexInteger index of the vertex.
Returns
VertexIterator.
See Also
verticesFromVertexEnd()

Definition at line 451 of file graph.hxx.

template<typename VISITOR >
Graph< VISITOR >::VertexIterator andres::graph::Graph< VISITOR >::verticesFromVertexEnd ( const std::size_t  vertex) const
inline

Get an iterator to the end of the sequence of vertices reachable from a given vertex via a single edge.

Parameters
vertexInteger index of the vertex.
Returns
VertexIterator.
See Also
verticesFromVertexBegin()

Definition at line 466 of file graph.hxx.

template<typename VISITOR >
Graph< VISITOR >::VertexIterator andres::graph::Graph< VISITOR >::verticesToVertexBegin ( const std::size_t  vertex) const
inline

Get an iterator to the beginning of the sequence of vertices from which a given vertex is reachable via a single edge.

Parameters
vertexInteger index of the vertex.
Returns
VertexIterator.
See Also
verticesToVertexEnd()

Definition at line 481 of file graph.hxx.

template<typename VISITOR >
Graph< VISITOR >::VertexIterator andres::graph::Graph< VISITOR >::verticesToVertexEnd ( const std::size_t  vertex) const
inline

Get an iterator to the end of the sequence of vertices from which a given vertex is reachable via a single edge.

Parameters
vertexInteger index of the vertex.
Returns
VertexIterator.
See Also
verticesToVertexBegin()

Definition at line 496 of file graph.hxx.