Generic fixed-capacity ring data structures for Go.
go get github.com/maxence2997/carousel
| Type | Description | Doc |
|---|---|---|
RingBuffer[T] |
Fixed-capacity FIFO circular buffer. Not safe for concurrent use. | docs/ringbuffer.md |
RingQueue[T] |
Concurrent blocking FIFO queue backed by RingBuffer. Supports drop-on-full and evict-oldest-on-full strategies. |
docs/ringqueue.md |
buf := carousel.NewRingBuffer[int](3)
buf.Push(1)
buf.Push(2)
buf.Push(3)
buf.ForcePush(4)
value, _ := buf.Pop()
fmt.Println(value)
fmt.Println(buf.Drain())q := carousel.NewRingQueue[string](3)
defer q.Close()
_ = q.Enqueue("alpha")
_ = q.Enqueue("beta")
item, _ := q.Pop(context.Background())
fmt.Println(item)
fmt.Println(q.Drain())See per-type results in docs/ringbuffer.md and docs/ringqueue.md.
Benchmark history (CI, linux/amd64): benchmarks
make examples-syncrefreshes runnable examples in the README and package docs from examples_test.go.make bench-syncreruns local benchmarks and rewrites the benchmark tables in docs/.make stresslabruns the local race/stress matrix for the queue regression tests.