Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Causality ¶
type Causality int
Causality is a type that represents the causality relationship between two vectors.
func Compare ¶
Compare returns the causality relationship between two vectors. Compare(a, b) == After means that a happened after b, and so on. Comparing values that have rolled over is tricky, so the implementation uses the following rules: if the clock value of a node is greater than the clock value of another node, and the rollover flags are different, it means that the value has wrapped around and we need to invert the comparison. For example, if a clock value is 2^32-1 and the other clock value is 0, and the rollover flags are different, it means that the clock value of the first node has wrapped around and the second node has not. In this case, the first node is considered to be less than the second node.
type Version ¶
Version represents a vector clock, which is a mapping of node IDs to clock values. The clock value is a monotonically increasing counter that is incremented every time the node makes an update. The clock value is used to determine the causality relationship between two events. If the clock value of a node is greater than the clock value of another node, it means that the first event happened after the second event. The implementation uses a 32-bit integer to store the clock value. The leftmost bit is used to indicate whether the clock value has rolled over. If the leftmost bit is set, the clock value has rolled over.
func FromString ¶
FromString decodes the vector clock from a string representation. The format is the same as the one used by ToString. If the string is empty, an empty vector clock is returned.
func Merge ¶
Merge returns a new vector that is the result of taking the maximum value for each key in the two vectors. The operation is commutative and associative, so that Merge(a, Merge(b, c)) == Merge(Merge(a, b), c).
func MustFromString ¶
MustFromString is like FromString but panics if the string cannot be decoded.
func (Version) String ¶
String returns a string representation of the vector clock. The string representation is a comma-separated list of key=value pairs, where the key is the node ID and the value is the clock value: {1=1, 2=2}. If the clock value has rolled over, the leftmost bit is set and the value is negative: {1=-1, 2=-2}.