Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item[V any] struct { Value V // contains filtered or unexported fields }
Item is a value in PriorityQueue
type PriorityQueue ¶
type PriorityQueue[V any] struct { // contains filtered or unexported fields }
PriorityQueue is a generic priority queue. It is not concurrency safe.
func New ¶
func New[V any](min bool) *PriorityQueue[V]
New creates a new priority queue. If min is true, items with lower priority are returned first. If min is false, items with higher priority are returned first.
func (*PriorityQueue[V]) Contains ¶
func (pq *PriorityQueue[V]) Contains(itm *Item[V]) bool
func (*PriorityQueue[V]) Len ¶
func (pq *PriorityQueue[V]) Len() int
func (*PriorityQueue[V]) Peek ¶ added in v0.33.0
func (pq *PriorityQueue[V]) Peek() V
func (*PriorityQueue[V]) Pop ¶
func (pq *PriorityQueue[V]) Pop() V
func (*PriorityQueue[V]) Push ¶
func (pq *PriorityQueue[V]) Push(val V, priority int) *Item[V]
func (*PriorityQueue[V]) Remove ¶
func (pq *PriorityQueue[V]) Remove(itm *Item[V])
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore implements a counting semaphore that's acquired in prioritized order. The implementation is derived from golang.org/x/sync/semaphore.
func NewSemaphore ¶
NewSemaphore creates a Semaphore where size is the maximum.
func (*Semaphore) Acquire ¶
Acquire acquires the semaphore with a priority. Higher priorities are acquired first. It blocks until the semaphore is acquired or ctx is cancelled. If ctx is cancelled, Acquire returns ctx.Err(), otherwise it always returns nil.
func (*Semaphore) Release ¶
func (s *Semaphore) Release()
Release releases a semaphore previously acquired with Acquire or TryAcquire.
func (*Semaphore) TryAcquire ¶
TryAcquire tries to immediately acquire the semaphore. It returns false if the semaphore is locked or there are items in the queue.