Trait graph_types::GraphEngine
source · pub trait GraphEngine<'a>where
Self: Sized,{
type NeighborIterator: DoubleEndedIterator<Item = NodeID>;
type BridgeIterator: DoubleEndedIterator<Item = IndeterminateEdge>;
type NodeTraverser: DoubleEndedIterator<Item = NodeID>;
type EdgeTraverser: DoubleEndedIterator<Item = EdgeID>;
type BridgeTraverser: DoubleEndedIterator<Item = IndeterminateEdge>;
Show 15 methods
// Required methods
fn graph_kind(&self) -> GraphKind;
fn get_node(&self, node: NodeID) -> Result<NodeID, GraphError>;
fn all_nodes(&'a self) -> Self::NodeTraverser;
fn all_neighbors(&'a self, node: NodeID) -> Self::NeighborIterator;
fn get_edge(&self, edge: EdgeID) -> Result<EdgeID, GraphError>;
fn all_edges(&'a self) -> Self::EdgeTraverser;
fn get_bridge(&self, edge: EdgeID) -> Result<IndeterminateEdge, GraphError>;
fn get_bridges(&'a self, from: NodeID, goto: NodeID) -> Self::BridgeIterator;
fn all_bridges(&'a self) -> Self::BridgeTraverser;
// Provided methods
fn count_nodes(&'a self) -> usize { ... }
fn get_outgoing(&'a self, node: NodeID) -> Self::NeighborIterator { ... }
fn get_incoming(&'a self, node: NodeID) -> Self::NeighborIterator { ... }
fn count_degree(&'a self, node: NodeID) -> NodeDegree { ... }
fn count_edges(&'a self) -> usize { ... }
fn size_hint(&self) -> usize { ... }
}
Expand description
Required Associated Types§
sourcetype NeighborIterator: DoubleEndedIterator<Item = NodeID>
type NeighborIterator: DoubleEndedIterator<Item = NodeID>
According to a given vertex, find all neighbor nodes
sourcetype BridgeIterator: DoubleEndedIterator<Item = IndeterminateEdge>
type BridgeIterator: DoubleEndedIterator<Item = IndeterminateEdge>
An iterator over the edges.
sourcetype NodeTraverser: DoubleEndedIterator<Item = NodeID>
type NodeTraverser: DoubleEndedIterator<Item = NodeID>
An iterator over the nodes.
sourcetype EdgeTraverser: DoubleEndedIterator<Item = EdgeID>
type EdgeTraverser: DoubleEndedIterator<Item = EdgeID>
An iterator over the edges.
sourcetype BridgeTraverser: DoubleEndedIterator<Item = IndeterminateEdge>
type BridgeTraverser: DoubleEndedIterator<Item = IndeterminateEdge>
An iterator over the edges.
Required Methods§
sourcefn graph_kind(&self) -> GraphKind
fn graph_kind(&self) -> GraphKind
Check the graph kind, it can be directed or undirected.
Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
assert_eq!(CompleteGraph::one_way(5).get_node(5), true);
assert_eq!(CompleteGraph::one_way(5).get_node(6), false);
sourcefn get_node(&self, node: NodeID) -> Result<NodeID, GraphError>
fn get_node(&self, node: NodeID) -> Result<NodeID, GraphError>
Check if the node exists, return the node id if exists.
Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
assert_eq!(CompleteGraph::one_way(5).get_node(5), true);
assert_eq!(CompleteGraph::one_way(5).get_node(6), false);
sourcefn all_nodes(&'a self) -> Self::NodeTraverser
fn all_nodes(&'a self) -> Self::NodeTraverser
Traverse all nodes in the graph.
Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
let mut graph = CompleteGraph::one_way(5);
assert_eq!(graph.all_nodes().count(), 20)
sourcefn all_neighbors(&'a self, node: NodeID) -> Self::NeighborIterator
fn all_neighbors(&'a self, node: NodeID) -> Self::NeighborIterator
sourcefn get_edge(&self, edge: EdgeID) -> Result<EdgeID, GraphError>
fn get_edge(&self, edge: EdgeID) -> Result<EdgeID, GraphError>
Check if the edge exists, return the node id if exists.
At most one element will be returned, even if there are multiple edges with the same starting point and ending point.
If you need to return all eligible edges, use Self::get_bridges.
Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
assert_eq!(CompleteGraph::one_way(5).get_node(5), true);
assert_eq!(CompleteGraph::one_way(5).get_node(6), false);
sourcefn all_edges(&'a self) -> Self::EdgeTraverser
fn all_edges(&'a self) -> Self::EdgeTraverser
Get the edges of the graph.
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
let mut graph = CompleteGraph::one_way(5);
assert_eq!(graph.all_nodes().count(), 20)
fn get_bridge(&self, edge: EdgeID) -> Result<IndeterminateEdge, GraphError>
sourcefn get_bridges(&'a self, from: NodeID, goto: NodeID) -> Self::BridgeIterator
fn get_bridges(&'a self, from: NodeID, goto: NodeID) -> Self::BridgeIterator
Give all edges matching the start and end points
Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
assert_eq!(CompleteGraph::one_way(5).get_node(5), true);
assert_eq!(CompleteGraph::one_way(5).get_node(6), false);
sourcefn all_bridges(&'a self) -> Self::BridgeTraverser
fn all_bridges(&'a self) -> Self::BridgeTraverser
Get the edges of the graph.
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
let mut graph = CompleteGraph::one_way(5);
assert_eq!(graph.all_nodes().count(), 20)
Provided Methods§
sourcefn count_nodes(&'a self) -> usize
fn count_nodes(&'a self) -> usize
Count the number of nodes in the graph.
Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
assert_eq!(CompleteGraph::one_way(5).count_nodes(), 5);
sourcefn get_outgoing(&'a self, node: NodeID) -> Self::NeighborIterator
fn get_outgoing(&'a self, node: NodeID) -> Self::NeighborIterator
sourcefn get_incoming(&'a self, node: NodeID) -> Self::NeighborIterator
fn get_incoming(&'a self, node: NodeID) -> Self::NeighborIterator
sourcefn count_degree(&'a self, node: NodeID) -> NodeDegree
fn count_degree(&'a self, node: NodeID) -> NodeDegree
sourcefn count_edges(&'a self) -> usize
fn count_edges(&'a self) -> usize
Count the number of edges in the graph.
Examples
assert_eq!(CycleGraph::one_way(5).count_edges(), 5);
assert_eq!(CycleGraph::two_way(5).count_edges(), 10);
assert_eq!(StarGraph::one_way(5).count_edges(), 5);
assert_eq!(StarGraph::two_way(5).count_edges(), 10);
assert_eq!(CompleteGraph::one_way(5).count_edges(), 5);
assert_eq!(CompleteGraph::one_way(5).count_edges(), 10);