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(
23                    array.dtype().clone(),
24                    array.symbols().clone(),
25                    array.symbol_lengths().clone(),
26                    array
27                        .codes()
28                        .slice(range.clone())?
29                        .try_downcast::<VarBin>()
30                        .map_err(|_| vortex_err!("cannot fail conversion"))?,
31                    array.uncompressed_lengths().slice(range)?,
32                )
33            }
34            .into_array(),
35        ))
36    }
37}