pub struct HlcClock { /* private fields */ }Expand description
The real hybrid logical clock (B3) — the proposal’s {wall_ms, counter}
state with the standard HLC send/receive rules (Kulkarni et al.):
- tick (local/send event):
l' = max(l, wall_now); if the wall didn’t advance past everything witnessed, bump the counter, else reset it — the issued stamp is strictly greater than every stamp this clock has issued or observed. - observe (receive rule): fold a remote stamp into
(l, c)as a component-wise max, so the next tick lands strictly above it.
Monotone by construction under clock skew (a peer’s future stamp is
absorbed via observe; local ticks ride the counter until the local
wall catches up), clock regression (a wall reading below l is
ignored — the counter carries the order), and same-millisecond
bursts (counter ties, broken across devices by Hlc::device_id).
The wall component never runs behind the physical clock reading it
was given, so wall_ms stays a meaningful timestamp bounded by the
max skew among devices — the “hybrid” in HLC.
Implementations§
Source§impl HlcClock
impl HlcClock
pub fn new() -> Self
Sourcepub fn tick(&mut self, wall_now: u64, device_id: &str) -> Hlc
pub fn tick(&mut self, wall_now: u64, device_id: &str) -> Hlc
Stamp a local event: strictly greater than every stamp previously
issued by or observed on this clock, regardless of what wall_now
reads (regression-safe).
Sourcepub fn observe(&mut self, remote: &Hlc)
pub fn observe(&mut self, remote: &Hlc)
Receive rule: fold an observed stamp so the next HlcClock::tick
lands strictly above it (and above everything observed before it).