RingBuffer<Element> is a random-access collection that allows mutation of its elements. It does not support
RangeReplaceableCollection, because adding elements is restricted to two methods:
pushThrough(asLastElement:). These methods insert an element and remove another at the same time, exposed as an optional return. The size of the ring is set by the initial sequence fed to it, which can't be empty. I stuffed as many Standard Library helper protocols as possible too.
It's originally meant to aid the various
Sequence methods who need to retain a limited number of elements while iterating. In fact,
RingBuffer is used in another search method to
Sequence in the same Gist. Of course,
RingBuffer assumes the rotation-related types also go in. It also supports internal rotation of the ring, moving the pointer of first index instead of swapping around elements.