All Projects → antifuchs → O

antifuchs / O

Licence: mit
Ring-buffers in go without interface{}

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to O

Hackerrank
HackerRank solutions in Java/JS/Python/C++/C#
Stars: ✭ 829 (+2412.12%)
Mutual labels:  data-structures
Data Structures In Open Source
Data structures used in open source projects around the world.
Stars: ✭ 9 (-72.73%)
Mutual labels:  data-structures
Xinblog
前端基础。Vue框架。数据结构与算法。计算机网络。夯实基础。
Stars: ✭ 29 (-12.12%)
Mutual labels:  data-structures
Sanest
sane nested dictionaries and lists for python
Stars: ✭ 19 (-42.42%)
Mutual labels:  data-structures
Ods
Mission: To provide a high-quality open content data structures textbook that is both mathematically rigorous and provides complete implementations.
Stars: ✭ 932 (+2724.24%)
Mutual labels:  data-structures
Huprog
A repo which includes the HUPROG'17(Hacettepe University Programming Contest)'s questions and the solutions of that questions.
Stars: ✭ 11 (-66.67%)
Mutual labels:  data-structures
Carvel Ytt
YAML templating tool that works on YAML structure instead of text
Stars: ✭ 816 (+2372.73%)
Mutual labels:  data-structures
Algos
Popular Algorithms and Data Structures implemented in popular languages
Stars: ✭ 966 (+2827.27%)
Mutual labels:  data-structures
Competitive Programming Library
A library designed to improve your competitive programming performance.
Stars: ✭ 26 (-21.21%)
Mutual labels:  data-structures
Ds Algo Point
This repository contains codes for various data structures and algorithms in C, C++, Java, Python, C#, Go, JavaScript, PHP, Kotlin and Scala
Stars: ✭ 949 (+2775.76%)
Mutual labels:  data-structures
The Uplift Project Dsa
Stars: ✭ 20 (-39.39%)
Mutual labels:  data-structures
Trie
A Mixed Trie and Levenshtein distance implementation in Java for extremely fast prefix string searching and string similarity.
Stars: ✭ 25 (-24.24%)
Mutual labels:  data-structures
Lintcode
📜 Lintcode/Leetcode algorithm written by Java, Python and JavaScript.
Stars: ✭ 21 (-36.36%)
Mutual labels:  data-structures
Eter
Lightweight collections for JavaScript
Stars: ✭ 16 (-51.52%)
Mutual labels:  data-structures
Fundamentals Of Python Data Structures
《数据结构(Python语言描述)》"Fundamentals of Python:Data Structures" 电子书和配套代码
Stars: ✭ 30 (-9.09%)
Mutual labels:  data-structures
Aabb Tree
A d-dimensional aabb-tree implementation for MATLAB.
Stars: ✭ 5 (-84.85%)
Mutual labels:  data-structures
Python Programming
Python Coding - Data Structure, Algorithm, Crypto, Web, Network, System
Stars: ✭ 9 (-72.73%)
Mutual labels:  data-structures
Algorithms
Study cases for Algorithms and Data Structures.
Stars: ✭ 32 (-3.03%)
Mutual labels:  data-structures
Algos And Data Structures
Collection of Test Specs and Implementation of various algorithms and data structures from the Princeton Coursera course: Intro to Algorithms part 1 and 2
Stars: ✭ 31 (-6.06%)
Mutual labels:  data-structures
Coding Challenges
solutions to coding challenges and algorithm and data structure building blocks
Stars: ✭ 28 (-15.15%)
Mutual labels:  data-structures

o - go ring buffers for arbitrary types without interface{}

godoc CircleCI codecov

This package provides the data structures that you need in order to implement an efficient ring buffer in go. In contrast to other ring buffer packages (and the Ring package in the go stdlib which really should not count as a ring buffer), this package has the following nice properties:

  • It provides the minimum functionality and maximum flexibility necessary for your own ring buffer structure.
  • It allows multiple modes of usage for different ring buffer usage scenarios.
  • It does not require casting from interface{}.

Minimum functionality - what do you get?

This package handles the grody integer math in ring buffers (it's not suuuper grody, but it's not easy to get right on the first try. Let me help!)

That's it. You are expected to use the o.Ring interface provided by this package in your own structure, with a buffer that you allocate, and you're supposed to put things onto the right index in that buffer (with o.Ring doing the grody integer math).

You get two buffer data structures: One that works for all kinds of capacities, and one that is optimized for powers of two.

Maximum flexibility & multiple usage modes

The default usage mode for o.Ring is to .Push and .Shift for LIFO operations, similar to queues and typical log buffers. You can find an example in the ringio package implemented here. These functions return errors if you push onto a full ring, or if you shift from an empty ring.

You can also use Ring.ForcePush to insert a new element regardless of whether the ring is full, overwriting the element that's there.

And then, if you do not want to shift out elements to read them, you can use o.ScanFIFO and o.ScanLIFO to get an iterator over the occupied indexes in the ring (LIFO for oldest to newest, FIFO for newest to oldest), and iterate over your ring's buffer using those indexes - it's your data structure! You get to go entirely hog wild.

Why do this at all?

Depending on where you intend to use a "generic" ring buffer (that backs onto an array of interface{}), it sometimes is difficult to reason about whether what you get out is what you expect. The error handling code for that sometimes gets grody, but really - that isn't the reason why I did this.

Mostly, I did it as a semi-joke that I thought could be useful in a problem I was solving. Now that I've actually written this, I'm no longer sure it ever was a joke. People might acually want to use this and feel good about using it, and now I'm terrified because I think this might actually be a reasonable thing to use.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].