@@ -31,18 +31,18 @@ import Effect (Effect)
31
31
-- API
32
32
33
33
-- | A priority queue that allows for efficient insertion and removal of elements.
34
- -- The queue can be created with a custom ordering function that determines the
35
- -- priority of elements.
36
- -- Note: it's not possible to have a meaninful Eq instance, as two queues with
37
- -- the same elements might have them in different order due to the heap structure.
38
- -- It's recommended to convert the queue to an array to compare it.
34
+ -- | The queue can be created with a custom ordering function that determines the
35
+ -- | priority of elements.
36
+ -- | Note: it's not possible to have a meaninful Eq instance, as two queues with
37
+ -- | the same elements might have them in different order due to the heap structure.
38
+ -- | It's recommended to convert the queue to an array to compare it.
39
39
newtype Queue a = Queue
40
40
{ contents :: STArray Global a
41
41
, ordering :: a -> a -> Boolean
42
42
}
43
43
44
44
-- | Create a new priority queue where the element with the smallest value
45
- -- according to the provided function will be at the front of the queue.
45
+ -- | according to the provided function will be at the front of the queue.
46
46
newMinQueue :: forall a . (a -> Number ) -> Effect (Queue a )
47
47
newMinQueue fn = toEffect do
48
48
contents <- STA .new
@@ -52,7 +52,7 @@ newMinQueue fn = toEffect do
52
52
}
53
53
54
54
-- | Create a new priority queue where the element with the largest value
55
- -- according to the provided function will be at the front of the queue.
55
+ -- | according to the provided function will be at the front of the queue.
56
56
newMaxQueue :: forall a . (a -> Number ) -> Effect (Queue a )
57
57
newMaxQueue fn = toEffect do
58
58
contents <- STA .new
@@ -76,8 +76,8 @@ pop (Queue { contents, ordering }) = toEffect do
76
76
removeMax contents ordering
77
77
78
78
-- | Remove and return the first n elements from the queue.
79
- -- Note: we guarantee that the elements are sorted in the order of the queue,
80
- -- first element is the one with the highest priority.
79
+ -- | Note: we guarantee that the elements are sorted in the order of the queue,
80
+ -- | first element is the one with the highest priority.
81
81
popN :: forall a . Int -> Queue a -> Effect (Array a )
82
82
popN n (Queue { contents, ordering }) = toEffect do
83
83
result <- STA .new
0 commit comments