Copyright | (c) Ross Paterson 2008 |
---|---|
License | BSD-style |
Maintainer | R.Paterson@city.ac.uk |
Stability | experimental |
Portability | non-portable (MPTCs and functional dependencies) |
Safe Haskell | Safe |
Language | Haskell2010 |
Min-priority queues implemented using the
FingerTree
type,
following section 4.6 of
- Ralf Hinze and Ross Paterson, "Finger trees: a simple general-purpose data structure", Journal of Functional Programming 16:2 (2006) pp 197-217. http://staff.city.ac.uk/~ross/papers/FingerTree.html
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.
Synopsis
- data PQueue k v
- empty :: Ord k => PQueue k v
- singleton :: Ord k => k -> v -> PQueue k v
- union :: Ord k => PQueue k v -> PQueue k v -> PQueue k v
- insert :: Ord k => k -> v -> PQueue k v -> PQueue k v
- add :: Ord k => k -> v -> PQueue k v -> PQueue k v
- fromList :: Ord k => [(k, v)] -> PQueue k v
- null :: Ord k => PQueue k v -> Bool
- minView :: Ord k => PQueue k v -> Maybe (v, PQueue k v)
- minViewWithKey :: Ord k => PQueue k v -> Maybe ((k, v), PQueue k v)
Documentation
Priority queues.
Instances
Ord k => Functor ( PQueue k) Source # | |
Ord k => Foldable ( PQueue k) Source # |
In ascending order of keys. |
Defined in Data.PriorityQueue.FingerTree fold :: Monoid m => PQueue k m -> m Source # foldMap :: Monoid m => (a -> m) -> PQueue k a -> m Source # foldMap' :: Monoid m => (a -> m) -> PQueue k a -> m Source # foldr :: (a -> b -> b) -> b -> PQueue k a -> b Source # foldr' :: (a -> b -> b) -> b -> PQueue k a -> b Source # foldl :: (b -> a -> b) -> b -> PQueue k a -> b Source # foldl' :: (b -> a -> b) -> b -> PQueue k a -> b Source # foldr1 :: (a -> a -> a) -> PQueue k a -> a Source # foldl1 :: (a -> a -> a) -> PQueue k a -> a Source # toList :: PQueue k a -> [a] Source # null :: PQueue k a -> Bool Source # length :: PQueue k a -> Int Source # elem :: Eq a => a -> PQueue k a -> Bool Source # maximum :: Ord a => PQueue k a -> a Source # minimum :: Ord a => PQueue k a -> a Source # |
|
( Ord k, Eq v) => Eq ( PQueue k v) Source # | |
( Ord k, Ord v) => Ord ( PQueue k v) Source # |
Lexicographical ordering |
Defined in Data.PriorityQueue.FingerTree compare :: PQueue k v -> PQueue k v -> Ordering Source # (<) :: PQueue k v -> PQueue k v -> Bool Source # (<=) :: PQueue k v -> PQueue k v -> Bool Source # (>) :: PQueue k v -> PQueue k v -> Bool Source # (>=) :: PQueue k v -> PQueue k v -> Bool Source # |
|
( Ord k, Show k, Show v) => Show ( PQueue k v) Source # |
In ascending key order |
Generic ( PQueue k v) Source # | |
Ord k => Semigroup ( PQueue k v) Source # | |
Ord k => Monoid ( PQueue k v) Source # | |
type Rep ( PQueue k v) Source # | |
Defined in Data.PriorityQueue.FingerTree |
Construction
fromList :: Ord k => [(k, v)] -> PQueue k v Source #
O(n) . Create a priority queue from a finite list of priorities and values.
Deconstruction
minViewWithKey :: Ord k => PQueue k v -> Maybe ((k, v), PQueue k v) Source #
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.
-
minViewWithKey
empty
=Nothing
-
minViewWithKey
(singleton
k v) =Just
((k, v),empty
) -
If
minViewWithKey
qi =Just
((ki, vi), qi')k1 <= k2
, thenminViewWithKey
(union
q1 q2) =Just
((k1, v1),union
q1' q2) -
If
minViewWithKey
qi =Just
((ki, vi), qi')k2 < k1
, thenminViewWithKey
(union
q1 q2) =Just
((k2, v2),union
q1 q2')