multiheadqueue

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2025 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewShard

func NewShard[T any](capacity uint64) *shard[T]

NewShard creates a new shard with the given capacity (rounded up to a power of 2).

Types

type MultiHeadQueue

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

MultiHeadQueue is a sharded MPMC queue.

func New

func New[T any](totalCapacity, numShards uint64) *MultiHeadQueue[T]

New creates a new MultiHeadQueue with the given total capacity and shard count. If numShards is zero, it defaults to runtime.NumCPU().

func (*MultiHeadQueue[T]) Dequeue

func (q *MultiHeadQueue[T]) Dequeue() (T, bool)

Dequeue scans shards in round-robin order starting from a rotating index.

func (*MultiHeadQueue[T]) Enqueue

func (q *MultiHeadQueue[T]) Enqueue(val T)

Enqueue inserts a value by selecting a shard in round-robin fashion.

func (*MultiHeadQueue[T]) FreeSlots

func (q *MultiHeadQueue[T]) FreeSlots() uint64

FreeSlots returns the total free slots across all shards.

func (*MultiHeadQueue[T]) UsedSlots

func (q *MultiHeadQueue[T]) UsedSlots() uint64

UsedSlots returns the total occupied slots across all shards.

Jump to

Keyboard shortcuts

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