container

package
v0.22.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Index

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL