ring

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ring

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

Ring 是一个固定容量的环形缓冲区(循环队列) 当缓冲区满时,新元素会覆盖最旧的元素 该实现不是并发安全的,如需并发使用请添加互斥锁

func NewRing

func NewRing[T any](size int) *Ring[T]

NewRing 创建一个指定容量的环形缓冲区

func (*Ring[T]) Cap

func (r *Ring[T]) Cap() int

Cap 返回容量

func (*Ring[T]) Items

func (r *Ring[T]) Items() iter.Seq2[int, T]

Items 返回一个迭代器,按从旧到新的顺序遍历所有元素 每个元素会返回其索引(0-based)和值

func (*Ring[T]) Len

func (r *Ring[T]) Len() int

Len 返回当前元素数量

func (*Ring[T]) Push

func (r *Ring[T]) Push(item T)

Push 添加一个元素到缓冲区 如果缓冲区已满,会覆盖最旧的元素

func (*Ring[T]) Reset

func (r *Ring[T]) Reset(size int)

Reset 重置缓冲区并设置新容量,丢弃现有数据

Jump to

Keyboard shortcuts

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