Struct PrioritySet

Source
pub struct PrioritySet<I: Ord + Hash + Clone, P: Ord + Copy> { /* private fields */ }
Expand description

A set that offers efficient iteration over its elements in priority-ascending order.

Implementations§

Source§

impl<I: Ord + Hash + Clone, P: Ord + Copy> PrioritySet<I, P>

Source

pub fn new() -> Self

Create a new PrioritySet.

Source

pub fn put(&mut self, item: I, priority: P)

Insert an item with a priority, overwriting the previous priority if it exists.

Source

pub fn get(&self, item: &I) -> Option<P>

Get the current priority of an item.

Source

pub fn remove(&mut self, item: &I) -> bool

Remove an item from the set.

Returns true if the item was present.

Source

pub fn reconcile(&mut self, keep: &[I], default: P)

Remove all previously inserted items not included in keep and add any items not yet seen with a priority of initial.

Source

pub fn contains(&self, item: &I) -> bool

Returns true if the set contains the item.

Source

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

Returns the item with the highest priority.

Source

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

Removes and returns the item with the highest priority.

Source

pub fn iter(&self) -> impl Iterator<Item = (&I, &P)>

Returns an iterator over all items in the set in priority-ascending order.

Source

pub fn len(&self) -> usize

Returns the number of items in the set.

Source

pub fn is_empty(&self) -> bool

Returns true if the set is empty.

Auto Trait Implementations§

§

impl<I, P> Freeze for PrioritySet<I, P>

§

impl<I, P> RefUnwindSafe for PrioritySet<I, P>

§

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

§

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

§

impl<I, P> Unpin for PrioritySet<I, P>
where I: Unpin, P: Unpin,

§

impl<I, P> UnwindSafe for PrioritySet<I, P>

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.