utilsk8s.io/utils/buffer Index | Files

package buffer

import "k8s.io/utils/buffer"

Index

Types

type Ring

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

Ring is a dynamically-sized ring buffer which can grow and shrink as-needed. The zero value has an initial size and normal size of 0 and is ready to use. Not thread safe.

func NewRing

func NewRing[T any](opts RingOptions) *Ring[T]

NewRing constructs a new Ring instance with provided parameters.

func (*Ring[T]) Cap

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

Cap returns the capacity of the buffer.

func (*Ring[T]) Len

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

Len returns the number of items in the buffer.

func (*Ring[T]) ReadOne

func (r *Ring[T]) ReadOne() (data T, ok bool)

ReadOne reads (consumes) first item from the buffer if it is available, otherwise returns false. When the buffer has been totally consumed and has grown in size beyond its normal size, it shrinks down to its normal size again.

func (*Ring[T]) WriteOne

func (r *Ring[T]) WriteOne(data T)

WriteOne adds an item to the end of the buffer, growing it if it is full.

type RingGrowing

type RingGrowing = TypedRingGrowing[any]

RingGrowing is a growing ring buffer. Not thread safe.

Deprecated: Use TypedRingGrowing[any] instead.

func NewRingGrowing

func NewRingGrowing(initialSize int) *RingGrowing

NewRingGrowing constructs a new RingGrowing instance with provided parameters.

Deprecated: Use NewTypedRingGrowing[any] instead.

type RingGrowingOptions

type RingGrowingOptions struct {
	// InitialSize is the number of pre-allocated elements in the
	// initial underlying storage buffer.
	InitialSize int
}

RingGrowingOptions sets parameters for RingGrowing and TypedRingGrowing.

type RingOptions

type RingOptions struct {
	// InitialSize is the number of pre-allocated elements in the
	// initial underlying storage buffer.
	InitialSize int
	// NormalSize is the number of elements to allocate for new storage
	// buffers once the Ring is consumed and
	// can shrink again.
	NormalSize int
}

RingOptions sets parameters for Ring.

type TypedRingGrowing

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

TypedRingGrowing is a growing ring buffer. The zero value has an initial size of 0 and is ready to use. Not thread safe.

func NewTypedRingGrowing

func NewTypedRingGrowing[T any](opts RingGrowingOptions) *TypedRingGrowing[T]

NewTypedRingGrowing constructs a new TypedRingGrowing instance with provided parameters.

func (*TypedRingGrowing[T]) Cap

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

Cap returns the capacity of the buffer.

func (*TypedRingGrowing[T]) Len

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

Len returns the number of items in the buffer.

func (*TypedRingGrowing[T]) ReadOne

func (r *TypedRingGrowing[T]) ReadOne() (data T, ok bool)

ReadOne reads (consumes) first item from the buffer if it is available, otherwise returns false.

func (*TypedRingGrowing[T]) WriteOne

func (r *TypedRingGrowing[T]) WriteOne(data T)

WriteOne adds an item to the end of the buffer, growing it if it is full.

Source Files

ring_growing.go

Version
v0.0.0-20250604170112-4c0f3b243397 (latest)
Published
Jun 4, 2025
Platform
js/wasm
Last checked
2 days ago

Tools for package owners.