Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve graphlib::iterators::Dijkstra API #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cemeyer
Copy link

@cemeyer cemeyer commented Dec 9, 2021

The Dijkstra::new() API computes the single-source shortest path between a given source and every other vertex in the graph. For a consumer that cares about the shortest path between a given source and two or more other graph nodes (e.g., AB, AC, etc), the SSSP computation can be reused. This is more efficient than recomputing it for every destination node (and part of why SSSP is a great algorithm).

These changes make reuse more ergonomic by not consuming the value, and referencing the Dijkstra object immutably rather than mutably.

Previously, one could reuse the results of the SSSP computation only by clone()ing the entire Dijkstra object, which is inefficient.

Tests continue to pass.

We only consume `self` for `iterator: VecDequeue`, which is unused
outside of this routine and might as well be a local variable.
While here, drop an unnecessary bare `Option::unwrap()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant