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.
Click to show internal directories.
Click to hide internal directories.