ringbuffer

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 0 Imported by: 0

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
}

A RingBuffer is a ring buffer. It acts as a heap that doesn't cause any allocations.

func (*RingBuffer[T]) Clear

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

Clear removes all elements.

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