Consistency Model (Strongest Satisfied)
Consistency Model (Strongest Satisfied)
For a single key, you are given a sequence of writes and reads with vector clocks. For each read, return the strongest consistency model it satisfies among:
linearizablecausaleventual
Rules:
- Let
latestbe the write with the greatestTimesuch thatwrite.Time <= read.Time. - Linearizable if
read.ValueVCequalslatest.VC. - Causal if
read.ValueVCdominatesread.Context(element-wise>=). - Otherwise the read is only eventual.
Return the label for each read in order.
Types
type Write struct {
Time int
VC []int
}
type Read struct {
Time int
Context []int
ValueVC []int
}
Function signature
func StrongestConsistency(writes []Write, reads []Read) []string
Example
writes = [{Time:1, VC:[1,0]}, {Time:5, VC:[2,0]}]
reads = [{Time:6, Context:[2,0], ValueVC:[2,0]}, {Time:6, Context:[1,0], ValueVC:[1,0]}]
output = ["linearizable", "causal"]
Constraints
0 <= len(writes), len(reads) <= 100000writesandreadsare sorted byTimeascending
Notes
- If no
latestwrite exists, treatlatest.VCas all zeros. - When comparing vector clocks of different lengths, missing entries are treated as 0.
Run tests to see results
No issues detected