crdt/counter
the identity of one replica.
Since: crdt-spice-plan C1
replica
(replica [s : Sym] :)
name a replica.
| s | an interned symbol, e.g. (quote alice) |
The ReplicaId for that name.
(replica (quote alice))
Since: crdt-spice-plan C1
GCounter
(defstruct GCounter [entries : int])
grow-only counter: per-replica totals.
Since: crdt-spice-plan C1
gcounter-new
(gcounter-new :)
an empty G-Counter.
A G-Counter with no replica entries; its value is 0.
(gcounter-new)
Since: crdt-spice-plan C1
gcounter-bump
(gcounter-bump [c : GCounter r : ReplicaId n : int] :)
add to one replica's own total.
| c | the counter | |
| r | the replica doing the increment | |
| n | how much to add (non-negative; a G-Counter never decreases) |
A new G-Counter; the old one remains valid.
(gcounter-bump (gcounter-new) (replica (quote alice)) 3)
Since: crdt-spice-plan C1
gcounter-value
(gcounter-value [^borrow c : GCounter] :)
the counter's reading.
| c | the counter |
The sum of every replica's total.
(gcounter-value c) ; => 8
Since: crdt-spice-plan C1
gcounter-replicas
(gcounter-replicas [^borrow c : GCounter] :)
how many replicas this counter has entries for.
| c | the counter |
The number of entries -- the counter's SIZE, as distinct from its value.
(gcounter-replicas c) ; => 3
Since: crdt-spice-plan C4
gcounter-delta-bump
(gcounter-delta-bump [^borrow c : GCounter r : ReplicaId n : int] :)
the DELTA of adding to one replica's own total.
| c | the counter, read for this replica's current total | |
| r | the replica doing the increment | |
| n | how much to add (non-negative) |
A one-entry G-Counter holding r's NEW total -- not the increment.
(gcounter-delta-bump c (replica (quote alice)) 3)
Since: crdt-spice-plan C4
PNCounter
(defstruct PNCounter [pos : GCounter neg : GCounter])
a counter that can decrease: increments and decrements apart.
Since: crdt-spice-plan C1
pncounter-new
(pncounter-new :)
an empty PN-Counter.
A PN-Counter whose value is 0.
(pncounter-new)
Since: crdt-spice-plan C1
pncounter-inc
(pncounter-inc [c : PNCounter r : ReplicaId n : int] :)
increment on one replica.
| c | the counter | |
| r | the replica | |
| n | amount (non-negative) |
A new PN-Counter.
(pncounter-inc (pncounter-new) (replica (quote alice)) 5)
Since: crdt-spice-plan C1
pncounter-dec
(pncounter-dec [c : PNCounter r : ReplicaId n : int] :)
decrement on one replica.
| c | the counter | |
| r | the replica | |
| n | amount (non-negative; it is ADDED to the decrement half) |
A new PN-Counter.
(pncounter-dec (pncounter-new) (replica (quote bob)) 2)
Since: crdt-spice-plan C1
pncounter-value
(pncounter-value [^borrow c : PNCounter] :)
the counter's reading.
| c | the counter |
increments minus decrements.
(pncounter-value c) ; => 3
Since: crdt-spice-plan C1
pncounter-replicas
(pncounter-replicas [^borrow c : PNCounter] :)
how many entries both halves hold together.
| c | the counter |
The size of the state, for comparison against a delta's.
(pncounter-replicas c) ; => 4
Since: crdt-spice-plan C4
pncounter-delta-inc
(pncounter-delta-inc [^borrow c : PNCounter r : ReplicaId n : int] :)
the DELTA of an increment on one replica.
| c | the counter | |
| r | the replica | |
| n | amount (non-negative) |
A PN-Counter whose increment half holds one entry and whose decrement half is empty.
(pncounter-delta-inc c (replica (quote alice)) 5)
Since: crdt-spice-plan C4
pncounter-delta-dec
(pncounter-delta-dec [^borrow c : PNCounter r : ReplicaId n : int] :)
the DELTA of a decrement on one replica.
| c | the counter | |
| r | the replica | |
| n | amount (non-negative; it lands in the decrement half) |
A PN-Counter whose decrement half holds one entry.
(pncounter-delta-dec c (replica (quote bob)) 2)
Since: crdt-spice-plan C4
Internal definitions
__sum-loop-- internal: sum the remaining iterator values into acc.__imax-- internal: the larger of two ints.JoinSemilattice[GCounter]-- pointwise maximum.BoundedJoin[GCounter]-- the empty counter is the least element.Eq[GCounter]-- equal readings and equal entry counts.DeltaCRDT[GCounter]-- the delta is another G-Counter.JoinSemilattice[PNCounter]-- join each half.BoundedJoin[PNCounter]-- both halves empty.Eq[PNCounter]-- equal on both halves.DeltaCRDT[PNCounter]-- the delta is another PN-Counter, one half empty.