internal

package
v0.0.0-...-93c852a Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchParallelize

func BatchParallelize[V, U any](q *WorkQueue, values []V, width int, fn func([]V) []U) iter.Seq[U]

BatchParallelize splits items into batches of at most width elements, submits each chunk as a single job to q, and returns an iterator that yields the results in order, flattened across batches.

Types

type Comparable

type Comparable[V cmp.Ordered] struct {
	Value V
}

Comparable implements Comparer for an cmp.Ordered value.

func (*Comparable[V]) Cmp

func (v *Comparable[V]) Cmp(u *Comparable[V]) int

type Comparer

type Comparer[V any] interface {
	*V
	Cmp(*V) int
}

type PriorityQueue

type PriorityQueue[U Comparer[V], V any] []V

A priority queue implemented as a min-heap, a binary tree encoded in a slice.

  • Element at index i has children at 2i+1 and 2i+2
  • Element at index i has parent at (i-1)/2
  • Index 0 is the root (the minimum)

func (PriorityQueue[U, V]) Len

func (q PriorityQueue[U, V]) Len() int

func (PriorityQueue[U, V]) Peek

func (q PriorityQueue[U, V]) Peek() V

func (*PriorityQueue[U, V]) Pop

func (q *PriorityQueue[U, V]) Pop() V

func (*PriorityQueue[U, V]) Push

func (q *PriorityQueue[U, V]) Push(v V)

type WorkBatch

type WorkBatch[V any] struct {
	// contains filtered or unexported fields
}

A WorkBatch is a set of jobs submitted to a WorkQueue whose results can be collected in submission order. A Batch must not be copied after first use.

func NewWorkBatch

func NewWorkBatch[V any](q *WorkQueue) *WorkBatch[V]

NewWorkBatch creates a new WorkBatch that submits jobs to q.

func (*WorkBatch[V]) Drain

func (b *WorkBatch[V]) Drain() iter.Seq[V]

Drain iterates job results in submission order, blocking until Seal is called and all submitted jobs have finished. If a job panicked, the panic is re-raised at its ordered position.

Seal must be called concurrently with Drain. Calling Seal before Drain works only if total submissions do not exceed the queue width, and will deadlock otherwise; prefer always calling them concurrently.

func (*WorkBatch[V]) Seal

func (b *WorkBatch[V]) Seal()

Seal signals that no more jobs will be submitted, then blocks until all submitted jobs have finished and closes the result channel.

func (*WorkBatch[V]) Submit

func (b *WorkBatch[V]) Submit(fn func() V)

Submit enqueues fn for execution. It blocks until a concurrency slot is available. Panics if called after Seal. Panics in the passed function are forwarded to WorkBatch.Drain.

type WorkQueue

type WorkQueue struct {
	// contains filtered or unexported fields
}

WorkQueue is a shared concurrency limiter. Multiple batches may submit jobs to the same queue simultaneously; the total number of concurrently running jobs across all batches is bounded by the width passed to New.

func NewWorkQueue

func NewWorkQueue(width int) *WorkQueue

NewWorkQueue creates a WorkQueue that allows at most width jobs to run simultaneously.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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