LQueue

Struct LQueue 

Source
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

  1. Create vectors with LQueue::lvec or LQueue::lvec_with_capacity
  2. Call LQueue::start to begin recording
  3. Perform operations on LVec instances (all operations are recorded, not executed)
  4. Call LQueue::end to execute all recorded operations in parallel
  5. Use LVec::materialize to 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

Source

pub fn new() -> Self

Creates a new operation queue.

§Examples
use leopard::LQueue;

let q = LQueue::new();
Source

pub fn lvec<T>(&self) -> LVec<T>
where T: Clone + Send + Sync + Default + 'static,

Creates a new LVec with the default capacity (128 elements).

§Type Parameters
  • T - The element type, must implement Clone + Send + Sync + Default
§Examples
use leopard::{LQueue, LVec};

let q = LQueue::new();
let vec: LVec<f64> = q.lvec();
assert_eq!(vec.capacity(), 128);
Source

pub fn lvec_with_capacity<T>(&self, capacity: usize) -> LVec<T>
where T: Clone + Send + Sync + Default + 'static,

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 implement Clone + 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);
Source

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

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();
Source

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§

Source§

impl Clone for LQueue

Source§

fn clone(&self) -> LQueue

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

impl Default for LQueue

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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