API

increment(clock, nodeId): increment a vector clock at "nodeId"

merge(a, b): given two vector clocks, returns a new vector clock with all values greater than those of the merged clocks

compare(a, b) / ascSort(a, b): compare two vector clocks, returns -1 for a < b and 1 for a > b; 0 for concurrent and identical values. Can be used to sort an array of objects by their "clock" key via [].sort(VClock.ascSort)

descSort(a, b): sorts in descending order (N, ... 3, 2, 1)

isConcurrent(a, b): if A and B are equal, or if they occurred concurrently.

isIdentical(a, b): if every value in both vector clocks is equal.

Implementing read repair using vector clocks

Here is one way to implement read repair by detecting which clocks are concurrent, and if necessary, returning multiple values: