Trait graph_types::GraphEngine
source · pub trait GraphEnginewhere
Self: Sized,{
type NodeIter: Iterator<Item = usize>;
// Required methods
fn graph_kind(&self) -> GraphKind;
fn has_node(&self, node_id: usize) -> Option<usize>;
fn count_nodes(&self) -> usize;
fn traverse_nodes(&self) -> NodesVisitor<'_, Self> ⓘ;
fn has_edge<E: Into<EdgeQuery>>(&self, edge: E) -> Option<usize>;
fn traverse_edges(&self) -> EdgesVisitor<'_, Self> ⓘ;
fn count_edges(&self) -> usize;
// Provided methods
fn get_node_degree(&self, node_id: usize) -> Result<usize, GraphError> { ... }
fn size_hint(&self) -> usize { ... }
}
Expand description
Required Associated Types§
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).has_node(5), true);
assert_eq!(CompleteGraph::one_way(5).has_node(6), false);
sourcefn has_node(&self, node_id: usize) -> Option<usize>
fn has_node(&self, node_id: usize) -> Option<usize>
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).has_node(5), true);
assert_eq!(CompleteGraph::one_way(5).has_node(6), false);
sourcefn count_nodes(&self) -> usize
fn count_nodes(&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 traverse_nodes(&self) -> NodesVisitor<'_, Self> ⓘ
fn traverse_nodes(&self) -> NodesVisitor<'_, Self> ⓘ
Traverse all nodes in the graph.
Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
let mut graph = CompleteGraph::one_way(5);
assert_eq!(graph.traverse_nodes().count(), 20)
sourcefn has_edge<E: Into<EdgeQuery>>(&self, edge: E) -> Option<usize>
fn has_edge<E: Into<EdgeQuery>>(&self, edge: E) -> Option<usize>
Check if the edge exists, return the node id if exists.
Examples
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
assert_eq!(CompleteGraph::one_way(5).has_node(5), true);
assert_eq!(CompleteGraph::one_way(5).has_node(6), false);
sourcefn traverse_edges(&self) -> EdgesVisitor<'_, Self> ⓘ
fn traverse_edges(&self) -> EdgesVisitor<'_, Self> ⓘ
Get the edges of the graph.
use graph_theory::{graph_engines::CompleteGraph, GraphEngine};
let mut graph = CompleteGraph::one_way(5);
assert_eq!(graph.traverse_nodes().count(), 20)
sourcefn count_edges(&self) -> usize
fn count_edges(&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);