G-Counter Merge

easy · distributed-systems, crdt, conflict-resolution

G-Counter Merge

A G-Counter stores one grow-only count per replica. The user-facing value is the sum of all slots.

To merge two G-Counter states, take the element-wise max.

Function signature

func MergeGCounter(a, b []int) (merged []int, total int)

Example

a = [1,2,0]
b = [2,1,4]
merged = [2,2,4]
total = 8

Notes

If lengths do not match, return nil, 0. Do not mutate the inputs.

Run tests to see results
No issues detected
    Join Discord