xmtp_proto/traits/vector_clock.rs
1use crate::types::{ClockOrdering, Cursor};
2
3/// common functions w.r.t vector clock types
4/// mostly used as an extension trait to [`GlobalCursor`](xmtp_proto::types::GlobalCursor)
5pub trait VectorClock {
6 /// Returns true if this clock dominates (has seen all updates of) the other
7 fn dominates(&self, other: &Self) -> bool;
8
9 /// gets all dependencies in `other` that are not in `self`.
10 fn missing(&self, other: &Self) -> Vec<Cursor>;
11
12 /// Merges another clock into this one by taking the max ordering per node
13 fn merge(&mut self, other: &Self);
14
15 /// Merges another clock into this one by taking the min ordering per node
16 fn merge_least(&mut self, other: &Self);
17
18 /// Compares this clock to another to determine their relative ordering
19 fn compare(&self, other: &Self) -> ClockOrdering;
20
21 /// apply a single update to this clock
22 fn apply(&mut self, cursor: &Cursor);
23}