Skip to content

maxence2997/carousel

Repository files navigation

carousel

CI Go Reference Go License: MIT

Generic fixed-capacity ring data structures for Go.

Quick install

go get github.com/maxence2997/carousel

Types

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

Quick start

RingBuffer

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())

RingQueue

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())

Benchmarks

See per-type results in docs/ringbuffer.md and docs/ringqueue.md.

Benchmark history (CI, linux/amd64): benchmarks

Tooling

  • make examples-sync refreshes runnable examples in the README and package docs from examples_test.go.
  • make bench-sync reruns local benchmarks and rewrites the benchmark tables in docs/.
  • make stresslab runs the local race/stress matrix for the queue regression tests.

License

MIT

About

Generic ring data structures for Go.

Resources

License

Stars

Watchers

Forks

Contributors