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