pub struct HlcGenerator<T: CurrentTimestamp = UtcTimestamp> { /* private fields */ }Expand description
Hybrid Logical Clock (HLC) generator.
Implementations§
Source§impl<T: CurrentTimestamp> HlcGenerator<T>
impl<T: CurrentTimestamp> HlcGenerator<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new HLC clock without any drift.
Whenever the clock running on a single node is required, there is no
need to worry about drift, as no adjustments are made to the clock,
i.e. update() is never called.
Sourcepub fn with_max_drift(max_drift: usize) -> Self
pub fn with_max_drift(max_drift: usize) -> Self
Creates a new HLC clock with the specified maximum drift.
Sourcepub fn ts_provider(&self) -> &T
pub fn ts_provider(&self) -> &T
Get timestamp provider.
Useful for testing purposes, where manual timestamps are used.
Sourcepub fn timestamp(&self) -> HlcTimestamp
pub fn timestamp(&self) -> HlcTimestamp
Current timestamp.
Use next_timestamp() to get the
timestamp for local or send events.
Sourcepub fn next_timestamp(&self) -> Option<HlcTimestamp>
pub fn next_timestamp(&self) -> Option<HlcTimestamp>
Timestamp for the local or send event.
Sourcepub fn update(&self, incoming_state: &HlcTimestamp) -> HlcResult<HlcTimestamp>
pub fn update(&self, incoming_state: &HlcTimestamp) -> HlcResult<HlcTimestamp>
Adjust the clock based on incoming timestamp.
Usually this happens when a timestamp is received from another node.
An error may occur if drift is exceeded (if max_drift is set to 0,
then such a check is ignored).
Updated timestamp is returned.