vortex_array/vtable/operations.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5use vortex_scalar::Scalar;
6
7use crate::ArrayRef;
8use crate::vtable::VTable;
9
10pub trait OperationsVTable<V: VTable> {
11 /// Perform a constant-time slice of the array.
12 ///
13 /// If an encoding cannot perform this slice in constant time, it should internally
14 /// store an offset and length in order to defer slicing until the array is accessed.
15 ///
16 /// This function returns [`ArrayRef`] since some encodings can return a simpler array for
17 /// some slices, for example a [`crate::arrays::ChunkedArray`] may slice into a single chunk.
18 ///
19 /// ## Preconditions
20 ///
21 /// Bounds-checking has already been performed by the time this function is called.
22 fn slice(array: &V::Array, start: usize, stop: usize) -> VortexResult<ArrayRef>;
23
24 /// Fetch the scalar at the given index.
25 ///
26 /// ## Preconditions
27 ///
28 /// Bounds-checking has already been performed by the time this function is called,
29 /// and the index is guaranteed to be non-null.
30 fn scalar_at(array: &V::Array, index: usize) -> VortexResult<Scalar>;
31}