A late change takes its place in time, and shifts what comes after it
Changes can arrive late, from a replica that caught up.
store.set("timeout", 40, 130)
print(store.times["timeout"])
print(store.values["timeout"])
print([store.get("timeout", t) for t in (129, 130, 159)])
[100, 130, 160, 220]
[30, 40, 45, 60]
[30, 40, 40]
The change at 130 arrived after the one at 220, and it still landed between 100 and 160. Both lists insert at the same index, so each value stays next to its time.
When times arrive in order, i is the end of the list and nothing shifts. A late change shifts everything after it: O(n), the same cost as insort.
A late change also rewrites past answers. Before it arrived, a read at 140 returned 30. Now it returns 40. Every read from 130 up to the next change, at 160, gets a new answer, so a cache that kept any of those answers now holds stale ones.
In the editor, write stale_reads(times, time). It finds the reads that a late change at 130, a tie at 160 and a change after the last one make stale.