pub struct ShortestPathTree<T: Display + Clone + Hash + Eq> { /* private fields */ }
Expand description
Structure to store the shortest path and distance from one node to other nodes after a pathfinding algorithm has been run on a graph.
Implementations§
Source§impl<T: Display + Clone + Eq + Hash> ShortestPathTree<T>
impl<T: Display + Clone + Eq + Hash> ShortestPathTree<T>
Sourcepub fn shortest_path(&self, target_id: &T) -> Option<&ShortestPath<T>>
pub fn shortest_path(&self, target_id: &T) -> Option<&ShortestPath<T>>
Returns the shortest path to the node with id target_id
.
If the target_id
is not contained within the shortest path tree,
None
is returned instead of the shortest path.
For further information and for what can be done with the shortest path see ShortestPath.
Sourcepub fn shortest_distance(&self, target_id: &T) -> Option<i32>
pub fn shortest_distance(&self, target_id: &T) -> Option<i32>
Returns the shortest distance to the node with id target_id
.
If the target_id
is not contained within the shortest path tree,
None
is returned instead of the distance.
§Example
use simple_graph_algorithms::{Graph, algorithms::dijkstra};
let mut graph = Graph::new();
graph.add_node('a');
graph.add_node('b');
graph.add_node('c');
graph.add_edge(1, &'a', &'b');
graph.add_edge(2, &'b', &'c');
let spt = dijkstra(&mut graph, &'a')?;
assert_eq!(spt.shortest_distance(&'b'), Some(1));
assert_eq!(spt.shortest_distance(&'c'), Some(3));
assert_eq!(spt.shortest_distance(&'d'), None);
Trait Implementations§
impl<T: Eq + Display + Clone + Hash + Eq> Eq for ShortestPathTree<T>
impl<T: Display + Clone + Hash + Eq> StructuralPartialEq for ShortestPathTree<T>
Auto Trait Implementations§
impl<T> Freeze for ShortestPathTree<T>where
T: Freeze,
impl<T> RefUnwindSafe for ShortestPathTree<T>where
T: RefUnwindSafe,
impl<T> Send for ShortestPathTree<T>where
T: Send,
impl<T> Sync for ShortestPathTree<T>where
T: Sync,
impl<T> Unpin for ShortestPathTree<T>where
T: Unpin,
impl<T> UnwindSafe for ShortestPathTree<T>where
T: UnwindSafe,
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