ringbuffer

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ringbuffer 提供线程安全的智能环形缓冲区

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 线程安全的环形缓冲区实现

func MustNew

func MustNew[T any](size int) *RingBuffer[T]

MustNew 创建环形缓冲区(失败时panic)

func New

func New[T any](size int) (*RingBuffer[T], error)

New 创建新的环形缓冲区

func (*RingBuffer[T]) Cap

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

Cap 缓冲区容量

func (*RingBuffer[T]) Clear

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

Clear 清空缓冲区

func (*RingBuffer[T]) GetAll

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

GetAll 获取所有元素

func (*RingBuffer[T]) GetLast

func (rb *RingBuffer[T]) GetLast(n int) []T

GetLast 获取最后n个元素

func (*RingBuffer[T]) IsEmpty

func (rb *RingBuffer[T]) IsEmpty() bool

IsEmpty 是否为空

func (*RingBuffer[T]) IsFull

func (rb *RingBuffer[T]) IsFull() bool

IsFull 是否已满

func (*RingBuffer[T]) Iterator

func (rb *RingBuffer[T]) Iterator() <-chan T

Iterator 创建元素迭代器

func (*RingBuffer[T]) Len

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

Len 当前元素数量

func (*RingBuffer[T]) Push

func (rb *RingBuffer[T]) Push(item T)

Push 添加单个元素

func (*RingBuffer[T]) PushAll

func (rb *RingBuffer[T]) PushAll(items []T)

PushAll 批量添加元素

Directories

Path Synopsis
Package calculator 定义环形缓冲区索引计算策略
Package calculator 定义环形缓冲区索引计算策略
Package impl 实现环形缓冲区的数组存储版本
Package impl 实现环形缓冲区的数组存储版本

Jump to

Keyboard shortcuts

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