vortex_array/vtable/
decode.rs

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