NuriKit v0.1.0b2
Loading...
Searching...
No Matches
nuri::Subgraph< NT, ET, is_const > Class Template Reference

A subgraph of a graph. More...

#include <nuri/core/graph/subgraph.h>

Public Types

using graph_type = Graph<NT, ET>
using parent_type = internal::const_if_t<is_const, graph_type>
using node_data_type = NT
using edge_data_type = ET
using iterator = internal::SubNodeIterator<Subgraph, is_const>
using node_iterator = iterator
using const_iterator = internal::SubNodeIterator<Subgraph, true>
using const_node_iterator = const_iterator
using NodeRef = internal::SubNodeWrapper<Subgraph, is_const>
using ConstNodeRef = internal::SubNodeWrapper<Subgraph, true>
using edge_iterator = internal::SubEdgeIterator<Subgraph, is_const>
using const_edge_iterator = internal::SubEdgeIterator<Subgraph, true>
using EdgeRef = internal::SubEdgeWrapper<Subgraph, is_const>
using ConstEdgeRef = internal::SubEdgeWrapper<Subgraph, true>
using EdgesWrapper = internal::EdgesWrapper<Subgraph, is_const>
using ConstEdgesWrapper = internal::EdgesWrapper<Subgraph, true>
using adjacency_iterator = internal::SubAdjIterator<Subgraph, is_const>
using const_adjacency_iterator = internal::SubAdjIterator<Subgraph, true>
using AdjRef = internal::SubAdjWrapper<Subgraph, is_const>
using ConstAdjRef = internal::SubAdjWrapper<Subgraph, true>
template<bool other_const>
using Other = Subgraph<NT, ET, other_const>

Public Member Functions

 Subgraph (graph_type &&graph)=delete
 Subgraph (parent_type &graph)
 Construct an empty subgraph.
template<bool other_const, std::enable_if_t< is_const &&!other_const, int > = 0>
 Subgraph (const Other< other_const > &other)
 Converting constructor to allow implicit conversion from a non-const subgraph to a const subgraph.
template<bool other_const, std::enable_if_t< is_const &&!other_const, int > = 0>
 Subgraph (Other< other_const > &&other) noexcept
 Converting constructor to allow implicit conversion from a non-const subgraph to a const subgraph.
template<bool other_const, std::enable_if_t< is_const &&!other_const, int > = 0>
Subgraphoperator= (const Other< other_const > &other)
 Converting assignment operator to allow implicit conversion from a non-const subgraph to a const subgraph.
template<bool other_const, std::enable_if_t< is_const &&!other_const, int > = 0>
Subgraphoperator= (Other< other_const > &&other) noexcept
 Converting assignment operator to allow implicit conversion from a non-const subgraph to a const subgraph.
bool empty () const
 Whether the subgraph is empty.
int size () const
 Count number of nodes in the subgraph.
int num_nodes () const
 Count number of nodes in the subgraph.
int num_edges () const
 Count number of edges in the subgraph.
void update (internal::IndexSet &&nodes, internal::IndexSet &&edges)
 Change the set of nodes and edges in the subgraph.
void update_nodes (internal::IndexSet &&nodes) noexcept
 Change the set of nodes in the subgraph.
void update_edges (internal::IndexSet &&edges) noexcept
 Change the set of edges in the subgraph.
void refresh_edges ()
 Make this graph an induced subgraph of the parent graph.
void clear () noexcept
 Clear the subgraph.
void clear_edges () noexcept
 Clear the edges.
void reserve_nodes (int num_nodes)
 Reserve space for a number of nodes.
void reserve_edges (int num_edges)
 Reserve space for a number of edges.
void add_node (int id)
 Add a node to the subgraph.
void add_edge (int id)
 Add an edge to the subgraph. Also adds the incident nodes.
void add_nodes (const internal::IndexSet &nodes)
 Add nodes to the subgraph.
void add_edges (const internal::IndexSet &edges)
 Add edges to the subgraph. Also adds the incident nodes.
void add_nodes_with_edges (const internal::IndexSet &nodes)
 Add nodes to the subgraph, and update the edges.
bool contains_node (int id) const
 Check if a node is in the subgraph.
bool contains_node (typename graph_type::ConstNodeRef node) const
 Check if a node is in the subgraph.
bool contains_edge (int id) const
 Check if an edge is in the subgraph.
bool contains_edge (typename graph_type::ConstEdgeRef edge) const
 Check if an edge is in the subgraph.
NodeRef operator[] (int idx)
 Get a node in the subgraph.
ConstNodeRef operator[] (int idx) const
 Get a node in the subgraph.
NodeRef node (int idx)
 Get a node in the subgraph.
ConstNodeRef node (int idx) const
 Get a node in the subgraph.
EdgeRef edge (int idx)
 Get an edge in the subgraph.
ConstEdgeRef edge (int idx) const
 Get an edge in the subgraph.
internal::const_if_t< is_const, NT > & node_data (int idx)
 Get data of a node in the subgraph.
const NT & node_data (int idx) const
 Get data of a node in the subgraph.
internal::const_if_t< is_const, ET > & edge_data (int idx)
 Get data of an edge in the subgraph.
const ET & edge_data (int idx) const
 Get data of an edge in the subgraph.
std::conditional_t< is_const, typename parent_type::ConstNodeRef, typename parent_type::NodeRef > parent_node (int idx)
 Get a parent node of a node in the subgraph.
parent_type::ConstNodeRef parent_node (int idx) const
 Get a parent node of a node in the subgraph.
std::conditional_t< is_const, typename parent_type::ConstEdgeRef, typename parent_type::EdgeRef > parent_edge (int idx)
 Get a parent edge of an edge in the subgraph.
parent_type::ConstEdgeRef parent_edge (int idx) const
 Get a parent edge of an edge in the subgraph.
