/go-ringbuffer

A ringbuffer implementation in golang

Primary LanguageGoCreative Commons Zero v1.0 UniversalCC0-1.0

Build Status

ringbuffer

Simple RingBuffer pacakge Ringbuffer is non blocking for readers and writers, writers will overwrite older data in a circular fashion. Readers will read from the current position and update it.

Usage

type RingBuffer

type RingBuffer struct {
	Size      int           // Size of the Ringbuffer
	Container []interface{} // Array container of objects
	Reader    int           // Reader position
	Writer    int           // Writer Position
}

RingBuffer Structure

func NewRingBuffer

func NewRingBuffer(size int) *RingBuffer

Create a new RingBuffer of initial size "size" Returns a pointer to the new RingBuffer

func (*RingBuffer) Read

func (r *RingBuffer) Read() interface{}

Read single object from the RingBuffer

func (*RingBuffer) Write

func (r *RingBuffer) Write(v interface{})

Write object into the RingBuffer