pub struct WorkQueue<T> { /* private fields */ }Expand description
A bounded, priority-ordered work queue.
Items are stored in a Vec sorted in ascending priority order so that
the highest-priority item is always at the back and can be removed in O(1).
Pushes maintain sorted order via binary search insertion at O(n) in the
worst case, which is acceptable for the typical small queue sizes used in
media pipeline scheduling.
§Examples
use oximedia_core::work_queue::{WorkItem, WorkQueue};
let mut q: WorkQueue<i32> = WorkQueue::new(4);
q.push(WorkItem::new(1, 5)).expect("queue not full");
q.push(WorkItem::new(2, 1)).expect("queue not full");
q.push(WorkItem::new(3, 9)).expect("queue not full");
assert_eq!(q.pop().expect("queue not empty").payload, 3); // priority 9 first
assert_eq!(q.len(), 2);Implementations§
Source§impl<T> WorkQueue<T>
impl<T> WorkQueue<T>
Sourcepub fn push(&mut self, item: WorkItem<T>) -> Result<(), QueueError>
pub fn push(&mut self, item: WorkItem<T>) -> Result<(), QueueError>
Pushes a work item into the queue in priority order.
§Errors
Returns QueueError::Full if the queue is at capacity.
Sourcepub fn pop(&mut self) -> Option<WorkItem<T>>
pub fn pop(&mut self) -> Option<WorkItem<T>>
Removes and returns the highest-priority item, or None if empty.
Sourcepub fn pop_batch(&mut self, n: usize) -> Result<Vec<WorkItem<T>>, QueueError>
pub fn pop_batch(&mut self, n: usize) -> Result<Vec<WorkItem<T>>, QueueError>
Removes and returns up to n highest-priority items.
§Errors
Returns QueueError::BatchTooLarge if n > capacity.
Sourcepub fn peek(&self) -> Option<&WorkItem<T>>
pub fn peek(&self) -> Option<&WorkItem<T>>
Peeks at the highest-priority item without removing it.
Sourcepub fn stats(&self) -> QueueStats
pub fn stats(&self) -> QueueStats
Returns a snapshot of the lifetime statistics.
Trait Implementations§
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> UnsafeUnpin for WorkQueue<T>
impl<T> UnwindSafe for WorkQueue<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more