ringbuffer

package module
v0.0.0-...-5353fe1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2020 License: MIT Imports: 0 Imported by: 0

README

ringbuffer

A simple ring buffer based on slice and support index read and write

Documentation

Overview

Package ringbuffer provides a simple implementation of a fixed size ring buffer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RingBuffer

type RingBuffer struct {
	// contains filtered or unexported fields
}

RingBuffer is a fixed size ring buffer.

func NewRingBuffer

func NewRingBuffer(size int) *RingBuffer

NewRingBuffer creates a new buffer of a given size.

func (*RingBuffer) Capacity

func (rb *RingBuffer) Capacity() int

Capacity returns the current capacity of the ring buffer.

func (*RingBuffer) Clear

func (rb *RingBuffer) Clear()

Clear clear the ring buffer

func (*RingBuffer) IsEmpty

func (rb *RingBuffer) IsEmpty() bool

IsEmpty checks if the ring buffer is empty

func (*RingBuffer) IsFull

func (rb *RingBuffer) IsFull() bool

IsFull checks if the ring buffer is full

func (*RingBuffer) Length

func (rb *RingBuffer) Length() int

Length returns the element counts inside the ring buffer.

func (*RingBuffer) Peek

func (rb *RingBuffer) Peek() interface{}

Peek peek the reader element and not affect the index

func (*RingBuffer) Read

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

Read read an element from the ring buffer, nil if empty

func (*RingBuffer) ReadAt

func (rb *RingBuffer) ReadAt(i int) interface{}

ReadAt read an element at index i, i could be negative

func (*RingBuffer) Write

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

Write an element into the ring buffer

func (*RingBuffer) WriteAt

func (rb *RingBuffer) WriteAt(i int, v interface{})

WriteAt write an element at index i, i could be negative

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL