def KCounter.merge.go

bend-kit-crdt@0.2.0.0 · crdt.bend:241

import bend-kit-crdt@0.2.0.0/crdt.bend as Crdt
import Base

241# q is KCounter.heads(a, b). Passing it in lets match pick the step without closures.
242def KCounter.merge.go(~K: Data, ~cmp: K -> K -> Cmp, +a: KCounter<K>, +b: KCounter<K>, q: Cmp) -> KCounter<K>:
243  match a b q:
244    case KNil{} _ _:
245      b
246    case KCon{x, c, r} KNil{} _:
247      KCon{x, c, r}
248    case KCon{+x, +c, +r} KCon{+y, +d, +t} LT{}:
249      KCon{x, c, KCounter.merge.go(~K, ~cmp, r, KCon{y, d, t}, KCounter.heads(~K, ~cmp, r, KCon{y, d, t}))}
250    case KCon{+x, +c, +r} KCon{+y, +d, +t} EQ{}:
251      KCon{x, U32.max(c, d), KCounter.merge.go(~K, ~cmp, r, t, KCounter.heads(~K, ~cmp, r, t))}
252    case KCon{+x, +c, +r} KCon{+y, +d, +t} GT{}:
253      KCon{y, d, KCounter.merge.go(~K, ~cmp, KCon{x, c, r}, t, KCounter.head(~K, ~cmp, x, t))}

Uses (5)

Used by (1)