ringbuf

package
v0.0.0-...-cc8504f Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ringbuf implements a dynamically growing ring buffer.

Index

Constants

This section is empty.

Variables

View Source
var ErrNegativeOffset = errors.New("negative offset")

Functions

This section is empty.

Types

type Buffer

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

func NewBuffer

func NewBuffer[T any](maxLen int, initialCap ...int) *Buffer[T]

NewBuffer returns a new ring buffer.

Incoming data grows the buffer from initialCap (which is zero if not provided) to maxLen, then overwrites old data.

func (*Buffer[T]) Bytes

func (r *Buffer[T]) Bytes() []T

Bytes returns a copy of the unread elements of the buffer.

If you want to access buffer data without copying/allocation, consider using Buffer.BytesSeq.

func (*Buffer[T]) BytesSeq

func (b *Buffer[T]) BytesSeq() iter.Seq[[]T]

BytesSeq returns an iterator over the unread elements of the buffer. It's similar to Buffer.Bytes

The returned slices alias the buffer content at least until the next buffer modification.

func (*Buffer[T]) Cap

func (b *Buffer[T]) Cap() int

func (*Buffer[T]) Grow

func (b *Buffer[T]) Grow(n int)

func (*Buffer[T]) Len

func (b *Buffer[T]) Len() int

Len returns the number of unread elements of the buffer; r.Len() == len(r.Bytes())

func (*Buffer[T]) MaxLen

func (b *Buffer[T]) MaxLen() int

func (*Buffer[T]) Next

func (b *Buffer[T]) Next(n int) []T

Next returns a copy of the first n unread elements of the buffer, advancing the buffer as if the data had been returned by Buffer.Read.

If you want to access this data without allocations, consider using Buffer.NextSeq.

func (*Buffer[T]) NextSeq

func (b *Buffer[T]) NextSeq(n int) iter.Seq[[]T]

NextSeq returns an iterator over the next n elements of the buffer, advancing the buffer as if the data had been returned by Buffer.Read.

The returned slices alias the buffer content at least until the next buffer modification.

func (*Buffer[T]) Read

func (b *Buffer[T]) Read(dest []T) (int, error)

func (*Buffer[T]) ReadAt

func (b *Buffer[T]) ReadAt(dest []T, offset int64) (n int, err error)

func (*Buffer[T]) ReadByte

func (b *Buffer[T]) ReadByte() (T, error)

func (*Buffer[T]) Reset

func (b *Buffer[T]) Reset()

func (*Buffer[T]) Write

func (b *Buffer[T]) Write(src []T) (n int, err error)

func (*Buffer[T]) WriteByte

func (b *Buffer[T]) WriteByte(v T) error

type ByteBuffer

type ByteBuffer struct {
	Buffer[byte]
	// contains filtered or unexported fields
}

func NewByteBuffer

func NewByteBuffer(maxLen int, initialCap ...int) *ByteBuffer

func (*ByteBuffer) ReadFrom

func (b *ByteBuffer) ReadFrom(r io.Reader) (n int64, err error)

func (*ByteBuffer) ReadRune

func (b *ByteBuffer) ReadRune() (r rune, size int, err error)

func (*ByteBuffer) String

func (b *ByteBuffer) String() string

String returns the contents of the buffer as a string. If *ByteBuffer is nil, it returns "<nil>".

func (*ByteBuffer) WriteRune

func (b *ByteBuffer) WriteRune(ru rune) (int, error)

func (*ByteBuffer) WriteString

func (b *ByteBuffer) WriteString(s string) (int, error)

func (*ByteBuffer) WriteTo

func (b *ByteBuffer) WriteTo(w io.Writer) (n int64, err error)

Jump to

Keyboard shortcuts

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