pub struct BfsTree {
pub dist: HashMap<NodeId, usize>,
pub parent: HashMap<NodeId, NodeId>,
}Expand description
BFS result containing both hop distances and the parent map for path reconstruction.
§Examples
use graph_core::{AdjacencyList, Graph};
use graph_traversal::bfs_tree;
let mut g: AdjacencyList<()> = AdjacencyList::directed();
let a = g.add_node(());
let b = g.add_node(());
g.add_edge(a, b, 1.0).unwrap();
let tree = bfs_tree(&g, a);
assert_eq!(tree.dist[&b], 1);
assert_eq!(tree.parent[&b], a);Fields§
§dist: HashMap<NodeId, usize>Shortest hop distance from the source to each reachable node.
parent: HashMap<NodeId, NodeId>Parent of each node in the BFS tree (source has no parent entry).
Auto Trait Implementations§
impl Freeze for BfsTree
impl RefUnwindSafe for BfsTree
impl Send for BfsTree
impl Sync for BfsTree
impl Unpin for BfsTree
impl UnwindSafe for BfsTree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more