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>
impl<T: Idx + From<usize>> WorkQueue<T>
Sourcepub fn with_all(len_idx: T) -> Self
pub fn with_all(len_idx: T) -> Self
Creates a new work queue with all the elements from (0..len).
Sourcepub fn with_none(len_idx: T) -> Self
pub fn with_none(len_idx: T) -> Self
Creates a new work queue that starts empty, where elements range from (0..len).
Sourcepub fn insert(&mut self, element: T) -> bool
pub fn insert(&mut self, element: T) -> bool
Attempt to enqueue element
in the work queue. Returns false if it was already present.
Sourcepub fn take(&mut self) -> Option<T>
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