pub struct VectorClock {
pub clocks: HashMap<String, u64>,
}Expand description
Vector clock for tracking causality in distributed systems Each instance maintains a logical clock value
Fields§
§clocks: HashMap<String, u64>Map of instance_id to logical clock value
Implementations§
Source§impl VectorClock
impl VectorClock
Sourcepub fn from_clocks(clocks: HashMap<String, u64>) -> Self
pub fn from_clocks(clocks: HashMap<String, u64>) -> Self
Create a vector clock from a HashMap
Sourcepub fn merge(&mut self, other: &VectorClock)
pub fn merge(&mut self, other: &VectorClock)
Merge with another vector clock (takes maximum for each instance)
Sourcepub fn happens_before(&self, other: &VectorClock) -> bool
pub fn happens_before(&self, other: &VectorClock) -> bool
Check if this clock causally precedes another
Sourcepub fn is_concurrent(&self, other: &VectorClock) -> bool
pub fn is_concurrent(&self, other: &VectorClock) -> bool
Check if two clocks are concurrent (neither happens before the other)
Sourcepub fn dominates(&self, other: &VectorClock) -> bool
pub fn dominates(&self, other: &VectorClock) -> bool
True when this clock has seen at least everything other has, in every
dimension.
This is the test a causal receiver needs, and it is not happens_before.
happens_before answers a question about ordering and returns false for
concurrent clocks, so a receiver using it would admit an operation whose
dependencies are genuinely unmet whenever the frontier happened to be
ahead in some unrelated dimension. Dominance asks only “have I seen
everything this operation needs”, which is what eligibility means.
Sourcepub fn causal_cmp(&self, other: &VectorClock) -> Ordering
pub fn causal_cmp(&self, other: &VectorClock) -> Ordering
Compare two vector clocks for causal ordering