Struct priority_queue::PriorityQueue [] [src]

pub struct PriorityQueue<I, P> where
    I: Hash + Eq,
    P: Ord
{ /* 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 type I, that must implement Hash and Eq.

Implemented as a heap of indexes, stores the items inside an IndexMap to be able to retrieve them quickly.

Methods

impl<I, P> PriorityQueue<I, P> where
    P: Ord,
    I: Hash + Eq
[src]

[src]

Creates an empty PriorityQueue

[src]

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 be no allocation.

[src]

Returns an iterator in arbitrary order over the (item, priority) elements in the queue

[src]

Return n iterator in arbitrary order over the (item, priority) elements in the queue.

The item and the priority are mutable references, but it's a logic error to modify the item in a way that change the result of Hash or Eq.

It's not an error, instead, to modify the priorities, because the heap will be rebuilt once the IterMut goes out of scope. It would be rebuilt even if no priority value would have been modified, but the procedure will not move anything, but just compare the priorities.

[src]

Returns the couple (item, priority) with the greatest priority in the queue, or None if it is empty.

Computes in O(1) time

[src]

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 push, change_priority or change_priority_by.

Computes in O(1) time

[src]

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.

[src]

Reserves capacity for at least additional more elements to be inserted in the given PriorityQueue. The collection may reserve more space to avoid frequent reallocations. 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.

[src]

Shrinks the capacity of the internal data structures that support this operation as much as possible.

[src]

Removes the item with the greatest priority from the priority queue and returns the pair (item, priority), or None if the queue is empty.

[src]

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.

[src]

Change the priority of an Item returning the old value of priority, or None if the item wasn't in the queue.

The item is found in O(1) thanks to the hash table. The operation is performed in O(log(N)) time.

[src]

Change the priority of an Item using the provided function. The item is found in O(1) thanks to the hash table. The operation is performed in O(log(N)) time (worst case).

[src]

Get the priority of an item, or None, if the item is not in the queue

[src]

Get the couple (item, priority) of an arbitrary element, as reference or None if the item is not in the queue.

[src]

Get the couple (item, priority) of an arbitrary element, or None if the item was not in the queue.

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 push, change_priority or change_priority_by.

[src]

Returns the items not ordered

[src]

Implements an HeapSort

[src]

Returns the number of elements in the priority queue.

[src]

Returns true if the priority queue contains no elements.

[src]

Drops all items from the priority queue

[src]

Move all items of the other queue to self ignoring the items Eq to elements already in self At the end, other will be empty.

Note that at the end, the priority of the duplicated elements inside self may be the one of the elements in other, if other is longer than self

[src]

Generates a new iterator from self that will extract the elements from the one with the highest priority to the lowest one.

Trait Implementations

impl<I: Clone, P: Clone> Clone for PriorityQueue<I, P> where
    I: Hash + Eq,
    P: Ord
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<I: Default, P: Default> Default for PriorityQueue<I, P> where
    I: Hash + Eq,
    P: Ord
[src]

[src]

Returns the "default value" for a type. Read more

impl<I: Eq, P: Eq> Eq for PriorityQueue<I, P> where
    I: Hash + Eq,
    P: Ord
[src]

impl<I, P> From<Vec<(I, P)>> for PriorityQueue<I, P> where
    I: Hash + Eq,
    P: Ord
[src]

[src]

Performs the conversion.

impl<I, P> FromIterator<(I, P)> for PriorityQueue<I, P> where
    I: Hash + Eq,
    P: Ord
[src]

[src]

Creates a value from an iterator. Read more

impl<I, P> IntoIterator for PriorityQueue<I, P> where
    I: Hash + Eq,
    P: Ord
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<'a, I, P> IntoIterator for &'a PriorityQueue<I, P> where
    I: Hash + Eq,
    P: Ord
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<'a, I, P> IntoIterator for &'a mut PriorityQueue<I, P> where
    I: Hash + Eq,
    P: Ord
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<I, P> Extend<(I, P)> for PriorityQueue<I, P> where
    I: Hash + Eq,
    P: Ord
[src]

[src]

Extends a collection with the contents of an iterator. Read more

impl<I, P> Debug for PriorityQueue<I, P> where
    I: Debug + Hash + Eq,
    P: Debug + Ord
[src]

[src]

Formats the value using the given formatter. Read more

impl<I, P1, P2> PartialEq<PriorityQueue<I, P2>> for PriorityQueue<I, P1> where
    I: Hash + Eq,
    P1: Ord,
    P1: PartialEq<P2>,
    Option<P1>: PartialEq<Option<P2>>,
    P2: Ord
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

Auto Trait Implementations

impl<I, P> Send for PriorityQueue<I, P> where
    I: Send,
    P: Send

impl<I, P> Sync for PriorityQueue<I, P> where
    I: Sync,
    P: Sync