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

Modulepsqueues-0.2.8.3Haskell2010

Data.HashPSQ

A HashPSQ offers very similar performance to IntPSQ. In case of collisions, it uses an OrdPSQ locally to solve those.

This means worst case complexity is usually given by O(min(n,W), log n), where W is the number of bits in an Int. This simplifies to O(min(n,W)) since log n is always smaller than W on current machines.

Contents
  1. Type
  2. Query
  3. Construction
  4. Insertion
  5. Delete/update
  6. Lists
  7. Views
  8. Traversal
  9. Unsafe operations
  10. Validity check
Synopsis
  • Packagepsqueues-0.2.8.3
  • Exports27
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceHashPSQ.hs

Type

newtypenewtype HashPSQ k p v

A priority search queue with keys of type k and priorities of type p and values of type v. It is strict in keys, priorities and values.

Instances6Functor, Foldable, Traversable, Eq, Show, NFData

Query

Construction

Insertion

valueinsert
  1. :: (Ord k, Hashable k, Ord p)
  2. => k
  3. -> p
  4. -> v
  5. -> HashPSQ k p v
  6. -> HashPSQ k p v

O(min(n,W)) Insert a new key, priority and value into the queue. If the key is already present in the queue, the associated priority and value are replaced with the supplied priority and value.

Delete/update

valuedelete :: (Hashable k, Ord k, Ord p) => k -> HashPSQ k p v -> HashPSQ k p v

O(min(n,W)) Delete a key and its priority and value from the queue. When the key is not a member of the queue, the original queue is returned.

valuedeleteMin :: (Hashable k, Ord k, Ord p) => HashPSQ k p v -> HashPSQ k p v

O(min(n,W)) Delete the binding with the least priority, and return the rest of the queue stripped of that binding. In case the queue is empty, the empty queue is returned again.

valuealter
  1. :: (Hashable k, Ord k, Ord p)
  2. => Maybe (p, v) -> (b, Maybe (p, v))
  3. -> k
  4. -> HashPSQ k p v
  5. -> (b, HashPSQ k p v)

O(min(n,W)) The expression alter f k queue alters the value x at k, or absence thereof. alter can be used to insert, delete, or update a value in a queue. It also allows you to calculate an additional value b.

Lists

valuefromList :: (Hashable k, Ord k, Ord p) => [(k, p, v)] -> HashPSQ k p v

O(n*min(n,W)) Build a queue from a list of (key, priority, value) tuples. If the list contains more than one priority and value for the same key, the last priority and value for the key is retained.

valuetoList :: (Hashable k, Ord k, Ord p) => HashPSQ k p v -> [(k, p, v)]

O(n) Convert a queue to a list of (key, priority, value) tuples. The order of the list is not specified.

Views

valueinsertView
  1. :: (Hashable k, Ord k, Ord p)
  2. => k
  3. -> p
  4. -> v
  5. -> HashPSQ k p v
  6. -> (Maybe (p, v), HashPSQ k p v)

O(min(n,W)) Insert a new key, priority and value into the queue. If the key is already present in the queue, then the evicted priority and value can be found the first element of the returned tuple.

valuedeleteView
  1. :: (Hashable k, Ord k, Ord p)
  2. => k
  3. -> HashPSQ k p v
  4. -> Maybe (p, v, HashPSQ k p v)

O(min(n,W)) Delete a key and its priority and value from the queue. If the key was present, the associated priority and value are returned in addition to the updated queue.

valueatMostView
  1. :: (Hashable k, Ord k, Ord p)
  2. => p
  3. -> HashPSQ k p v
  4. -> ([(k, p, v)], HashPSQ k p v)

Return a list of elements ordered by key whose priorities are at most pt, and the rest of the queue stripped of these elements. The returned list of elements can be in any order: no guarantees there.

Traversal

valueunsafeMapMonotonic
  1. :: k -> p -> v -> (q, w)
  2. -> HashPSQ k p v
  3. -> HashPSQ k q w

O(n) Maps a function over the values and priorities of the queue. The function f must be monotonic with respect to the priorities. I.e. if x < y, then fst (f k x v) < fst (f k y v). The precondition is not checked. If f is not monotonic, then the result will be invalid.

valuefold' :: (k -> p -> v -> a -> a) -> a -> HashPSQ k p v -> a

O(n) Strict fold over every key, priority and value in the queue. The order in which the fold is performed is not specified.

Unsafe operations

Validity check