use timely::order::PartialOrder;
pub trait Lattice : PartialOrder {
fn minimum() -> Self;
fn maximum() -> Self;
fn join(&self, &Self) -> Self;
fn meet(&self, &Self) -> Self;
#[inline(always)]
fn advance_by(&self, frontier: &[Self]) -> Self where Self: Sized{
if frontier.len() > 0 {
let mut result = self.join(&frontier[0]);
for f in &frontier[1..] {
result = result.meet(&self.join(f));
}
result
}
else {
Self::maximum()
}
}
}
use timely::progress::nested::product::Product;
impl<T1: Lattice, T2: Lattice> Lattice for Product<T1, T2> {
#[inline(always)]
fn minimum() -> Self { Product::new(T1::minimum(), T2::minimum()) }
#[inline(always)]
fn maximum() -> Self { Product::new(T1::maximum(), T2::maximum()) }
#[inline(always)]
fn join(&self, other: &Product<T1, T2>) -> Product<T1, T2> {
Product {
outer: self.outer.join(&other.outer),
inner: self.inner.join(&other.inner),
}
}
#[inline(always)]
fn meet(&self, other: &Product<T1, T2>) -> Product<T1, T2> {
Product {
outer: self.outer.meet(&other.outer),
inner: self.inner.meet(&other.inner),
}
}
}
macro_rules! implement_lattice {
($index_type:ty, $minimum:expr, $maximum:expr) => (
impl Lattice for $index_type {
#[inline(always)] fn minimum() -> Self { $minimum }
#[inline(always)] fn maximum() -> Self { $maximum }
#[inline(always)] fn join(&self, other: &Self) -> Self { ::std::cmp::max(*self, *other) }
#[inline(always)] fn meet(&self, other: &Self) -> Self { ::std::cmp::min(*self, *other) }
}
)
}
use timely::progress::timestamp::RootTimestamp;
implement_lattice!(RootTimestamp, RootTimestamp, RootTimestamp);
implement_lattice!(usize, usize::min_value(), usize::max_value());
implement_lattice!(u64, u64::min_value(), u64::max_value());
implement_lattice!(u32, u32::min_value(), u32::max_value());
implement_lattice!(i32, i32::min_value(), i32::max_value());
implement_lattice!((), (), ());