pub trait GraphEngine: Sized {
type NeighborIterator<'a>: DoubleEndedIterator<Item = usize>
where Self: 'a;
type BridgeIterator<'a>: DoubleEndedIterator<Item = IndeterminateEdge>
where Self: 'a;
type NodeTraverser<'a>: DoubleEndedIterator<Item = usize>
where Self: 'a;
type EdgeTraverser<'a>: DoubleEndedIterator<Item = usize>
where Self: 'a;
type BridgeTraverser<'a>: DoubleEndedIterator<Item = IndeterminateEdge>
where Self: 'a;
Show 15 methods
// Required methods
fn graph_kind(&self) -> GraphKind;
fn get_node(&self, node: usize) -> Result<usize, GraphError>;
fn all_nodes<'a>(&'a self) -> Self::NodeTraverser<'a>;
fn all_neighbors<'a>(&'a self, node: usize) -> Self::NeighborIterator<'a>;
fn get_edge(&self, edge: usize) -> Result<usize, GraphError>;
fn all_edges<'a>(&'a self) -> Self::EdgeTraverser<'a>;
fn get_bridge(&self, edge: usize) -> Result<IndeterminateEdge, GraphError>;
fn get_bridges<'a>(
&'a self,
from: usize,
goto: usize,
) -> Self::BridgeIterator<'a>;
fn all_bridges<'a>(&'a self) -> Self::BridgeTraverser<'a>;
// Provided methods
fn count_nodes<'a>(&'a self) -> usize { ... }
fn all_outgoing<'a>(&'a self, node: usize) -> Self::NeighborIterator<'a> { ... }
fn all_incoming<'a>(&'a self, node: usize) -> Self::NeighborIterator<'a> { ... }
fn count_degree<'a>(&'a self, node: usize) -> NodeDegree { ... }
fn count_edges<'a>(&'a self) -> usize { ... }
fn size_hint(&self) -> usize { ... }
}
Expand description
Required Associated Types§
Sourcetype NeighborIterator<'a>: DoubleEndedIterator<Item = usize>
where
Self: 'a
type NeighborIterator<'a>: DoubleEndedIterator<Item = usize> where Self: 'a
According to a given vertex, find all neighbor nodes. See more in Self::all_neighbors, Self::all_incoming, Self::all_outgoing.
Sourcetype BridgeIterator<'a>: DoubleEndedIterator<Item = IndeterminateEdge>
where
Self: 'a
type BridgeIterator<'a>: DoubleEndedIterator<Item = IndeterminateEdge> where Self: 'a
An iterator over the edges.
Sourcetype NodeTraverser<'a>: DoubleEndedIterator<Item = usize>
where
Self: 'a
type NodeTraverser<'a>: DoubleEndedIterator<Item = usize> where Self: 'a
Traverse all nodes in the graph, note that this traversal is neither BFS nor DFS, but the most friendly traversal to the data structure. See more in Self::all_nodes.
Sourcetype EdgeTraverser<'a>: DoubleEndedIterator<Item = usize>
where
Self: 'a
type EdgeTraverser<'a>: DoubleEndedIterator<Item = usize> where Self: 'a
An iterator over the edges.
Sourcetype BridgeTraverser<'a>: DoubleEndedIterator<Item = IndeterminateEdge>
where
Self: 'a
type BridgeTraverser<'a>: DoubleEndedIterator<Item = IndeterminateEdge> where Self: 'a
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: usize) -> Result<usize, GraphError>
fn get_node(&self, node: usize) -> Result<usize, 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>(&'a self) -> Self::NodeTraverser<'a>
fn all_nodes<'a>(&'a self) -> Self::NodeTraverser<'a>
Traverse all nodes in the entire graph in the most friendly way to the data structure, and the order of this traversal is arbitrary.
§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>(&'a self, node: usize) -> Self::NeighborIterator<'a>
fn all_neighbors<'a>(&'a self, node: usize) -> Self::NeighborIterator<'a>
Sourcefn get_edge(&self, edge: usize) -> Result<usize, GraphError>
fn get_edge(&self, edge: usize) -> Result<usize, 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>(&'a self) -> Self::EdgeTraverser<'a>
fn all_edges<'a>(&'a self) -> Self::EdgeTraverser<'a>
Traverse all edges in the entire graph in the most friendly way to the data structure, the order of traversal is arbitrary.
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: usize) -> Result<IndeterminateEdge, GraphError>
Sourcefn get_bridges<'a>(
&'a self,
from: usize,
goto: usize,
) -> Self::BridgeIterator<'a>
fn get_bridges<'a>( &'a self, from: usize, goto: usize, ) -> Self::BridgeIterator<'a>
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>(&'a self) -> Self::BridgeTraverser<'a>
fn all_bridges<'a>(&'a self) -> Self::BridgeTraverser<'a>
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>(&'a self) -> usize
fn count_nodes<'a>(&'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 all_outgoing<'a>(&'a self, node: usize) -> Self::NeighborIterator<'a>
fn all_outgoing<'a>(&'a self, node: usize) -> Self::NeighborIterator<'a>
Given a vertex as the starting point, return the ids corresponding to all ending points.
In an undirected graph, it is equivalent to calling Self::all_neighbors.
§Examples
use graph_theory::{graph_engines::UnGraphAND, GraphEngine};
let graph = UnGraphAND::default();
assert_eq!(graph.all_outgoing(5).count(), 5);
Sourcefn all_incoming<'a>(&'a self, node: usize) -> Self::NeighborIterator<'a>
fn all_incoming<'a>(&'a self, node: usize) -> Self::NeighborIterator<'a>
Given a vertex as the ending point, return the ids corresponding to all starting points.
In an undirected graph, it is equivalent to calling Self::all_neighbors.
§Examples
use graph_theory::{graph_engines::UnGraphAND, GraphEngine};
let graph = UnGraphAND::default();
assert_eq!(graph.all_incoming(5).count(), 5);
Sourcefn count_degree<'a>(&'a self, node: usize) -> NodeDegree
fn count_degree<'a>(&'a self, node: usize) -> NodeDegree
Sourcefn count_edges<'a>(&'a self) -> usize
fn count_edges<'a>(&'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);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.