No matching definitions.

crdt/counter

src/crdt/counter.tur

the identity of one replica.

Since: crdt-spice-plan C1

defn

replica

(replica [s : Sym] :)

name a replica.

san interned symbol, e.g. (quote alice)

The ReplicaId for that name.

(replica (quote alice))

Since: crdt-spice-plan C1

defstruct

GCounter

(defstruct GCounter [entries : int])

grow-only counter: per-replica totals.

Since: crdt-spice-plan C1

defn

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

defn

gcounter-bump

(gcounter-bump [c : GCounter r : ReplicaId n : int] :)

add to one replica's own total.

cthe counter
rthe replica doing the increment
nhow 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

defn

gcounter-value

(gcounter-value [^borrow c : GCounter] :)

the counter's reading.

cthe counter

The sum of every replica's total.

(gcounter-value c)   ; => 8

Since: crdt-spice-plan C1

defn

gcounter-replicas

(gcounter-replicas [^borrow c : GCounter] :)

how many replicas this counter has entries for.

cthe counter

The number of entries -- the counter's SIZE, as distinct from its value.

(gcounter-replicas c)   ; => 3

Since: crdt-spice-plan C4

defn

gcounter-delta-bump

(gcounter-delta-bump [^borrow c : GCounter r : ReplicaId n : int] :)

the DELTA of adding to one replica's own total.

cthe counter, read for this replica's current total
rthe replica doing the increment
nhow 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

defstruct

PNCounter

(defstruct PNCounter [pos : GCounter neg : GCounter])

a counter that can decrease: increments and decrements apart.

Since: crdt-spice-plan C1

defn

pncounter-new

(pncounter-new :)

an empty PN-Counter.

A PN-Counter whose value is 0.

(pncounter-new)

Since: crdt-spice-plan C1

defn

pncounter-inc

(pncounter-inc [c : PNCounter r : ReplicaId n : int] :)

increment on one replica.

cthe counter
rthe replica
namount (non-negative)

A new PN-Counter.

(pncounter-inc (pncounter-new) (replica (quote alice)) 5)

Since: crdt-spice-plan C1

defn

pncounter-dec

(pncounter-dec [c : PNCounter r : ReplicaId n : int] :)

decrement on one replica.

cthe counter
rthe replica
namount (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

defn

pncounter-value

(pncounter-value [^borrow c : PNCounter] :)

the counter's reading.

cthe counter

increments minus decrements.

(pncounter-value c)   ; => 3

Since: crdt-spice-plan C1

defn

pncounter-replicas

(pncounter-replicas [^borrow c : PNCounter] :)

how many entries both halves hold together.

cthe counter

The size of the state, for comparison against a delta's.

(pncounter-replicas c)   ; => 4

Since: crdt-spice-plan C4

defn

pncounter-delta-inc

(pncounter-delta-inc [^borrow c : PNCounter r : ReplicaId n : int] :)

the DELTA of an increment on one replica.

cthe counter
rthe replica
namount (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

defn

pncounter-delta-dec

(pncounter-delta-dec [^borrow c : PNCounter r : ReplicaId n : int] :)

the DELTA of a decrement on one replica.

cthe counter
rthe replica
namount (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.