@@ -98,7 +98,8 @@ import Data.Semigroup (Semigroup((<>)))
9898import qualified Data.List as List
9999
100100import qualified BinomialQueue.Min as MinQ
101- import Data.PQueue.Internals.Down
101+ import Data.PQueue.Internals.Down (getDown )
102+ import Data.Ord (Down (.. ))
102103
103104#ifdef __GLASGOW_HASKELL__
104105import GHC.Exts (build )
@@ -115,7 +116,7 @@ findMax = fromMaybe (error "Error: findMax called on empty queue") . getMax
115116
116117-- | \(O(1)\). The top (maximum) element of the queue, if there is one.
117118getMax :: Ord a => MaxQueue a -> Maybe a
118- getMax (MaxQueue q) = unDown <$> MinQ. getMin q
119+ getMax (MaxQueue q) = getDown <$> MinQ. getMin q
119120
120121-- | \(O(\log n)\). Deletes the maximum element. If the queue is empty, does nothing.
121122deleteMax :: Ord a => MaxQueue a -> MaxQueue a
@@ -142,19 +143,19 @@ q !! n = (List.!!) (toDescList q) n
142143-- | 'takeWhile', applied to a predicate @p@ and a queue @queue@, returns the
143144-- longest prefix (possibly empty) of @queue@ of elements that satisfy @p@.
144145takeWhile :: 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
146147
147148-- | 'dropWhile' @p queue@ returns the queue remaining after 'takeWhile' @p queue@.
148149dropWhile :: 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
150151
151152-- | 'span', applied to a predicate @p@ and a queue @queue@, returns a tuple where
152153-- first element is longest prefix (possibly empty) of @queue@ of elements that
153154-- satisfy @p@ and second element is the remainder of the queue.
154155span :: Ord a => (a -> Bool ) -> MaxQueue a -> ([a ], MaxQueue a )
155156span 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)
158159
159160-- | 'break', applied to a predicate @p@ and a queue @queue@, returns a tuple where
160161-- 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)
177178splitAt :: Ord a => Int -> MaxQueue a -> ([a ], MaxQueue a )
178179splitAt n (MaxQueue queue)
179180 | (l, r) <- MinQ. splitAt n queue
180- = (fmap unDown l, MaxQueue r)
181+ = (fmap getDown l, MaxQueue r)
181182
182183-- | \(O(n)\). Returns the queue with all elements not satisfying @p@ removed.
183184filter :: 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
185186
186187-- | \(O(n)\). Returns a pair where the first queue contains all elements satisfying @p@, and the second queue
187188-- contains all elements not satisfying @p@.
188189partition :: Ord a => (a -> Bool ) -> MaxQueue a -> (MaxQueue a , MaxQueue a )
189190partition p = go . unMaxQueue
190191 where
191192 go queue
192- | (l, r) <- MinQ. partition (p . unDown ) queue
193+ | (l, r) <- MinQ. partition (p . getDown ) queue
193194 = (MaxQueue l, MaxQueue r)
194195
195196-- | \(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
202203--
203204-- If the order of the elements is irrelevant, consider using 'toListU'.
204205toList :: Ord a => MaxQueue a -> [a ]
205- toList = fmap unDown . MinQ. toAscList . unMaxQueue
206+ toList = fmap getDown . MinQ. toAscList . unMaxQueue
206207
207208toAscList :: Ord a => MaxQueue a -> [a ]
208- toAscList = fmap unDown . MinQ. toDescList . unMaxQueue
209+ toAscList = fmap getDown . MinQ. toDescList . unMaxQueue
209210
210211toDescList :: Ord a => MaxQueue a -> [a ]
211- toDescList = fmap unDown . MinQ. toAscList . unMaxQueue
212+ toDescList = fmap getDown . MinQ. toAscList . unMaxQueue
212213
213214-- | \(O(n \log n)\). Performs a right fold on the elements of a priority queue in descending order.
214215foldrDesc :: Ord a => (a -> b -> b ) -> b -> MaxQueue a -> b
@@ -245,7 +246,7 @@ elemsU = toListU
245246
246247-- | Convert to a list in an arbitrary order.
247248toListU :: MaxQueue a -> [a ]
248- toListU = fmap unDown . MinQ. toListU . unMaxQueue
249+ toListU = fmap getDown . MinQ. toListU . unMaxQueue
249250
250251-- | Get the number of elements in a 'MaxQueue'.
251252size :: MaxQueue a -> Int
@@ -255,7 +256,7 @@ empty :: MaxQueue a
255256empty = MaxQueue MinQ. empty
256257
257258foldMapU :: Monoid m => (a -> m ) -> MaxQueue a -> m
258- foldMapU f = MinQ. foldMapU (f . unDown ) . unMaxQueue
259+ foldMapU f = MinQ. foldMapU (f . getDown ) . unMaxQueue
259260
260261seqSpine :: MaxQueue a -> b -> b
261262seqSpine = MinQ. seqSpine . unMaxQueue
@@ -267,7 +268,7 @@ foldlU' :: (b -> a -> b) -> b -> MaxQueue a -> b
267268foldlU' f b = MinQ. foldlU' (\ acc (Down a) -> f acc a) b . unMaxQueue
268269
269270foldrU :: (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
271272
272273null :: MaxQueue a -> Bool
273274null = MinQ. null . unMaxQueue
@@ -276,13 +277,13 @@ singleton :: a -> MaxQueue a
276277singleton = MaxQueue . MinQ. singleton . Down
277278
278279mapMaybe :: 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
280281
281282insert :: Ord a => a -> MaxQueue a -> MaxQueue a
282283insert a (MaxQueue q) = MaxQueue (MinQ. insert (Down a) q)
283284
284285mapEither :: (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
286287 (l, r) -> (MaxQueue l, MaxQueue r)
287288
288289union :: Ord a => MaxQueue a -> MaxQueue a -> MaxQueue a
0 commit comments