Documentation
¶
Overview ¶
ringbuf provides the RingBuf data structure.
A RingBuf is a slice of contiguous data that acts as a fixed-length queue. Writes exceeding the capacity of the RingBuf will wrap around to the front, and begin overwriting values.
Index ¶
- type Iterator
- type RingBuf
- func (b *RingBuf[T]) Clear()
- func (b *RingBuf[T]) Collect(values ...T)
- func (b *RingBuf[T]) Dequeue() (*T, error)
- func (b *RingBuf[T]) Enqueue(item T)
- func (b *RingBuf[T]) FromIterator(iter iterator.Iterator[T]) error
- func (b *RingBuf[T]) IntoIterator() iterator.Iterator[T]
- func (b RingBuf[T]) Peek() (*T, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RingBuf ¶
type RingBuf[T any] struct { // contains filtered or unexported fields }
RingBuf is the ring buffer data structure
func (*RingBuf[T]) Clear ¶
func (b *RingBuf[T]) Clear()
Clear reconstructs the RingBuf in place, effectively zeroing all the items.
func (*RingBuf[T]) Collect ¶
func (b *RingBuf[T]) Collect(values ...T)
Collect writes a variable number of items into the RingBuf. This method implements part of the Iterator interface.
func (*RingBuf[T]) Dequeue ¶
Dequeue reads an item from the RingBuf, advancing the head pointer. Returns nil, errors.Empty if ring buffer is empty.
func (*RingBuf[T]) Enqueue ¶
func (b *RingBuf[T]) Enqueue(item T)
Enqueue writes an item into the RingBuf, advancing the tail pointer.
func (*RingBuf[T]) FromIterator ¶
FromIterator collects the elements from the iterator into the ring buffer. This method implements part of the Iterable interface.
func (*RingBuf[T]) IntoIterator ¶
IntoIterator returns an iterator over the items in the RingBuf. This method implements part of the Iterable interface.