crdt.bend checks
raw source on the hub · import bend-kit-crdt@0.1.0.0/crdt.bend as Crdt
Replicated data types: a grow-only counter with a proved merge. Source: https://github.com/paymog/bend-kit/tree/main/crdt
A GCounter is a list of U32 counts. Entry i is the count of replica i, and a missing entry counts as 0. This is the state-based G-Counter of Shapiro et al. (2011). Each replica must increment only its own entry.
3 imports
import Base import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes import bend-kit-cbor@0.2.0.0/cbor.bend as Cbor
Definitions
def GCounter.new source · line 11 · raw
List<&2, U32>
The counter with no increments.
def GCounter.get source · line 15 · raw
@s:List<&2, U32> -> @i:Nat -> U32
The count of replica i.
def GCounter.merge source · line 25 · raw
@a:List<&2, U32> -> @b:List<&2, U32> -> List<&2, U32>
Component-wise maximum. It is commutative, associative, and idempotent.
def GCounter.merge_all source · line 37 · raw
@xs:List<&2, List<&2, U32>> -> List<&2, U32>
The merge of every state in the list.
def GCounter.pad source · line 45 · raw
@i:Nat -> List<&2, U32>
Zeros for replicas 0 to i - 1, then 1 for replica i.
def GCounter.cons source · line 52 · raw
@c:U32 -> @m:Maybe<&2, List<&2, U32>> -> Maybe<&2, List<&2, U32>>
def GCounter.inc.at source · line 60 · raw
@ok:Bool -> @n:U32 -> @t:List<&2, U32> -> Maybe<&2, List<&2, U32>>
ok is false when n wrapped to 0.
def GCounter.inc source · line 68 · raw
@s:List<&2, U32> -> @i:Nat -> Maybe<&2, List<&2, U32>>
Adds 1 to the count of replica i. None when that count is 4294967295.
def GCounter.add source · line 77 · raw
@m:Maybe<&2, U32> -> @+c:U32 -> Maybe<&2, U32>
def GCounter.value.go source · line 84 · raw
@s:List<&2, U32> -> @acc:Maybe<&2, U32> -> Maybe<&2, U32>
def GCounter.value source · line 92 · raw
@s:List<&2, U32> -> Maybe<&2, U32>
The sum of all counts. None when the sum does not fit in a U32.
def GCounter.le source · line 96 · raw
@a:List<&2, U32> -> @b:List<&2, U32> -> Bool
True when a is at most b in every entry.
def GCounter.valid.go source · line 105 · raw
@t:List<&2, U32> -> @last:U32 -> Bool
def GCounter.valid source · line 113 · raw
@s:List<&2, U32> -> Bool
A valid state has no trailing 0, so each count vector has one form.
def GCounter.size source · line 120 · raw
@s:List<&2, U32> -> U32
def GCounter.to_cbor.items source · line 127 · raw
@s:List<&2, U32> -> List<&1, 0x50d253ff02f68be1c140402a881a0ac9/cbor.Val>
def GCounter.to_cbor source · line 135 · raw
@s:List<&2, U32> -> 0x50d253ff02f68be1c140402a881a0ac9/cbor.Val
A CBOR array of unsigned integers: the count of replica i is item i.
def GCounter.from_cbor.word source · line 138 · raw
@ok:Bool -> @lo:U32 -> @rest:Maybe<&2, List<&2, U32>> -> Maybe<&2, List<&2, U32>>
def GCounter.from_cbor.item source · line 145 · raw
@v:0x50d253ff02f68be1c140402a881a0ac9/cbor.Val -> @rest:Maybe<&2, List<&2, U32>> -> Maybe<&2, List<&2, U32>>
def GCounter.from_cbor.items source · line 153 · raw
@xs:List<&1, 0x50d253ff02f68be1c140402a881a0ac9/cbor.Val> -> Maybe<&2, List<&2, U32>>
def GCounter.from_cbor.gate source · line 160 · raw
@ok:Bool -> @s:List<&2, U32> -> Maybe<&2, List<&2, U32>>
def GCounter.from_cbor.check source · line 167 · raw
@m:Maybe<&2, List<&2, U32>> -> @+cap:U32 -> Maybe<&2, List<&2, U32>>
def GCounter.from_cbor source · line 175 · raw
@v:0x50d253ff02f68be1c140402a881a0ac9/cbor.Val -> @+cap:U32 -> Maybe<&2, List<&2, U32>>
A valid state with at most cap replicas, or None.
def GCounter.encode source · line 183 · raw
@s:List<&2, U32> -> Maybe<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>
Always Some: every item is an unsigned integer.
def GCounter.decode.go source · line 186 · raw
@m:Maybe<&1, 0x50d253ff02f68be1c140402a881a0ac9/cbor.Val> -> @+cap:U32 -> Maybe<&2, List<&2, U32>>
def GCounter.decode source · line 194 · raw
@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+cap:U32 -> Maybe<&2, List<&2, U32>>
CBOR bytes to a valid state with at most cap replicas, or None.