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