ringbuffer

package
v0.0.0-...-5d524ee Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 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 Growable

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

Growable represents a growable ring buffer in which we can add items to and it will resize to fit everything in it

However as we pop and dequeue items from it it will never shrink in size. This is useful for storing temporary lists without needing to allocate new slices constantly

func NewGrowable

func NewGrowable[T any]() *Growable[T]

NewGrowable returns a growable ring buffer, that can be used as temporary storage

func (*Growable[T]) Dequeue

func (rb *Growable[T]) Dequeue() (value T, valid bool)

Dequeue removes the first value from the buffer

func (*Growable[T]) Len

func (rb *Growable[T]) Len() int

Len returns the current length of the ring buffer

func (*Growable[T]) PeekN

func (rb *Growable[T]) PeekN(n int) []T

PeekN returns upto N items from the buffer

If n is larger than the length of the buffer, the full buffer will be returned.

The slice it returns is not safe to be reused or modified as it may be taken from the internals of the ring buffer.

func (*Growable[T]) Push

func (rb *Growable[T]) Push(value T)

Push adds the value to the end of the buffer

Jump to

Keyboard shortcuts

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