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