ringbuf

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: GPL-3.0 Imports: 2 Imported by: 1

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
}

func NewRingBuffer

func NewRingBuffer[T any](size int) *RingBuffer[T]

func (*RingBuffer[T]) Cap

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

Cap returns the total space of the buffer

func (*RingBuffer[T]) Clear added in v1.1.0

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

Clear set ring buffer's length to zero It does not dereference old elements

func (*RingBuffer[T]) ForEach

func (r *RingBuffer[T]) ForEach(iter func(v T) bool)

ForEach iterate the buffer from first to last if the iterator returns false, the iterate will break

func (*RingBuffer[T]) ForEachReversed added in v1.3.0

func (r *RingBuffer[T]) ForEachReversed(iter func(v T) bool)

ForEachReversed iterate the buffer from last to first if the iterator returns false, the iterate will break

func (*RingBuffer[T]) Get

func (r *RingBuffer[T]) Get(index int) T

Get returns the i-th element in the buffer It will panic if index is out of bounds

func (*RingBuffer[T]) Iter added in v1.3.0

func (r *RingBuffer[T]) Iter() iter.Seq[T]

Iter returns an iterator of the buffer that iterate from first to last

func (*RingBuffer[T]) IterReversed added in v1.3.0

func (r *RingBuffer[T]) IterReversed() iter.Seq[T]

IterReversed returns an iterator of the buffer that iterate from last to first

func (*RingBuffer[T]) Len

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

Len returns the used space of the buffer

func (*RingBuffer[T]) Poll

func (r *RingBuffer[T]) Poll() (v T, ok bool)

Poll removes the earliest pushed element from the ring buffer

func (*RingBuffer[T]) Push

func (r *RingBuffer[T]) Push(v T)

Push puts an element into the ring buffer It will overwrite the earliest element if there is no space avaliable

func (*RingBuffer[T]) Reset added in v1.1.0

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

Reset set ring buffer's length to zero and dereference all elements

Jump to

Keyboard shortcuts

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