Trait queue_queue::PriorityQueue
source · pub trait PriorityQueue<P: PartialOrd + PartialEq + Eq, T: PartialEq + Eq> {
Show 15 methods
// Required methods
fn enqueue(&mut self, priority: P, data: T);
fn dequeue(&mut self) -> Option<(P, T)>;
fn peek(&self) -> Option<(&P, &T)>;
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
fn capacity(&self) -> usize;
fn with_capacity(capacity: usize) -> Self;
fn append(&mut self, other: Self);
fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = (P, T)>;
fn reserve(&mut self, additional: usize);
fn reserve_exact(&mut self, additional: usize);
fn shrink_to_fit(&mut self);
fn shrink_to(&mut self, capacity: usize);
fn clear(&mut self);
fn drain(&mut self) -> impl Iterator<Item = (P, T)> + '_;
}Required Methods§
sourcefn with_capacity(capacity: usize) -> Self
fn with_capacity(capacity: usize) -> Self
Create a new priority queue with a given capacity
§Example:
RustyPriorityQueue::<usize, &str>::with_capacity(10)
sourcefn append(&mut self, other: Self)
fn append(&mut self, other: Self)
Append another priority queue into this one
- Consumes the other priority queue
sourcefn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (P, T)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (P, T)>,
Extend the priority queue with an IntoIterator of (P, T) => (Priority, Data)
where P: PartialOrd + PartialEq + Eq, T: PartialEq + Eq
sourcefn reserve(&mut self, additional: usize)
fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional elements more than the current length.
The allocator may reserve more space to speculatively avoid frequent allocations.
After calling reserve, capacity will be greater than or equal to self.len() + additional.
Does nothing if capacity is already sufficient.
§Panics
Panics if the new capacity overflows usize.
sourcefn reserve_exact(&mut self, additional: usize)
fn reserve_exact(&mut self, additional: usize)
Reserves the minimum capacity for at least additional elements more than the current length.
Unlike reserve, this will not deliberately over-allocate to speculatively avoid frequent allocations.
After calling reserve_exact, capacity will be greater than or equal to self.len() + additional.
Does nothing if the capacity is already sufficient.
§Panics
Panics if the new capacity overflows usize.
sourcefn shrink_to_fit(&mut self)
fn shrink_to_fit(&mut self)
Discards as much additional capacity as possible.
sourcefn shrink_to(&mut self, capacity: usize)
fn shrink_to(&mut self, capacity: usize)
Discards capacity with a lower bound. The capacity will remain at least as large as both the length and the supplied value. If the current capacity is less than the lower limit, this is a no-op.
sourcefn drain(&mut self) -> impl Iterator<Item = (P, T)> + '_
fn drain(&mut self) -> impl Iterator<Item = (P, T)> + '_
Clears the binary heap, returning an iterator over the removed elements in arbitrary order. If the iterator is dropped before being fully consumed, it drops the remaining elements in arbitrary order.
The returned iterator keeps a mutable borrow on the heap to optimize its implementation.
§Examples
Basic usage:
let mut prio = RustyPriorityQueue::<usize, String>::default();
prio.enqueue(2, "hello".to_string());
assert!(!prio.is_empty());
for x in prio.drain() {
println!("{x:?}");
}
assert!(prio.is_empty());