vortex_runend/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4pub use array::*;
5pub use iter::trimmed_ends_iter;
6
7mod array;
8#[cfg(feature = "arrow")]
9mod arrow;
10pub mod compress;
11mod compute;
12mod iter;
13mod ops;
14mod rules;
15
16#[doc(hidden)]
17pub mod _benchmarking {
18    pub use compute::filter::filter_run_end;
19    pub use compute::take::take_indices_unchecked;
20
21    use super::*;
22}
23
24use vortex_array::ArrayBufferVisitor;
25use vortex_array::ArrayChildVisitor;
26use vortex_array::Canonical;
27use vortex_array::session::ArraySessionExt;
28use vortex_array::vtable::ArrayVTableExt;
29use vortex_array::vtable::EncodeVTable;
30use vortex_array::vtable::VisitorVTable;
31use vortex_error::VortexResult;
32use vortex_session::VortexSession;
33
34use crate::compress::runend_encode;
35
36impl EncodeVTable<RunEndVTable> for RunEndVTable {
37    fn encode(
38        _vtable: &RunEndVTable,
39        canonical: &Canonical,
40        _like: Option<&RunEndArray>,
41    ) -> VortexResult<Option<RunEndArray>> {
42        let parray = canonical.clone().into_primitive();
43        let (ends, values) = runend_encode(&parray);
44        // SAFETY: runend_decode implementation must return valid RunEndArray
45        //  components.
46        unsafe {
47            Ok(Some(RunEndArray::new_unchecked(
48                ends.to_array(),
49                values,
50                0,
51                parray.len(),
52            )))
53        }
54    }
55}
56
57impl VisitorVTable<RunEndVTable> for RunEndVTable {
58    fn visit_buffers(_array: &RunEndArray, _visitor: &mut dyn ArrayBufferVisitor) {}
59
60    fn visit_children(array: &RunEndArray, visitor: &mut dyn ArrayChildVisitor) {
61        visitor.visit_child("ends", array.ends());
62        visitor.visit_child("values", array.values());
63    }
64}
65
66/// Initialize run-end encoding in the given session.
67pub fn initialize(session: &mut VortexSession) {
68    session.arrays().register(RunEndVTable.as_vtable());
69}
70
71#[cfg(test)]
72mod tests {
73    use vortex_array::ProstMetadata;
74    use vortex_array::test_harness::check_metadata;
75    use vortex_dtype::PType;
76
77    use crate::RunEndMetadata;
78
79    #[cfg_attr(miri, ignore)]
80    #[test]
81    fn test_runend_metadata() {
82        check_metadata(
83            "runend.metadata",
84            ProstMetadata(RunEndMetadata {
85                ends_ptype: PType::U64 as i32,
86                num_runs: u64::MAX,
87                offset: u64::MAX,
88            }),
89        );
90    }
91}