Skip to content

Commit

Permalink
readme, license, contributing & coc
Browse files Browse the repository at this point in the history
  • Loading branch information
antifuchs committed Mar 16, 2019
1 parent 5c588eb commit 850d08d
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 0 deletions.
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Thanks for contributing to this project!

I'm completely thrilled that you find this project useful enough to
spend your time on!

## Code of Conduct

Contributors are expected to adhere to the
[Contributor Covenant Code of Conduct](http://contributor-covenant.org/version/1/4/),
version 1.4. See [CoC.md](CoC.md) for the full text.

## Things you might do

Feel free to:

* [Report issues](../../issues)
* [Send me a pull request](../../pulls) or
* Just get in touch with me: [email protected]!

## Found a security issue?

If you find a bug in this program that might be security-relevant, feel free to reach out to [the author](mailto:[email protected]) with an encrypted message. You can find the most current OpenPGP keys (and other encrypted contact methods) on [keybase](https://keybase.io/asf)!
74 changes: 74 additions & 0 deletions CoC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
20 changes: 20 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2018 Andreas Fuchs

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# o - go ring buffers for arbitrary types without `interface{}`

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 `o.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.Ring.All` to get an array containing all the occupied
indexes in the ring (for oldest to newest), and iterate over them -
it's your data structure! You get to go hog wild. `o.Ring.Rev` exists
too, in case you wanted to go from newest to oldest.

If you just can't afford to allocate another ring buffer-sized array
of `uint`, you can also use the index helpers `o.Start1`, `o.End1`,
and `o.End2` to get bounds for two `for` loops. Like I said, go _hog_
wild.

## Why do this at all?

Depending on where you intend to use a ring buffer, it might be
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 could be useful. Now that I've
written this, I'm no longer sure it is 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,
under some circumstances.

0 comments on commit 850d08d

Please sign in to comment.