circular

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

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 thread-safe circular structure, designed to store most recent data. When the buffer is full, the oldest data is overwritten.

func NewRingBuffer

func NewRingBuffer[T any](capacity int) *RingBuffer[T]

NewRingBuffer creates a new ring buffer with the fixed capacity.

func (*RingBuffer[T]) Read

func (rb *RingBuffer[T]) Read() (T, bool)

Read returns the next value from buffer and true if the value was read successfully. When the buffer is empty, it returns false.

func (*RingBuffer[T]) Size

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

Size returns the number of elements in the buffer.

func (*RingBuffer[T]) Write

func (rb *RingBuffer[T]) Write(value T)

Write inserts a value to the buffer. When the buffer is full, the oldest data is overwritten.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