MemoryBoundedQueue

Struct MemoryBoundedQueue 

Source
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 Ord implementation (higher priority first)
  • push() blocks when adding would exceed capacity
  • pull() 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>

Source

pub fn new(capacity_bytes: usize) -> Self

Create a new memory-bounded priority queue

§Arguments
  • capacity_bytes - Maximum total bytes allowed in queue
§Example
use ragc_core::MemoryBoundedQueue;
// Note: T must implement Ord for priority ordering
let queue: MemoryBoundedQueue<usize> = MemoryBoundedQueue::new(2 * 1024 * 1024 * 1024); // 2 GB
Source

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 push
  • size_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!
Source

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.

Source

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!
Source

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).

Source

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
Source

pub fn is_closed(&self) -> bool

Check if queue is closed

Source

pub fn current_size(&self) -> usize

Get current size in bytes

Source

pub fn len(&self) -> usize

Get current item count

Source

pub fn is_empty(&self) -> bool

Check if queue is empty

Source

pub fn capacity(&self) -> usize

Get capacity in bytes

Trait Implementations§

Source§

impl<T: Ord> Clone for MemoryBoundedQueue<T>

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

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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.