use std::ops::Deref;
use std::sync::Arc;
pub use adapter::*;
pub use ext::*;
use vortex_dtype::DType;
use vortex_error::VortexResult;
use crate::Array;
mod adapter;
mod ext;
pub const ITER_BATCH_SIZE: usize = 1024;
pub trait ArrayIterator: Iterator<Item = VortexResult<Array>> {
fn dtype(&self) -> &DType;
}
pub type AccessorRef<T> = Arc<dyn Accessor<T>>;
pub trait Accessor<T>: Send + Sync + Deref<Target = Array> {
fn batch_size(&self, start_idx: usize) -> usize {
usize::min(ITER_BATCH_SIZE, self.len() - start_idx)
}
fn value_unchecked(&self, index: usize) -> T;
#[inline]
fn decode_batch(&self, start_idx: usize) -> Vec<T> {
let batch_size = self.batch_size(start_idx);
let mut batch = Vec::with_capacity(batch_size);
for (idx, batch_item) in batch
.spare_capacity_mut()
.iter_mut()
.enumerate()
.take(batch_size)
{
batch_item.write(self.value_unchecked(start_idx + idx));
}
unsafe {
batch.set_len(batch_size);
}
batch
}
}