cgv
Loading...
Searching...
No Matches
cgv::math::adjacency_list< v_type > Class Template Reference

A graph represented in an adjacency list. More...

#include <adjacency_list.h>

Public Types

typedef v_type vertex_type
 
typedef v_type::edge_type edge_type
 

Public Member Functions

 adjacency_list (const unsigned vnum, bool directed=true)
 creates a graph with vnum vertices and zero edges the graph is directed if the flag directed is true
 
 adjacency_list (const adjacency_list &al)
 copy constructor
 
adjacency_listoperator= (const adjacency_list &al)
 assignment operator
 
virtual ~adjacency_list ()
 destructor of adjacency_list
 
void resize (const unsigned &vnum)
 resize number of vertices, all edge data is removed
 
void clear ()
 
const unsigned nverts () const
 return number of vertices
 
void remove_all_edges ()
 removes all edges
 
vertex_type & vertex (unsigned i)
 access vertex i
 
const vertex_type & vertex (unsigned i) const
 access const vertex i
 
bool is_directed () const
 returns true if the graph is a directed one
 
bool edge_exists (int start, int end) const
 checks if edge is already in list
 
bool add_edge (const edge_type &e)
 adds an edge to the list definded by the start and end vertex
 
bool add_edge (unsigned int start, unsigned int end)
 adds an edge to the list definded by the start and end vertex
 
void add_vertex (const vertex_type &v)
 add new vertex to graph
 

Public Attributes

std::vector< vertex_type > * vertices
 vertices
 
bool directed
 flag indicating a directed/undirected graph
 

Detailed Description

template<typename v_type>
class cgv::math::adjacency_list< v_type >

A graph represented in an adjacency list.

To create a basic graph without extra information stored per vertex or edge use the predefined type cgv::math::graph: cgv::math::graph g;

To create a basic weighted graph with an additional weight attribute per edge use the predefined type cgv::math::weighted_graph; cgv::math::weighted_graph wg;

To create a graph with extra attributes per edge and vertex:

struct my_edge: public cgv::math::edge { double my_extra_edge_attr; };

struct my_vertex : public cgv::math::vertex<my_edge> { int my_extra_vertex_attr; };

typedef cgv::math::adjacency_list< my_vertex > my_graph; my_graph g; ...

Definition at line 73 of file adjacency_list.h.

Member Typedef Documentation

◆ edge_type

template<typename v_type >
typedef v_type::edge_type cgv::math::adjacency_list< v_type >::edge_type

Definition at line 77 of file adjacency_list.h.

◆ vertex_type

template<typename v_type >
typedef v_type cgv::math::adjacency_list< v_type >::vertex_type

Definition at line 76 of file adjacency_list.h.

Constructor & Destructor Documentation

◆ adjacency_list() [1/3]

template<typename v_type >
cgv::math::adjacency_list< v_type >::adjacency_list ( )
inline

Definition at line 86 of file adjacency_list.h.

◆ adjacency_list() [2/3]

template<typename v_type >
cgv::math::adjacency_list< v_type >::adjacency_list ( const unsigned  vnum,
bool  directed = true 
)
inline

creates a graph with vnum vertices and zero edges the graph is directed if the flag directed is true

Definition at line 94 of file adjacency_list.h.

References cgv::math::adjacency_list< v_type >::directed, and cgv::math::adjacency_list< v_type >::vertices.

◆ adjacency_list() [3/3]

template<typename v_type >
cgv::math::adjacency_list< v_type >::adjacency_list ( const adjacency_list< v_type > &  al)
inline

◆ ~adjacency_list()

template<typename v_type >
virtual cgv::math::adjacency_list< v_type >::~adjacency_list ( )
inlinevirtual

destructor of adjacency_list

Definition at line 124 of file adjacency_list.h.

References cgv::math::adjacency_list< v_type >::vertices.

Member Function Documentation

◆ add_edge() [1/2]

template<typename v_type >
bool cgv::math::adjacency_list< v_type >::add_edge ( const edge_type &  e)
inline

adds an edge to the list definded by the start and end vertex

Definition at line 207 of file adjacency_list.h.

References cgv::math::adjacency_list< v_type >::directed, cgv::math::adjacency_list< v_type >::edge_exists(), and cgv::math::adjacency_list< v_type >::nverts().

◆ add_edge() [2/2]

template<typename v_type >
bool cgv::math::adjacency_list< v_type >::add_edge ( unsigned int  start,
unsigned int  end 
)
inline

adds an edge to the list definded by the start and end vertex

Definition at line 235 of file adjacency_list.h.

References cgv::math::adjacency_list< v_type >::directed, cgv::math::adjacency_list< v_type >::edge_exists(), and cgv::math::adjacency_list< v_type >::nverts().

◆ add_vertex()

template<typename v_type >
void cgv::math::adjacency_list< v_type >::add_vertex ( const vertex_type &  v)
inline

add new vertex to graph

Definition at line 266 of file adjacency_list.h.

References cgv::math::adjacency_list< v_type >::vertices.

◆ clear()

template<typename v_type >
void cgv::math::adjacency_list< v_type >::clear ( )
inline

Definition at line 143 of file adjacency_list.h.

◆ edge_exists()

template<typename v_type >
bool cgv::math::adjacency_list< v_type >::edge_exists ( int  start,
int  end 
) const
inline

checks if edge is already in list

Definition at line 191 of file adjacency_list.h.

Referenced by cgv::math::adjacency_list< v_type >::add_edge(), and cgv::math::adjacency_list< v_type >::add_edge().

◆ is_directed()

template<typename v_type >
bool cgv::math::adjacency_list< v_type >::is_directed ( ) const
inline

returns true if the graph is a directed one

Definition at line 184 of file adjacency_list.h.

References cgv::math::adjacency_list< v_type >::directed.

Referenced by cgv::math::adjacency_list< v_type >::adjacency_list(), and cgv::math::adjacency_list< v_type >::operator=().

◆ nverts()

template<typename v_type >
const unsigned cgv::math::adjacency_list< v_type >::nverts ( ) const
inline

◆ operator=()

template<typename v_type >
adjacency_list & cgv::math::adjacency_list< v_type >::operator= ( const adjacency_list< v_type > &  al)
inline

◆ remove_all_edges()

template<typename v_type >
void cgv::math::adjacency_list< v_type >::remove_all_edges ( )
inline

removes all edges

Definition at line 161 of file adjacency_list.h.

References cgv::math::adjacency_list< v_type >::nverts().

Referenced by cgv::math::adjacency_list< v_type >::resize().

◆ resize()

template<typename v_type >
void cgv::math::adjacency_list< v_type >::resize ( const unsigned &  vnum)
inline

resize number of vertices, all edge data is removed

Definition at line 131 of file adjacency_list.h.

References cgv::math::adjacency_list< v_type >::remove_all_edges(), and cgv::math::adjacency_list< v_type >::vertices.

◆ vertex() [1/2]

template<typename v_type >
vertex_type & cgv::math::adjacency_list< v_type >::vertex ( unsigned  i)
inline

access vertex i

Definition at line 170 of file adjacency_list.h.

References cgv::math::adjacency_list< v_type >::vertices.

◆ vertex() [2/2]

template<typename v_type >
const vertex_type & cgv::math::adjacency_list< v_type >::vertex ( unsigned  i) const
inline

access const vertex i

Definition at line 176 of file adjacency_list.h.

References cgv::math::adjacency_list< v_type >::vertices.

Member Data Documentation

◆ directed

◆ vertices


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