package buffer
import "k8s.io/utils/buffer"
Index ¶
- Variables
- type Ring
- func NewRing[T any](opts RingOptions) *Ring[T]
- func (r *Ring[T]) Cap() int
- func (r *Ring[T]) Len() int
- func (r *Ring[T]) ReadOne() (data T, ok bool)
- func (r *Ring[T]) WriteOne(data T)
- type RingGrowing
- type RingGrowingOptions
- type RingOptions
- type TypedRingFixed
- func NewTypedRingFixed[T any](size int) (*TypedRingFixed[T], error)
- func (r *TypedRingFixed[T]) Len() int
- func (r *TypedRingFixed[T]) Reset()
- func (r *TypedRingFixed[T]) Size() int
- func (r *TypedRingFixed[T]) Slice() []T
- func (r *TypedRingFixed[T]) TotalWritten() int64
- func (r *TypedRingFixed[T]) Write(p []T) (int, error)
- type TypedRingGrowing
Variables ¶
ErrInvalidSize indicates size must be > 0
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 ¶
Cap returns the capacity of the buffer.
func (*Ring[T]) Len ¶
Len returns the number of items in the buffer.
func (*Ring[T]) ReadOne ¶
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 TypedRingFixed ¶
type TypedRingFixed[T any] struct { // contains filtered or unexported fields }
TypedRingFixed is a fixed-size circular buffer for elements of type T. Writes overwrite older data, keeping only the last N elements. Not thread safe.
func NewTypedRingFixed ¶
func NewTypedRingFixed[T any](size int) (*TypedRingFixed[T], error)
NewTypedRingFixed creates a circular buffer with the given capacity (must be > 0).
func (*TypedRingFixed[T]) Len ¶
func (r *TypedRingFixed[T]) Len() int
Len returns how many elements are currently in the buffer.
func (*TypedRingFixed[T]) Reset ¶
func (r *TypedRingFixed[T]) Reset()
Reset clears the buffer.
func (*TypedRingFixed[T]) Size ¶
func (r *TypedRingFixed[T]) Size() int
Size returns the buffer capacity.
func (*TypedRingFixed[T]) Slice ¶
func (r *TypedRingFixed[T]) Slice() []T
Slice returns buffer contents in write order. Don't modify the returned slice.
func (*TypedRingFixed[T]) TotalWritten ¶
func (r *TypedRingFixed[T]) TotalWritten() int64
TotalWritten returns total elements ever written (including overwritten ones).
func (*TypedRingFixed[T]) Write ¶
func (r *TypedRingFixed[T]) Write(p []T) (int, error)
Write writes p to the buffer, overwriting old data if needed.
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_fixed.go ring_growing.go
- Version
- v0.0.0-20260319190234-28399d86e0b5 (latest)
- Published
- Mar 19, 2026
- Platform
- linux/amd64
- Imports
- 2 packages
- Last checked
- 9 hours ago –
Tools for package owners.