pub struct LQueue { /* private fields */ }Expand description
The operation queue that records and executes parallel operations.
LQueue is the central coordinator for deferred parallel execution. It manages
the recording of operations and their bulk execution, minimizing thread pool
overhead by batching all operations together.
§Workflow
- Create vectors with
LQueue::lvecorLQueue::lvec_with_capacity - Call
LQueue::startto begin recording - Perform operations on
LVecinstances (all operations are recorded, not executed) - Call
LQueue::endto execute all recorded operations in parallel - Use
LVec::materializeto retrieve results
§Type Agnostic
A single LQueue can manage vectors of different types simultaneously:
use leopard::{LQueue, LVec};
let q = LQueue::new();
let integers: LVec<i32> = q.lvec_with_capacity(100);
let floats: LVec<f64> = q.lvec_with_capacity(100);
// Both can be used in the same recording session§Examples
use leopard::{LQueue, LVec};
let q = LQueue::new();
let x: LVec<f64> = q.lvec_with_capacity(1000);
let y: LVec<f64> = q.lvec_with_capacity(1000);
q.start();
let x = x.fill_with(|i| i as f64);
let y = y.fill_with(|i| (i * 2) as f64);
let z = &x + &y;
q.end();
let result = z.materialize().unwrap();
println!("Sum: {:?}", &result[0..5]);Implementations§
Source§impl LQueue
impl LQueue
Sourcepub fn lvec_with_capacity<T>(&self, capacity: usize) -> LVec<T>
pub fn lvec_with_capacity<T>(&self, capacity: usize) -> LVec<T>
Creates a new LVec with the specified capacity.
§Arguments
capacity- The number of elements the vector can hold
§Type Parameters
T- The element type, must implementClone + Send + Sync + Default
§Examples
use leopard::{LQueue, LVec};
let q = LQueue::new();
let vec: LVec<f64> = q.lvec_with_capacity(10000);
assert_eq!(vec.capacity(), 10000);Sourcepub fn start(&self)
pub fn start(&self)
Starts recording operations.
After calling start(), all operations on LVec instances created from
this queue will be recorded rather than executed. The operations will be
executed when LQueue::end is called.
§Panics
Operations on LVec will panic if called outside of a start()/end() block.
§Examples
use leopard::{LQueue, LVec};
let q = LQueue::new();
let x: LVec<f64> = q.lvec_with_capacity(100);
q.start(); // Begin recording
let x = x.fill(42.0);
// ... more operations ...
q.end(); // Execute all recorded operationsSourcepub fn end(&self)
pub fn end(&self)
Stops recording and executes all recorded operations in parallel.
This method executes all operations that were recorded since the last
LQueue::start call. Operations are executed in dependency order,
with independent operations running in parallel.
After end() is called, results can be retrieved using LVec::materialize.
§Performance
All parallel execution happens in this single call, minimizing thread pool creation overhead compared to executing operations individually.
§Examples
use leopard::{LQueue, LVec};
let q = LQueue::new();
let x: LVec<f64> = q.lvec_with_capacity(1000);
q.start();
let x = x.fill_with(|i| i as f64);
let y = x.map(|_, v| v * 2.0);
q.end(); // Both fill and map execute here
let result = y.materialize().unwrap();Sourcepub fn is_recording(&self) -> bool
pub fn is_recording(&self) -> bool
Returns true if the queue is currently recording operations.
§Examples
use leopard::LQueue;
let q = LQueue::new();
assert!(!q.is_recording());
q.start();
assert!(q.is_recording());
q.end();
assert!(!q.is_recording());Trait Implementations§
Auto Trait Implementations§
impl Freeze for LQueue
impl !RefUnwindSafe for LQueue
impl !Send for LQueue
impl !Sync for LQueue
impl Unpin for LQueue
impl !UnwindSafe for LQueue
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
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>
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>
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