Skip to main content

vortex_compressor/scheme/
exclusion.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! Exclusion rules that keep incompatible schemes out of a cascade chain.
5
6use crate::scheme::SchemeId;
7
8/// Selects which children of a cascading scheme a rule applies to.
9#[derive(Debug, Clone, Copy)]
10pub enum ChildSelection {
11    /// Rule applies to all children.
12    All,
13    /// Rule applies to a single child.
14    One(usize),
15    /// Rule applies to multiple specific children.
16    Many(&'static [usize]),
17}
18
19impl ChildSelection {
20    /// Returns `true` if this selection includes the given child index.
21    pub fn contains(&self, child_index: usize) -> bool {
22        match self {
23            ChildSelection::All => true,
24            ChildSelection::One(idx) => *idx == child_index,
25            ChildSelection::Many(indices) => indices.contains(&child_index),
26        }
27    }
28}
29
30/// Push rule: declared by a cascading scheme to exclude another scheme from the subtree
31/// rooted at the specified children.
32///
33/// Use this when the declaring scheme (the ancestor) knows about the excluded scheme. For example,
34/// `ZigZag` excludes `Dict` from all its children.
35#[derive(Debug, Clone, Copy)]
36pub struct DescendantExclusion {
37    /// The scheme to exclude from descendants.
38    pub excluded: SchemeId,
39    /// Which children of the declaring scheme this rule applies to.
40    pub children: ChildSelection,
41}
42
43/// Pull rule: declared by a scheme to exclude itself when the specified ancestor is in the
44/// cascade chain.
45///
46/// Use this when the excluded scheme (the descendant) knows about the ancestor. For example,
47/// `Sequence` excludes itself when `IntDict` is an ancestor on its codes child.
48#[derive(Debug, Clone, Copy)]
49pub struct AncestorExclusion {
50    /// The ancestor scheme that makes the declaring scheme ineligible.
51    pub ancestor: SchemeId,
52    /// Which children of the ancestor this rule applies to.
53    pub children: ChildSelection,
54}