Vector Clock Comparison

easy · distributed-systems, clocks, ordering

Vector Clock Comparison

Two events in a distributed system can be ordered with vector clocks. Given two vector clocks a and b, classify their order:

  • equal: all entries are equal
  • before: for all i, a[i] <= b[i] and at least one a[i] < b[i]
  • after: for all i, a[i] >= b[i] and at least one a[i] > b[i]
  • concurrent: neither is before/after the other

Return one of: "before", "after", "concurrent", "equal".

Function signature

func CompareVectorClocks(a, b []int) string

Example

a = [1,2,3]
b = [1,3,3]
output = "before"

Constraints

  • 0 <= len(a) <= 100000
  • 0 <= a[i], b[i]

Notes

  • If lengths differ, missing entries are treated as 0.
  • Vector clocks detect concurrency; Lamport clocks do not.
Run tests to see results
No issues detected