ringbuffer

package
v1.86.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: BSD-3-Clause Imports: 1 Imported by: 0 modules, 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

Overview

Package ringbuffer contains a fixed-size concurrency-safe generic ring buffer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RingBuffer

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

RingBuffer is a concurrency-safe ring buffer.

func New

func New[T any](max int) *RingBuffer[T]

New creates a new RingBuffer containing at most max items.

func (*RingBuffer[T]) Add

func (rb *RingBuffer[T]) Add(t T)

Add appends a new item to the RingBuffer, possibly overwriting the oldest item in the buffer if it is already full.

It does nothing if rb is nil.

func (*RingBuffer[T]) Clear

func (rb *RingBuffer[T]) Clear()

Clear will empty the ring buffer.

func (*RingBuffer[T]) GetAll

func (rb *RingBuffer[T]) GetAll() []T

GetAll returns a copy of all the entries in the ring buffer in the order they were added.

It returns nil if rb is nil.

func (*RingBuffer[T]) Len

func (rb *RingBuffer[T]) Len() int

Len returns the number of elements in the ring buffer. Note that this value could change immediately after being returned if a concurrent caller modifies the buffer.

Jump to

Keyboard shortcuts

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