Skip to main content

vortex_array/expr/stats/
stat_bound.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use crate::expr::stats::Precision;
5use crate::expr::stats::Stat;
6use crate::expr::stats::bound::IntersectionResult;
7
8/// `StatType` define the bound of a given statistic. (e.g. `Max` is an upper bound),
9/// this is used to extract the bound from a `Precision` value, (e.g. `p::bound<Max>()`).
10pub trait StatType<T> {
11    type Bound: StatBound<T>;
12
13    const STAT: Stat;
14}
15
16/// `StatBound` defines the operations that can be performed on a bound.
17/// The main bounds are Upper (e.g. max) and Lower (e.g. min).
18pub trait StatBound<T>: Sized {
19    /// Creates a new bound from a Precision statistic.
20    fn lift(value: Precision<T>) -> Self;
21
22    /// Converts `Self` back to `Precision<T>`, inverse of `lift`.
23    fn into_value(self) -> Precision<T>;
24
25    /// Finds the smallest bound that covers both bounds.
26    /// A.k.a. the `meet` of the bound.
27    fn union(&self, other: &Self) -> Option<Self>;
28
29    /// Refines the bounds to the most precise estimate we can make for that bound.
30    /// If the bounds are disjoint, then the result is `None`.
31    /// e.g. `Precision::Inexact(5)` and `Precision::Exact(6)` would result in `Precision::Inexact(5)`.
32    /// A.k.a. the `join` of the bound.
33    fn intersection(&self, other: &Self) -> Option<IntersectionResult<Self>>;
34
35    /// Returns the exact value from the bound if that value is exact, otherwise `None`.
36    fn to_exact(&self) -> Option<&T>;
37}