Documentation
¶
Index ¶
- Constants
- type RingBuffer
- func (rb *RingBuffer[T]) Capacity() int
- func (rb *RingBuffer[T]) Empty() bool
- func (rb *RingBuffer[T]) Len() int
- func (rb *RingBuffer[T]) Peek() (T, bool)
- func (rb *RingBuffer[T]) PeekAt(index int) (T, bool)
- func (rb *RingBuffer[T]) PeekTail() (T, bool)
- func (rb *RingBuffer[T]) Pop() (T, bool)
- func (rb *RingBuffer[T]) PopTail() (T, bool)
- func (rb *RingBuffer[T]) Push(v T)
Constants ¶
View Source
const (
UnlimitedCapacity = 0
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RingBuffer ¶
type RingBuffer[T any] struct { // contains filtered or unexported fields }
RingBuffer is a ring buffer that grows as needed when new items are added. It is not goroutine-safe.
func NewBoundedRingBuffer ¶
func NewBoundedRingBuffer[T any](capacity int) *RingBuffer[T]
func NewRingBuffer ¶
func NewRingBuffer[T any]() *RingBuffer[T]
func (*RingBuffer[T]) Capacity ¶
func (rb *RingBuffer[T]) Capacity() int
func (*RingBuffer[T]) Empty ¶
func (rb *RingBuffer[T]) Empty() bool
func (*RingBuffer[T]) Len ¶
func (rb *RingBuffer[T]) Len() int
func (*RingBuffer[T]) Peek ¶
func (rb *RingBuffer[T]) Peek() (T, bool)
func (*RingBuffer[T]) PeekAt ¶
func (rb *RingBuffer[T]) PeekAt(index int) (T, bool)
func (*RingBuffer[T]) PeekTail ¶
func (rb *RingBuffer[T]) PeekTail() (T, bool)
func (*RingBuffer[T]) Pop ¶
func (rb *RingBuffer[T]) Pop() (T, bool)
Removes and returns the least recently used item from the buffer. The second value indicates whether the buffer was empty and a zero-value item was returned instead.
func (*RingBuffer[T]) PopTail ¶
func (rb *RingBuffer[T]) PopTail() (T, bool)
Removes and returns the most recently used item from the buffer. The second value indicates whether the buffer was empty and a zero-value item was returned.
func (*RingBuffer[T]) Push ¶
func (rb *RingBuffer[T]) Push(v T)
Pushes an item into the buffer. If the buffer is full, it will grow to accommodate the new item. If the buffer is full and bounded, the oldest item will be discarded.
Click to show internal directories.
Click to hide internal directories.