Vector Clock
A generic vector clock.
Vector clocks generate timestamps with precise information about which events were known at the time that an event occurred. Their disadvantage is that they are large and computationally expensive: their size, as well as the computational complexity of comparing two instances, are proportional to the number of nodes in the system.
This implementation is thread-safe.
Example instantiation where node IDs are of type String and logical time is expressed as a Long:
fun stringLongVectorClock(
localNodeId: String,
initialTime: VectorTimestamp<String, Long>,
onNewTime: suspend (VectorTimestamp<String, Long>) -> Unit = {}
): VectorClock<String, Long> = VectorClock(
localNodeId,
initialTime,
Long::inc,
onNewTime
)Constructors
Functions
Returns a logical timestamp that is greater than the current logical timestamp of this clock and updates the clock's internal state accordingly.
Updates the internal state of the clock to reflect the occurrence of an external event with the given logical timestamp.