priority-queue
priority-queue copied to clipboard
Add a pop_lowest_priority API
It would be helpful to add a pop API that extracts the lowest priority from the queue and not only the greatest one (as documented here)
If you need a PriorityQueue
that can extract at any time the greatest or the lowest priority, you can use the DoublePriorityQueue
data structure. It features two methods: pop_max()
and pop_min()
.
If you always want to extract the minimum priority item, you can wrap your priorities in a standard wrapper called Reverse<T>
Oh, thank you! Could you please provide some examples in README or inside the examples directory about these two patterns you just mentioned? That would be really helpful! Thank you!
@Luni-4 I needed this too - here's an example:
let mut pq: PriorityQueue<String, Reverse<u64>> = PriorityQueue::new();
pq.push("1".into(), Reverse(10));
pq.push("2".into(), Reverse(15));