pub trait LeastUpperBound : PartialOrd {
fn max() -> Self;
fn least_upper_bound(&self, &Self) -> Self;
}
use timely::progress::nested::product::Product;
impl<T1: LeastUpperBound, T2: LeastUpperBound> LeastUpperBound for Product<T1, T2> {
#[inline(always)]
fn max() -> Self { Product::new(T1::max(), T2::max()) }
fn least_upper_bound(&self, other: &Product<T1, T2>) -> Product<T1, T2> {
Product {
outer: self.outer.least_upper_bound(&other.outer),
inner: self.inner.least_upper_bound(&other.inner),
}
}
}
use timely::progress::timestamp::RootTimestamp;
impl LeastUpperBound for RootTimestamp {
fn max() -> RootTimestamp { RootTimestamp }
fn least_upper_bound(&self, _: &RootTimestamp) -> RootTimestamp { RootTimestamp }
}
impl LeastUpperBound for u64 {
fn max() -> u64 { u64::max_value() }
fn least_upper_bound(&self, other: &u64) -> u64 { if self < other { *other } else { *self }}
}
impl LeastUpperBound for u32 {
fn max() -> u32 { u32::max_value() }
fn least_upper_bound(&self, other: &u32) -> u32 { if self < other { *other } else { *self }}
}
impl LeastUpperBound for i32 {
fn max() -> i32 { i32::max_value() }
fn least_upper_bound(&self, other: &i32) -> i32 { if self < other { *other } else { *self }}
}
pub fn close_under_lub<T: LeastUpperBound>(vector: &mut Vec<T>) {
let mut first = 0;
while first < vector.len() {
let mut next = first + 1;
while next < vector.len() {
let lub = vector[first].least_upper_bound(&vector[next]);
if !vector.contains(&lub) {
vector.push(lub);
}
next += 1;
}
first += 1;
}
}