Skip to main content

vortex_runend/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4#[cfg(feature = "arbitrary")]
5mod arbitrary;
6#[cfg(feature = "arbitrary")]
7pub use arbitrary::ArbitraryRunEndArray;
8pub use array::*;
9pub use iter::trimmed_ends_iter;
10
11mod array;
12#[cfg(feature = "arrow")]
13mod arrow;
14pub mod compress;
15mod compute;
16pub mod decompress_bool;
17mod iter;
18mod kernel;
19mod ops;
20mod rules;
21
22#[doc(hidden)]
23pub mod _benchmarking {
24    pub use compute::take::take_indices_unchecked;
25
26    use super::*;
27}
28
29use vortex_array::ArrayVTable;
30use vortex_array::aggregate_fn::AggregateFnVTable;
31use vortex_array::aggregate_fn::fns::is_constant::IsConstant;
32use vortex_array::aggregate_fn::fns::is_sorted::IsSorted;
33use vortex_array::aggregate_fn::fns::min_max::MinMax;
34use vortex_array::aggregate_fn::session::AggregateFnSessionExt;
35use vortex_array::session::ArraySessionExt;
36use vortex_session::VortexSession;
37
38/// Initialize run-end encoding in the given session.
39pub fn initialize(session: &VortexSession) {
40    session.arrays().register(RunEnd);
41    kernel::initialize(session);
42
43    // Register the RunEnd-specific aggregate kernels.
44    session.aggregate_fns().register_aggregate_kernel(
45        RunEnd.id(),
46        Some(MinMax.id()),
47        &compute::min_max::RunEndMinMaxKernel,
48    );
49    session.aggregate_fns().register_aggregate_kernel(
50        RunEnd.id(),
51        Some(IsConstant.id()),
52        &compute::is_constant::RunEndIsConstantKernel,
53    );
54    session.aggregate_fns().register_aggregate_kernel(
55        RunEnd.id(),
56        Some(IsSorted.id()),
57        &compute::is_sorted::RunEndIsSortedKernel,
58    );
59}
60
61#[cfg(test)]
62mod tests {
63    use std::sync::LazyLock;
64
65    use prost::Message;
66    use vortex_array::dtype::PType;
67    use vortex_array::test_harness::check_metadata;
68    use vortex_session::VortexSession;
69
70    use crate::RunEndMetadata;
71
72    pub static SESSION: LazyLock<VortexSession> = LazyLock::new(|| {
73        let session = vortex_array::array_session();
74        crate::initialize(&session);
75        session
76    });
77
78    #[cfg_attr(miri, ignore)]
79    #[test]
80    fn test_runend_metadata() {
81        check_metadata(
82            "runend.metadata",
83            &RunEndMetadata {
84                ends_ptype: PType::U64 as i32,
85                num_runs: u64::MAX,
86                offset: u64::MAX,
87            }
88            .encode_to_vec(),
89        );
90    }
91}