-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy patharray.rs
More file actions
71 lines (60 loc) · 1.88 KB
/
Copy patharray.rs
File metadata and controls
71 lines (60 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use std::ops::Range;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_panic;
use crate::ArrayRef;
use crate::stats::ArrayStats;
/// The underlying child array being sliced.
pub(super) const CHILD_SLOT: usize = 0;
pub(super) const NUM_SLOTS: usize = 1;
pub(super) const SLOT_NAMES: [&str; NUM_SLOTS] = ["child"];
#[derive(Clone, Debug)]
pub struct SliceArray {
pub(super) slots: Vec<Option<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 {
slots: vec![Some(child)],
range,
stats: ArrayStats::default(),
})
}
pub fn new(child: ArrayRef, range: Range<usize>) -> Self {
Self::try_new(child, range).vortex_expect("failed")
}
/// The range used to slice the child array.
pub fn slice_range(&self) -> &Range<usize> {
&self.range
}
/// The child array being sliced.
pub fn child(&self) -> &ArrayRef {
self.slots[CHILD_SLOT]
.as_ref()
.vortex_expect("SliceArray child slot")
}
/// Consume the slice array and return its components.
pub fn into_parts(mut self) -> SliceArrayParts {
SliceArrayParts {
child: self.slots[CHILD_SLOT]
.take()
.vortex_expect("SliceArray child slot"),
range: self.range,
}
}
}