Skip to main content

vortex_fsst/
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::ArrayView;
8use vortex_array::IntoArray;
9use vortex_array::arrays::VarBin;
10use vortex_array::arrays::slice::SliceReduce;
11use vortex_error::VortexResult;
12use vortex_error::vortex_err;
13
14use crate::FSST;
15use crate::FSSTArrayExt;
16
17impl SliceReduce for FSST {
18    fn slice(array: ArrayView<'_, Self>, range: Range<usize>) -> VortexResult<Option<ArrayRef>> {
19        // SAFETY: slicing the `codes` leaves the symbol table intact
20        Ok(Some(
21            unsafe {
22                FSST::new_unchecked_with_symbol_table(
23                    array.dtype().clone(),
24                    array.symbol_table(),
25                    array
26                        .codes()
27                        .slice(range.clone())?
28                        .try_downcast::<VarBin>()
29                        .map_err(|_| vortex_err!("cannot fail conversion"))?,
30                    array.uncompressed_lengths().slice(range)?,
31                )
32            }
33            .into_array(),
34        ))
35    }
36}