Documentation
¶
Index ¶
- type RingBuffer
- func (r *RingBuffer[T]) Cap() int
- func (r *RingBuffer[T]) Clear()
- func (r *RingBuffer[T]) ForEach(iter func(v T) bool)
- func (r *RingBuffer[T]) ForEachReversed(iter func(v T) bool)
- func (r *RingBuffer[T]) Get(index int) T
- func (r *RingBuffer[T]) Iter() iter.Seq[T]
- func (r *RingBuffer[T]) IterReversed() iter.Seq[T]
- func (r *RingBuffer[T]) Len() int
- func (r *RingBuffer[T]) Poll() (v T, ok bool)
- func (r *RingBuffer[T]) Push(v T)
- func (r *RingBuffer[T]) Reset()
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