Correct code. Ten seconds per buffer.
transcript
This cleanup code is correct. It still stops the dock gate for ten seconds. Let us count why.
A dock gate stores each scan in a fixed buffer. A failed read is stored as minus 1. Remove the no-reads. Keep the order. Use no second buffer.
The first attempt finds each no-read. It deletes it and slides every later scan left. Here that is ten moves. Instant.
Now a busy gate on a wet day. A full buffer holds 100,000 scans. One scan in five is a no-read. That is 20,000 deletions. Each one slides about 50,000 scans. That is about a billion moves.
A computer does about a hundred million steps a second. So one cleanup takes about ten seconds. The gate cannot scan meanwhile. The limit is one second.
Here is the clue. Look at the scans that slide. Most of them are kept anyway. They move again and again, one slot at a time.
Full breakdown in the lecture.