Documentation
¶
Overview ¶
Package ringbuffer provides ring buffers.
Index ¶
- type RingBuffer
- func (b RingBuffer[T]) All() iter.Seq[T]
- func (b RingBuffer[T]) Append(value T)
- func (b RingBuffer[T]) Backward() iter.Seq[T]
- func (b RingBuffer[T]) Cap() int
- func (b RingBuffer[T]) Copy() RingBuffer[T]
- func (b RingBuffer[T]) Get(index int) T
- func (b RingBuffer[T]) Indexed() iter.Seq2[int, T]
- func (b RingBuffer[T]) IsNil() bool
- func (b RingBuffer[T]) Len() int
- func (b RingBuffer[T]) Set(index int, value T)
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]) 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]) Set ¶ added in v0.5.0
func (b RingBuffer[T]) Set(index int, value T)
Set sets given value for element with given index.