Class: VectorTimestamp

VectorTimestamp

A VectorTimestamp is a timestamp used according to the Vector Clock Algorithm It is so named because it contains a vector of numerical clock values for different hosts. VectorTimestamps are immutable.

Constructor

new VectorTimestamp(clock, host)

Constructs a VectorTimestamp with the provided clock and host.
Parameters:
Name Type Description
clock Object.<String, Number> The vector clock with host names corresponding to timestamps for host
host String The host the timestamp belongs to
Source:
See:
Throws:
An error string if the vector clock does not contain an entry for the host
Type
String

Methods

compareTo(other) → {Number}

Compares two vector timestamp.

Returns a negative number if this timestamp happens before other. Returns a positive number if other timestamp happens before this. Returns zero if both are concurrent or equal.

Let x[host] be the logical clock value for host in vector clock x. A vector timestamp x is said to happen before y if for all hosts, x[host] <= y[host] AND there exists at least one host h such that x[h] < y[h]. x and y are said to be concurrent if x does not happen before y AND y does not happen before x

Parameters:
Name Type Description
other VectorTimestamp the timestamp to compare to
Source:
Returns:
the result of the comparison as defined above
Type
Number

compareToLocal(other) → {Number}

Compare two timestamps based on their local times only.

Returns zero if this.host is not equal to other.host. Returns a negative number if this happens before other. Returns a positive number is other happens before this.

A vector clock x is said to happen before y if they have the same host and x[host] < y[host]

Parameters:
Name Type Description
other VectorTimestamp the timestamp to compare to
Source:
Returns:
the result of the comparison as defined above
Type
Number

equals(other) → {Boolean}

Checks if this VectorTimestamp is equal to another. Two vector timestamps are considered equal if they have they exact same host and the exact same key-value pairs.

Parameters:
Name Type Description
other VectorTimestamp The other VectorTimestamp to compare against
Source:
Returns:
True if this equals other
Type
Boolean

getClock() → {Object}

Returns the entire vector clock as a JSON object
Source:
Returns:
the clock
Type
Object

getOwnHost() → {String}

Returns the host name of the host this vector timestamp belongs to
Source:
Returns:
The host name
Type
String

getOwnTime() → {Number}

Returns the clock value of the host
Source:
Returns:
The clock value
Type
Number

increment() → {VectorTimestamp}

Gets the vector timestamp that is identical to this current one, except its own hosts clock has been incremented by one.

Note that this method does not modify this, as VectorTimestamps are immutable.

Source:
Returns:
A vector timestamp identical to this, except with its own host's clock incremented by one
Type
VectorTimestamp

update(other) → {VectorTimestamp}

Returns a vector timestamp that is this updated with the argument. The timestamp updating is done according to the Vector Clock algorithm. That is, for each key in the set of all keys, newVT.clock[key] = max(this.clock[key], other.clock[key]). The host of the returned timestamp is the same as the host of this.

Note that the returned timestamp is the updated timestamp. Neither this nor the argument timestamp is modified in any way, as VectorTimestamps are immutable

Parameters:
Name Type Description
other VectorTimestamp The other timestamp used to update the current one
Source:
See:
Returns:
The updated vector timestamp.
Type
VectorTimestamp