ringbuffer

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package ringbuffer provides ring buffers.

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 of elements with values of type T.

Values of this type are references to shared internal state. Use the Copy method to make separate copy.

func New

func New[T any](cap int) RingBuffer[T]

New initializes and returns new RingBuffer of given capacity.

func (RingBuffer[T]) All added in v0.5.0

func (b RingBuffer[T]) All() iter.Seq[T]

All returns iterator that iterates over all elements in direct order, producing their values.

func (RingBuffer[T]) Append

func (b RingBuffer[T]) Append(value T)

Append appends element with given value to buffer's end. If resulting number of elements exceeds capacity, the first element will be removed from buffer.

func (RingBuffer[T]) Backward added in v0.5.0

func (b RingBuffer[T]) Backward() iter.Seq[T]

Backward returns iterator that iterates over all elements in backward order, producing their values.

func (RingBuffer[T]) Cap

func (b RingBuffer[T]) Cap() int

Cap returns capacity of buffer.

func (RingBuffer[T]) Copy

func (b RingBuffer[T]) Copy() RingBuffer[T]

Copy returns copy of buffer.

func (RingBuffer[T]) Get

func (b RingBuffer[T]) Get(index int) T

Get returns value of element with given index.

func (RingBuffer[T]) Indexed added in v0.5.0

func (b RingBuffer[T]) Indexed() iter.Seq2[int, T]

Indexed returns iterator that iterates over all elements in direct order, producing both their indexes and values.

func (RingBuffer[T]) IsNil

func (b RingBuffer[T]) IsNil() bool

IsNil reports whether buffer is nil.

func (RingBuffer[T]) Len

func (b RingBuffer[T]) Len() int

Len returns number of elements.

func (RingBuffer[T]) Set added in v0.5.0

func (b RingBuffer[T]) Set(index int, value T)

Set sets given value for element with given index.

Jump to

Keyboard shortcuts

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