@@ -98,7 +98,8 @@ import Data.Semigroup (Semigroup((<>)))
98
98
import qualified Data.List as List
99
99
100
100
import qualified BinomialQueue.Min as MinQ
101
- import Data.PQueue.Internals.Down
101
+ import Data.PQueue.Internals.Down (getDown )
102
+ import Data.Ord (Down (.. ))
102
103
103
104
#ifdef __GLASGOW_HASKELL__
104
105
import GHC.Exts (build )
@@ -115,7 +116,7 @@ findMax = fromMaybe (error "Error: findMax called on empty queue") . getMax
115
116
116
117
-- | \(O(1)\). The top (maximum) element of the queue, if there is one.
117
118
getMax :: Ord a => MaxQueue a -> Maybe a
118
- getMax (MaxQueue q) = unDown <$> MinQ. getMin q
119
+ getMax (MaxQueue q) = getDown <$> MinQ. getMin q
119
120
120
121
-- | \(O(\log n)\). Deletes the maximum element. If the queue is empty, does nothing.
121
122
deleteMax :: Ord a => MaxQueue a -> MaxQueue a
@@ -142,19 +143,19 @@ q !! n = (List.!!) (toDescList q) n
142
143
-- | 'takeWhile', applied to a predicate @p@ and a queue @queue@, returns the
143
144
-- longest prefix (possibly empty) of @queue@ of elements that satisfy @p@.
144
145
takeWhile :: Ord a => (a -> Bool ) -> MaxQueue a -> [a ]
145
- takeWhile p = fmap unDown . MinQ. takeWhile (p . unDown ) . unMaxQueue
146
+ takeWhile p = fmap getDown . MinQ. takeWhile (p . getDown ) . unMaxQueue
146
147
147
148
-- | 'dropWhile' @p queue@ returns the queue remaining after 'takeWhile' @p queue@.
148
149
dropWhile :: Ord a => (a -> Bool ) -> MaxQueue a -> MaxQueue a
149
- dropWhile p = MaxQueue . MinQ. dropWhile (p . unDown ) . unMaxQueue
150
+ dropWhile p = MaxQueue . MinQ. dropWhile (p . getDown ) . unMaxQueue
150
151
151
152
-- | 'span', applied to a predicate @p@ and a queue @queue@, returns a tuple where
152
153
-- first element is longest prefix (possibly empty) of @queue@ of elements that
153
154
-- satisfy @p@ and second element is the remainder of the queue.
154
155
span :: Ord a => (a -> Bool ) -> MaxQueue a -> ([a ], MaxQueue a )
155
156
span p (MaxQueue queue)
156
- | (front, rear) <- MinQ. span (p . unDown ) queue
157
- = (fmap unDown front, MaxQueue rear)
157
+ | (front, rear) <- MinQ. span (p . getDown ) queue
158
+ = (fmap getDown front, MaxQueue rear)
158
159
159
160
-- | 'break', applied to a predicate @p@ and a queue @queue@, returns a tuple where
160
161
-- first element is longest prefix (possibly empty) of @queue@ of elements that
@@ -177,19 +178,19 @@ drop n (MaxQueue queue) = MaxQueue (MinQ.drop n queue)
177
178
splitAt :: Ord a => Int -> MaxQueue a -> ([a ], MaxQueue a )
178
179
splitAt n (MaxQueue queue)
179
180
| (l, r) <- MinQ. splitAt n queue
180
- = (fmap unDown l, MaxQueue r)
181
+ = (fmap getDown l, MaxQueue r)
181
182
182
183
-- | \(O(n)\). Returns the queue with all elements not satisfying @p@ removed.
183
184
filter :: Ord a => (a -> Bool ) -> MaxQueue a -> MaxQueue a
184
- filter p = MaxQueue . MinQ. filter (p . unDown ) . unMaxQueue
185
+ filter p = MaxQueue . MinQ. filter (p . getDown ) . unMaxQueue
185
186
186
187
-- | \(O(n)\). Returns a pair where the first queue contains all elements satisfying @p@, and the second queue
187
188
-- contains all elements not satisfying @p@.
188
189
partition :: Ord a => (a -> Bool ) -> MaxQueue a -> (MaxQueue a , MaxQueue a )
189
190
partition p = go . unMaxQueue
190
191
where
191
192
go queue
192
- | (l, r) <- MinQ. partition (p . unDown ) queue
193
+ | (l, r) <- MinQ. partition (p . getDown ) queue
193
194
= (MaxQueue l, MaxQueue r)
194
195
195
196
-- | \(O(n)\). Creates a new priority queue containing the images of the elements of this queue.
@@ -202,13 +203,13 @@ map f = MaxQueue . MinQ.map (fmap f) . unMaxQueue
202
203
--
203
204
-- If the order of the elements is irrelevant, consider using 'toListU'.
204
205
toList :: Ord a => MaxQueue a -> [a ]
205
- toList = fmap unDown . MinQ. toAscList . unMaxQueue
206
+ toList = fmap getDown . MinQ. toAscList . unMaxQueue
206
207
207
208
toAscList :: Ord a => MaxQueue a -> [a ]
208
- toAscList = fmap unDown . MinQ. toDescList . unMaxQueue
209
+ toAscList = fmap getDown . MinQ. toDescList . unMaxQueue
209
210
210
211
toDescList :: Ord a => MaxQueue a -> [a ]
211
- toDescList = fmap unDown . MinQ. toAscList . unMaxQueue
212
+ toDescList = fmap getDown . MinQ. toAscList . unMaxQueue
212
213
213
214
-- | \(O(n \log n)\). Performs a right fold on the elements of a priority queue in descending order.
214
215
foldrDesc :: Ord a => (a -> b -> b ) -> b -> MaxQueue a -> b
@@ -245,7 +246,7 @@ elemsU = toListU
245
246
246
247
-- | Convert to a list in an arbitrary order.
247
248
toListU :: MaxQueue a -> [a ]
248
- toListU = fmap unDown . MinQ. toListU . unMaxQueue
249
+ toListU = fmap getDown . MinQ. toListU . unMaxQueue
249
250
250
251
-- | Get the number of elements in a 'MaxQueue'.
251
252
size :: MaxQueue a -> Int
@@ -255,7 +256,7 @@ empty :: MaxQueue a
255
256
empty = MaxQueue MinQ. empty
256
257
257
258
foldMapU :: Monoid m => (a -> m ) -> MaxQueue a -> m
258
- foldMapU f = MinQ. foldMapU (f . unDown ) . unMaxQueue
259
+ foldMapU f = MinQ. foldMapU (f . getDown ) . unMaxQueue
259
260
260
261
seqSpine :: MaxQueue a -> b -> b
261
262
seqSpine = MinQ. seqSpine . unMaxQueue
@@ -267,7 +268,7 @@ foldlU' :: (b -> a -> b) -> b -> MaxQueue a -> b
267
268
foldlU' f b = MinQ. foldlU' (\ acc (Down a) -> f acc a) b . unMaxQueue
268
269
269
270
foldrU :: (a -> b -> b ) -> b -> MaxQueue a -> b
270
- foldrU c n = MinQ. foldrU (c . unDown ) n . unMaxQueue
271
+ foldrU c n = MinQ. foldrU (c . getDown ) n . unMaxQueue
271
272
272
273
null :: MaxQueue a -> Bool
273
274
null = MinQ. null . unMaxQueue
@@ -276,13 +277,13 @@ singleton :: a -> MaxQueue a
276
277
singleton = MaxQueue . MinQ. singleton . Down
277
278
278
279
mapMaybe :: Ord b => (a -> Maybe b ) -> MaxQueue a -> MaxQueue b
279
- mapMaybe f = MaxQueue . MinQ. mapMaybe (fmap Down . f . unDown ) . unMaxQueue
280
+ mapMaybe f = MaxQueue . MinQ. mapMaybe (fmap Down . f . getDown ) . unMaxQueue
280
281
281
282
insert :: Ord a => a -> MaxQueue a -> MaxQueue a
282
283
insert a (MaxQueue q) = MaxQueue (MinQ. insert (Down a) q)
283
284
284
285
mapEither :: (Ord b , Ord c ) => (a -> Either b c ) -> MaxQueue a -> (MaxQueue b , MaxQueue c )
285
- mapEither f (MaxQueue q) = case MinQ. mapEither (bimap Down Down . f . unDown ) q of
286
+ mapEither f (MaxQueue q) = case MinQ. mapEither (bimap Down Down . f . getDown ) q of
286
287
(l, r) -> (MaxQueue l, MaxQueue r)
287
288
288
289
union :: Ord a => MaxQueue a -> MaxQueue a -> MaxQueue a
0 commit comments