Problem statement
Design the object model and public API for a fixed-capacity ring buffer (circular queue) that serves as a bounded in-memory pipe handing items from a producer to a consumer.
Operating context. One process, one shared buffer. Capacity is fixed at construction and never grows. One thread produces and one thread consumes (single-producer / single-consumer). When the buffer is full, a configured overflow policy decides between rejecting the new item and overwriting the oldest one. Elements are generic references, not values tied to one concrete type.
Out of scope. Persistence or replay, a growable / resizable buffer, general multi-producer multi-consumer lock-free variants (name the seam, do not build it), serialization across processes, and any distributed queue semantics.
What to produce. The class hierarchy (the RingBuffer, its backing array, the pluggable overflow policy), the public method signatures (push, pop, peek, size, capacity, isEmpty, isFull, clear), the head / tail index arithmetic with wrap-around, and how you resolve the full-versus-empty ambiguity (an explicit count, a one-slot-open convention, or monotonic sequence numbers) — state the invariant explicitly.
Requirements
The requirements come with Premium
PremiumThe statement above is free to read.