ringbuf

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package ringbuf provides a generic implementation of a circular ring buffer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IterFunc

type IterFunc[T any] func(v T)

IterFunc is a function which will be executed for every element in the Ringbuf

type Ringbuf

type Ringbuf[T any] struct {
	// contains filtered or unexported fields
}

Ringbuf is a circular buffer of items with type T. It can hold a constant number of items (specifically: len(items)-1).

func NewRingbuf

func NewRingbuf[T any](capacity int) Ringbuf[T]

NewRingbuf creates a Ringbuf of T with the specified capacity.

func (*Ringbuf[T]) Cap

func (r *Ringbuf[T]) Cap() int

Cap returns the capacity of the ringbuf.

func (*Ringbuf[T]) Empty

func (r *Ringbuf[T]) Empty() bool

Empty returns whether or not there are no items in the ringbuf.

func (*Ringbuf[T]) Full

func (r *Ringbuf[T]) Full() bool

Full returns whether or not it is possible to push another item.

func (*Ringbuf[T]) Iter

func (r *Ringbuf[T]) Iter(fn IterFunc[T])

Iter iterates through all the elements in the Ringbuf, calling fn on each one.

func (*Ringbuf[T]) Len

func (r *Ringbuf[T]) Len() int

Len returns the number of items in the ringbuf currently.

func (*Ringbuf[T]) PopBack

func (r *Ringbuf[T]) PopBack() (T, bool)

PopBack returns a copy of the value at the back of the ringbuf and removes it. If the ringbuf is empty then it returns the default value and false for the bool return value.

func (*Ringbuf[T]) PopFront

func (r *Ringbuf[T]) PopFront() (T, bool)

PopFront returns a copy of the value at the front of the ringbuf and removes it. If the ringbuf is empty then it returns the default value and false for the bool return value.

func (*Ringbuf[T]) PushBack

func (r *Ringbuf[T]) PushBack(v T) bool

PushBack adds v to the back of the ringbuf.

func (*Ringbuf[T]) PushFront

func (r *Ringbuf[T]) PushFront(v T) bool

PushFront adds v to the front of the ringbuf.

Jump to

Keyboard shortcuts

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