Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
f-f committed Jul 24, 2024
1 parent b70d8bb commit 6bca471
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/PriorityQueue.purs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ import Effect (Effect)
-- API

-- | 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.
-- | 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.
newtype Queue a = Queue
{ contents :: STArray Global a
, ordering :: a -> a -> Boolean
}

-- | 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.
-- | according to the provided function will be at the front of the queue.
newMinQueue :: forall a. (a -> Number) -> Effect (Queue a)
newMinQueue fn = toEffect do
contents <- STA.new
Expand All @@ -52,7 +52,7 @@ newMinQueue fn = toEffect do
}

-- | 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.
-- | according to the provided function will be at the front of the queue.
newMaxQueue :: forall a. (a -> Number) -> Effect (Queue a)
newMaxQueue fn = toEffect do
contents <- STA.new
Expand All @@ -76,8 +76,8 @@ pop (Queue { contents, ordering }) = toEffect do
removeMax contents ordering

-- | 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.
-- | Note: we guarantee that the elements are sorted in the order of the queue,
-- | first element is the one with the highest priority.
popN :: forall a. Int -> Queue a -> Effect (Array a)
popN n (Queue { contents, ordering }) = toEffect do
result <- STA.new
Expand Down

0 comments on commit 6bca471

Please sign in to comment.