pub struct MemoryBoundedQueue<T: Ord> { /* private fields */ }Expand description
A priority queue bounded by total bytes (not item count)
Key properties:
- Items are ordered by their
Ordimplementation (higher priority first) push()blocks when adding would exceed capacitypull()returns highest priority item, blocks when queue is empty (returns None when closed)- Provides automatic backpressure for constant memory usage
This matches C++ AGC’s CBoundedPQueue architecture.
Implementations§
Source§impl<T: Ord> MemoryBoundedQueue<T>
impl<T: Ord> MemoryBoundedQueue<T>
Sourcepub fn push(&self, item: T, size_bytes: usize) -> Result<(), PushError>
pub fn push(&self, item: T, size_bytes: usize) -> Result<(), PushError>
Push an item to the queue with its size
BLOCKS if adding this item would exceed capacity. Returns error if queue is closed.
§Arguments
item- The item to pushsize_bytes- Size of the item in bytes
§Example
let contig_data = vec![b'A'; 1000];
queue.push(contig_data.clone(), contig_data.len()).unwrap(); // Blocks if queue is full!Sourcepub fn try_push(&self, item: T, size_bytes: usize) -> Result<(), TryPushError>
pub fn try_push(&self, item: T, size_bytes: usize) -> Result<(), TryPushError>
Try to push without blocking
Returns Err(WouldBlock) if adding would exceed capacity.
Sourcepub fn pull(&self) -> Option<T>
pub fn pull(&self) -> Option<T>
Pull highest-priority item from the queue
BLOCKS if queue is empty.
Returns None if queue is closed and empty.
Items are returned in priority order (highest priority first).
§Example
while let Some(item) = queue.pull() {
// process highest-priority item
}
// Queue is closed and empty - we're done!Sourcepub fn try_pull(&self) -> Option<T>
pub fn try_pull(&self) -> Option<T>
Try to pull highest-priority item without blocking
Returns None if queue is empty (even if not closed).
Sourcepub fn close(&self)
pub fn close(&self)
Close the queue
After closing:
- No more pushes allowed (returns error)
- Pulls will drain remaining items, then return None
- Workers can detect completion via
pull()returning None
Sourcepub fn current_size(&self) -> usize
pub fn current_size(&self) -> usize
Get current size in bytes
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for MemoryBoundedQueue<T>
impl<T> RefUnwindSafe for MemoryBoundedQueue<T>
impl<T> Send for MemoryBoundedQueue<T>where
T: Send,
impl<T> Sync for MemoryBoundedQueue<T>where
T: Send,
impl<T> Unpin for MemoryBoundedQueue<T>
impl<T> UnwindSafe for MemoryBoundedQueue<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more