ring

package
v1.17.6 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ring

type Ring[T any] struct {
	// contains filtered or unexported fields
}

Ring is a very simple ring buffer implementation that uses a slice. The internal slice will only grow, never shrink. When it grows, it grows in chunks of "chunkSize" (given as argument in the New function). Pointer and reference types can be safely used because memory is cleared.

func New

func New[T any](chunkSize int) *Ring[T]

func (*Ring[T]) Cap

func (r *Ring[T]) Cap() int

func (*Ring[T]) Dequeue

func (r *Ring[T]) Dequeue() (v T, ok bool)

Dequeue returns the oldest value.

func (*Ring[T]) Enqueue

func (r *Ring[T]) Enqueue(v T)

Enqueue adds an item to the ring.

func (*Ring[T]) Len

func (r *Ring[T]) Len() int

func (*Ring[T]) Nth

func (r *Ring[T]) Nth(n int) (v T, ok bool)

Nth returns the n-th oldest value (zero-based) in the ring without making any change.

func (*Ring[T]) Reset

func (r *Ring[T]) Reset()

Jump to

Keyboard shortcuts

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