queue

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 0 Imported by: 0

README

Queue 模块

TrackedQueue
  ├─ Hooks (enqueue/dequeue callbacks)
  ├─ MutateFunc (长度/容量同步)
  └─ Items (用于节点自定义逻辑)
  • TrackedQueue:维护队列元素、容量约束以及事件钩子,供节点统一处理入队/出队逻辑。
  • QueueHooks:在入队和出队时触发,负责记录事务事件或其他副作用。
  • MutateFunc:每次长度或容量变化时调用,用于回写节点的 QueueInfo 信息。

Documentation

Index

Constants

View Source
const UnlimitedCapacity = -1

Variables

This section is empty.

Functions

This section is empty.

Types

type MutateFunc

type MutateFunc func(length int, capacity int)

MutateFunc is invoked after queue length or capacity changes.

type QueueHooks

type QueueHooks[T any] struct {
	OnEnqueue func(item T, cycle int)
	OnDequeue func(item T, cycle int)
}

QueueHooks defines callbacks for queue lifecycle events.

type TrackedQueue

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

TrackedQueue maintains items with length/capacity bookkeeping and hooks.

func NewTrackedQueue

func NewTrackedQueue[T any](name string, capacity int, mutate MutateFunc, hooks QueueHooks[T]) *TrackedQueue[T]

NewTrackedQueue constructs a tracked queue with optional hooks and mutate callback.

func (*TrackedQueue[T]) CanAccept

func (q *TrackedQueue[T]) CanAccept(itemsCount int) bool

CanAccept checks if the queue can accept additional itemsCount entries respecting capacity.

func (*TrackedQueue[T]) Capacity

func (q *TrackedQueue[T]) Capacity() int

Capacity returns current capacity (-1 for unlimited).

func (*TrackedQueue[T]) Enqueue

func (q *TrackedQueue[T]) Enqueue(item T, cycle int) bool

Enqueue appends an item. Returns false if capacity exceeded.

func (*TrackedQueue[T]) Items

func (q *TrackedQueue[T]) Items() []T

Items exposes the underlying slice (read-only operations only).

func (*TrackedQueue[T]) Len

func (q *TrackedQueue[T]) Len() int

Len returns the number of items.

func (*TrackedQueue[T]) Name

func (q *TrackedQueue[T]) Name() string

Name returns the queue name.

func (*TrackedQueue[T]) PopFront

func (q *TrackedQueue[T]) PopFront(cycle int) (T, bool)

PopFront removes and returns the front item.

func (*TrackedQueue[T]) RemoveAt

func (q *TrackedQueue[T]) RemoveAt(idx int, cycle int) (T, bool)

RemoveAt deletes the item at index.

func (*TrackedQueue[T]) RemoveMatch

func (q *TrackedQueue[T]) RemoveMatch(match func(T) bool, cycle int) (T, bool)

RemoveMatch removes the first item matching predicate.

func (*TrackedQueue[T]) SetCapacity

func (q *TrackedQueue[T]) SetCapacity(capacity int)

SetCapacity updates queue capacity and triggers mutate callback.

Jump to

Keyboard shortcuts

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