Skip to main content

vortex_sequence/compute/
slice.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::ops::Range;
5
6use vortex_array::ArrayRef;
7use vortex_array::IntoArray;
8use vortex_array::arrays::slice::SliceReduce;
9use vortex_error::VortexResult;
10
11use crate::Sequence;
12use crate::SequenceArray;
13
14impl SliceReduce for Sequence {
15    fn slice(array: &Self::Array, range: Range<usize>) -> VortexResult<Option<ArrayRef>> {
16        // SAFETY: this is a slice of an already-validated `SequenceArray`, so this is still valid.
17        Ok(Some(
18            unsafe {
19                SequenceArray::new_unchecked(
20                    array.index_value(range.start),
21                    array.multiplier(),
22                    array.ptype(),
23                    array.dtype().nullability(),
24                    range.len(),
25                )
26            }
27            .into_array(),
28        ))
29    }
30}