-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Priority Search Queue -- -- A priority search queue efficiently supports the opperations of -- both a search tree and a priority queue. A Binding is a product -- of a key and a priority. Bindings can be inserted, deleted, modified -- and queried in logarithmic time, and the binding with the least -- priority can be retrieved in constant time. A queue can be built from -- a list of bindings, sorted by keys, in linear time. @package PSQueue @version 1.1.0.1 -- | A priority search queue (henceforth queue) efficiently -- supports the opperations of both a search tree and a priority queue. A -- Binding is a product of a key and a priority. Bindings can be -- inserted, deleted, modified and queried in logarithmic time, and the -- binding with the least priority can be retrieved in constant time. A -- queue can be built from a list of bindings, sorted by keys, in linear -- time. -- -- This implementation is due to Ralf Hinze. -- -- module Data.PSQueue -- | k :-> p binds the key k with the priority -- p. data Binding k p (:->) :: k -> p -> Binding k p infix 0 :-> -- | The key of a binding key :: Binding k p -> k -- | The priority of a binding prio :: Binding k p -> p -- | A mapping from keys k to priorites p. data PSQ k p -- | O(1) The number of bindings in a queue. size :: PSQ k p -> Int -- | O(1) True if the queue is empty. null :: PSQ k p -> Bool -- | O(log n) The priority of a given key, or Nothing if the key is -- not bound. lookup :: (Ord k, Ord p) => k -> PSQ k p -> Maybe p empty :: (Ord k, Ord p) => PSQ k p -- | O(1) Build a queue with one binding. singleton :: (Ord k, Ord p) => k -> p -> PSQ k p -- | O(log n) Insert a binding into the queue. insert :: (Ord k, Ord p) => k -> p -> PSQ k p -> PSQ k p -- | O(log n) Insert a binding with a combining function. insertWith :: (Ord k, Ord p) => (p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p -- | O(log n) Remove a binding from the queue. delete :: (Ord k, Ord p) => k -> PSQ k p -> PSQ k p -- | O(log n) Adjust the priority of a key. adjust :: (Ord p, Ord k) => (p -> p) -> k -> PSQ k p -> PSQ k p -- | O(log n) Adjust the priority of a key. adjustWithKey :: (Ord k, Ord p) => (k -> p -> 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. update :: (Ord k, Ord p) => (p -> Maybe p) -> k -> PSQ k p -> 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. updateWithKey :: (Ord k, Ord p) => (k -> 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. alter :: (Ord k, Ord p) => (Maybe p -> Maybe p) -> k -> PSQ k p -> PSQ k p -- | O(n) The keys of a priority queue keys :: (Ord k, Ord p) => PSQ k p -> [k] -- | O(n) Convert a queue to a list. toList :: (Ord k, Ord p) => PSQ k p -> [Binding k p] -- | O(n) Convert a queue to a list in ascending order of keys. toAscList :: (Ord k, Ord p) => PSQ k p -> [Binding k p] -- | O(n) Convert a queue to a list in descending order of keys. toDescList :: (Ord k, Ord p) => PSQ k p -> [Binding k p] -- | O(n log n) Build a queue from a list of bindings. fromList :: (Ord 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. fromAscList :: (Ord k, 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. fromDistinctAscList :: (Ord k, Ord p) => [Binding k p] -> PSQ k p -- | O(1) The binding with the lowest priority. findMin :: (Ord k, Ord p) => PSQ k p -> Maybe (Binding k p) -- | O(log n) Remove the binding with the lowest priority. deleteMin :: (Ord k, Ord p) => PSQ 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. minView :: (Ord k, Ord p) => PSQ k p -> Maybe (Binding k p, PSQ 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
--   
atMost :: (Ord k, Ord p) => p -> 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'
--   
atMostRange :: (Ord k, Ord p) => p -> (k, k) -> PSQ k p -> [Binding k p] -- | Right fold over the bindings in the queue, in key order. foldr :: (Ord k, Ord p) => (Binding k p -> b -> b) -> b -> PSQ k p -> b -- | Left fold over the bindings in the queue, in key order. foldl :: (Ord k, Ord p) => (b -> Binding k p -> b) -> b -> PSQ k p -> b instance (GHC.Read.Read k, GHC.Read.Read p) => GHC.Read.Read (Data.PSQueue.Binding k p) instance (GHC.Show.Show k, GHC.Show.Show p) => GHC.Show.Show (Data.PSQueue.Binding k p) instance (GHC.Classes.Ord k, GHC.Classes.Ord p) => GHC.Classes.Ord (Data.PSQueue.Binding k p) instance (GHC.Classes.Eq k, GHC.Classes.Eq p) => GHC.Classes.Eq (Data.PSQueue.Binding k p) instance GHC.Show.Show a => GHC.Show.Show (Data.PSQueue.Sequ a) instance (GHC.Show.Show k, GHC.Show.Show p, GHC.Classes.Ord k, GHC.Classes.Ord p) => GHC.Show.Show (Data.PSQueue.PSQ k p)