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