Documentation
¶
Overview ¶
Package ringbuffer provides a generic thread-safe circular buffer with deduplication.
Index ¶
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 is a thread-safe circular buffer. When full, new items overwrite the oldest. Deduplicates by key within each flush window — if an identical item is already in the buffer, the new one is silently dropped.
func New ¶
func New[T any](capacity int, keyFunc func(T) string) *RingBuffer[T]
New creates a RingBuffer with the given capacity and deduplication key function. The keyFunc extracts a deduplication key from each item.
func (*RingBuffer[T]) Add ¶
func (rb *RingBuffer[T]) Add(item T)
Add inserts an item into the buffer, overwriting the oldest if full. Duplicate items (same key) are silently dropped.
func (*RingBuffer[T]) Capacity ¶
func (rb *RingBuffer[T]) Capacity() int
Capacity returns the buffer capacity.
func (*RingBuffer[T]) Count ¶
func (rb *RingBuffer[T]) Count() int
Count returns the current number of stored items.
func (*RingBuffer[T]) Drain ¶
func (rb *RingBuffer[T]) Drain() []T
Drain returns all items in chronological order (oldest first) and clears the buffer.