{"id":21262778,"url":"https://github.com/boinkor-net/o","last_synced_at":"2025-07-11T04:30:59.426Z","repository":{"id":39902576,"uuid":"175921588","full_name":"boinkor-net/o","owner":"boinkor-net","description":"Ring-buffers in go without interface{}","archived":false,"fork":false,"pushed_at":"2024-06-09T14:16:33.000Z","size":211,"stargazers_count":36,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-21T20:54:05.738Z","etag":null,"topics":["data-structures","golang","ring-buffer"],"latest_commit_sha":null,"homepage":"https://github.com/boinkor-net/o","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/boinkor-net.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-16T03:28:36.000Z","updated_at":"2024-06-09T14:16:35.000Z","dependencies_parsed_at":"2024-04-04T02:43:22.666Z","dependency_job_id":"688f8e74-3116-48a7-a6fc-82e19775dd5f","html_url":"https://github.com/boinkor-net/o","commit_stats":null,"previous_names":["boinkor-net/o","antifuchs/o"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boinkor-net%2Fo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boinkor-net%2Fo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boinkor-net%2Fo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boinkor-net%2Fo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boinkor-net","download_url":"https://codeload.github.com/boinkor-net/o/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225674901,"owners_count":17506272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-structures","golang","ring-buffer"],"created_at":"2024-11-21T04:59:21.796Z","updated_at":"2024-11-21T04:59:22.449Z","avatar_url":"https://github.com/boinkor-net.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# o - go ring buffers for arbitrary types without `interface{}`\n[![godoc](https://godoc.org/github.com/boinkor-net/o?status.svg)](https://godoc.org/github.com/boinkor-net/o) [![CI](https://github.com/boinkor-net/o/actions/workflows/ci.yml/badge.svg)](https://github.com/boinkor-net/o/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/antifuchs/o/branch/master/graph/badge.svg)](https://codecov.io/gh/boinkor-net/o)\n\n\nThis package provides the data structures that you need in order to\nimplement an efficient ring buffer in go. In contrast to other ring\nbuffer packages (and the `Ring` package in the go stdlib which really\nshould not count as a ring buffer), this package has the following\nnice properties:\n\n* It provides the minimum functionality and maximum flexibility\n  necessary for your own ring buffer structure.\n* It allows multiple modes of usage for different ring buffer usage\n  scenarios.\n* It does not require casting from `interface{}`.\n\n## Minimum functionality - what do you get?\n\nThis package handles the grody integer math in ring buffers (it's not\nsuuuper grody, but it's not easy to get right on the first try. Let me\nhelp!)\n\nThat's it. You are expected to use the `o.Ring` interface provided by\nthis package in your own structure, with a buffer that you allocate,\nand you're supposed to put things onto the right index in that buffer\n(with `o.Ring` doing the grody integer math).\n\nYou get two buffer data structures: One that works for all kinds of\ncapacities, and one that is optimized for powers of two.\n\n## Maximum flexibility \u0026 multiple usage modes\n\nThe default usage mode for `o.Ring` is to `.Push` and `.Shift` for\nLIFO operations, similar to queues and typical log buffers. You can\nfind an example in the `ringio` package implemented here. These\nfunctions return errors if you push onto a full ring, or if you shift\nfrom an empty ring.\n\nYou can also use `Ring.ForcePush` to insert a new element regardless\nof whether the ring is full, overwriting the element that's there.\n\nAnd then, if you do not want to shift out elements to read them, you\ncan use `o.ScanFIFO` and `o.ScanLIFO` to get an iterator over the\noccupied indexes in the ring (LIFO for oldest to newest, FIFO for\nnewest to oldest), and iterate over your ring's buffer using those\nindexes - it's your data structure! You get to go entirely hog wild.\n\n## Why do this at all?\n\nDepending on where you intend to use a \"generic\" ring buffer (that\nbacks onto an array of `interface{}`), it sometimes is difficult to\nreason about whether what you get out is what you expect. The error\nhandling code for that sometimes gets grody, but really - that isn't\nthe reason why I did this.\n\nMostly, I did it as a semi-joke that I thought could be useful in a\nproblem I was solving. Now that I've actually written this, I'm no\nlonger sure it ever was a joke. People might acually want to use this\nand feel good about using it, and now I'm terrified because I think\nthis might actually be a reasonable thing to use.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboinkor-net%2Fo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboinkor-net%2Fo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboinkor-net%2Fo/lists"}