Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abhinav/ring-go
Efficient, general-purpose FIFO queue backed by a ring buffer.
https://github.com/abhinav/ring-go
Last synced: about 2 months 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 (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-26T04:54:25.000Z (6 months ago)
- Last Synced: 2024-11-02T07:33:22.462Z (about 2 months ago)
- Language: Go
- Homepage: https://abhinav.github.io/ring-go/
- Size: 62.5 KB
- Stars: 9
- 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
[![Go Reference](https://pkg.go.dev/badge/go.abhg.dev/container/ring.svg)](https://pkg.go.dev/go.abhg.dev/container/ring)
[![CI](https://github.com/abhinav/ring-go/actions/workflows/ci.yml/badge.svg)](https://github.com/abhinav/ring-go/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/abhinav/ring-go/branch/main/graph/badge.svg?token=zXfHANxPoF)](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.