crdt/register
LwwRegister
(defstruct LwwRegister [value : int stamp : Hlc])
one value, last writer wins by HLC stamp.
Since: crdt-spice-plan C3
lww-new
(lww-new [r : Sym] :)
a register owned by a replica, holding 0.
| r | the replica |
A register at the zero stamp.
(lww-new (quote alice))
Since: crdt-spice-plan C3
lww-set
(lww-set [^borrow g : LwwRegister v : int now : int] :)
write a value.
| g | the register | |
| v | the new value | |
| now | current wall time |
A register holding v, stamped strictly after the old one.
(lww-set (lww-new (quote alice)) 42 1000)
Since: crdt-spice-plan C3
lww-value
(lww-value [^borrow g : LwwRegister] :)
the current value.
| g | the register |
Its value.
(lww-value g) ; => 42
Since: crdt-spice-plan C3
lww-stamp
(lww-stamp [^borrow g : LwwRegister] :)
the stamp of the winning write.
| g | the register |
Its HLC stamp.
(lww-stamp g)
Since: crdt-spice-plan C3
lww-delta-set
(lww-delta-set [^borrow g : LwwRegister v : int now : int] :)
the DELTA of a write.
| g | the register | |
| v | the new value | |
| now | current wall time |
A register holding v, stamped strictly after g -- which is exactly the new state.
(lww-delta-set g 42 1000)
Since: crdt-spice-plan C4
MvRegister
(defstruct MvRegister [vals : int stamp : Hlc])
every concurrent value, for the caller to resolve.
Since: crdt-spice-plan C3
mv-new
(mv-new [r : Sym] :)
an empty multi-value register.
| r | the replica |
A register holding no values.
(mv-new (quote alice))
Since: crdt-spice-plan C3
mv-set
(mv-set [^borrow g : MvRegister v : int now : int] :)
write a value, replacing everything this replica has observed.
| g | the register | |
| v | the new value | |
| now | current wall time |
A register holding only v.
(mv-set (mv-new (quote alice)) 42 1000)
Since: crdt-spice-plan C3
mv-values
(mv-values [^borrow g : MvRegister] :)
how many distinct concurrent values are held.
| g | the register |
The number of values; 1 when there is no conflict.
(mv-values g) ; => 2
Since: crdt-spice-plan C3
mv-count
(mv-count [^borrow g : MvRegister] :)
alias for mv-values, for symmetry with the set types.
| g | the register |
The number of values held.
(mv-count g) ; => 1
Since: crdt-spice-plan C3
mv-delta-set
(mv-delta-set [^borrow g : MvRegister v : int now : int] :)
the DELTA of a write.
| g | the register | |
| v | the new value | |
| now | current wall time |
A register holding only v.
(mv-delta-set g 42 1000)
Since: crdt-spice-plan C4
Internal definitions
__lww-pick-- internal: the later of two registers.JoinSemilattice[LwwRegister]-- the later stamp wins.Eq[LwwRegister]-- same value and same stamp.DeltaCRDT[LwwRegister]-- the delta is the register itself.__mv-merge-- internal: union the value sets.__mv-loop-- internal.JoinSemilattice[MvRegister]-- keep every value from both sides.Eq[MvRegister]-- same number of values.DeltaCRDT[MvRegister]-- the delta is the register itself.