PN-Counter Merge

easy · distributed-systems, crdt, conflict-resolution

PN-Counter Merge

A PN-Counter supports increments and decrements using two G-Counters:

  • P tracks increments;
  • N tracks decrements;
  • value is sum(P) - sum(N).

Merge both vectors by element-wise max.

Types

type PNCounter struct {
    P []int
    N []int
}

Function signature

func MergePNCounter(a, b PNCounter) (PNCounter, int)

If lengths do not match, return an empty counter and value 0.

Run tests to see results
No issues detected
    Join Discord