Next

Vector clock merge on receive

Write codeEasy18 minAmazon style

Your task

When a replica receives a message, it merges the incoming vector clock with its own by taking the componentwise maximum, then increments its own entry by one to account for the receive event. Given the local node's id me, the local vector clock local (a dict; missing node = 0), and the incoming vector clock incoming, return the merged-and-incremented vector clock as a dict that includes every node mentioned in either clock plus me.

Examples

vc_merge_recv(me: str, local: dict[str,int], incoming: dict[str,int]) -> dict[str,int]
Example 1
Inputvc_merge_recv("n1", {"n1": 2, "n2": 1}, {"n1": 1, "n2": 3, "n3": 1})
Output{"n1": 3, "n2": 3, "n3": 1}