Struct rs_graph::reversedigraph::ReverseDigraph
[−]
[src]
pub struct ReverseDigraph<G>(_);
A digraph wrapping an existing graph with edges in opposite directions.
The sets of outgoing and incoming edges handled by the methods of
Digraph
and Network
are swapped, so incoming edges becoming
outgoing edges and vice versa.
Example
use rs_graph::{Graph, Digraph, IndexGraph, ReverseDigraph, LinkedListGraph}; use rs_graph::reverse; use rs_graph::classes::star; let g = star::<LinkedListGraph>(42); assert_eq!(g.num_nodes(), 43); assert_eq!(g.num_edges(), 42); assert!(g.edges().all(|e| g.node_id(g.src(e)) == 0 && g.node_id(g.snk(e)) > 0)); assert!(g.outedges(g.id2node(0)).all(|(_,v)| g.node_id(v) > 0)); assert!(g.inedges(g.id2node(0)).all(|(_,v)| g.node_id(v) == 0)); assert_eq!(g.outedges(g.id2node(0)).count(), 42); assert_eq!(g.inedges(g.id2node(0)).count(), 0); // Can be used by wrapping a reference. { let g = reverse(&g); assert_eq!(g.num_nodes(), 43); assert_eq!(g.num_edges(), 42); } // Or by conversion. let g = reverse(g); assert_eq!(g.num_nodes(), 43); assert_eq!(g.num_edges(), 42); assert!(g.edges().all(|e| g.node_id(g.snk(e)) == 0 && g.node_id(g.src(e)) > 0)); assert!(g.outedges(g.id2node(0)).all(|(_,v)| g.node_id(v) == 0)); assert!(g.inedges(g.id2node(0)).all(|(_,v)| g.node_id(v) > 0)); assert_eq!(g.outedges(g.id2node(0)).count(), 0); assert_eq!(g.inedges(g.id2node(0)).count(), 42);
Trait Implementations
impl<'a, G> Graph<'a> for ReverseDigraph<G> where
G: Graph<'a>,
[src]
G: Graph<'a>,
type Node = G::Node
Type of a node.
type Edge = G::Edge
Type of an edge.
type NodeIter = G::NodeIter
Type of an iterator over all nodes.
type EdgeIter = G::EdgeIter
Type of an iterator over all edges.
type NeighIter = G::NeighIter
Type of an iterator over incident edges.
fn num_nodes(&self) -> usize
[src]
Return the number of nodes.
fn num_edges(&self) -> usize
[src]
Return the number of edges.
fn enodes(&'a self, e: Self::Edge) -> (Self::Node, Self::Node)
[src]
Return the nodes connected by an edge. Read more
fn nodes(&'a self) -> Self::NodeIter
[src]
Return an iterator over all nodes.
fn edges(&'a self) -> Self::EdgeIter
[src]
Return an iterator over all edges. Read more
fn neighs(&'a self, u: Self::Node) -> Self::NeighIter
[src]
Return an iterator over the edges adjacent to some node. Read more
impl<'a, G> IndexGraph<'a> for ReverseDigraph<G> where
G: IndexGraph<'a>,
[src]
G: IndexGraph<'a>,
fn node_id(&self, u: Self::Node) -> usize
[src]
Return a unique id associated with a node.
fn id2node(&'a self, id: usize) -> Self::Node
[src]
Return the node associated with the given id. Read more
fn edge_id(&self, e: Self::Edge) -> usize
[src]
Return a unique id associated with an edge. Read more
fn id2edge(&'a self, id: usize) -> Self::Edge
[src]
Return the edge associated with the given id. Read more
impl<'a, G> Digraph<'a> for ReverseDigraph<G> where
G: Digraph<'a>,
[src]
G: Digraph<'a>,
type OutEdgeIter = G::InEdgeIter
Type of an iterator over the forward edges leaving a node.
type InEdgeIter = G::OutEdgeIter
Type of an iterator over the backward edges entering a node.
fn src(&'a self, e: Self::Edge) -> Self::Node
[src]
Return the source node of an edge.
fn snk(&'a self, e: Self::Edge) -> Self::Node
[src]
Return the sink node of an edge.
fn outedges(&'a self, u: Self::Node) -> Self::OutEdgeIter
[src]
Return an iterator over the outgoing edges of a node. Read more
fn inedges(&'a self, u: Self::Node) -> Self::InEdgeIter
[src]
Return an iterator over the incoming edges of a node. Read more
impl<'a, G> Network<'a> for ReverseDigraph<G> where
G: Network<'a>,
[src]
G: Network<'a>,
fn is_reverse(&self, e: Self::Edge, f: Self::Edge) -> bool
[src]
Return true if e is the reverse edge of f.
fn reverse(&'a self, e: Self::Edge) -> Self::Edge
[src]
Return the reverse edge of e.
fn is_forward(&self, e: Self::Edge) -> bool
[src]
Return true if e is a forward edge.
fn forward(&'a self, e: Self::Edge) -> Self::Edge
[src]
Return the forward edge of e. Read more
fn is_backward(&self, e: Self::Edge) -> bool
[src]
Return true if e is a backward edge.
fn backward(&'a self, e: Self::Edge) -> Self::Edge
[src]
Return the backward edge of e. Read more
fn bisrc(&'a self, e: Self::Edge) -> Self::Node
[src]
Return the source of the directed edge e. Read more
fn bisnk(&'a self, e: Self::Edge) -> Self::Node
[src]
Return the sink of the directed edge e. Read more
impl<'a, G> IndexNetwork<'a> for ReverseDigraph<G> where
G: IndexNetwork<'a>,
[src]
G: IndexNetwork<'a>,
fn biedge_id(&self, e: Self::Edge) -> usize
[src]
Return a unique id associated with a directed edge. Read more
fn id2biedge(&'a self, id: usize) -> Self::Edge
[src]
Return the edge associated with the given id. Read more