All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
List of all members | Classes | Public Member Functions | Private Member Functions
ListGraph Class Reference

Detailed Description

ListGraph is a versatile and fast undirected graph implementation based on linked lists that are stored in std::vector structures.

This type fully conforms to the Graph concept and it also provides several useful additional functionalities. Most of its member functions and nested classes are documented only in the concept class.

This class provides only linear time counting for nodes, edges and arcs.

See Also
concepts::Graph
ListDigraph

#include <lemon/list_graph.h>

Inherits GraphExtender< Base >.

Classes

class  Snapshot
 Class to make a snapshot of the graph and restore it later. More...
 

Public Member Functions

 ListGraph ()
 
Node addNode ()
 Add a new node to the graph.
 
Edge addEdge (Node u, Node v)
 Add a new edge to the graph.
 
void erase (Node n)
 Erase a node from the graph.
 
void erase (Edge e)
 Erase an edge from the graph.
 
bool valid (Node n) const
 Node validity check.
 
bool valid (Edge e) const
 Edge validity check.
 
bool valid (Arc a) const
 Arc validity check.
 
void changeU (Edge e, Node n)
 Change the first node of an edge.
 
void changeV (Edge e, Node n)
 Change the second node of an edge.
 
void contract (Node a, Node b, bool r=true)
 Contract two nodes.
 
void clear ()
 Clear the graph.
 
void reserveNode (int n)
 Reserve memory for nodes.
 
void reserveEdge (int m)
 Reserve memory for edges.
 

Private Member Functions

 ListGraph (const ListGraph &)
 Graphs are not copy constructible. Use GraphCopy instead.
 
void operator= (const ListGraph &)
 Assignment of a graph to another one is not allowed. Use GraphCopy instead.
 

Constructor & Destructor Documentation

ListGraph ( )
inline

Constructor.

Member Function Documentation

Node addNode ( )
inline

This function adds a new node to the graph.

Returns
The new node.
Edge addEdge ( Node  u,
Node  v 
)
inline

This function adds a new edge to the graph between nodes u and v with inherent orientation from node u to node v.

Returns
The new edge.
void erase ( Node  n)
inline

This function erases the given node along with its incident arcs from the graph.

Note
All iterators referencing the removed node or the incident edges are invalidated, of course.
void erase ( Edge  e)
inline

This function erases the given edge from the graph.

Note
All iterators referencing the removed edge are invalidated, of course.
bool valid ( Node  n) const
inline

This function gives back true if the given node is valid, i.e. it is a real node of the graph.

Warning
A removed node could become valid again if new nodes are added to the graph.
bool valid ( Edge  e) const
inline

This function gives back true if the given edge is valid, i.e. it is a real edge of the graph.

Warning
A removed edge could become valid again if new edges are added to the graph.
bool valid ( Arc  a) const
inline

This function gives back true if the given arc is valid, i.e. it is a real arc of the graph.

Warning
A removed arc could become valid again if new edges are added to the graph.
void changeU ( Edge  e,
Node  n 
)
inline

This function changes the first node of the given edge e to n.

Note
EdgeIt and ArcIt iterators referencing the changed edge are invalidated and all other iterators whose base node is the changed node are also invalidated.
Warning
This functionality cannot be used together with the Snapshot feature.
void changeV ( Edge  e,
Node  n 
)
inline

This function changes the second node of the given edge e to n.

Note
EdgeIt iterators referencing the changed edge remain valid, but ArcIt iterators referencing the changed edge and all other iterators whose base node is the changed node are also invalidated.
Warning
This functionality cannot be used together with the Snapshot feature.
void contract ( Node  a,
Node  b,
bool  r = true 
)
inline

This function contracts the given two nodes. Node b is removed, but instead of deleting its incident edges, they are joined to node a. If the last parameter r is true (this is the default value), then the newly created loops are removed.

Note
The moved edges are joined to node a using changeU() or changeV(), thus all edge and arc iterators whose base node is b are invalidated. Moreover all iterators referencing node b or the removed loops are also invalidated. Other iterators remain valid.
Warning
This functionality cannot be used together with the Snapshot feature.
void clear ( )
inline

This function erases all nodes and arcs from the graph.

Note
All iterators of the graph are invalidated, of course.
void reserveNode ( int  n)
inline

Using this function, it is possible to avoid superfluous memory allocation: if you know that the graph you want to build will be large (e.g. it will contain millions of nodes and/or edges), then it is worth reserving space for this amount before starting to build the graph.

See Also
reserveEdge()
void reserveEdge ( int  m)
inline

Using this function, it is possible to avoid superfluous memory allocation: if you know that the graph you want to build will be large (e.g. it will contain millions of nodes and/or edges), then it is worth reserving space for this amount before starting to build the graph.

See Also
reserveNode()