priorityqueue

package
v0.43.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

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

func (Item[V]) Priority added in v0.33.0

func (i Item[V]) Priority() int

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

func NewSemaphore(size int) *Semaphore

NewSemaphore creates a Semaphore where size is the maximum.

func (*Semaphore) Acquire

func (s *Semaphore) Acquire(ctx context.Context, priority int) error

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

func (s *Semaphore) TryAcquire() bool

TryAcquire tries to immediately acquire the semaphore. It returns false if the semaphore is locked or there are items in the queue.

Jump to

Keyboard shortcuts

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