pub trait ZeroCopyOps<A: Clone + Copy + 'static + Send + Sync> {
// Required methods
fn map_zero_copy<F>(&self, f: F) -> CoreResult<MemoryMappedArray<A>>
where F: Fn(A) -> A + Send + Sync;
fn reduce_zero_copy<F>(&self, init: A, f: F) -> CoreResult<A>
where F: Fn(A, A) -> A + Send + Sync;
fn combine_zero_copy<F>(
&self,
other: &Self,
f: F,
) -> CoreResult<MemoryMappedArray<A>>
where F: Fn(A, A) -> A + Send + Sync;
fn filter_zero_copy<F>(&self, predicate: F) -> CoreResult<Vec<A>>
where F: Fn(&A) -> bool + Send + Sync;
fn max_zero_copy(&self) -> CoreResult<A>
where A: PartialOrd;
fn min_zero_copy(&self) -> CoreResult<A>
where A: PartialOrd;
fn sum_zero_copy(&self) -> CoreResult<A>
where A: Add<Output = A> + From<u8>;
fn product_zero_copy(&self) -> CoreResult<A>
where A: Mul<Output = A> + From<u8>;
fn mean_zero_copy(&self) -> CoreResult<A>
where A: Add<Output = A> + Div<Output = A> + From<u8> + From<usize>;
}Expand description
Trait for zero-copy operations on memory-mapped arrays.
This trait provides methods for performing operations on memory-mapped arrays without unnecessary memory allocations or copies. The operations are designed to work efficiently with large datasets by processing data in chunks and maintaining memory-mapping where possible.
Required Methods§
Sourcefn map_zero_copy<F>(&self, f: F) -> CoreResult<MemoryMappedArray<A>>
fn map_zero_copy<F>(&self, f: F) -> CoreResult<MemoryMappedArray<A>>
Maps a function over each element of the array without loading the entire array.
This is similar to the map function in functional programming, but implemented
to work efficiently with memory-mapped arrays by processing chunks.
§Arguments
f- A function that takes an element of typeAand returns a new element of the same type
§Returns
A new memory-mapped array containing the mapped values
§Example
// Double each element
let doubled = mmap.map_zero_copy(|x| x * 2.0);Sourcefn reduce_zero_copy<F>(&self, init: A, f: F) -> CoreResult<A>
fn reduce_zero_copy<F>(&self, init: A, f: F) -> CoreResult<A>
Reduces the array to a single value by applying a binary operation.
This is similar to the fold or reduce function in functional programming,
but implemented to work efficiently with memory-mapped arrays by processing chunks.
§Arguments
init- The initial value for the reductionf- A function that takes two values of typeAand combines them into one
§Returns
The reduced value
§Example
// Sum all elements
let sum = mmap.reduce_zero_copy(0.0, |acc, x| acc + x);Sourcefn combine_zero_copy<F>(
&self,
other: &Self,
f: F,
) -> CoreResult<MemoryMappedArray<A>>
fn combine_zero_copy<F>( &self, other: &Self, f: F, ) -> CoreResult<MemoryMappedArray<A>>
Performs a binary operation between two memory-mapped arrays element-wise.
This allows for operations like addition, subtraction, etc. between two arrays without loading both arrays entirely into memory.
§Arguments
other- Another memory-mapped array with the same shapef- A function that takes two elements (one from each array) and returns a new element
§Returns
A new memory-mapped array containing the result of the binary operation
§Example
// Add two arrays element-wise
let sum_array = mmap1.combine_zero_copy(&mmap2, |a, b| a + b);Sourcefn filter_zero_copy<F>(&self, predicate: F) -> CoreResult<Vec<A>>
fn filter_zero_copy<F>(&self, predicate: F) -> CoreResult<Vec<A>>
Filters elements based on a predicate function.
Returns a new array containing only the elements that satisfy the predicate.
§Arguments
predicate- A function that takes an element and returns a boolean
§Returns
A new array containing only the elements that satisfy the predicate
§Example
// Get only positive elements
let positives = mmap.filter_zero_copy(|&x| x > 0.0);Sourcefn max_zero_copy(&self) -> CoreResult<A>where
A: PartialOrd,
fn max_zero_copy(&self) -> CoreResult<A>where
A: PartialOrd,
Sourcefn min_zero_copy(&self) -> CoreResult<A>where
A: PartialOrd,
fn min_zero_copy(&self) -> CoreResult<A>where
A: PartialOrd,
Sourcefn sum_zero_copy(&self) -> CoreResult<A>
fn sum_zero_copy(&self) -> CoreResult<A>
Sourcefn product_zero_copy(&self) -> CoreResult<A>
fn product_zero_copy(&self) -> CoreResult<A>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.