ringbuf

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 0 Imported by: 0

README

Ring Buffer

Design

1 item

in |out | w | r ----+----+----+---- 0 | 0 | 0 | 0 1 | 0 | 1 | 0 1 | 1 | 1 | 1

Documentation

Overview

Package ringbuf provides ring buffer.

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
}

Buffer provides ring buffer.

func New

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

New creates a ring buffer with specified capacity.

func (*Buffer[T]) Clear

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

Clear remove all values.

func (*Buffer[T]) Empty

func (b *Buffer[T]) Empty() bool

Empty checks the buffer is empty or not.

func (*Buffer[T]) Get

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

Get retrieves a value.

func (*Buffer[T]) Len added in v1.14.0

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

Len returns number of valid items in the ringbuf

func (*Buffer[T]) Peek added in v1.14.0

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

Peek peeks checks a n'th value in ringbuf without removing the value.

func (*Buffer[T]) Put

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

Put puts a value.

Jump to

Keyboard shortcuts

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