ring

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

func NewBuffer

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

New creates a new ring buffer with s specified size.

func (*Buffer[T]) Len

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

Len returns a number of elements currently in the buffer.

func (*Buffer[T]) Peek

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

Peek returns first buffered element without consuming it. Function returns zero value if the buffer is empty.

func (*Buffer[T]) Pop

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

Pop returns the first element and consumes it. Function returns zero value if the buffer is empty.

func (*Buffer[T]) Push

func (b *Buffer[T]) Push(v T)

Push adds an element into the end of the buffer. It discards the oldest element if the buffer is already full.

func (*Buffer[T]) Read

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

Read a number of elements from the buffer. Function returns io.EOF if the buffer is empty.

func (*Buffer[T]) Size

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

Size returns underlying size of the buffer.

func (*Buffer[T]) TryPeek

func (b *Buffer[T]) TryPeek() (T, bool)

TryPeek tries to access first buffered element without consuming it. Function returns false if the buffer is empty.

func (*Buffer[T]) TryPop

func (b *Buffer[T]) TryPop() (T, bool)

TryPop returns the first element and consumes it. Function returns false if the buffer is empty.

func (*Buffer[T]) TryPush

func (b *Buffer[T]) TryPush(v T) bool

TryPush attempts to add an element into the end of the buffer. It returns false if the buffer is full.

func (*Buffer[T]) Write

func (b *Buffer[T]) Write(p []T) (int, error)

Write a number of elements into the buffer. Oldest elements will be discarded if the buffer cannot fit all elements.

Jump to

Keyboard shortcuts

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