mod merge;
pub use merge::merge_neighbours_with_same_class;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Interval<A, C> {
Lower { below: A, class: C },
Range { from: A, below: A, class: C },
Upper { from: A, class: C },
Infinite { class: C },
}
impl<A, C> Interval<A, C>
where
A: PartialOrd + Copy,
C: Copy,
{
pub fn lower(below: A, class: C) -> Self {
Interval::Lower { below, class }
}
pub fn range(from: A, below: A, class: C) -> Self {
Interval::Range { from, below, class }
}
pub fn upper(from: A, class: C) -> Self {
Interval::Upper { from, class }
}
pub fn matches(&self, value: A) -> bool {
match self {
Interval::Lower { below, .. } => value < *below,
Interval::Range { from, below, .. } => value >= *from && value < *below,
Interval::Upper { from, .. } => value >= *from,
Interval::Infinite { .. } => true,
}
}
pub fn class(&self) -> &C {
match self {
Interval::Lower { class, .. } => class,
Interval::Range { class, .. } => class,
Interval::Upper { class, .. } => class,
Interval::Infinite { class } => class,
}
}
}