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

ModulePSQueue-1.2.2Haskell2010

Data.PSQueue.Internal

Contents
  1. Binding Type
  2. Priority Search Queue Type
  3. Query
  4. Construction
  5. Insertion
  6. Delete/Update
  7. Conversion
  8. Priority Queue
  9. Fold
  10. Internals
Synopsis
  • PackagePSQueue-1.2.2
  • Exports67
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceInternal.hs

Binding Type

datadata Binding k p

k :-> p binds the key k with the priority p.

Constructors

Instances4Eq, Ord, Read, Show
  • (Eq k, Eq p) => Eq (Binding k p)Defined in PSQueue-1.2.2 · Data.PSQueue.Internal
  • (Ord k, Ord p) => Ord (Binding k p)Defined in PSQueue-1.2.2 · Data.PSQueue.Internal
  • (Read k, Read p) => Read (Binding k p)Defined in PSQueue-1.2.2 · Data.PSQueue.Internal
  • (Show k, Show p) => Show (Binding k p)Defined in PSQueue-1.2.2 · Data.PSQueue.Internal

Priority Search Queue Type

datadata PSQ k p

A mapping from keys k to priorites p.

Constructors

Instances2Eq, Show
  • (Eq k, Eq p) => Eq (PSQ k p)Defined in PSQueue-1.2.2 · Data.PSQueue.Internal
  • (Show k, Show p) => Show (PSQ k p)Defined in PSQueue-1.2.2 · Data.PSQueue.Internal

Query

valuelookup :: Ord k => k -> PSQ k p -> Maybe p

O(log n) The priority of a given key, or Nothing if the key is not bound.

Construction

Insertion

Delete/Update

valueupdate :: (Ord k, Ord p) => (p -> Maybe p) -> k -> PSQ k p -> PSQ k p

O(log n) The expression (update f k q) updates the priority p bound k (if it is in the queue). If (f p) is Nothing, the binding is deleted. If it is (Just z), the key k is bound to the new priority z.

valueupdateWithKey
  1. :: (Ord k, Ord p)
  2. => k -> p -> Maybe p
  3. -> k
  4. -> PSQ k p
  5. -> PSQ k p

O(log n). The expression (updateWithKey f k q) updates the priority p bound k (if it is in the queue). If (f k p) is Nothing, the binding is deleted. If it is (Just z), the key k is bound to the new priority z.

valuealter :: (Ord k, Ord p) => (Maybe p -> Maybe p) -> k -> PSQ k p -> PSQ k p

O(log n). The expression (alter f k q) alters the priority p bound to k, or absence thereof. alter can be used to insert, delete, or update a priority in a queue.

Conversion

valuekeys :: PSQ k p -> [k]

O(n) The keys of a priority queue

valuefromAscList :: (Eq k, Ord p) => [Binding k p] -> PSQ k p

O(n) Build a queue from a list of bindings in order of ascending keys. The precondition that the keys are ascending is not checked.

valuefromDistinctAscList :: Ord p => [Binding k p] -> PSQ k p

O(n) Build a queue from a list of distinct bindings in order of ascending keys. The precondition that keys are distinct and ascending is not checked.

valuefoldm :: (a -> a -> a) -> a -> [a] -> a
#

Priority Queue

valueminView :: Ord p => PSQ k p -> Maybe (Binding k p, PSQ k p)

O(log n) Retrieve the binding with the least priority, and the rest of the queue stripped of that binding.

valueatMost :: Ord p => p -> PSQ k p -> [Binding k p]

O(r(log n - log r) atMost p q is a list of all the bindings in q with priority less than p, in order of ascending keys. Effectively,

  atMost p' q = filter (\(k:->p) -> p<=p') . toList
valueatMostRange :: (Ord k, Ord p) => p -> (k, k) -> PSQ k p -> [Binding k p]

O(r(log n - log r)) atMostRange p (l,u) q is a list of all the bindings in q with a priority less than p and a key in the range (l,u) inclusive. Effectively,

   atMostRange p' (l,u) q = filter (\(k:->p) -> l<=k && k<=u ) . atMost p'

Fold

valuefoldr :: (Binding k p -> b -> b) -> b -> PSQ k p -> b

Right fold over the bindings in the queue, in key order.

valuefoldl :: (b -> Binding k p -> b) -> b -> PSQ k p -> b

Left fold over the bindings in the queue, in key order.

Internals