vortex_array/array/canonical.rs
1use vortex_error::VortexResult;
2
3use crate::Canonical;
4use crate::builders::ArrayBuilder;
5
6/// Implementation trait for canonicalization functions.
7///
8/// These functions should not be called directly, rather their equivalents on the base
9/// [`crate::Array`] trait should be used.
10pub trait ArrayCanonicalImpl {
11 /// Returns the canonical representation of the array.
12 ///
13 /// ## Post-conditions
14 /// - The length is equal to that of the input array.
15 /// - The [`vortex_dtype::DType`] is equal to that of the input array.
16 fn _to_canonical(&self) -> VortexResult<Canonical>;
17
18 /// Writes the array into the 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(&self, builder: &mut dyn ArrayBuilder) -> VortexResult<()> {
23 let canonical = self._to_canonical()?;
24 builder.extend_from_array(canonical.as_ref())
25 }
26}