HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulefingertree-0.1.6.2Haskell2010

Data.PriorityQueue.FingerTree

Min-priority queues implemented using the FingerTree type, following section 4.6 of

These have the same big-O complexity as skew heap implementations, but are approximately an order of magnitude slower. On the other hand, they are stable, so they can be used for fair queueing. They are also shallower, so that fmap consumes less space.

An amortized running time is given for each operation, with n referring to the size of the priority queue. These bounds hold even in a persistent (shared) setting.

Note: Many of these operations have the same names as similar operations on lists in the Prelude. The ambiguity may be resolved using either qualification or the hiding clause.

  • 1 type
  • 9 values
  • Packagefingertree-0.1.6.2
  • Exports10
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFingerTree.hs
newtypenewtype PQueue k v
#

Priority queues.

Instances10Functor, Foldable, Eq, Ord, Show, Generic, …

Construction

6 declarations
valueunion :: Ord k => PQueue k v -> PQueue k v -> PQueue k v
#

O(log(min(n1,n2))). Concatenate two priority queues. union is associative, with identity empty.

If there are entries with the same priority in both arguments, minView of union xs ys will return those from xs before those from ys.

valueadd :: Ord k => k -> v -> PQueue k v -> PQueue k v
#

O(log n). Add a (priority, value) pair to the back of a priority queue.

If q contains entries with the same priority k, minView of add k v q will return them before this one.

valuefromList :: Ord k => [(k, v)] -> PQueue k v
#

O(n). Create a priority queue from a finite list of priorities and values.

Deconstruction

3 declarations
valueminViewWithKey :: Ord k => PQueue k v -> Maybe ((k, v), PQueue k v)
#

O(1) for the element, O(log(n)) for the reduced queue. Returns Nothing for an empty map, or the minimal (priority, value) pair together with the rest of the priority queue.