ringbuffer

package
v0.0.0-...-c635e59 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0, BSD-2-Clause Imports: 1 Imported by: 1

Documentation

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 thread-safe fixed buffer of elements with FIFO semantics. When the buffer is full, adding a new element overwrites the oldest element.

func NewRingBuffer

func NewRingBuffer[T any](capacity int) *RingBuffer[T]

NewRingBuffer creates a new RingBuffer with a maximum size of capacity.

func (*RingBuffer[T]) Add

func (r *RingBuffer[T]) Add(element T) bool

Add adds an element to the buffer, overwriting the oldest element if the buffer is full.

func (*RingBuffer[T]) ToSlice

func (r *RingBuffer[T]) ToSlice() []T

ToSlice returns all the elements currently in the buffer, from newest to oldest.

Jump to

Keyboard shortcuts

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