use std::cmp::Ordering;
pub trait Lattice: Clone + PartialEq {
fn bottom() -> Self;
fn join(&self, other: &Self) -> Self;
fn partial_cmp_lattice(&self, other: &Self) -> Option<Ordering> {
let joined = self.join(other);
if &joined == self && &joined == other {
Some(Ordering::Equal)
} else if &joined == other {
Some(Ordering::Less)
} else if &joined == self {
Some(Ordering::Greater)
} else {
None }
}
fn leq(&self, other: &Self) -> bool {
matches!(
self.partial_cmp_lattice(other),
Some(Ordering::Less) | Some(Ordering::Equal)
)
}
fn join_assign(&mut self, other: &Self) {
*self = self.join(other);
}
}
pub trait DeltaCRDT: Lattice {
type Delta: Lattice;
fn split_delta(&mut self) -> Option<Self::Delta>;
fn apply_delta(&mut self, delta: &Self::Delta);
}