Documentation
¶
Overview ¶
Package ringbuf provides a generic implementation of a circular ring buffer.
Index ¶
- type IterFunc
- type Ringbuf
- func (r *Ringbuf[T]) Cap() int
- func (r *Ringbuf[T]) Empty() bool
- func (r *Ringbuf[T]) Full() bool
- func (r *Ringbuf[T]) Iter(fn IterFunc[T])
- func (r *Ringbuf[T]) Len() int
- func (r *Ringbuf[T]) PopBack() (T, bool)
- func (r *Ringbuf[T]) PopFront() (T, bool)
- func (r *Ringbuf[T]) PushBack(v T) bool
- func (r *Ringbuf[T]) PushFront(v T) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IterFunc ¶
type IterFunc[T any] func(v T)
IterFunc is a function which will be executed for every element in the Ringbuf
type Ringbuf ¶
type Ringbuf[T any] struct { // contains filtered or unexported fields }
Ringbuf is a circular buffer of items with type T. It can hold a constant number of items (specifically: len(items)-1).
func NewRingbuf ¶
NewRingbuf creates a Ringbuf of T with the specified capacity.
func (*Ringbuf[T]) Iter ¶
Iter iterates through all the elements in the Ringbuf, calling fn on each one.
func (*Ringbuf[T]) PopBack ¶
PopBack returns a copy of the value at the back of the ringbuf and removes it. If the ringbuf is empty then it returns the default value and false for the bool return value.
func (*Ringbuf[T]) PopFront ¶
PopFront returns a copy of the value at the front of the ringbuf and removes it. If the ringbuf is empty then it returns the default value and false for the bool return value.