Documentation
¶
Index ¶
- Constants
- type PriorityQueue
- type PriorityQueueImpl
- func (pq *PriorityQueueImpl[T]) ForEach(fn func(item T) bool)
- func (pq *PriorityQueueImpl[T]) Keys() []string
- func (pq *PriorityQueueImpl[T]) Len() int
- func (pq *PriorityQueueImpl[T]) Pop(n int) []T
- func (pq *PriorityQueueImpl[T]) Push(item T, priority int64)
- func (pq *PriorityQueueImpl[T]) Remove(keys ...string)
- func (pq *PriorityQueueImpl[T]) UpdatePriority(key string, newPriority int64) bool
- func (pq *PriorityQueueImpl[T]) Values() []T
- type PriorityQueueItem
- type WorkerPool
Constants ¶
const (
DefaultWorkerParallelism = 8
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PriorityQueue ¶
type PriorityQueue[T PriorityQueueItem] interface { Keys() []string Values() []T Push(item T, priority int64) Pop(n int) []T Remove(keys ...string) UpdatePriority(key string, priority int64) bool Len() int // ForEach iterates over all items in priority order (highest first) // while holding the lock. The callback returns true to continue, // false to break. Items are visited in priority order. ForEach(fn func(item T) bool) }
func NewPriorityQueue ¶
func NewPriorityQueue[T PriorityQueueItem]() PriorityQueue[T]
NewPriorityQueue creates a new priority queue.
type PriorityQueueImpl ¶
type PriorityQueueImpl[T PriorityQueueItem] struct { // contains filtered or unexported fields }
PriorityQueueImpl is a heap-based priority queue that supports dynamic priority updates and reordering.
Higher priority values come first (max-heap behavior).
func (*PriorityQueueImpl[T]) ForEach ¶
func (pq *PriorityQueueImpl[T]) ForEach(fn func(item T) bool)
ForEach iterates over all items in priority order (highest first) while holding the lock. The callback fn returns true to continue, false to break. Iteration stops immediately when fn returns false.
func (*PriorityQueueImpl[T]) Keys ¶
func (pq *PriorityQueueImpl[T]) Keys() []string
Keys returns all keys in the queue.
func (*PriorityQueueImpl[T]) Len ¶
func (pq *PriorityQueueImpl[T]) Len() int
Len returns the number of items in the queue.
func (*PriorityQueueImpl[T]) Pop ¶
func (pq *PriorityQueueImpl[T]) Pop(n int) []T
Pop removes and returns the highest priority items.
func (*PriorityQueueImpl[T]) Push ¶
func (pq *PriorityQueueImpl[T]) Push(item T, priority int64)
Push adds an item with the given priority.
func (*PriorityQueueImpl[T]) Remove ¶
func (pq *PriorityQueueImpl[T]) Remove(keys ...string)
Remove removes items from the queue.
func (*PriorityQueueImpl[T]) UpdatePriority ¶
func (pq *PriorityQueueImpl[T]) UpdatePriority(key string, newPriority int64) bool
UpdatePriority changes an item's priority and reorders the heap. Returns true if the item was found and updated.
func (*PriorityQueueImpl[T]) Values ¶
func (pq *PriorityQueueImpl[T]) Values() []T
List returns all items in priority order (highest first).
type PriorityQueueItem ¶
type PriorityQueueItem interface {
Key() string
}
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool manages a pool of goroutines that execute submitted functions. Submit() adds a function to the pool, Wait() blocks until all submitted functions complete.
func NewWorkerPool ¶
func NewWorkerPool(parallelism int) *WorkerPool
NewWorkerPool creates a new worker pool with the given parallelism.
func (*WorkerPool) Start ¶
func (p *WorkerPool) Start(ctx context.Context)
Start starts the worker pool goroutines and waits for them to be ready.
func (*WorkerPool) Stop ¶
func (p *WorkerPool) Stop()
Stop stops the worker pool and waits for all goroutines to exit.
func (*WorkerPool) Submit ¶
func (p *WorkerPool) Submit(fn func())
Submit submits a function to be executed by a worker goroutine. Submit increments the WaitGroup before sending to the channel, ensuring Wait() can track completion.
func (*WorkerPool) Wait ¶
func (p *WorkerPool) Wait()
Wait blocks until all submitted functions have completed.