pub trait PriorityQueue<P: PartialOrd + PartialEq + Eq, T: PartialEq + Eq> {
Show 21 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 contains(&self, data: &T) -> bool;
fn contains_at(&self, priority: &P, data: &T) -> bool;
fn remove(&mut self, data: &T) -> bool;
fn remove_at(&mut self, priority: &P, data: &T) -> bool;
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)> + '_;
fn max_node(&self) -> Option<(&P, &T)>;
fn min_node(&self) -> Option<(&P, &T)>;
}
Required Methods§
Sourcefn contains(&self, data: &T) -> bool
fn contains(&self, data: &T) -> bool
Check if an item exists in the queue true if it exists, false if it does not
Sourcefn contains_at(&self, priority: &P, data: &T) -> bool
fn contains_at(&self, priority: &P, data: &T) -> bool
Check if an item exists in the queue at a certain priority true if it exists, false if it does not
Sourcefn remove(&mut self, data: &T) -> bool
fn remove(&mut self, data: &T) -> bool
Remove all existing items from the queue true if it was removed, false if it was not
Sourcefn remove_at(&mut self, priority: &P, data: &T) -> bool
fn remove_at(&mut self, priority: &P, data: &T) -> bool
Remove an item from the queue if exists at a certain priority true if it was removed, false if it was not
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());
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.