ringbuffer

package
v1.73.0-pre Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: BSD-3-Clause Imports: 1 Imported by: 2

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