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

Re-pushing with the highest priority does not always put the item in the top #6

Closed
da-x opened this issue Jan 12, 2018 · 2 comments
Closed
Assignees
Labels

Comments

@da-x
Copy link

da-x commented Jan 12, 2018

The following example re-pushes "d" with the highest priority among all already pushed items. We expect to see "d" as the first time in .pop(), but we see "a" instead, and "d" comes second.

extern crate priority_queue;

use priority_queue::PriorityQueue;

fn main() {
    let mut pq : PriorityQueue<&'static str, usize> = PriorityQueue::new();

    pq.push("a", 9);
    pq.push("b", 8);
    pq.push("c", 7);
    pq.push("d", 6);

    // Re-pushing with the highest priority
    pq.push("d", 20);

    let mut prev_opt = None;
    for (item, x) in pq.into_sorted_iter() {
        println!("{:?} {:?}", item, x);
        if let Some(prev) = prev_opt {
            if prev < x {
                println!("WTF");
            }
        }
        prev_opt = Some(x);
    }
}

Output:

"a" 9
"d" 20
WTF
"b" 8
"c" 7

Tested along with:

[dependencies]
priority-queue = { git = "https://github.com/garro95/priority-queue" }
@garro95 garro95 self-assigned this Jan 12, 2018
@garro95 garro95 added the bug label Jan 12, 2018
@da-x
Copy link
Author

da-x commented Jan 12, 2018

I think change_priority also needs a fix for this bug.

Thanks.

garro95 pushed a commit that referenced this issue Jan 13, 2018
@garro95
Copy link
Owner

garro95 commented Jan 13, 2018

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants