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;
14
15#[doc(hidden)]
16pub mod _benchmarking {
17    pub use compute::filter::filter_run_end;
18    pub use compute::take::take_indices_unchecked;
19
20    use super::*;
21}
22
23use vortex_array::ArrayBufferVisitor;
24use vortex_array::ArrayChildVisitor;
25use vortex_array::Canonical;
26use vortex_array::vtable::EncodeVTable;
27use vortex_array::vtable::VisitorVTable;
28use vortex_error::VortexResult;
29
30use crate::compress::runend_encode;
31
32impl EncodeVTable<RunEndVTable> for RunEndVTable {
33    fn encode(
34        _vtable: &RunEndVTable,
35        canonical: &Canonical,
36        _like: Option<&RunEndArray>,
37    ) -> VortexResult<Option<RunEndArray>> {
38        let parray = canonical.clone().into_primitive();
39        let (ends, values) = runend_encode(&parray);
40        // SAFETY: runend_decode implementation must return valid RunEndArray
41        //  components.
42        unsafe {
43            Ok(Some(RunEndArray::new_unchecked(
44                ends.to_array(),
45                values,
46                0,
47                parray.len(),
48            )))
49        }
50    }
51}
52
53impl VisitorVTable<RunEndVTable> for RunEndVTable {
54    fn visit_buffers(_array: &RunEndArray, _visitor: &mut dyn ArrayBufferVisitor) {}
55
56    fn visit_children(array: &RunEndArray, visitor: &mut dyn ArrayChildVisitor) {
57        visitor.visit_child("ends", array.ends());
58        visitor.visit_child("values", array.values());
59    }
60}
61
62#[cfg(test)]
63mod tests {
64    use vortex_array::ProstMetadata;
65    use vortex_array::test_harness::check_metadata;
66    use vortex_dtype::PType;
67
68    use crate::RunEndMetadata;
69
70    #[cfg_attr(miri, ignore)]
71    #[test]
72    fn test_runend_metadata() {
73        check_metadata(
74            "runend.metadata",
75            ProstMetadata(RunEndMetadata {
76                ends_ptype: PType::U64 as i32,
77                num_runs: u64::MAX,
78                offset: u64::MAX,
79            }),
80        );
81    }
82}