raiigraph
C++ RAII for igraph data structures
Loading...
Searching...
No Matches
Public Member Functions | List of all members
raiigraph::Graph Class Reference

Wrapper around igraph_t objects with RAII behavior. More...

#include <Graph.hpp>

Public Member Functions

 Graph (igraph_integer_t num_vertices=0, igraph_bool_t directed=false)
 
 Graph (const IntVector &edges, igraph_integer_t num_vertices, igraph_bool_t directed)
 
 Graph (const igraph_vector_int_t *edges, igraph_integer_t num_vertices, igraph_bool_t directed)
 
 Graph (igraph_t &&graph)
 
 Graph (const Graph &other)
 
Graphoperator= (const Graph &other)
 
 Graph (Graph &&other)
 
Graphoperator= (Graph &&other)
 
 ~Graph ()
 
igraph_integer_t vcount () const
 
igraph_integer_t ecount () const
 
IntVector get_edgelist (igraph_bool_t by_col=false) const
 
igraph_bool_t is_directed () const
 
igraph_bool_t is_connected (igraph_connectedness_t mode=IGRAPH_WEAK) const
 
igraph_bool_t is_simple () const
 
igraph_bool_t has_loop () const
 
igraph_bool_t has_multiple () const
 
igraph_bool_t has_mutual (igraph_bool_t loops=false) const
 
bool is_tree (igraph_neimode_t mode=IGRAPH_ALL) const
 
bool is_forest (igraph_neimode_t mode=IGRAPH_ALL) const
 
bool is_dag () const
 
bool is_acyclic () const
 
 operator igraph_t * ()
 
 operator const igraph_t * () const
 
igraph_t * get ()
 
const igraph_t * get () const
 

Detailed Description

Wrapper around igraph_t objects with RAII behavior.

This class has ownership of the underlying igraph_t object, handling both its initialization and destruction. Users should only pass instances of this class to igraph functions that accept an already-initialized graph. Users should not attempt to destroy the graph manually as this is done automatically when the Graph goes out of scope.

Constructor & Destructor Documentation

◆ Graph() [1/6]

raiigraph::Graph::Graph ( igraph_integer_t  num_vertices = 0,
igraph_bool_t  directed = false 
)
inline

Create an empty graph, i.e., with no edges.

Parameters
num_verticesNumber of vertices.
directedWhether the graph is directed.

◆ Graph() [2/6]

raiigraph::Graph::Graph ( const IntVector edges,
igraph_integer_t  num_vertices,
igraph_bool_t  directed 
)
inline
Parameters
edgesEdges between vertices, stored as row-major matrix with two columns. Each row corresponds to an edge and contains its connected vertices. For example, the i-th edge is defined from the first vertex at edges[2 * i] to the second vertex at edges[2 * i + 1].
num_verticesNumber of vertices in the graph. This should be greater than the largest index in edges.
directedWhether the graph is directed.

◆ Graph() [3/6]

raiigraph::Graph::Graph ( const igraph_vector_int_t *  edges,
igraph_integer_t  num_vertices,
igraph_bool_t  directed 
)
inline
Parameters
edgesEdges between vertices, stored as a vector of non-negative vertex indices of length equal to twice the number of edges. The i-th edge is defined from the first vertex at edges[2 * i] to the second vertex at edges[2 * i + 1].
num_verticesNumber of vertices in the graph. This should be greater than the largest index in edges.
directedWhether the graph is directed.

◆ Graph() [4/6]

raiigraph::Graph::Graph ( igraph_t &&  graph)
inline
Parameters
graphAn initialized graph to take ownership of.

◆ Graph() [5/6]

raiigraph::Graph::Graph ( const Graph other)
inline
Parameters
otherGraph to be copy-constructed from.

◆ Graph() [6/6]

raiigraph::Graph::Graph ( Graph &&  other)
inline
Parameters
otherGraph to be move-constructed from. This constructor will leave other in a valid but unspecified state.

◆ ~Graph()

raiigraph::Graph::~Graph ( )
inline

Destructor.

Member Function Documentation

◆ ecount()

igraph_integer_t raiigraph::Graph::ecount ( ) const
inline
Returns
Number of edges in the graph.

