Skip to main content

vortex_array/arrays/bool/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_error::VortexResult;
7
8use crate::ArrayRef;
9use crate::IntoArray;
10use crate::array::ArrayView;
11use crate::arrays::Bool;
12use crate::arrays::BoolArray;
13use crate::arrays::bool::BoolArrayExt;
14use crate::arrays::slice::SliceReduce;
15
16impl SliceReduce for Bool {
17    fn slice(array: ArrayView<'_, Bool>, range: Range<usize>) -> VortexResult<Option<ArrayRef>> {
18        let bit_buffer = array.to_bit_buffer().slice(range.clone());
19        let validity = array.validity()?.slice(range)?;
20
21        // Safety:
22        // range is verified in the callers and is the same for both bits and validity.
23        let array = unsafe { BoolArray::new_unchecked(bit_buffer, validity).into_array() };
24
25        Ok(Some(array))
26    }
27}