vortex_array/vtable/
decode.rs

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