vortex_array/arrays/slice/
array.rs1use std::ops::Range;
5
6use vortex_error::VortexExpect;
7use vortex_error::VortexResult;
8use vortex_error::vortex_panic;
9
10use crate::ArrayRef;
11use crate::stats::ArrayStats;
12
13#[derive(Clone, Debug)]
14pub struct SliceArray {
15 pub(super) child: ArrayRef,
16 pub(super) range: Range<usize>,
17 pub(super) stats: ArrayStats,
18}
19
20pub struct SliceArrayParts {
21 pub child: ArrayRef,
22 pub range: Range<usize>,
23}
24
25impl SliceArray {
26 pub fn try_new(child: ArrayRef, range: Range<usize>) -> VortexResult<Self> {
27 if range.end > child.len() {
28 vortex_panic!(
29 "SliceArray range out of bounds: range {:?} exceeds child array length {}",
30 range,
31 child.len()
32 );
33 }
34 Ok(Self {
35 child,
36 range,
37 stats: ArrayStats::default(),
38 })
39 }
40
41 pub fn new(child: ArrayRef, range: Range<usize>) -> Self {
42 Self::try_new(child, range).vortex_expect("failed")
43 }
44
45 pub fn slice_range(&self) -> &Range<usize> {
47 &self.range
48 }
49
50 pub fn child(&self) -> &ArrayRef {
52 &self.child
53 }
54
55 pub fn into_parts(self) -> SliceArrayParts {
57 SliceArrayParts {
58 child: self.child,
59 range: self.range,
60 }
61 }
62}