iterator find_node (int id)
 Find a node with the given id.
iterator find_node (typename graph_type::ConstNodeRef node)
 Find a node with the given id.
const_iterator find_node (int id) const
 Find a node with the given id.
const_iterator find_node (typename graph_type::ConstNodeRef node) const
 Find a node with the given id.
edge_iterator find_edge (int id)
 Find an edge with the given id.
edge_iterator find_edge (typename graph_type::ConstEdgeRef edge)
 Find an edge with the given id.
const_edge_iterator find_edge (int id) const
 Find an edge with the given id.
const_edge_iterator find_edge (typename graph_type::ConstEdgeRef edge) const
 Find an edge with the given id.
void erase_node (int idx)
 Erase a node from the subgraph. Corresponding edges will also be removed.
void erase_node (ConstNodeRef node)
 Erase a node from the subgraph.
void erase_edge (int idx)
 Erase an edge from the subgraph.
void erase_edge (ConstEdgeRef edge)
 Erase an edge from the subgraph.
void erase_nodes (const_iterator begin, const_iterator end)
 Erase range of nodes from the subgraph. Corresponding edges will also be removed.
void erase_edges (const_edge_iterator begin, const_edge_iterator end)
 Erase range of edges from the subgraph.
void erase_node_of (int id)
 Erase a node with given id from the subgraph. Corresponding edges will also be removed.
void erase_node_of (typename graph_type::ConstNodeRef node)
 Erase a node with given id from the subgraph. Corresponding edges will also be removed.
void erase_edge_of (int id)
 Erase an edge with given id from the subgraph.
void erase_edge_of (typename graph_type::ConstEdgeRef edge)
 Erase an edge with given id from the subgraph.
template<class UnaryPred>
void erase_nodes_if (UnaryPred pred)
 Erase matching nodes from the subgraph. Corresponding edges will also be removed.
template<class UnaryPred>
void erase_edges_if (UnaryPred &&pred)
 Erase matching edges from the subgraph.
void remap (const std::vector< int > &node_map, const std::vector< int > &edge_map)
 Re-map node/edge ids.
void remap_nodes (const std::vector< int > &node_map)
 Re-map node ids.
void remap_edges (const std::vector< int > &old_to_new)
 Re-map edge ids.
iterator begin ()
iterator end ()
const_iterator begin () const
const_iterator end () const
const_iterator cbegin () const
const_iterator cend () const
node_iterator node_begin ()
node_iterator node_end ()
const_node_iterator node_begin () const
const_node_iterator node_end () const
const_node_iterator node_cbegin () const
const_node_iterator node_cend () const
EdgesWrapper edges ()
ConstEdgesWrapper edges () const
edge_iterator edge_begin ()
edge_iterator edge_end ()
const_edge_iterator edge_begin () const
const_edge_iterator edge_end () const
const_edge_iterator edge_cbegin () const
const_edge_iterator edge_cend () const
const std::vector< int > & node_ids () const
 Get all node ids in the subgraph.
const std::vector< int > & edge_ids () const
 Get all edge ids in the subgraph.
int degree (int idx) const
 Count in-subgraph neighbors of a node.
edge_iterator find_edge (ConstNodeRef src, ConstNodeRef dst)
 Find edge between two nodes.
const_edge_iterator find_edge (ConstNodeRef src, ConstNodeRef dst) const
 Find edge between two nodes.
edge_iterator find_edge (typename graph_type::ConstNodeRef src, typename graph_type::ConstNodeRef dst)
 Find edge between two nodes.
const_edge_iterator find_edge (typename graph_type::ConstNodeRef src, typename graph_type::ConstNodeRef dst) const
 Find edge between two nodes.
adjacency_iterator find_adjacent (ConstNodeRef src, ConstNodeRef dst)
 Find adjacent node of a node.
const_adjacency_iterator find_adjacent (ConstNodeRef src, ConstNodeRef dst) const
 Find adjacent node of a node.
adjacency_iterator adj_begin (int idx)
adjacency_iterator adj_end (int idx)
const_adjacency_iterator adj_begin (int idx) const
const_adjacency_iterator adj_end (int idx) const
const_adjacency_iterator adj_cbegin (int idx) const
const_adjacency_iterator adj_cend (int idx) const
void rebind (parent_type &parent)
 Re-bind the subgraph to a new parent graph.

Static Public Member Functions

static Subgraph from_indices (parent_type &graph, internal::IndexSet &&nodes, internal::IndexSet &&edges)
 Construct a subgraph with the given nodes and edges.
static Subgraph from_nodes (parent_type &graph, internal::IndexSet &&nodes)
 Construct a subgraph with the given nodes and all edges connecting the nodes.
static Subgraph from_edges (parent_type &graph, internal::IndexSet &&edges)
 Construct a subgraph with the given edges and all nodes connected to the edges.

Friends

class Subgraph< NT, ET, true >

Detailed Description

template<class NT, class ET, bool is_const = false>
class nuri::Subgraph< NT, ET, is_const >

A subgraph of a graph.

Template Parameters
NTnode data type
ETedge data type
is_constwhether the subgraph is const. This is to support creating subgraphs of const graphs.
Note
Removing nodes/edges on the parent graph will invalidate the subgraph.

The subgraph is a non-owning view of a graph. A subgraph could be constructed by selecting nodes of the parent graph. The resulting subgraph will contain only the nodes and edges that are incident to the selected nodes.

The subgraph has very similar API to the graph. Here, we note major differences:

  • Adding/removing nodes/edges will just mark the nodes/edges as selected/unselected.
  • Some methods have different time complexity requirements. Refer to the documentation of each method for details.

In all time complexity specifications, \(V\) and \(E\) are the number of nodes and edges in the parent graph, and \(V'\) and \(E'\) are the number of nodes and edges in the subgraph, respectively.

