ringbuffer

package
v0.47.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metrics

type Metrics interface {
	IncBufferLength()
	DecBufferLength()
}

type RingBuffer

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

func NewRingBuffer

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

NewRingBuffer returns a new ring buffer with the given capacity.

Capacity must be in the range [1, MaxInt/2].

func (*RingBuffer[T]) Pop

func (rb *RingBuffer[T]) Pop() (elem T, ok bool)

Pop removes and returns the oldest element in the buffer if the buffer isn't empty.

func (*RingBuffer[T]) Push

func (rb *RingBuffer[T]) Push(elem T)

Push adds an element to the buffer. If the buffer is full, it overwrites the oldest element.

Jump to

Keyboard shortcuts

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