PQueue

abstract class PQueue[F[_], A] extends PQueueSource[F, A] with PQueueSink[F, A]

A purely functional Priority Queue implementation based on a binomial heap (Okasaki)

Assumes an Order instance is in scope for A

Companion:
object
trait PQueueSink[F, A]
trait PQueueSource[F, A]
class Object
trait Matchable
class Any
PQueue[F, A]

Value members

Concrete methods

def mapK[G[_]](f: FunctionK[F, G]): PQueue[G, A]

Modifies the context in which this PQueue is executed using the natural transformation f.

Modifies the context in which this PQueue is executed using the natural transformation f.

O(1)

Returns:

a PQueue in the new context obtained by mapping the current one using f

Inherited methods

def offer(a: A): F[Unit]

Enqueues the given element, possibly fiber blocking until sufficient capacity becomes available.

Enqueues the given element, possibly fiber blocking until sufficient capacity becomes available.

O(log(n))

Value parameters:
a

the element to be put in the PQueue

Inherited from:
PQueueSink
def size: F[Int]
Inherited from:
PQueueSource
def take: F[A]

Dequeues the least element from the PQueue, possibly fiber blocking until an element becomes available.

Dequeues the least element from the PQueue, possibly fiber blocking until an element becomes available.

O(log(n))

Note: If there are multiple elements with least priority, the order in which they are dequeued is undefined. If you want to break ties with FIFO order you will need an additional Ref[F, Long] to track insertion, and embed that information into your instance for Order[A].

Inherited from:
PQueueSource
def tryOffer(a: A): F[Boolean]

Attempts to enqueue the given element without fiber blocking.

Attempts to enqueue the given element without fiber blocking.

O(log(n))

Value parameters:
a

the element to be put in the PQueue

Returns:

an effect that describes whether the enqueuing of the given element succeeded without blocking

Inherited from:
PQueueSink
def tryTake: F[Option[A]]

Attempts to dequeue the least element from the PQueue, if one is available without fiber blocking.

Attempts to dequeue the least element from the PQueue, if one is available without fiber blocking.

O(log(n))

Returns:

an effect that describes whether the dequeueing of an element from the PQueue succeeded without blocking, with None denoting that no element was available Note: If there are multiple elements with least priority, the order in which they are dequeued is undefined. If you want to break ties with FIFO order you will need an additional Ref[F, Long] to track insertion, and embed that information into your instance for Order[A].

Inherited from:
PQueueSource