Member Typedef Documentation

◆ adjacency_iterator

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::adjacency_iterator = internal::SubAdjIterator<Subgraph, is_const>

◆ AdjRef

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::AdjRef = internal::SubAdjWrapper<Subgraph, is_const>

◆ const_adjacency_iterator

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::const_adjacency_iterator = internal::SubAdjIterator<Subgraph, true>

◆ const_edge_iterator

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::const_edge_iterator = internal::SubEdgeIterator<Subgraph, true>

◆ const_iterator

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::const_iterator = internal::SubNodeIterator<Subgraph, true>

◆ const_node_iterator

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::const_node_iterator = const_iterator

◆ ConstAdjRef

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::ConstAdjRef = internal::SubAdjWrapper<Subgraph, true>

◆ ConstEdgeRef

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::ConstEdgeRef = internal::SubEdgeWrapper<Subgraph, true>

◆ ConstEdgesWrapper

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::ConstEdgesWrapper = internal::EdgesWrapper<Subgraph, true>

◆ ConstNodeRef

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::ConstNodeRef = internal::SubNodeWrapper<Subgraph, true>

◆ edge_data_type

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::edge_data_type = ET

◆ edge_iterator

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::edge_iterator = internal::SubEdgeIterator<Subgraph, is_const>

◆ EdgeRef

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::EdgeRef = internal::SubEdgeWrapper<Subgraph, is_const>

◆ EdgesWrapper

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::EdgesWrapper = internal::EdgesWrapper<Subgraph, is_const>

◆ graph_type

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::graph_type = Graph<NT, ET>

◆ iterator

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::iterator = internal::SubNodeIterator<Subgraph, is_const>

◆ node_data_type

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::node_data_type = NT

◆ node_iterator

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::node_iterator = iterator

◆ NodeRef

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::NodeRef = internal::SubNodeWrapper<Subgraph, is_const>

◆ Other

template<class NT, class ET, bool is_const = false>
template<bool other_const>
using nuri::Subgraph< NT, ET, is_const >::Other = Subgraph<NT, ET, other_const>

◆ parent_type

template<class NT, class ET, bool is_const = false>
using nuri::Subgraph< NT, ET, is_const >::parent_type = internal::const_if_t<is_const, graph_type>

Constructor & Destructor Documentation

◆ Subgraph() [1/4]

template<class NT, class ET, bool is_const = false>
nuri::Subgraph< NT, ET, is_const >::Subgraph ( graph_type && graph)
delete

◆ Subgraph() [2/4]

template<class NT, class ET, bool is_const = false>
nuri::Subgraph< NT, ET, is_const >::Subgraph ( parent_type & graph)
inline

Construct an empty subgraph.

Parameters
graphThe parent graph

◆ Subgraph() [3/4]

template<class NT, class ET, bool is_const = false>
template<bool other_const, std::enable_if_t< is_const &&!other_const, int > = 0>
nuri::Subgraph< NT, ET, is_const >::Subgraph ( const Other< other_const > & other)
inline

Converting constructor to allow implicit conversion from a non-const subgraph to a const subgraph.

Parameters
otherThe non-const subgraph

◆ Subgraph() [4/4]

template<class NT, class ET, bool is_const = false>
template<bool other_const, std::enable_if_t< is_const &&!other_const, int > = 0>
nuri::Subgraph< NT, ET, is_const >::Subgraph ( Other< other_const > && other)
inlinenoexcept

Converting constructor to allow implicit conversion from a non-const subgraph to a const subgraph.

Parameters
otherThe non-const subgraph

Member Function Documentation

◆ add_edge()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::add_edge ( int id)
inline

Add an edge to the subgraph. Also adds the incident nodes.

