vortex_array/vtable/
decode.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5
6use crate::Canonical;
7use crate::builders::ArrayBuilder;
8use crate::vtable::VTable;
9
10// TODO(ngates): rename to `DecodeVTable`.
11pub trait CanonicalVTable<V: VTable> {
12    /// Returns the canonical representation of the array.
13    ///
14    /// ## Post-conditions
15    /// - The length is equal to that of the input array.
16    /// - The [`vortex_dtype::DType`] is equal to that of the input array.
17    // TODO(ngates): rename to `decode`
18    fn canonicalize(array: &V::Array) -> VortexResult<Canonical>;
19
20    /// Writes the array into a canonical builder.
21    ///
22    /// ## Post-conditions
23    /// - The length of the builder is incremented by the length of the input array.
24    fn append_to_builder(array: &V::Array, builder: &mut dyn ArrayBuilder) -> VortexResult<()> {
25        let canonical = Self::canonicalize(array)?;
26        builder.extend_from_array(canonical.as_ref())
27    }
28}