ringbuffer

package
v0.0.0-...-9ca7e33 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

README

Ringbuffer

This is a direct copy from https://github.com/tailscale/tailscale/tree/main/util/ringbuffer

When trying to go get this package there are a lot of dep conflicts and replace directives needed in early testers. Opted to just copy these files for now.

Documentation

Overview

Package ringbuffer contains a fixed-size concurrency-safe generic ring buffer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RingBuffer

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

RingBuffer is a concurrency-safe ring buffer.

func New

func New[T any](max int) *RingBuffer[T]

New creates a new RingBuffer containing at most max items.

func (*RingBuffer[T]) Add

func (rb *RingBuffer[T]) Add(t T)

Add appends a new item to the RingBuffer, possibly overwriting the oldest item in the buffer if it is already full.

func (*RingBuffer[T]) Clear

func (rb *RingBuffer[T]) Clear()

Clear will empty the ring buffer.

func (*RingBuffer[T]) GetAll

func (rb *RingBuffer[T]) GetAll() []T

GetAll returns a copy of all the entries in the ring buffer in the order they were added.

func (*RingBuffer[T]) Len

func (rb *RingBuffer[T]) Len() int

Len returns the number of elements in the ring buffer. Note that this value could change immediately after being returned if a concurrent caller modifies the buffer.

Jump to

Keyboard shortcuts

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