tailscale.comtailscale.com/util/ringbuffer Index | Files

package ringbuffer

import "tailscale.com/util/ringbuffer"

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

Index

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.

Source Files

ringbuffer.go

Version
v1.84.0 (latest)
Published
May 21, 2025
Platform
linux/amd64
Imports
1 packages
Last checked
1 day ago

Tools for package owners.