linkedbuffer

package
v2.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEOF = errors.New("EOF")

Functions

This section is empty.

Types

type Buffer

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

Buffer implements a generic Buffer that can store any type of data. It is not thread-safe and should be used with a mutex. It is used by LinkedBuffer to store data and is not intended to be used directly.

func NewBuffer

func NewBuffer[T any](capacity int) *Buffer[T]

func (*Buffer[T]) Cap

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

Cap returns the capacity of the buffer.

func (*Buffer[T]) Read

func (b *Buffer[T]) Read(values []T) (n int, err error)

Read reads values from the buffer and returns the number of elements read. If the buffer is empty, it returns 0 elements. If the buffer has been read completely, it returns an EOF error.

func (*Buffer[T]) Write

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

Write writes values to the buffer.

type LinkedBuffer

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

LinkedBuffer implements an unbounded generic buffer that can be written to and read from concurrently. It is implemented using a linked list of buffers.

func NewLinkedBuffer

func NewLinkedBuffer[T any](initialCapacity, maxCapacity int) *LinkedBuffer[T]

func (*LinkedBuffer[T]) Len

func (b *LinkedBuffer[T]) Len() uint64

Len returns the number of elements in the buffer that haven't yet been read

func (*LinkedBuffer[T]) Read

func (b *LinkedBuffer[T]) Read(values []T) int

Read reads values from the buffer and returns the number of elements read

func (*LinkedBuffer[T]) ReadCount

func (b *LinkedBuffer[T]) ReadCount() uint64

ReadCount returns the number of elements read from the buffer since it was created

func (*LinkedBuffer[T]) Write

func (b *LinkedBuffer[T]) Write(values []T)

Write writes values to the buffer

func (*LinkedBuffer[T]) WriteCount

func (b *LinkedBuffer[T]) WriteCount() uint64

WriteCount returns the number of elements written to the buffer since it was created

Jump to

Keyboard shortcuts

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