https://github.com/abhinav/ring-go
Efficient, general-purpose FIFO queue backed by a ring buffer.
https://github.com/abhinav/ring-go
Last synced: 25 days ago
JSON representation
Efficient, general-purpose FIFO queue backed by a ring buffer.
- Host: GitHub
- URL: https://github.com/abhinav/ring-go
- Owner: abhinav
- License: bsd-3-clause
- Created: 2023-04-03T00:42:10.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-19T23:31:42.000Z (about 1 month ago)
- Last Synced: 2025-05-07T03:43:56.342Z (25 days ago)
- Language: Go
- Homepage: https://abhinav.github.io/ring-go/
- Size: 70.3 KB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# container/ring
[](https://pkg.go.dev/go.abhg.dev/container/ring)
[](https://github.com/abhinav/ring-go/actions/workflows/ci.yml)
[](https://codecov.io/gh/abhinav/ring-go)container/ring provides an efficient queue data structure
intended to be used in performance-sensitive contexts
with usage patterns that have:- a similar rate of pushes and pops
- bursts of pushes followed by bursts of pops## Example
As an example, this is a good place to store pending nodes
during a breadth-first traversal of a graph.
It will allocate only if a node has more direct children
than capacity in the queue.
For example, given a hypothetical tree structure:```go
var pending ring.Q[Node]
pending.Push(root)for !pending.Empty() {
current := pending.Pop()
visit(current)
for _, child := range current.Children {
pending.Push(child)
}
}
```See [API Reference](https://abhinav.github.io/ring-go) for more details.
## Motivation
I often find myself needing a queue in projects.
In a hurry, I reach for `container/list` or a slice.
However, they are both allocation-heavy (depending on usage pattern).This repository largely exists so that there's a known working version
of a more efficient queue implementation (for specific usage patterns)
that I can use or copy-paste directly where I need.
Feel free to use it in the same way if it meets your needs.## License
This software is made available under the BSD3 license.