Struct PriorityQueue

Source
pub struct PriorityQueue<K, P>
where K: Clone + Hash, P: Clone + Ord + PartialEq,
{ /* private fields */ }
Expand description

§About

See the module-level documentation for more information.

Implementations§

Source§

impl<K, P> PriorityQueue<K, P>
where K: Debug + Clone + Hash, P: Clone + Debug + Ord + PartialEq,

Source

pub fn new() -> Self

Creates a new, zero-sized PriorityQueue. Warning: Unimplemented

Source

pub fn new_with_capacity(capacity: usize) -> Self

Creates a new PriorityQueue that pre-allocates to the given capacity.

Source

pub fn len(&self) -> usize

Returns the number of live elements in the queue.

Source

pub fn is_empty(&self) -> bool

Returns true if the queue is empty.

Source

pub fn contains(&self, key: K) -> bool

Returns true if the provided key exists within the priority queue.

Source

pub fn put(&mut self, key: K, priority: P)

Adds an element to the heap in O(log(n)) time. It is the caller’s responsibility to ensure key uniqueness; this function overwrites priority values for duplicate keys.

Source

pub fn try_put(&mut self, key: K, priority: P) -> Result<(), &str>

Attempts to add an element to the heap in O(log(n)) time. Returns an error if the key already exists in the queue.

Source

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

Returns a tuple containing an immutable reference to the data at the top of the front of the queue in O(1) time, if the queue is not empty. Otherwise, returns None.

Source

pub fn mutate_priority(&mut self, key: K, new_priority: P) -> Result<P, &str>

Operates like put(K, P) but returns a Result that contains the old priority, if it exists. Operation requires O(log(n)) time.

Source

pub fn mutate_key(&mut self, old_key: K, new_key: K) -> Result<K, &str>

Attempts to replace the key in a key:value pair in the queue in O(1) time, if it exists. If the key does not exist, the operation returns an error.

Source

pub fn clean(&mut self)

A manual tool to rehash and shrink the structure’s map down to a load factor <= 0.5. The structure automatically rehashes the underlying map for remove and key mutation operations to reduce spatial bloat in long-lived queues with many such mutations. This operation provides a manual way to actually shrink the underlying map down to a load factor of 0.5 over live entries only. This operation uses the map’s shrink_to_fit() operation to clean up the backing structure for long-lived queues in O(n) time where n is the number of live entries in the queue.

Source

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

Removes and returns the highest priority pair in the queue. This operation automatically checks for spatial bloat and rehashes the underlying map when tombstones outnumber live entries. Amortized cost is O(log n), but a rehash may occasionally incur O(n) time where n is the number of live entries in the queue.

Source

pub fn remove(&mut self, key: K) -> Option<(K, P)>

Removes and returns an arbitrarily-located entry for the given key. This operation automatically checks for spatial bloat and rehashes the underlying map when tombstones outnumber live entries. Amortized cost is O(log n), but a rehash may occasionally incur O(n) time where n is the number of live entries in the queue.

Trait Implementations§

Source§

impl<K, P> Debug for PriorityQueue<K, P>
where K: Clone + Hash + Debug, P: Clone + Ord + PartialEq + Debug,

Source§

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

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

impl<K, P> Default for PriorityQueue<K, P>
where K: Debug + Clone + Hash, P: Clone + Debug + Ord + PartialEq,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<K, P> Freeze for PriorityQueue<K, P>

§

impl<K, P> RefUnwindSafe for PriorityQueue<K, P>

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V