use crate::{EndpointToggle, Interval, Intervals, LeftT};
pub struct IntervalsSingle<E, V> {
v: Interval<E, V>,
}
impl<E, V> IntervalsSingle<E, V> {
pub fn new(v: Interval<E, V>) -> Self {
Self { v }
}
}
impl<E, V> Intervals for IntervalsSingle<E, V>
where
E: Clone + EndpointToggle,
LeftT<E>: Ord,
V: Copy,
{
type Endpoint = E;
type Value = V;
fn head(
&mut self,
pos: Option<LeftT<Self::Endpoint>>,
) -> Option<Interval<Self::Endpoint, Self::Value>> {
match pos {
Some(p) => {
if p < self.v.right().into_left() {
let r = Interval::new_lr(self.v.left().max(p), self.v.right(), self.v.value());
Some(r)
} else {
None
}
}
None => Some(self.v.clone()),
}
}
}