pub struct PriorityQueue<K: Ord, T>(/* private fields */);
Expand description

A utility type implementing a queue which can be used to automatically sort data by its time in ascending order.

Note that the performance of this queue is very relevant to overall algorithm performance of many graph-walking algorithms, and as it stands our implementation is about 6% slower in practice, probably also depending on the size of the stored data.

Implementations§

source§

impl<K: Ord, T> PriorityQueue<K, T>

source

pub fn new() -> Self

Create a new instance.

source

pub fn insert(&mut self, key: K, value: T)

Insert value so that it is ordered according to key.

source

pub fn pop_value(&mut self) -> Option<T>

Pop the highest-priority item value off the queue.

source

pub fn pop(&mut self) -> Option<(K, T)>

Pop the highest-priority item key and value off the queue.

source

pub fn iter_unordered(&self) -> impl Iterator<Item = &T>

Iterate all items ordered from highest to lowest priority.

source

pub fn into_iter_unordered(self) -> impl Iterator<Item = (K, T)>

Turn this instance into an iterator over its keys and values in arbitrary order.

source

pub fn is_empty(&self) -> bool

Return true if the queue is empty.

source

pub fn len(&self) -> usize

Return true the amount of items on the queue.

source

pub fn peek(&self) -> Option<(&K, &T)>

Returns the greatest item (K, T) tuple, as ordered by K, if the queue is not empty, without removing it.

source

pub fn clear(&mut self)

Drop all items from the queue, without changing its capacity.

Trait Implementations§

source§

impl<K, T> Clone for PriorityQueue<K, T>where K: Clone + Ord, T: Clone,

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K: Ord + Debug, T: Debug> Debug for PriorityQueue<K, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K: Default + Ord, T: Default> Default for PriorityQueue<K, T>

source§

fn default() -> PriorityQueue<K, T>

Returns the “default value” for a type. Read more
source§

impl<K: Ord, T> FromIterator<(K, T)> for PriorityQueue<K, T>

source§

fn from_iter<I: IntoIterator<Item = (K, T)>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<K, T> RefUnwindSafe for PriorityQueue<K, T>where K: RefUnwindSafe, T: RefUnwindSafe,

§

impl<K, T> Send for PriorityQueue<K, T>where K: Send, T: Send,

§

impl<K, T> Sync for PriorityQueue<K, T>where K: Sync, T: Sync,

§

impl<K, T> Unpin for PriorityQueue<K, T>where K: Unpin, T: Unpin,

§

impl<K, T> UnwindSafe for PriorityQueue<K, T>where K: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.