use crate::array::*;
use super::handle::{ArrayFetchBatchOpHandle, ArrayFetchOpHandle};
#[doc(alias("One-sided", "onesided"))]
pub trait ReadOnlyOps<T: ElementOps>: private::LamellarArrayPrivate<T> {
fn load<'a>(&self, index: usize) -> ArrayFetchOpHandle<T> {
let dummy_val = self.inner_array().dummy_val(); self.inner_array()
.initiate_batch_fetch_op_2(
dummy_val,
index,
ArrayOpCmd::Load,
self.as_lamellar_byte_array(),
)
.into()
}
fn blocking_load(&self, index: usize) -> T {
self.load(index).block()
}
fn batch_load<'a>(&self, index: impl OpInput<'a, usize>) -> ArrayFetchBatchOpHandle<T> {
let dummy_val = self.inner_array().dummy_val(); self.inner_array().initiate_batch_fetch_op_2(
dummy_val,
index,
ArrayOpCmd::Load,
self.as_lamellar_byte_array(),
)
}
}
#[doc(alias("One-sided", "onesided"))]
pub trait UnsafeReadOnlyOps<T: ElementOps>: private::LamellarArrayPrivate<T> {
unsafe fn load<'a>(&self, index: usize) -> ArrayFetchOpHandle<T> {
let dummy_val = self.inner_array().dummy_val(); self.inner_array()
.initiate_batch_fetch_op_2(
dummy_val,
index,
ArrayOpCmd::Load,
self.as_lamellar_byte_array(),
)
.into()
}
unsafe fn batch_load<'a>(&self, index: impl OpInput<'a, usize>) -> ArrayFetchBatchOpHandle<T> {
let dummy_val = self.inner_array().dummy_val(); self.inner_array().initiate_batch_fetch_op_2(
dummy_val,
index,
ArrayOpCmd::Load,
self.as_lamellar_byte_array(),
)
}
}
#[doc(hidden)]
pub trait LocalReadOnlyOps<T: ElementOps> {
fn local_load<'a>(&self, idx_vals: impl Iterator<Item = (usize, T)>) -> Vec<T>;
}
impl<T: ElementOps> LocalReadOnlyOps<T> for __LamellarMutLocalData<'_, T> {
fn local_load<'a>(&self, idx_vals: impl Iterator<Item = (usize, T)>) -> Vec<T> {
match self {
__LamellarMutLocalData::Slice(data) => data.local_load(idx_vals),
__LamellarMutLocalData::LocalLock(data) => {
let slice: &[T] = &*data;
slice.local_load(idx_vals)
}
__LamellarMutLocalData::GlobalLock(data) => {
let slice: &[T] = &*data;
slice.local_load(idx_vals)
}
__LamellarMutLocalData::NativeAtomic(data) => data.local_load(idx_vals),
__LamellarMutLocalData::GenericAtomic(data) => data.local_load(idx_vals),
__LamellarMutLocalData::NetworkAtomic(data) => data.local_load(idx_vals),
}
}
}
impl<T: ElementOps> LocalReadOnlyOps<T> for __LamellarLocalData<'_, T> {
fn local_load<'a>(&self, idx_vals: impl Iterator<Item = (usize, T)>) -> Vec<T> {
match self {
__LamellarLocalData::Slice(data) => data.local_load(idx_vals),
__LamellarLocalData::LocalLock(data) => {
let slice: &[T] = &*data;
slice.local_load(idx_vals)
}
__LamellarLocalData::GlobalLock(data) => {
let slice: &[T] = &*data;
slice.local_load(idx_vals)
}
__LamellarLocalData::NativeAtomic(data) => data.local_load(idx_vals),
__LamellarLocalData::GenericAtomic(data) => data.local_load(idx_vals),
__LamellarLocalData::NetworkAtomic(data) => data.local_load(idx_vals),
}
}
}
impl<T: ElementOps> LocalReadOnlyOps<T> for &mut [T] {
fn local_load<'a>(&self, idx_vals: impl Iterator<Item = (usize, T)>) -> Vec<T> {
idx_vals.map(|(i, _)| self[i]).collect()
}
}
impl<T: ElementOps> LocalReadOnlyOps<T> for &[T] {
fn local_load<'a>(&self, idx_vals: impl Iterator<Item = (usize, T)>) -> Vec<T> {
idx_vals.map(|(i, _)| self[i]).collect()
}
}