Documentation
¶
Index ¶
- type RingBuffer
- func (rb *RingBuffer[T]) Cap() int
- func (rb *RingBuffer[T]) IsEmpty() bool
- func (rb *RingBuffer[T]) IsFull() bool
- func (rb *RingBuffer[T]) Peek() (result T, ok bool)
- func (rb *RingBuffer[T]) Pop() (result T, ok bool)
- func (rb *RingBuffer[T]) PushEvict(item T) (evicted T, didEvict bool)
- func (rb *RingBuffer[T]) SetCap(cap int)
- func (rb *RingBuffer[T]) Size() int
- func (rb *RingBuffer[T]) TryPush(item T) (ok bool)
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 implements a fixed capacity ring buffer for items of type T. NOTE: THIS IMPLEMENTATION IS NOT SAFE FOR CONCURRENT USE.
func NewRingBuffer ¶
func NewRingBuffer[T any](cap int) *RingBuffer[T]
func (*RingBuffer[T]) Cap ¶
func (rb *RingBuffer[T]) Cap() int
func (*RingBuffer[T]) IsEmpty ¶
func (rb *RingBuffer[T]) IsEmpty() bool
func (*RingBuffer[T]) IsFull ¶
func (rb *RingBuffer[T]) IsFull() bool
func (*RingBuffer[T]) Peek ¶
func (rb *RingBuffer[T]) Peek() (result T, ok bool)
Peek returns the front (=oldest) item without removing it. Return false as second argument if there are no items in the ring buffer.
func (*RingBuffer[T]) Pop ¶
func (rb *RingBuffer[T]) Pop() (result T, ok bool)
Pop removes and returns the front (=oldest) item. Return false as second argument if there are no items in the ring buffer.
func (*RingBuffer[T]) PushEvict ¶
func (rb *RingBuffer[T]) PushEvict(item T) (evicted T, didEvict bool)
Push new item to the back of the ring buffer. If the buffer is currently full, the front (=oldest) item is evicted and returned to make space for the new item.
func (*RingBuffer[T]) SetCap ¶
func (rb *RingBuffer[T]) SetCap(cap int)
func (*RingBuffer[T]) Size ¶
func (rb *RingBuffer[T]) Size() int
func (*RingBuffer[T]) TryPush ¶
func (rb *RingBuffer[T]) TryPush(item T) (ok bool)
Try to push a new item to the back of the ring buffer. Returns
- true if the item was added, or
- false if the item cannot be added because the buffer is currently full.
Click to show internal directories.
Click to hide internal directories.