pub struct HLC { /* private fields */ }
Expand description
An Hybric Logical Clock generating Timestamp
s
Implementations§
source§impl HLC
impl HLC
sourcepub fn new_timestamp(&self) -> Timestamp
pub fn new_timestamp(&self) -> Timestamp
Generate a new Timestamp
.
This timestamp is unique in the system and is always greater
than the latest timestamp generated by the HLC and than the
latest incoming timestamp that was used to update this HLC
(using HLC::update_with_timestamp()
).
§Examples
use uhlc::HLC;
let hlc = HLC::default();
let ts1 = hlc.new_timestamp();
let ts2 = hlc.new_timestamp();
assert!(ts2 > ts1);
sourcepub fn get_id(&self) -> &ID
pub fn get_id(&self) -> &ID
Returns the HLC ID
.
This ID is the specific identifier for this HLC instance.
sourcepub fn get_delta(&self) -> &NTP64
pub fn get_delta(&self) -> &NTP64
Returns the HLC delta as NTP64
.
The maximum delta accepted by an HLC when updating it’s logical clock calling HLC::update_with_timestamp()
.
sourcepub fn update_with_timestamp(&self, timestamp: &Timestamp) -> Result<(), String>
pub fn update_with_timestamp(&self, timestamp: &Timestamp) -> Result<(), String>
Update this HLC
with a Timestamp
.
Typically, this timestamp should have been generated by another HLC.
If the timestamp exceeds the current time of this HLC by more than the configured maximum delta
(see HLCBuilder::with_max_delta()
) an Err
is returned.
§Examples
use uhlc::HLC;
let hlc1 = HLC::default();
// update the HLC with a timestamp incoming from another HLC
// (typically remote, but not in this example...)
let hlc2 = HLC::default();
let other_ts = hlc2.new_timestamp();
if ! hlc1.update_with_timestamp(&other_ts).is_ok() {
println!(r#"The incoming timestamp would make this HLC
to drift too much. You should refuse it!"#);
}
let ts = hlc1.new_timestamp();
assert!(ts > other_ts);