use std::ops::Range;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_panic;
use crate::ArrayRef;
use crate::stats::ArrayStats;
#[derive(Clone, Debug)]
pub struct SliceArray {
pub(super) child: ArrayRef,
pub(super) range: Range<usize>,
pub(super) stats: ArrayStats,
}
pub struct SliceArrayParts {
pub child: ArrayRef,
pub range: Range<usize>,
}
impl SliceArray {
pub fn try_new(child: ArrayRef, range: Range<usize>) -> VortexResult<Self> {
if range.end > child.len() {
vortex_panic!(
"SliceArray range out of bounds: range {:?} exceeds child array length {}",
range,
child.len()
);
}
Ok(Self {
child,
range,
stats: ArrayStats::default(),
})
}
pub fn new(child: ArrayRef, range: Range<usize>) -> Self {
Self::try_new(child, range).vortex_expect("failed")
}
pub fn slice_range(&self) -> &Range<usize> {
&self.range
}
pub fn child(&self) -> &ArrayRef {
&self.child
}
pub fn into_parts(self) -> SliceArrayParts {
SliceArrayParts {
child: self.child,
range: self.range,
}
}
}