Thanks to visit codestin.com
Credit goes to docs.rs

Struct ShortestPathTree

Source
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>

Source

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.

Source

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§

Source§

impl<T: Debug + Display + Clone + Hash + Eq> Debug for ShortestPathTree<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq + Display + Clone + Hash + Eq> PartialEq for ShortestPathTree<T>

Source§

fn eq(&self, other: &ShortestPathTree<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq + Display + Clone + Hash + Eq> Eq for ShortestPathTree<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.