Parameters
idThe id of the edge to add
Note
Time complexity: \(O(E' + V')\) when the edge is not in the graph, \(O(\log E')\) otherwise.
If the edge is already in the subgraph, this is a no-op. If the edge id is out of range, the behavior is undefined.

◆ add_edges()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::add_edges ( const internal::IndexSet & edges)
inline

Add edges to the subgraph. Also adds the incident nodes.

Parameters
edgesThe new set of edges
Note
Time complexity: \(O(V' + E' + N \log N)\), where \(N\) is the number of new edges.
If any of the edge id is out of range, the behavior is undefined.

◆ add_node()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::add_node ( int id)
inline

Add a node to the subgraph.

Parameters
idThe id of the node to add
Note
Time complexity: \(O(V')\) when the node is not in the graph, \(O(\log V')\) otherwise.
If the node is already in the subgraph, this is a no-op. If the node id is out of range, the behavior is undefined.

◆ add_nodes()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::add_nodes ( const internal::IndexSet & nodes)
inline

Add nodes to the subgraph.

Parameters
nodesThe new set of nodes
Note
Time complexity: \(O(V')\).
If any of the node id is out of range, the behavior is undefined.

◆ add_nodes_with_edges()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::add_nodes_with_edges ( const internal::IndexSet & nodes)
inline

Add nodes to the subgraph, and update the edges.

Parameters
nodesThe new set of nodes
Note
Time complexity: same as from_nodes().
If any of the node id is out of range, the behavior is undefined.

◆ adj_begin() [1/2]

template<class NT, class ET, bool is_const = false>
adjacency_iterator nuri::Subgraph< NT, ET, is_const >::adj_begin ( int idx)
inline

◆ adj_begin() [2/2]

template<class NT, class ET, bool is_const = false>
const_adjacency_iterator nuri::Subgraph< NT, ET, is_const >::adj_begin ( int idx) const
inline

◆ adj_cbegin()

template<class NT, class ET, bool is_const = false>
const_adjacency_iterator nuri::Subgraph< NT, ET, is_const >::adj_cbegin ( int idx) const
inline

◆ adj_cend()

template<class NT, class ET, bool is_const = false>
const_adjacency_iterator nuri::Subgraph< NT, ET, is_const >::adj_cend ( int idx) const
inline

◆ adj_end() [1/2]

template<class NT, class ET, bool is_const = false>
adjacency_iterator nuri::Subgraph< NT, ET, is_const >::adj_end ( int idx)
inline

◆ adj_end() [2/2]

template<class NT, class ET, bool is_const = false>
const_adjacency_iterator nuri::Subgraph< NT, ET, is_const >::adj_end ( int idx) const
inline

◆ begin() [1/2]

template<class NT, class ET, bool is_const = false>
iterator nuri::Subgraph< NT, ET, is_const >::begin ( )
inline

◆ begin() [2/2]

template<class NT, class ET, bool is_const = false>
const_iterator nuri::Subgraph< NT, ET, is_const >::begin ( ) const
inline

◆ cbegin()

template<class NT, class ET, bool is_const = false>
const_iterator nuri::Subgraph< NT, ET, is_const >::cbegin ( ) const
inline

◆ cend()

template<class NT, class ET, bool is_const = false>
const_iterator nuri::Subgraph< NT, ET, is_const >::cend ( ) const
inline

◆ clear()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::clear ( )
inlinenoexcept

Clear the subgraph.

Note
This does not affect the parent graph.
There is no clear_nodes() member function because it is equivalent to this function.

◆ clear_edges()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::clear_edges ( )
inlinenoexcept

Clear the edges.

Note
This does not affect the parent graph.

◆ contains_edge() [1/2]

template<class NT, class ET, bool is_const = false>
bool nuri::Subgraph< NT, ET, is_const >::contains_edge ( int id) const
inline

Check if an edge is in the subgraph.

Parameters
idthe id of the edge to check
Returns
true if the edge is in the subgraph, false otherwise
Note
Time complexity: \(O(\log E')\).

◆ contains_edge() [2/2]

template<class NT, class ET, bool is_const = false>
bool nuri::Subgraph< NT, ET, is_const >::contains_edge ( typename graph_type::ConstEdgeRef edge) const
inline

Check if an edge is in the subgraph.

Parameters
edgeThe edge to check
Returns
true if the edge is in the subgraph, false otherwise
Note
This is equivalent to calling contains_edge(edge.id()).
Time complexity: \(O(\log E')\).

◆ contains_node() [1/2]

template<class NT, class ET, bool is_const = false>
bool nuri::Subgraph< NT, ET, is_const >::contains_node ( int id) const
inline

Check if a node is in the subgraph.

Parameters
idthe id of the node to check
Returns
true if the node is in the subgraph, false otherwise
Note
Time complexity: \(O(\log V')\).

◆ contains_node() [2/2]

template<class NT, class ET, bool is_const = false>
bool nuri::Subgraph< NT, ET, is_const >::contains_node ( typename graph_type::ConstNodeRef node) const
inline

Check if a node is in the subgraph.

Parameters
nodeThe node to check
Returns
true if the node is in the subgraph, false otherwise
Note
This is equivalent to calling contains_node(node.id()).
Time complexity: \(O(\log V')\).

◆ degree()

template<class NT, class ET, bool is_const = false>
int nuri::Subgraph< NT, ET, is_const >::degree ( int idx) const
inline

Count in-subgraph neighbors of a node.

Parameters
idxThe index of the node
Returns
The number of neighbors of the node that are in the subgraph
Note
The behavior is undefined if the node is not in the subgraph.
Time complexity: \(O(E/V (\log V' + \log E'))\).

◆ edge() [1/2]

template<class NT, class ET, bool is_const = false>
EdgeRef nuri::Subgraph< NT, ET, is_const >::edge ( int idx)
inline

Get an edge in the subgraph.

Parameters
idxThe index of the edge to get
Returns
A reference wrapper to the edge (might be const)
Note
Time complexity: \(O(\log V')\).

◆ edge() [2/2]

template<class NT, class ET, bool is_const = false>
ConstEdgeRef nuri::Subgraph< NT, ET, is_const >::edge ( int idx) const
inline

Get an edge in the subgraph.

Parameters
idxThe index of the edge to get
Returns
A const-reference wrapper to the edge
Note
Time complexity: \(O(\log V')\).

◆ edge_begin() [1/2]

template<class NT, class ET, bool is_const = false>
edge_iterator nuri::Subgraph< NT, ET, is_const >::edge_begin ( )
inline

◆ edge_begin() [2/2]

template<class NT, class ET, bool is_const = false>
const_edge_iterator nuri::Subgraph< NT, ET, is_const >::edge_begin ( ) const
inline

◆ edge_cbegin()

template<class NT, class ET, bool is_const = false>
const_edge_iterator nuri::Subgraph< NT, ET, is_const >::edge_cbegin ( ) const
inline

◆ edge_cend()

template<class NT, class ET, bool is_const = false>
const_edge_iterator nuri::Subgraph< NT, ET, is_const >::edge_cend ( ) const
inline

◆ edge_data() [1/2]

template<class NT, class ET, bool is_const = false>
internal::const_if_t< is_const, ET > & nuri::Subgraph< NT, ET, is_const >::edge_data ( int idx)
inline

Get data of an edge in the subgraph.

Parameters
idxThe index of the edge to get
Returns
A reference to the edge data (might be const)

◆ edge_data() [2/2]

template<class NT, class ET, bool is_const = false>
const ET & nuri::Subgraph< NT, ET, is_const >::edge_data ( int idx) const
inline

Get data of an edge in the subgraph.

Parameters
idxThe index of the edge to get
Returns
A const-reference to the edge data

◆ edge_end() [1/2]

template<class NT, class ET, bool is_const = false>
edge_iterator nuri::Subgraph< NT, ET, is_const >::edge_end ( )
inline

◆ edge_end() [2/2]

template<class NT, class ET, bool is_const = false>
const_edge_iterator nuri::Subgraph< NT, ET, is_const >::edge_end ( ) const
inline

◆ edge_ids()

template<class NT, class ET, bool is_const = false>
const std::vector< int > & nuri::Subgraph< NT, ET, is_const >::edge_ids ( ) const
inline

Get all edge ids in the subgraph.

Returns
The edge ids in the subgraph, in an unspecified order

◆ edges() [1/2]

template<class NT, class ET, bool is_const = false>
EdgesWrapper nuri::Subgraph< NT, ET, is_const >::edges ( )
inline

◆ edges() [2/2]

template<class NT, class ET, bool is_const = false>
ConstEdgesWrapper nuri::Subgraph< NT, ET, is_const >::edges ( ) const
inline

◆ empty()

template<class NT, class ET, bool is_const = false>
bool nuri::Subgraph< NT, ET, is_const >::empty ( ) const
inline

Whether the subgraph is empty.

Returns
true if the subgraph is empty, false otherwise

◆ end() [1/2]

template<class NT, class ET, bool is_const = false>
iterator nuri::Subgraph< NT, ET, is_const >::end ( )
inline

◆ end() [2/2]

template<class NT, class ET, bool is_const = false>
const_iterator nuri::Subgraph< NT, ET, is_const >::end ( ) const
inline

◆ erase_edge() [1/2]

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::erase_edge ( ConstEdgeRef edge)
inline

Erase an edge from the subgraph.

Parameters
edgeThe edge to erase
Note
This is equivalent to calling erase_edge(edge.id()).
Time complexity: same as erase_edge(int).

◆ erase_edge() [2/2]

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::erase_edge ( int idx)
inline

Erase an edge from the subgraph.

Parameters
idxThe index of the edge to erase
Note
The behavior is undefined if the index is out of range.
Time complexity: \(O(E')\) in worst case.

◆ erase_edge_of() [1/2]

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::erase_edge_of ( int id)
inline

Erase an edge with given id from the subgraph.

Parameters
idThe id of the edge to erase
Note
This is a no-op if the edge is not in the subgraph.
Time complexity: same as erase_edge().

◆ erase_edge_of() [2/2]

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::erase_edge_of ( typename graph_type::ConstEdgeRef edge)
inline

Erase an edge with given id from the subgraph.

Parameters
edgeThe parent edge to erase
Note
This is a no-op if the edge is not in the subgraph.
Time complexity: same as erase_edge().

◆ erase_edges()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::erase_edges ( const_edge_iterator begin,
const_edge_iterator end )
inline

Erase range of edges from the subgraph.

Parameters
beginIterator pointing to the first edge to erase
endIterator pointing to the edge after the last edge to erase
Note
Time complexity: \(O(E')\) in worst case.

◆ erase_edges_if()

template<class NT, class ET, bool is_const = false>
template<class UnaryPred>
void nuri::Subgraph< NT, ET, is_const >::erase_edges_if ( UnaryPred && pred)
inline

Erase matching edges from the subgraph.

Template Parameters
UnaryPredType of the unary predicate
Parameters
predUnary predicate that returns true for edges to erase
Note
Time complexity: \(O(E')\) in worst case.

◆ erase_node() [1/2]

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::erase_node ( ConstNodeRef node)
inline

Erase a node from the subgraph.

Parameters
nodeThe node to erase
Note
This is equivalent to calling erase_node(node.id()).
Time complexity: same as erase_node(int).

◆ erase_node() [2/2]

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::erase_node ( int idx)
inline

Erase a node from the subgraph. Corresponding edges will also be removed.

Parameters
idxThe index of the node to erase.
Note
The behavior is undefined if the index is out of range.
Time complexity: \(O(E/V (\log V' + \log E') + V' + E')\).

◆ erase_node_of() [1/2]

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::erase_node_of ( int id)
inline

Erase a node with given id from the subgraph. Corresponding edges will also be removed.

Parameters
idThe id of the node to erase
Note
This is a no-op if the node is not in the subgraph.
Time complexity: same as erase_node().

◆ erase_node_of() [2/2]

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::erase_node_of ( typename graph_type::ConstNodeRef node)
inline

Erase a node with given id from the subgraph. Corresponding edges will also be removed.

Parameters
nodeThe parent node to erase
Note
This is a no-op if the node is not in the subgraph.
Time complexity: same as erase_node().

◆ erase_nodes()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::erase_nodes ( const_iterator begin,
const_iterator end )
inline

Erase range of nodes from the subgraph. Corresponding edges will also be removed.

Parameters
beginIterator pointing to the first node to erase
endIterator pointing to the node after the last node to erase
Note
Time complexity: \(O(N E/V (\log V' + \log E') + V' + E')\), where \(N\) is the distance between begin and end.

◆ erase_nodes_if()

template<class NT, class ET, bool is_const = false>
template<class UnaryPred>
void nuri::Subgraph< NT, ET, is_const >::erase_nodes_if ( UnaryPred pred)
inline

Erase matching nodes from the subgraph. Corresponding edges will also be removed.

Template Parameters
UnaryPredType of the unary predicate
Parameters
predUnary predicate that returns true for nodes to erase
Note
Time complexity: same as erase_nodes().

◆ find_adjacent() [1/2]

template<class NT, class ET, bool is_const = false>
adjacency_iterator nuri::Subgraph< NT, ET, is_const >::find_adjacent ( ConstNodeRef src,
ConstNodeRef dst )
inline

Find adjacent node of a node.

Parameters
srcThe source atom
dstThe destination atom
Returns
An iterator to the adjacent node if found, adj_end(src) otherwise.
Note
This will only find edges that are in the subgraph.
Time complexity: same as find_edge().

◆ find_adjacent() [2/2]

template<class NT, class ET, bool is_const = false>
const_adjacency_iterator nuri::Subgraph< NT, ET, is_const >::find_adjacent ( ConstNodeRef src,
ConstNodeRef dst ) const
inline

Find adjacent node of a node.

Parameters
srcThe source atom
dstThe destination atom
Returns
A const-iterator to the adjacent node if found, adj_end(src) otherwise.
Note
This will only find edges that are in the subgraph.
Time complexity: same as find_edge().

◆ find_edge() [1/8]

template<class NT, class ET, bool is_const = false>
edge_iterator nuri::Subgraph< NT, ET, is_const >::find_edge ( ConstNodeRef src,
ConstNodeRef dst )
inline

Find edge between two nodes.

Parameters
srcThe source atom
dstThe destination atom
Returns
An iterator to the edge if found, edge_end() otherwise.
Note
This will only find edges that are in the subgraph.
Time complexity: \(O(E/V + \log E')\).

◆ find_edge() [2/8]

template<class NT, class ET, bool is_const = false>
const_edge_iterator nuri::Subgraph< NT, ET, is_const >::find_edge ( ConstNodeRef src,
ConstNodeRef dst ) const
inline

Find edge between two nodes.

Parameters
srcThe source atom
dstThe destination atom
Returns
An iterator to the edge if found, edge_end() otherwise.
Note
This will only find edges that are in the subgraph.
Time complexity: \(O(E/V + \log E')\).

◆ find_edge() [3/8]

template<class NT, class ET, bool is_const = false>
edge_iterator nuri::Subgraph< NT, ET, is_const >::find_edge ( int id)
inline

Find an edge with the given id.

Parameters
idThe id of the edge to find
Returns
An iterator to the edge if found, edge_end() otherwise.
Note
Time complexity: \(O(\log E')\).

◆ find_edge() [4/8]

template<class NT, class ET, bool is_const = false>
const_edge_iterator nuri::Subgraph< NT, ET, is_const >::find_edge ( int id) const
inline

Find an edge with the given id.

Parameters
idThe id of the edge to find
Returns
A const_iterator to the edge if found, edge_end() otherwise
Note
Time complexity: same as find_edge(int).

◆ find_edge() [5/8]

template<class NT, class ET, bool is_const = false>
edge_iterator nuri::Subgraph< NT, ET, is_const >::find_edge ( typename graph_type::ConstEdgeRef edge)
inline

Find an edge with the given id.

Parameters
edgeThe edge to find
Returns
An iterator to the edge if found, edge_end() otherwise.
Note
This is equivalent to calling find_edge(edge.id()).
Time complexity: same as find_edge(int).

◆ find_edge() [6/8]

template<class NT, class ET, bool is_const = false>
const_edge_iterator nuri::Subgraph< NT, ET, is_const >::find_edge ( typename graph_type::ConstEdgeRef edge) const
inline

Find an edge with the given id.

Parameters
edgeThe edge to find
Returns
A const_iterator to the edge if found, edge_end() otherwise.
Note
This is equivalent to calling find_edge(edge.id()).
Time complexity: same as find_edge(int).

◆ find_edge() [7/8]

template<class NT, class ET, bool is_const = false>
edge_iterator nuri::Subgraph< NT, ET, is_const >::find_edge ( typename graph_type::ConstNodeRef src,
typename graph_type::ConstNodeRef dst )
inline

Find edge between two nodes.

Parameters
srcThe parent node of one node
dstThe parent node of the other node
Returns
An iterator to the edge if found, edge_end() otherwise.
Note
This will only find edges that are in the subgraph. If any of the nodes are not in the subgraph, returns edge_end().
Time complexity: \(O(\log V' + E/V + \log E')\).

◆ find_edge() [8/8]

template<class NT, class ET, bool is_const = false>
const_edge_iterator nuri::Subgraph< NT, ET, is_const >::find_edge ( typename graph_type::ConstNodeRef src,
typename graph_type::ConstNodeRef dst ) const
inline

Find edge between two nodes.

Parameters
srcThe index of one node
dstThe index of the other node
Returns
An iterator to the edge if found, edge_end() otherwise.
Note
This will only find edges that are in the subgraph. If any of the nodes are not in the subgraph, returns edge_end().
Time complexity: \(O(\log V' + E/V + \log E')\).

◆ find_node() [1/4]

template<class NT, class ET, bool is_const = false>
iterator nuri::Subgraph< NT, ET, is_const >::find_node ( int id)
inline

Find a node with the given id.

Parameters
idThe id of the node to find
Returns
An iterator to the node if found, end() otherwise.
Note
Time complexity: \(O(\log V')\).

◆ find_node() [2/4]

template<class NT, class ET, bool is_const = false>
const_iterator nuri::Subgraph< NT, ET, is_const >::find_node ( int id) const
inline

Find a node with the given id.

Parameters
idThe id of the node to find
Returns
A const_iterator to the node if found, end() otherwise
Note
Time complexity: same as find_node(int).

◆ find_node() [3/4]

template<class NT, class ET, bool is_const = false>
iterator nuri::Subgraph< NT, ET, is_const >::find_node ( typename graph_type::ConstNodeRef node)
inline

Find a node with the given id.

Parameters
nodeThe node to find
Returns
An iterator to the node if found, end() otherwise.
Note
This is equivalent to calling find_node(node.id()).
Time complexity: same as find_node(int).

◆ find_node() [4/4]

template<class NT, class ET, bool is_const = false>
const_iterator nuri::Subgraph< NT, ET, is_const >::find_node ( typename graph_type::ConstNodeRef node) const
inline

Find a node with the given id.

Parameters
nodeThe node to find
Returns
A const_iterator to the node if found, end() otherwise.
Note
This is equivalent to calling find_node(node.id()).
Time complexity: same as find_node(int).

◆ from_edges()

template<class NT, class ET, bool is_const = false>
Subgraph nuri::Subgraph< NT, ET, is_const >::from_edges ( parent_type & graph,
internal::IndexSet && edges )
inlinestatic

Construct a subgraph with the given edges and all nodes connected to the edges.

Parameters
graphThe parent graph
edgesThe set of edges
Returns
The created subgraph
Note
Time complexity: \(O(E' \log E')\)
The behavior is undefined if any of the edge ids are not in the parent graph.

◆ from_indices()

template<class NT, class ET, bool is_const = false>
Subgraph nuri::Subgraph< NT, ET, is_const >::from_indices ( parent_type & graph,
internal::IndexSet && nodes,
internal::IndexSet && edges )
inlinestatic

Construct a subgraph with the given nodes and edges.

Parameters
graphThe parent graph
nodesThe set of nodes
edgesThe set of edges
Returns
The created subgraph
Note
The nodes connected to the edges will be automatically added even if they are not in the nodes set.
Time complexity:
  1. Building node set: \(O(V' \log V')\)
  2. Building edge set: \(O(E' \log E')\)
  3. Finding nodes connected to edges: \(O(E')\)
The behavior is undefined if any of the node or edge ids are not in the parent graph.

◆ from_nodes()

template<class NT, class ET, bool is_const = false>
Subgraph nuri::Subgraph< NT, ET, is_const >::from_nodes ( parent_type & graph,
internal::IndexSet && nodes )
inlinestatic

Construct a subgraph with the given nodes and all edges connecting the nodes.

Parameters
graphThe parent graph
nodesThe set of nodes
Returns
The created subgraph
Note
Time complexity:
  1. Building node set: \(O(V' \log V')\)
  2. Finding edges connecting the nodes: \(O(V' E/V \log V')\)
  3. Building edge set: \(O(E' \log E')\)
The behavior is undefined if any of the node ids are not in the parent graph.

◆ node() [1/2]

template<class NT, class ET, bool is_const = false>
NodeRef nuri::Subgraph< NT, ET, is_const >::node ( int idx)
inline

Get a node in the subgraph.

Parameters
idxThe index of the node to get
Returns
A reference wrapper to the node (might be const)

◆ node() [2/2]

template<class NT, class ET, bool is_const = false>
ConstNodeRef nuri::Subgraph< NT, ET, is_const >::node ( int idx) const
inline

Get a node in the subgraph.

Parameters
idxThe index of the node to get
Returns
A const-reference wrapper to the node

◆ node_begin() [1/2]

template<class NT, class ET, bool is_const = false>
node_iterator nuri::Subgraph< NT, ET, is_const >::node_begin ( )
inline

◆ node_begin() [2/2]

template<class NT, class ET, bool is_const = false>
const_node_iterator nuri::Subgraph< NT, ET, is_const >::node_begin ( ) const
inline

◆ node_cbegin()

template<class NT, class ET, bool is_const = false>
const_node_iterator nuri::Subgraph< NT, ET, is_const >::node_cbegin ( ) const
inline

◆ node_cend()

template<class NT, class ET, bool is_const = false>
const_node_iterator nuri::Subgraph< NT, ET, is_const >::node_cend ( ) const
inline

◆ node_data() [1/2]

template<class NT, class ET, bool is_const = false>
internal::const_if_t< is_const, NT > & nuri::Subgraph< NT, ET, is_const >::node_data ( int idx)
inline

Get data of a node in the subgraph.

Parameters
idxThe index of the node to get
Returns
A reference to the node data (might be const)

◆ node_data() [2/2]

template<class NT, class ET, bool is_const = false>
const NT & nuri::Subgraph< NT, ET, is_const >::node_data ( int idx) const
inline

Get data of a node in the subgraph.

Parameters
idxThe index of the node to get
Returns
A const-reference to the node data

◆ node_end() [1/2]

template<class NT, class ET, bool is_const = false>
node_iterator nuri::Subgraph< NT, ET, is_const >::node_end ( )
inline

◆ node_end() [2/2]

template<class NT, class ET, bool is_const = false>
const_node_iterator nuri::Subgraph< NT, ET, is_const >::node_end ( ) const
inline

◆ node_ids()

template<class NT, class ET, bool is_const = false>
const std::vector< int > & nuri::Subgraph< NT, ET, is_const >::node_ids ( ) const
inline

Get all node ids in the subgraph.

Returns
The node ids in the subgraph, in an unspecified order

◆ num_edges()

template<class NT, class ET, bool is_const = false>
int nuri::Subgraph< NT, ET, is_const >::num_edges ( ) const
inline

Count number of edges in the subgraph.

Returns
The number of edges in the subgraph

◆ num_nodes()

template<class NT, class ET, bool is_const = false>
int nuri::Subgraph< NT, ET, is_const >::num_nodes ( ) const
inline

Count number of nodes in the subgraph.

Returns
The number of nodes in the subgraph

◆ operator=() [1/2]

template<class NT, class ET, bool is_const = false>
template<bool other_const, std::enable_if_t< is_const &&!other_const, int > = 0>
Subgraph & nuri::Subgraph< NT, ET, is_const >::operator= ( const Other< other_const > & other)
inline

Converting assignment operator to allow implicit conversion from a non-const subgraph to a const subgraph.

Parameters
otherThe non-const subgraph

◆ operator=() [2/2]

template<class NT, class ET, bool is_const = false>
template<bool other_const, std::enable_if_t< is_const &&!other_const, int > = 0>
Subgraph & nuri::Subgraph< NT, ET, is_const >::operator= ( Other< other_const > && other)
inlinenoexcept

Converting assignment operator to allow implicit conversion from a non-const subgraph to a const subgraph.

Parameters
otherThe non-const subgraph

◆ operator[]() [1/2]

template<class NT, class ET, bool is_const = false>
NodeRef nuri::Subgraph< NT, ET, is_const >::operator[] ( int idx)
inline

Get a node in the subgraph.

Parameters
idxThe index of the node to get
Returns
A reference wrapper to the node (might be const)

◆ operator[]() [2/2]

template<class NT, class ET, bool is_const = false>
ConstNodeRef nuri::Subgraph< NT, ET, is_const >::operator[] ( int idx) const
inline

Get a node in the subgraph.

Parameters
idxThe index of the node to get
Returns
A const-reference wrapper to the node

◆ parent_edge() [1/2]

template<class NT, class ET, bool is_const = false>
std::conditional_t< is_const, typename parent_type::ConstEdgeRef, typename parent_type::EdgeRef > nuri::Subgraph< NT, ET, is_const >::parent_edge ( int idx)
inline

Get a parent edge of an edge in the subgraph.

Parameters
idxThe index of the edge to get
Returns
A reference wrapper to the edge (might be const)

◆ parent_edge() [2/2]

template<class NT, class ET, bool is_const = false>
parent_type::ConstEdgeRef nuri::Subgraph< NT, ET, is_const >::parent_edge ( int idx) const
inline

Get a parent edge of an edge in the subgraph.

Parameters
idxThe index of the edge to get
Returns
A const-reference wrapper to the edge.

◆ parent_node() [1/2]

template<class NT, class ET, bool is_const = false>
std::conditional_t< is_const, typename parent_type::ConstNodeRef, typename parent_type::NodeRef > nuri::Subgraph< NT, ET, is_const >::parent_node ( int idx)
inline

Get a parent node of a node in the subgraph.

Parameters
idxThe index of the node to get
Returns
A reference wrapper to the node (might be const)

◆ parent_node() [2/2]

template<class NT, class ET, bool is_const = false>
parent_type::ConstNodeRef nuri::Subgraph< NT, ET, is_const >::parent_node ( int idx) const
inline

Get a parent node of a node in the subgraph.

Parameters
idxThe index of the node to get
Returns
A const-reference wrapper to the node.

◆ rebind()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::rebind ( parent_type & parent)
inline

Re-bind the subgraph to a new parent graph.

Parameters
parentThe new parent graph to bind.
Warning
This method does no bookkeeping, so it is the caller's responsibility to ensure that the new parent graph is compatible with the subgraph. The behavior is undefined otherwise.

◆ refresh_edges()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::refresh_edges ( )
inline

Make this graph an induced subgraph of the parent graph.

Replace the current set of edges with the set of edges connecting the current set of nodes.

Note
Time complexity: same as from_edges().

◆ remap()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::remap ( const std::vector< int > & node_map,
const std::vector< int > & edge_map )
inline

Re-map node/edge ids.

Parameters
node_mapA vector that maps old node ids to new node ids, so that old_to_new[old_id] = new_id. If old_to_new[old_id] < 0, then the node is removed from the subgraph.
edge_mapA vector that maps old edge ids to new edge ids, so that old_to_new[old_id] = new_id. If old_to_new[old_id] < 0, then the edge is removed from the subgraph.
Note
Time complexity: \(O(V' + E')\).

◆ remap_edges()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::remap_edges ( const std::vector< int > & old_to_new)
inline

Re-map edge ids.

Parameters
old_to_newA vector that maps old edge ids to new edge ids, so that old_to_new[old_id] = new_id. If old_to_new[old_id] < 0, then the edge is removed from the subgraph.
Note
Time complexity: \(O(E')\).

◆ remap_nodes()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::remap_nodes ( const std::vector< int > & node_map)
inline

Re-map node ids.

Parameters
node_mapA vector that maps old node ids to new node ids, so that old_to_new[old_id] = new_id. If old_to_new[old_id] < 0, then the node is removed from the subgraph.
Note
The caller is responsible for ensuring that the new node ids are compatible with the selected edges; otherwise, the behavior is undefined.
Time complexity: \(O(V')\).

◆ reserve_edges()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::reserve_edges ( int num_edges)
inline

Reserve space for a number of edges.

Parameters
num_edgesThe number of edges to reserve space for

◆ reserve_nodes()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::reserve_nodes ( int num_nodes)
inline

Reserve space for a number of nodes.

Parameters
num_nodesThe number of nodes to reserve space for

◆ size()

template<class NT, class ET, bool is_const = false>
int nuri::Subgraph< NT, ET, is_const >::size ( ) const
inline

Count number of nodes in the subgraph.

Returns
The number of nodes in the subgraph

◆ update()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::update ( internal::IndexSet && nodes,
internal::IndexSet && edges )
inline

Change the set of nodes and edges in the subgraph.

Parameters
nodesThe new set of nodes.
edgesThe new set of edges.
Note
The nodes connected to the edges will be automatically added even if they are not in the nodes set.
Time complexity: same as from_indices().
If any of the node ids are not in the parent graph, the behavior is undefined.

◆ update_edges()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::update_edges ( internal::IndexSet && edges)
inlinenoexcept

Change the set of edges in the subgraph.

Parameters
edgesThe new set of edges. All nodes connected to the edges will be automatically added.
Note
Time complexity: same as from_edges().
If any of the edge ids are not in the parent graph, the behavior is undefined.

◆ update_nodes()

template<class NT, class ET, bool is_const = false>
void nuri::Subgraph< NT, ET, is_const >::update_nodes ( internal::IndexSet && nodes)
inlinenoexcept

Change the set of nodes in the subgraph.

Parameters
nodesThe new set of nodes. Edges will be automatically updated.
Note
Time complexity: same as from_nodes().
If any of the node ids are not in the parent graph, the behavior is undefined.

◆ Subgraph< NT, ET, true >

template<class NT, class ET, bool is_const = false>
friend class Subgraph< NT, ET, true >
friend

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