Struct WorkQueue

Source
pub struct WorkQueue<T: Idx + From<usize>> {
    pub deque: VecDeque<T>,
    pub set: BitSet<T>,
}
Expand description

A work queue is a handy data structure for tracking work left to do. (For example, basic blocks left to process.) It is basically a de-duplicating queue; so attempting to insert X if X is already enqueued has no effect. This implementation assumes that the elements are dense indices, so it can allocate the queue to size and also use a bit set to track occupancy.

Fields§

§deque: VecDeque<T>§set: BitSet<T>

Implementations§

Source§

impl<T: Idx + From<usize>> WorkQueue<T>

Source

pub fn with_all(len_idx: T) -> Self

Creates a new work queue with all the elements from (0..len).

Source

pub fn with_none(len_idx: T) -> Self

Creates a new work queue that starts empty, where elements range from (0..len).

Source

pub fn insert(&mut self, element: T) -> bool

Attempt to enqueue element in the work queue. Returns false if it was already present.

Source

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

Attempt to pop an element from the work queue.

Source

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

Attempt to take an element from from the work queue This function does not remove the item from the iternal set As such any element removed using take can never be inserted again. For must use cases [pop]should be used

This is useful when you want to write a worklist based algorithm that processes every element exactly one

Source

pub fn is_empty(&self) -> bool

Returns true if nothing is enqueued.

Trait Implementations§

Source§

impl<I: Idx + From<usize> + Debug> Debug for WorkQueue<I>

Source§

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

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

impl<I: Idx + From<usize>> From<BitSet<I>> for WorkQueue<I>

Source§

fn from(set: BitSet<I>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for WorkQueue<T>

§

impl<T> RefUnwindSafe for WorkQueue<T>
where T: RefUnwindSafe,

§

impl<T> Send for WorkQueue<T>
where T: Send,

§

impl<T> Sync for WorkQueue<T>
where T: Sync,

§

impl<T> Unpin for WorkQueue<T>
where T: Unpin,

§

impl<T> UnwindSafe for WorkQueue<T>
where T: 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.