A blocked swipe leaves no trace
transcript
A card allows only two swipes. The window is ten seconds long. The third swipe in that window is blocked.
Keep a queue of the accepted swipe times. The oldest time sits at the front. Drop the times as old as the window.
Swipes arrive at seconds zero, three, five, nine and ten. The swipes at zero and three are accepted. The swipes at five and nine are blocked.
Store nothing for a blocked swipe, and ten is accepted. Store the blocked swipes, and ten is blocked as well.
Each card has its own queue of times. All the cards share one more queue. Accept a swipe only if both have room.
A count first drops the expired times. Then it reads the length of the queue. It never stores anything new.
The check must run on every swipe. A queue gives constant time for each one. Traffic grows, but the cost per swipe stays.
Keep a queue of accepted times. A blocked swipe is forgotten. Full breakdown in the lecture.