Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Types | Public Member Functions
nom::Graph< T, U > Class Template Reference

A simple graph implementation. More...

#include <Graph.h>

Public Types

using SubgraphType = Subgraph< T, U... >
 
using NodeRef = Node< T, U... > *
 
using EdgeRef = Edge< T, U... > *
 

Public Member Functions

 Graph (const Graph &)=delete
 
 Graph (Graph &&)=default
 
Graphoperator= (Graph &&)=default
 
NodeRef createNode (T &&data)
 Creates a node and retains ownership of it. More...
 
template<class Arg >
NodeRef createNode (Arg &&arg)
 
NodeRef createNode ()
 
void moveNode (NodeRef node, Graph< T, U... > *destGraph)
 
void moveEdge (EdgeRef edge, Graph< T, U... > *destGraph)
 
void moveSubgraph (const Subgraph< T, U... > &subgraph, Graph< T, U... > *destGraph)
 
bool isValid ()
 
void swapNodes (NodeRef n1, NodeRef n2)
 
void replaceNode (const NodeRef &oldNode, const NodeRef &newNode)
 Replace a node in the graph with another node. More...
 
void replaceOutEdges (const NodeRef &oldNode, const NodeRef &newNode)
 
void replaceInEdges (const NodeRef &oldNode, const NodeRef &newNode)
 
EdgeRef createEdge (NodeRef tail, NodeRef head, U...data)
 Creates a directed edge and retains ownership of it. More...
 
EdgeRef getEdgeIfExists (NodeRef tail, NodeRef head) const
 Get a reference to the edge between two nodes if it exists. More...
 
bool hasEdge (NodeRef tail, NodeRef head) const
 Returns true if there is an edge between the given two nodes.
 
bool hasEdge (EdgeRef e) const
 
EdgeRef getEdge (NodeRef tail, NodeRef head) const
 Get a reference to the edge between two nodes if it exists. More...
 
void deleteNode (NodeRef n)
 Deletes a node from the graph. More...
 
void deleteNodes (const std::unordered_set< NodeRef > &nodes)
 
bool hasNode (NodeRef node) const
 
void deleteEdge (EdgeRef e)
 Deletes a edge from the graph. More...
 
const std::vector< NodeRefgetMutableNodes ()
 
size_t getNodesCount () const
 
const std::vector< EdgeRefgetMutableEdges ()
 
size_t getEdgesCount () const
 

Detailed Description

template<typename T, typename... U>
class nom::Graph< T, U >

A simple graph implementation.

Everything is owned by the graph to simplify storage concerns.

Definition at line 29 of file Graph.h.

Member Function Documentation

template<typename T, typename... U>
EdgeRef nom::Graph< T, U >::createEdge ( NodeRef  tail,
NodeRef  head,
U...  data 
)
inline

Creates a directed edge and retains ownership of it.

tail The node that will have this edge as an out-edge. head The node that will have this edge as an in-edge.

Returns
A reference to the edge created.

Definition at line 415 of file Graph.h.

template<typename T, typename... U>
NodeRef nom::Graph< T, U >::createNode ( T &&  data)
inline

Creates a node and retains ownership of it.

data An rvalue of the data being held in the node.

Returns
A reference to the node created.

Definition at line 240 of file Graph.h.

template<typename T, typename... U>
void nom::Graph< T, U >::deleteEdge ( EdgeRef  e)
inline

Deletes a edge from the graph.

e A reference to the edge.

Definition at line 496 of file Graph.h.

template<typename T, typename... U>
void nom::Graph< T, U >::deleteNode ( NodeRef  n)
inline

Deletes a node from the graph.

Parameters
nA reference to the node.

Definition at line 460 of file Graph.h.

template<typename T, typename... U>
EdgeRef nom::Graph< T, U >::getEdge ( NodeRef  tail,
NodeRef  head 
) const
inline

Get a reference to the edge between two nodes if it exists.

note: will fail assertion if the edge does not exist.

Definition at line 452 of file Graph.h.

template<typename T, typename... U>
EdgeRef nom::Graph< T, U >::getEdgeIfExists ( NodeRef  tail,
NodeRef  head 
) const
inline

Get a reference to the edge between two nodes if it exists.

Returns nullptr if the edge does not exist.

Definition at line 427 of file Graph.h.

template<typename T, typename... U>
void nom::Graph< T, U >::replaceNode ( const NodeRef oldNode,
const NodeRef newNode 
)
inline

Replace a node in the graph with another node.

Note
The node replaced simply has its edges cut, but it not deleted from the graph. Call Graph::deleteNode to delete it. oldNode A node to be replaced in the graph. newNode The node that inherit the old node's in-edges and out-edges.

Definition at line 384 of file Graph.h.


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