Head meets tail: full or empty?
transcript
A ring buffer has a head and a tail. Now both point at the same cell. Is the ring full? Or is it empty? Look at both cases.
Four cells hold four values. Every cell is in use. The tail has caught up with the head. Both point at cell zero.
Now take all four values out. Each dequeue moves the head on. The head catches up with the tail. Both point at cell zero again.
The indexes look the same both times. So they cannot tell you which it is. Keep a count of the values. Count equals capacity means full. Count equals zero means empty.
Many rings test head equals tail for empty. Then a full ring looks empty. The whole queue is dropped. Test the count instead.
The two indexes cannot tell. A count always can. Add one to every ring. Try it in the sandbox. Full breakdown in the lecture.