Skip to content

remove_until like API, removes all items until a predicate matches #55

Description

@Dav1dde

The idea is similar to #47 but instead of being able to skip items, it would remove all items until a predicate matches (excluding that element).

For example in Rust pseudo code:

let mut queue = PriorityQueue::new();
queue.push(1, "a");
queue.push(2, "b");
queue.push(3, "c");

let items = queue.remove_until(|k| k < 3).collect::<Vec<_>>();
assert_eq!(items, vec![(1, "a"), (2, "b")]);

assert_eq!(queue.peek(), Some((3, "c")));

Currently this requires to either peek and pop:

while let Some((k, _)) = queue.peek() {
    if k < 3 { 
        break 
    }

    let Some((k, v)) = queue.pop().unwrap();
} 

Or constant pops() with a push of the removed item which does not match the predicate.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions