Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- data Binding k p = !k :-> !p
- key :: Binding k p -> k
- prio :: Binding k p -> p
- data PSQ k p
- size :: PSQ k p -> Int
- null :: PSQ k p -> Bool
- lookup :: Ord k => k -> PSQ k p -> Maybe p
- empty :: PSQ k p
- singleton :: k -> p -> PSQ k p
- insert :: (Ord k, Ord p) => k -> p -> PSQ k p -> PSQ k p
- insertWith :: (Ord k, Ord p) => (p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p
- insertWithKey :: (Ord k, Ord p) => (k -> p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p
- delete :: (Ord k, Ord p) => k -> PSQ k p -> PSQ k p
- adjust :: (Ord p, Ord k) => (p -> p) -> k -> PSQ k p -> PSQ k p
- adjustWithKey :: (Ord k, Ord p) => (k -> p -> p) -> k -> PSQ k p -> PSQ k p
- update :: (Ord k, Ord p) => (p -> Maybe p) -> k -> PSQ k p -> PSQ k p
- updateWithKey :: (Ord k, Ord p) => (k -> p -> Maybe p) -> k -> PSQ k p -> PSQ k p
- alter :: (Ord k, Ord p) => (Maybe p -> Maybe p) -> k -> PSQ k p -> PSQ k p
- keys :: PSQ k p -> [k]
- fromList :: (Ord k, Ord p) => [Binding k p] -> PSQ k p
- fromAscList :: (Eq k, Ord p) => [Binding k p] -> PSQ k p
- fromDistinctAscList :: Ord p => [Binding k p] -> PSQ k p
- foldm :: (a -> a -> a) -> a -> [a] -> a
- toList :: PSQ k p -> [Binding k p]
- toAscList :: PSQ k p -> [Binding k p]
- toAscLists :: PSQ k p -> Sequ (Binding k p)
- toDescList :: PSQ k p -> [Binding k p]
- toDescLists :: PSQ k p -> Sequ (Binding k p)
- findMin :: PSQ k p -> Maybe (Binding k p)
- deleteMin :: Ord p => PSQ k p -> PSQ k p
- minView :: Ord p => PSQ k p -> Maybe (Binding k p, PSQ k p)
- secondBest :: Ord p => LTree k p -> k -> PSQ k p
- atMost :: Ord p => p -> PSQ k p -> [Binding k p]
- atMosts :: Ord p => p -> PSQ k p -> Sequ (Binding k p)
- atMostRange :: (Ord k, Ord p) => p -> (k, k) -> PSQ k p -> [Binding k p]
- atMostRanges :: (Ord k, Ord p) => p -> (k, k) -> PSQ k p -> Sequ (Binding k p)
- inrange :: Ord a => a -> (a, a) -> Bool
- foldr :: (Binding k p -> b -> b) -> b -> PSQ k p -> b
- foldl :: (b -> Binding k p -> b) -> b -> PSQ k p -> b
- type Size = Int
- data LTree k p
- size' :: LTree k p -> Size
- left :: LTree a b -> LTree a b
- right :: LTree a b -> LTree a b
- maxKey :: PSQ k p -> k
- lloser :: k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- rloser :: k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- omega :: Int
- lbalance :: Ord p => k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- rbalance :: Ord p => k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- lbalanceLeft :: Ord p => k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- lbalanceRight :: Ord p => k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- rbalanceLeft :: Ord p => k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- rbalanceRight :: Ord p => k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- lsingleLeft :: Ord p => k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- rsingleLeft :: k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- lsingleRight :: k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- rsingleRight :: Ord p => k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- ldoubleLeft :: Ord p => k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- ldoubleRight :: Ord p => k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- rdoubleLeft :: Ord p => k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- rdoubleRight :: Ord p => k -> p -> LTree k p -> k -> LTree k p -> LTree k p
- play :: Ord p => PSQ k p -> PSQ k p -> PSQ k p
- data TourView k p
- tourView :: PSQ k p -> TourView k p
Binding Type
k :-> p
binds the key k
with the priority p
.
!k :-> !p infix 0 |
Instances
(Read k, Read p) => Read (Binding k p) Source # | |
(Show k, Show p) => Show (Binding k p) Source # | |
(Eq k, Eq p) => Eq (Binding k p) Source # | |
(Ord k, Ord p) => Ord (Binding k p) Source # | |
Defined in Data.PSQueue.Internal |
Priority Search Queue Type
A mapping from keys k
to priorites p
.
Query
lookup :: Ord k => k -> PSQ k p -> Maybe p Source #
O(log n) The priority of a given key, or Nothing if the key is not bound.
Construction
Insertion
insert :: (Ord k, Ord p) => k -> p -> PSQ k p -> PSQ k p Source #
O(log n) Insert a binding into the queue.
insertWith :: (Ord k, Ord p) => (p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p Source #
O(log n) Insert a binding with a combining function.
insertWithKey :: (Ord k, Ord p) => (k -> p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p Source #
O(log n) Insert a binding with a combining function.
Delete/Update
delete :: (Ord k, Ord p) => k -> PSQ k p -> PSQ k p Source #
O(log n) Remove a binding from the queue.
adjust :: (Ord p, Ord k) => (p -> p) -> k -> PSQ k p -> PSQ k p Source #
O(log n) Adjust the priority of a key.
adjustWithKey :: (Ord k, Ord p) => (k -> p -> p) -> k -> PSQ k p -> PSQ k p Source #
O(log n) Adjust the priority of a key.
alter :: (Ord k, Ord p) => (Maybe p -> Maybe p) -> k -> PSQ k p -> PSQ k p Source #
O(log n). The expression (
) alters the priority alter
f k qp
bound to k
, or absence thereof.
alter can be used to insert, delete, or update a priority in a queue.
Conversion
fromList :: (Ord k, Ord p) => [Binding k p] -> PSQ k p Source #
O(n log n) Build a queue from a list of bindings.
fromAscList :: (Eq k, Ord p) => [Binding k p] -> PSQ k p Source #
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.
fromDistinctAscList :: Ord p => [Binding k p] -> PSQ k p Source #
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.
toAscList :: PSQ k p -> [Binding k p] Source #
O(n) Convert a queue to a list in ascending order of keys.
toAscLists :: PSQ k p -> Sequ (Binding k p) Source #
toDescList :: PSQ k p -> [Binding k p] Source #
O(n) Convert a queue to a list in descending order of keys.
toDescLists :: PSQ k p -> Sequ (Binding k p) Source #
Priority Queue
deleteMin :: Ord p => PSQ k p -> PSQ k p Source #
O(log n) Remove the binding with the lowest priority.
minView :: Ord p => PSQ k p -> Maybe (Binding k p, PSQ k p) Source #
O(log n) Retrieve the binding with the least priority, and the rest of the queue stripped of that binding.
atMost :: Ord p => p -> PSQ k p -> [Binding k p] Source #
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
atMostRange :: (Ord k, Ord p) => p -> (k, k) -> PSQ k p -> [Binding k p] Source #
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
foldr :: (Binding k p -> b -> b) -> b -> PSQ k p -> b Source #
Right fold over the bindings in the queue, in key order.
foldl :: (b -> Binding k p -> b) -> b -> PSQ k p -> b Source #
Left fold over the bindings in the queue, in key order.