Module

Data.PriorityQueue

Package
purescript-priority-queue
Repository
spacchetti/purescript-priority-queue

#Queue Source

newtype Queue a

A priority queue that allows for efficient insertion and removal of elements. The queue can be created with a custom ordering function that determines the priority of elements. Note: it's not possible to have a meaninful Eq instance, as two queues with the same elements might have them in different order due to the heap structure. It's recommended to convert the queue to an array to compare it.

#newMaxQueue Source

newMaxQueue :: forall a. (a -> Number) -> Effect (Queue a)

Create a new priority queue where the element with the largest value according to the provided function will be at the front of the queue.

#newMinQueue Source

newMinQueue :: forall a. (a -> Number) -> Effect (Queue a)

Create a new priority queue where the element with the smallest value according to the provided function will be at the front of the queue.

#peekFront Source

peekFront :: forall a. Queue a -> Effect (Maybe a)

Return the element at the front of the queue without removing it.

#pop Source

pop :: forall a. Queue a -> Effect (Maybe a)

Remove and return the element at the front of the queue.

#popN Source

popN :: forall a. Int -> Queue a -> Effect (Array a)

Remove and return the first n elements from the queue. Note: we guarantee that the elements are sorted in the order of the queue, first element is the one with the highest priority.

#push Source

push :: forall a. Queue a -> a -> Effect Unit

Add an element to the queue.

#pushMany Source

pushMany :: forall a. Queue a -> Array a -> Effect Unit

Add multiple elements to the queue.

#size Source

size :: forall a. Queue a -> Effect Int

Return the number of elements in the queue.

#toArray Source

toArray :: forall a. Queue a -> Effect (Array a)

Convert the queue to an array.

#toList Source

toList :: forall a. Queue a -> Effect (List a)

Convert the queue to a list.