Struct priority_queue::PriorityQueue
[−]
[src]
pub struct PriorityQueue<I, P> where
I: Hash + Eq, { /* fields omitted */ }
A priority queue with efficient change function to change the priority of an element.
The priority is of type P, that must implement std::cmp::Ord
.
The item is of typer I, that must implement Hash
and Eq
Implemented as an heap of indexes, stores the items inside an OrderMap
to be able to retrieve them quickly.
Methods
impl<I, P> PriorityQueue<I, P> where
P: Ord,
I: Hash + Eq,
[src]
P: Ord,
I: Hash + Eq,
fn new() -> PriorityQueue<I, P>
Creates an empty PriorityQueue
fn with_capacity(capacity: usize) -> PriorityQueue<I, P>
Creates an empty PriorityQueue
with the specified capacity.
The internal collections will be able to hold at least capacity
elements without reallocating.
If capacity
is 0, there will no allocation.
fn peek(&self) -> Option<(&I, &P)>
Returns the couple (item, priority) with the greatest priority in the queue, or None if it is empty.
Computes in O(1) time
fn peek_mut(&mut self) -> Option<(&mut I, &P)>
Returns the couple (item, priority) with the greatest priority in the queue, or None if it is empty.
The item is a mutable reference, but it's a logic error to modify it
in a way that change the result of Hash
or Eq
.
The priority cannot be modified with a call to this function. To modify the priority use ...
Computes in O(1) time
fn capacity(&self) -> usize
Returns the number of elements the internal map can hold without reallocating.
This number is a lower bound; the map might be able to hold more, but is guaranteed to be able to hold at least this many.
fn shrink_to_fit(&mut self)
Shrinks the capacity of the internal data structures that support this operation as much as possible.
fn pop(&mut self) -> Option<(I, P)>
Removes the item with the greatest priority from the priority queue and returns the pair (item, priority), or None if it is empty.
fn push(&mut self, item: I, priority: P) -> Option<P>
Insert the item-priority pair into the queue.
If an element equals to item
was already into the queue,
it is updated and the old value of its priority returned in Some
;
otherwise, return None
.
Computes in O(log(N)) time.
fn change_priority<Q: ?Sized>(&mut self, item: &Q, new_priority: P) -> Option<P> where
I: Borrow<Q>,
Q: Eq + Hash,
I: Borrow<Q>,
Q: Eq + Hash,
Change the priority of an Item. The item is found in O(1) thanks to the hash table. The operation is performed in O(lon(N)) time.
fn into_vec(self) -> Vec<I>
Returns the items not ordered
fn into_sorted_vec(self) -> Vec<I>
Implements an HeapSort
fn len(&self) -> usize
Returns the number of elements in the priority queue.
fn is_empty(&self) -> bool
Returns true if the priority queue contains no elements.
fn clear(&mut self)
Drops all items from the priority queue
Trait Implementations
impl<I: Clone, P: Clone> Clone for PriorityQueue<I, P> where
I: Hash + Eq,
[src]
I: Hash + Eq,
fn clone(&self) -> PriorityQueue<I, P>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<I: Debug, P: Debug> Debug for PriorityQueue<I, P> where
I: Hash + Eq,
[src]
I: Hash + Eq,
impl<I, P> From<Vec<(I, P)>> for PriorityQueue<I, P> where
I: Hash + Eq,
P: Ord,
[src]
I: Hash + Eq,
P: Ord,
fn from(vec: Vec<(I, P)>) -> PriorityQueue<I, P>
Performs the conversion.
impl<I, P> FromIterator<(I, P)> for PriorityQueue<I, P> where
I: Hash + Eq,
P: Ord,
[src]
I: Hash + Eq,
P: Ord,
fn from_iter<IT>(iter: IT) -> PriorityQueue<I, P> where
IT: IntoIterator<Item = (I, P)>,
IT: IntoIterator<Item = (I, P)>,
Creates a value from an iterator. Read more