crdt/hlc
Hlc
(defstruct Hlc [wall : int logical : int replica : Sym])
a hybrid logical clock stamp.
Since: crdt-spice-plan C3
hlc-max-drift
(hlc-max-drift :)
how far ahead of local wall time a remote stamp may be.
The bound, in the same unit the caller uses for wall time.
(hlc-max-drift) ; => 60000
Since: crdt-spice-plan C3
hlc-zero
(hlc-zero [r : Sym] :)
a fresh clock for a replica.
| r | the replica |
A stamp at wall 0, logical 0.
(hlc-zero (quote alice))
Since: crdt-spice-plan C3
hlc-wall
(hlc-wall [^borrow h : Hlc] :)
the wall component.
| h | the stamp |
Its wall time.
(hlc-wall h) ; => 1000
Since: crdt-spice-plan C3
hlc-logical
(hlc-logical [^borrow h : Hlc] :)
the logical counter.
| h | the stamp |
Its logical component.
(hlc-logical h) ; => 2
Since: crdt-spice-plan C3
hlc-replica
(hlc-replica [^borrow h : Hlc] :)
the replica that issued the stamp.
| h | the stamp |
Its replica.
(hlc-replica h) ; => alice
Since: crdt-spice-plan C3
hlc-tick
(hlc-tick [^borrow h : Hlc now : int] :)
stamp a local event.
| h | the replica's current clock | |
| now | current wall time |
A stamp strictly after h.
(hlc-tick (hlc-zero (quote alice)) 1000)
Since: crdt-spice-plan C3
hlc-recv
(hlc-recv [^borrow h : Hlc ^borrow m : Hlc now : int] :)
advance the local clock on receiving a remote stamp.
| h | the replica's current clock | |
| m | the remote stamp | |
| now | current wall time |
A stamp at least as large as both h and m.
(hlc-recv mine theirs 1000)
Since: crdt-spice-plan C3
hlc-after?
(hlc-after? [^borrow a : Hlc ^borrow b : Hlc] :)
is a strictly later than b in the total order?
| a | first stamp | |
| b | second stamp |
true when a > b by (wall, logical, replica).
(hlc-after? later earlier) ; => true
Since: crdt-spice-plan C3
hlc-later
(hlc-later [^borrow a : Hlc ^borrow b : Hlc] :)
the later of two stamps.
| a | first stamp | |
| b | second stamp |
Whichever is later in the total order.
(hlc-later mine theirs)
Since: crdt-spice-plan C3