contiguousCompletedMax function
Largest M such that chunks 0..M are all in completed (else -1). Expresses
an out-of-order completed set as a backward-compatible high-water mark.
Implementation
int contiguousCompletedMax(Set<int> completed) {
var i = 0;
while (completed.contains(i)) {
i++;
}
return i - 1;
}