Constructor
new VectorTimestamp(clock, 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 |
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:
- 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:
- 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:
- Type
- Boolean
getClock() → {Object}
- Source:
Returns:
- Type
- Object
getOwnHost() → {String}
- Source:
Returns:
- Type
- String
getOwnTime() → {Number}
- Source:
Returns:
- 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:
- 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 |
Returns:
- Type
- VectorTimestamp