◆ get() [1/2]

igraph_t * raiigraph::Graph::get ( )
inline
Returns
Pointer to the underlying igraph graph. This is guaranteed to be non-NULL and initialized.

◆ get() [2/2]

const igraph_t * raiigraph::Graph::get ( ) const
inline
Returns
Pointer to the underlying igraph graph. This is guaranteed to be non-NULL and initialized.

◆ get_edgelist()

IntVector raiigraph::Graph::get_edgelist ( igraph_bool_t  by_col = false) const
inline
Parameters
by_colWhether to return the edges in a column-major array.
Returns
Vector containing a matrix with two columns. Each row corresponds to an edge and contains its connected vertices. If by_col = false, this is the same as the sequence of edges used in the constructor.

◆ has_loop()

igraph_bool_t raiigraph::Graph::has_loop ( ) const
inline
Returns
Whether the graph contains a loop edge, i.e., from a vertex to itself.

◆ has_multiple()

igraph_bool_t raiigraph::Graph::has_multiple ( ) const
inline
Returns
Whether the graph contains multiple edges between the same pair of vertices.

◆ has_mutual()

igraph_bool_t raiigraph::Graph::has_mutual ( igraph_bool_t  loops = false) const
inline
Parameters
loopsWhether to consider directed self-loops to be mutual.
Returns
Whether the directed graph contains mutual edges, i.e., an edge from A to B and also an edge from B back to A.

◆ is_acyclic()

bool raiigraph::Graph::is_acyclic ( ) const
inline
Returns
Whether the graph is an acyclic graph.

◆ is_connected()

igraph_bool_t raiigraph::Graph::is_connected ( igraph_connectedness_t  mode = IGRAPH_WEAK) const
inline
Parameters
modeThe connectedness mode, for directed graphs. This can be either IGRAPH_WEAK or IGRAPH_STRONG. Ignored for undirected graphs.
Returns
Whether the graph is (weakly or strongly) connected.

◆ is_dag()

bool raiigraph::Graph::is_dag ( ) const
inline
Returns
Whether the graph is a directed acyclic graph.

◆ is_directed()

igraph_bool_t raiigraph::Graph::is_directed ( ) const
inline
Returns
Whether the graph is directed.

◆ is_forest()

bool raiigraph::Graph::is_forest ( igraph_neimode_t  mode = IGRAPH_ALL) const
inline
Parameters
modeWhether to test for an out-tree, an in-tree or to ignore edge directions, for directed graphs; see is_tree().
Returns
Whether a graph is a forest, i.e., all connected components are trees.

◆ is_simple()

igraph_bool_t raiigraph::Graph::is_simple ( ) const
inline
Returns
Whether the graph is simple, i.e., no loops or multiple edges.

◆ is_tree()

bool raiigraph::Graph::is_tree ( igraph_neimode_t  mode = IGRAPH_ALL) const
inline
Parameters
modeWhether to test for an out-tree, an in-tree or to ignore edge directions, for directed graphs. The respective possible values are IGRAPH_OUT, IGRAPH_IN and IGRAPH_ALL. Ignored for undirected graphs.
Returns
Whether the graph is a tree, i.e., connected with no cycles.

◆ operator const igraph_t *()

raiigraph::Graph::operator const igraph_t * ( ) const
inline
Returns
Const pointer to the underlying igraph graph object. This is guaranteed to be non-NULL and initialized.

◆ operator igraph_t *()

raiigraph::Graph::operator igraph_t * ( )
inline
Returns
Pointer to the underlying igraph graph object. This is guaranteed to be non-NULL and initialized.

◆ operator=() [1/2]

Graph & raiigraph::Graph::operator= ( const Graph other)
inline
Parameters
otherGraph to be copy-assigned from.

◆ operator=() [2/2]

Graph & raiigraph::Graph::operator= ( Graph &&  other)
inline
Parameters
otherGraph to be move-assigned from. This constructor will leave other in a valid but unspecified state.

◆ vcount()

igraph_integer_t raiigraph::Graph::vcount ( ) const
inline
Returns
Number of vertices in the graph.

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