buffer

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ring

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

A Ring is a generic container/ring.Ring with convenient methods for adding and removing values. The generic type T should be a pointer type or interface because the default value of T will be returned by Pop and Peek if the value is unset.

func NewRing

func NewRing[T any](size int) *Ring[T]

NewRing creates a new RingBuffer

func (*Ring[T]) Add

func (r *Ring[T]) Add(block T)

Add adds a value to the RingBuffer, overwriting the oldest value if full

func (*Ring[T]) Len

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

func (*Ring[T]) Peek

func (r *Ring[T]) Peek() T

Peek returns the RingBuffer value If the value is unset, the empty T is returned

func (*Ring[T]) Pop

func (r *Ring[T]) Pop() T

Pop removes the value from the buffer

func (*Ring[T]) Reset

func (r *Ring[T]) Reset()

Reset resets the buffer, unsetting all values

Jump to

Keyboard shortcuts

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