pub mod lamport;
use std::cmp::Ordering;
pub use lamport::LamportTimestamp;
pub trait CausalState {
type Time;
fn happens_before(&self, t1: &Self::Time, t2: &Self::Time) -> bool;
}
pub fn concurrent<CS: CausalState>(st: &CS, t1: &CS::Time, t2: &CS::Time) -> bool {
!CausalState::happens_before(st, t1, t2) && !CausalState::happens_before(st, t2, t1)
}
pub fn compare_with_tiebreak<CS: CausalState<Time: Ord>>(
st: &CS,
t1: &CS::Time,
t2: &CS::Time,
) -> Ordering {
if CausalState::happens_before(st, t1, t2) {
Ordering::Less
} else if CausalState::happens_before(st, t2, t1) {
Ordering::Greater
} else {
t1.cmp(t2)
}
}