pub struct HlcClock {
physical: AtomicU64,
logical: AtomicU64,
node_id: u64,
max_drift_us: u64,
}Expand description
Hybrid Logical Clock for generating causally-ordered timestamps.
Thread-safe implementation using atomics for the state.
Fields§
§physical: AtomicU64Current physical time (atomically updated).
logical: AtomicU64Current logical counter (atomically updated).
node_id: u64Node identifier.
max_drift_us: u64Maximum allowed clock drift in microseconds.
Implementations§
Source§impl HlcClock
impl HlcClock
Sourcepub fn with_max_drift(node_id: u64, max_drift_ms: u64) -> Self
pub fn with_max_drift(node_id: u64, max_drift_ms: u64) -> Self
Create a new HLC clock with custom max drift.
Sourcepub fn now(&self) -> HlcTimestamp
pub fn now(&self) -> HlcTimestamp
Get current timestamp without advancing the clock.
Sourcepub fn tick(&self) -> HlcTimestamp
pub fn tick(&self) -> HlcTimestamp
Generate a new timestamp, advancing the clock.
Sourcepub fn update(&self, received: &HlcTimestamp) -> Result<HlcTimestamp>
pub fn update(&self, received: &HlcTimestamp) -> Result<HlcTimestamp>
Update clock on receiving a message with the given timestamp.
Returns the new local timestamp that causally follows the received timestamp.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for HlcClock
impl RefUnwindSafe for HlcClock
impl Send for HlcClock
impl Sync for HlcClock
impl Unpin for HlcClock
impl UnwindSafe for HlcClock
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
§fn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Gets the layout of the type.