Skip to content

Commit

Permalink
add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
metajar committed Jan 27, 2024
1 parent a924a9a commit bfb5ab0
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# RingBuffer - A Generic Circular Buffer in Go

## Introduction
`RingBuffer` is a generic, type-safe circular buffer implementation in Go (Golang). It allows efficient, FIFO (first-in-first-out) operations in a fixed-size buffer. Ideal for scenarios where you need a fixed-size, rolling storage of elements.

## Features
- Generic: Can store any data type.
- Automatic Overwriting: When full, new elements replace the oldest.
- Concurrent Access: Suitable for producer-consumer scenarios. (Note: Does not include synchronization primitives, you'll need to handle concurrency as per your use case.)
- Simple API: Easy to use methods for common operations.

## Installation
To install the package, use the following `go get` command:

```sh
go get github.com/metajar/ringbuff
```

## Usage
Here's a simple example of how to use the `RingBuffer`:

```go
package main

import (
"fmt"
"github.com/metajar/ringbuff" // Replace with the correct import path
)

func main() {
ringBuffer := ringbuff.NewRingBuffer[int](4)

// Adding elements
ringBuffer.Push(1)
ringBuffer.Push(2)
ringBuffer.Push(3)
ringBuffer.Push(4)

// Popping and printing elements
for i := 0; i < 4; i++ {
value, err := ringBuffer.Pop()
if err != nil {
fmt.Println("Error:", err)
break
}
fmt.Println(value)
}
}
```

## Running Tests
To run the tests for the `RingBuffer`, navigate to the package directory and use the `go test` command:

```sh
go test
```


0 comments on commit bfb5ab0

Please sign in to comment.