Skip to content

Commit

Permalink
Fix purpleprotocol#56 - Drop unneeded mut from Dijkstra::get_distance
Browse files Browse the repository at this point in the history
While here, drop an unnecessary bare `Option::unwrap()`.
  • Loading branch information
cemeyer committed Dec 9, 2021
1 parent 727f7bd commit de406ab
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/iterators/dijkstra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,12 @@ impl<'a, T> Dijkstra<'a, T> {
Ok(VertexIter(Box::new(iter::empty())))
}

pub fn get_distance(&mut self, vert: &'a VertexId) -> Result<f32, GraphErr> {
pub fn get_distance(&self, vert: &'a VertexId) -> Result<f32, GraphErr> {
if self.iterable.fetch(vert).is_none() {
return Err(GraphErr::NoSuchVertex);
}

if self.distances.contains_key(vert) {
return Ok(*self.distances.get(vert).unwrap());
}

Ok(f32::MAX)
Ok(self.distances.get(vert).copied().unwrap_or(f32::MAX))
}

fn calc_distances(&mut self) {
Expand Down

0 comments on commit de406ab

Please sign in to comment.