bufferutil

package
v0.48.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoundedCircularBuffer

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

func NewBoundedCircularBuffer

func NewBoundedCircularBuffer[T any](capacity int, maxSize int64) *BoundedCircularBuffer[T]

NewBoundedCircularBuffer creates a new bounded circular buffer with the given capacity and max size. capacity is the number of items that can be stored in the buffer. maxSize is the total size of all items that can be stored in the buffer. If the buffer is full, the oldest items will be dropped until there is enough space for the new item. This buffer is not concurrency safe.

func (*BoundedCircularBuffer[T]) Count

func (cb *BoundedCircularBuffer[T]) Count() int

func (*BoundedCircularBuffer[T]) Iterate

func (cb *BoundedCircularBuffer[T]) Iterate(callback func(item Item[T]), limit int)

Iterate iterates over the buffer from oldest to newest. The callback function will be called for each item in the buffer. The limit parameter specifies the maximum number of items to iterate over. No validation on limit is done. Caller is responsible for ensuring limit is a valid value.

func (*BoundedCircularBuffer[T]) Peek

func (cb *BoundedCircularBuffer[T]) Peek() (Item[T], error)

func (*BoundedCircularBuffer[T]) Pop

func (cb *BoundedCircularBuffer[T]) Pop() (Item[T], error)

func (*BoundedCircularBuffer[T]) Push

func (cb *BoundedCircularBuffer[T]) Push(item Item[T])

func (*BoundedCircularBuffer[T]) ReverseIterate

func (cb *BoundedCircularBuffer[T]) ReverseIterate(callback func(item Item[T]), limit int)

ReverseIterate iterates over the buffer from newest to oldest. The callback function will be called for each item in the buffer. The limit parameter specifies the maximum number of items to iterate over. No validation on limit is done. Caller is responsible for ensuring limit is a valid value.

func (*BoundedCircularBuffer[T]) ReverseIterateUntil added in v0.40.0

func (cb *BoundedCircularBuffer[T]) ReverseIterateUntil(callback func(item Item[T]) bool)

ReverseIterateUntil iterates over the buffer from oldest to newest until the callback function returns false, or it has iterated over the entire buffer.

type Item

type Item[T any] struct {
	Value T
	Size  int
}

Jump to

Keyboard shortcuts

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