P N Counter
A delta-based CRDT PN-counter.
Initialized to 0, it can be concurrently incremented and decremented.
For each replica, both sum of increments and decrements performed on the replica are retained as grow-only counters. The PN-Counter value is computed as the difference between increments and decrements of all replicas.
When merging, the maximum value of every increment and decrement counter is retained (following grow-only semantic).
Its JSON serialization respects the following schema:
{
"type": "PNCounter",
"metadata": {
"increment": [
(( ClientUId.toJson(), {
"first": $value, // $value is an integer
"second": Timestamp.toJson()
}, )*( ClientUId.toJson(), {
"first": $value, // $value is an integer
"second": Timestamp.toJson()
} ))?
],
"decrement": [
(( ClientUId.toJson(), {
"first": $value, // $value is an integer
"second": Timestamp.toJson()
}, )*( ClientUId.toJson(), {
"first": $value, // $value is an integer
"second": Timestamp.toJson()
} ))?
]
},
"value": $value // $value is an integer
}