The patch adds a new package:
IContext is just a general interface to manipulate context byte. Basically, create(), update() and reconcile().
create(): create a new/empty context.
update(): update this context w/ the local node's id.
reconcile(): pass in a list of context-value pairs and it'll return a merged context (that supersedes all the passed in contexts) and a list of values that it couldn't automatically reconcile.
VersionVectorContext is a version vector implementation.
The VV format is a concatenated list of node id (IPv4's 4 bytes), count (int), and timestamp (long) tuples in a byte.
create(): returns an empty byte.
update(): will look for the local node's tuple in the byte, increment its count, then prepend it to the front of the byte w/ an updated timestamp. So, that the byte is always in timestamp descending order.
reconcile(): looks for all disjoint (incompatible) VVs and collapses all VVs that are a subset of another VV in the list. (implementation note: if 2 VVs are equal, but their values are not equivalent, both values will be added to the set of values that need to be manually reconciled. It seems inefficient, though, so when I go through the rest of the system, I'm going to see if I can avoid this check. Since, it's a problem that can only happen on the local node.)
VersionVectorContext helper methods of interest:
compareContexts(): sorts contexts by id, then steps through both contexts to determine pairwise: equality, superset, subset, disjoint.
mergeContexts(): creates a map from node id to count-timestamp pairs, then create a timestamp-sorted array and pulls off up to the max entries to form the new merged context.