Documentation
¶
Overview ¶
Package ringbuf implements a dynamically growing ring buffer.
Index ¶
- Variables
- type Buffer
- func (r *Buffer[T]) Bytes() []T
- func (b *Buffer[T]) BytesSeq() iter.Seq[[]T]
- func (b *Buffer[T]) Cap() int
- func (b *Buffer[T]) Grow(n int)
- func (b *Buffer[T]) Len() int
- func (b *Buffer[T]) MaxLen() int
- func (b *Buffer[T]) Next(n int) []T
- func (b *Buffer[T]) NextSeq(n int) iter.Seq[[]T]
- func (b *Buffer[T]) Read(dest []T) (int, error)
- func (b *Buffer[T]) ReadAt(dest []T, offset int64) (n int, err error)
- func (b *Buffer[T]) ReadByte() (T, error)
- func (b *Buffer[T]) Reset()
- func (b *Buffer[T]) Write(src []T) (n int, err error)
- func (b *Buffer[T]) WriteByte(v T) error
- type ByteBuffer
- func (b *ByteBuffer) ReadFrom(r io.Reader) (n int64, err error)
- func (b *ByteBuffer) ReadRune() (r rune, size int, err error)
- func (b *ByteBuffer) String() string
- func (b *ByteBuffer) WriteRune(ru rune) (int, error)
- func (b *ByteBuffer) WriteString(s string) (int, error)
- func (b *ByteBuffer) WriteTo(w io.Writer) (n int64, err error)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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]) Len ¶
Len returns the number of unread elements of the buffer; r.Len() == len(r.Bytes())
func (*Buffer[T]) Next ¶
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 ¶
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.
type ByteBuffer ¶
func NewByteBuffer ¶
func NewByteBuffer(maxLen int, initialCap ...int) *ByteBuffer
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) WriteString ¶
func (b *ByteBuffer) WriteString(s string) (int, error)