Struct PrioritySet

Source
pub struct PrioritySet<I: PartialEq, const N: usize> { /* private fields */ }
Expand description

PrioritySet is a fixed size Priority Set.

It never allocates, instead dropping the lowest priority item when inserting a new one.

Implementations§

Source§

impl<I: PartialEq, const N: usize> PrioritySet<I, N>

Source

pub fn new() -> Self

Initializes a new empty PrioritySet with N free slots.

Source

pub fn len(&self) -> usize

Counts the number of occupied entries in the set

Source

pub fn is_full(&self) -> bool

Returns true if all slots in the priority set are occupied

Source

pub fn insert(&mut self, priority: Priority, item: I) -> InsertResult

Inserts an item with priority.

If the item already exists in the set, the priority is updated. The highest priority is chosen between the existing priority and the new priority.

If the set is full the least prioritary item is dropped. If all items are of higher priority than the item being inserted, no change occurs.

Returns true if the item was inserted, false if it was dropped.

Source

pub fn priority(&self, item: &I) -> Option<Priority>

Gets the priority of a item, if it exists

Source

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

Returns an iterator over the entries

Iteration order is not guaranteed.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut PriorityEntry<I>>

Returns a mutable iterator over the entries

Iteration order is not guaranteed.

Source

pub fn entry(&self, item: &I) -> Option<&PriorityEntry<I>>

Finds an item entry

Source

pub fn entry_mut(&mut self, item: &I) -> Option<&mut PriorityEntry<I>>

Returns a mutable entry to an item

Source

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

Pops the highest priority item from the set

Source

pub fn pop_entry(&mut self) -> Option<PriorityEntry<I>>

Pops the highest priority item entry from the set

Trait Implementations§

Source§

impl<I: PartialEq + Clone, const N: usize> Clone for PrioritySet<I, N>

Source§

fn clone(&self) -> Self

Returns a duplicate 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<I: Debug + PartialEq, const N: usize> Debug for PrioritySet<I, N>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<I, const N: usize> Freeze for PrioritySet<I, N>
where I: Freeze,

§

impl<I, const N: usize> RefUnwindSafe for PrioritySet<I, N>
where I: RefUnwindSafe,

§

impl<I, const N: usize> Send for PrioritySet<I, N>
where I: Send,

§

impl<I, const N: usize> Sync for PrioritySet<I, N>
where I: Sync,

§

impl<I, const N: usize> Unpin for PrioritySet<I, N>
where I: Unpin,

§

impl<I, const N: usize> UnwindSafe for PrioritySet<I, N>
where I: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.