HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulepqueue-1.7.0.0Haskell2010

Data.PQueue.Max

General purpose priority queue, supporting view-maximum operations.

An amortized running time is given for each operation, with n referring to the length of the sequence and k being the integral index used by some operations. These bounds hold even in a persistent (shared) setting.

This implementation is based on a binomial heap augmented with a global root.

This implementation does not guarantee stable behavior.

This implementation offers a number of methods of the form xxxU, where U stands for unordered. No guarantees whatsoever are made on the execution or traversal order of these functions.

Contents
  1. Basic operations
  2. Query operations
  3. Construction operations
  4. Subsets
  5. Extracting subsets
  6. Predicates
  7. Filter/Map
  8. Fold/Functor/Traversable variations
  9. List operations
  10. Unordered operations
  11. Miscellaneous operations
Synopsis
  • Packagepqueue-1.7.0.0
  • Exports47
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceMax.hs
newtypenewtype MaxQueue a

A priority queue with elements of type a. Supports extracting the maximum element. Implemented as a wrapper around MinQueue.

Instances8Eq, Data, Ord, Read, Show, Semigroup, …

Basic operations

Query operations

valuefindMax :: MaxQueue a -> a

O(1). Returns the maximum element of the queue. Throws an error on an empty queue.

Construction operations

Subsets

Extracting subsets

value(!!) :: Ord a => MaxQueue a -> Int -> a

O(k \log n). Returns the (k+1)th largest element of the queue.

valuetake :: Ord a => Int -> MaxQueue a -> [a]

O(k \log n). Returns the list of the k largest elements of the queue, in descending order, or all elements of the queue, if k >= n.

Predicates

valuetakeWhile :: Ord a => (a -> Bool) -> MaxQueue a -> [a]

takeWhile, applied to a predicate p and a queue queue, returns the longest prefix (possibly empty) of queue of elements that satisfy p.

valuespan :: Ord a => (a -> Bool) -> MaxQueue a -> ([a], MaxQueue a)

span, applied to a predicate p and a queue queue, returns a tuple where first element is longest prefix (possibly empty) of queue of elements that satisfy p and second element is the remainder of the queue.

valuebreak :: Ord a => (a -> Bool) -> MaxQueue a -> ([a], MaxQueue a)

break, applied to a predicate p and a queue queue, returns a tuple where first element is longest prefix (possibly empty) of queue of elements that do not satisfy p and second element is the remainder of the queue.

Filter/Map

valuepartition :: Ord a => (a -> Bool) -> MaxQueue a -> (MaxQueue a, MaxQueue a)

O(n). Returns a pair of queues, where the left queue contains those elements that satisfy the predicate, and the right queue contains those that do not.

Fold/Functor/Traversable variations

valuemap :: Ord b => (a -> b) -> MaxQueue a -> MaxQueue b

O(n). Creates a new priority queue containing the images of the elements of this queue. Equivalent to fromList . Data.List.map f . toList.

valuemapMonotonic :: (a -> b) -> MaxQueue a -> MaxQueue b

O(n). Assumes that the function it is given is (weakly) monotonic (meaning that x <= y implies f x <= f y), and applies this function to every element of the priority queue, as in fmap. If the function is not monotonic, the result is undefined.

valuefoldrDesc :: Ord a => (a -> b -> b) -> b -> MaxQueue a -> b

O(n \log n). Performs a right-fold on the elements of a priority queue in descending order.

valuefoldlDesc :: Ord a => (b -> a -> b) -> b -> MaxQueue a -> b

O(n \log n). Performs a left-fold on the elements of a priority queue in descending order.

List operations

valuetoList :: Ord a => MaxQueue a -> [a]

O(n \log n). Returns the elements of the priority queue in descending order. Equivalent to toDescList.

If the order of the elements is irrelevant, consider using toListU.

valuefromAscList :: [a] -> MaxQueue a

O(n). Constructs a priority queue from an ascending list. Warning: Does not check the precondition.

valuefromDescList :: [a] -> MaxQueue a

O(n). Constructs a priority queue from a descending list. Warning: Does not check the precondition.

Unordered operations

valuefoldrU :: (a -> b -> b) -> b -> MaxQueue a -> b

O(n). Unordered right fold on a priority queue.

valuefoldlU :: (b -> a -> b) -> b -> MaxQueue a -> b

O(n). Unordered left fold on a priority queue. This is rarely what you want; foldrU and foldlU' are more likely to perform well.

valuefoldlU' :: (b -> a -> b) -> b -> MaxQueue a -> b

O(n). Unordered strict left fold on a priority queue.

valuetoListU :: MaxQueue a -> [a]

O(n). Returns a list of the elements of the priority queue, in no particular order.

Miscellaneous operations

valueseqSpine :: MaxQueue a -> b -> b

Deprecated. This function is no longer necessary or useful.

O(\log n). seqSpine q r forces the spine of q and returns r.

Note: The spine of a MaxQueue is stored somewhat lazily. In earlier versions of this package, some operations could produce chains of thunks along the spine, occasionally necessitating manual forcing. Now, all operations are careful to force enough to avoid this problem.