Causal Delivery Check

easy · distributed-systems, clocks, ordering, causality

Causal Delivery Check

In a causally ordered system, a message from sender s with vector timestamp msg can be delivered at a receiver only if:

  • msg[s] == local[s] + 1 (next message from sender)
  • For all i != s, msg[i] <= local[i] (receiver has seen all causal dependencies)

You are given the receiver's current vector clock local, the message's vector clock msg, and the sender index s. Determine whether the message is causally deliverable now.

Function signature

func IsCausallyDeliverable(local []int, msg []int, sender int) bool

Example

local  = [2,0,1]
msg    = [2,1,1]
sender = 1
output = true

Constraints

  • len(local) == len(msg)
  • 1 <= len(local) <= 100000
  • 0 <= sender < len(local)
  • 0 <= local[i], msg[i]

Notes

  • If the message is not deliverable, it should be buffered.
Run tests to see results
No issues detected