Skip to content

Main example for priority queue using dijkstra's algorithm. #15857

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

Merged
merged 1 commit into from
Jul 22, 2014
Merged

Main example for priority queue using dijkstra's algorithm. #15857

merged 1 commit into from
Jul 22, 2014

Conversation

treeman
Copy link
Contributor

@treeman treeman commented Jul 21, 2014

I wanted to have a slightly larger example compared to the method examples, but I'm unsure how it worked out.

Feedback would nice.

//! #[deriving(Eq, PartialEq)]
//! struct State {
//! cost: uint,
//! pos: uint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bikeshed alert: wonder if this shouldn't be a full position instead. It's not that much longer.

@steveklabnik
Copy link
Member

I really like this idea.

@treeman
Copy link
Contributor Author

treeman commented Jul 22, 2014

Great! Thanks for the pointers.

//!
//! // Examine the frontier with lower cost nodes first (min-heap)
//! while !pq.is_empty() {
//! let State { position: u, cost: curr_cost } = pq.pop().unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be

loop {
    let State { position, cost } = match pq.pop() {
        None => break, // empty
        Some(s) => s
    };

    // ...
}

@alexcrichton
Copy link
Member

This is a fantastic example, nice job!

This looks good to go with two minor comments and some squashings, thanks!

@treeman
Copy link
Contributor Author

treeman commented Jul 22, 2014

Cool, thanks!

bors added a commit that referenced this pull request Jul 22, 2014
I wanted to have a slightly larger example compared to the method examples, but I'm unsure how it worked out.

Feedback would nice.
@bors bors closed this Jul 22, 2014
@bors bors merged commit 94500b8 into rust-lang:master Jul 22, 2014
@treeman treeman deleted the doc-dijkstra-example branch September 17, 2014 09:50
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 4, 2023
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.

5 participants