buffer

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 1 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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