ringbuffer

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 0 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

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 growable FIFO queue that reuses its backing storage. The slice length stores the queue length, so wrapped positions are accessed by reslicing to capacity.

func (*RingBuffer[T]) Clear

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

Clear removes all elements while retaining the allocated storage.

func (*RingBuffer[T]) Empty

func (r *RingBuffer[T]) Empty() bool

Empty says if the ring buffer is empty.

func (*RingBuffer[T]) Init

func (r *RingBuffer[T]) Init(size int)

Init preallocates a buffer with a certain size.

func (*RingBuffer[T]) Len

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

Len returns the number of elements in the ring buffer.

func (*RingBuffer[T]) PeekFront

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

PeekFront returns the next element. It must not be called when the buffer is empty, that means that callers might need to check if there are elements in the buffer first.

func (*RingBuffer[T]) PopFront

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

PopFront returns the next element. It must not be called when the buffer is empty, that means that callers might need to check if there are elements in the buffer first.

func (*RingBuffer[T]) PushBack

func (r *RingBuffer[T]) PushBack(t T)

PushBack adds a new element. If the ring buffer is full, its capacity is increased first.

Jump to

Keyboard shortcuts

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