planet-mitchell-0.1.0: Planet Mitchell

Safe HaskellSafe
LanguageHaskell2010

Queue.Prio.Ord

Contents

Synopsis

OrdPSQ

data OrdPSQ k p v #

A mapping from keys k to priorites p and values v. It is strict in keys, priorities and values.

Instances
Functor (OrdPSQ k p) 
Instance details

Defined in Data.OrdPSQ.Internal

Methods

fmap :: (a -> b) -> OrdPSQ k p a -> OrdPSQ k p b #

(<$) :: a -> OrdPSQ k p b -> OrdPSQ k p a #

Foldable (OrdPSQ k p) 
Instance details

Defined in Data.OrdPSQ.Internal

Methods

fold :: Monoid m => OrdPSQ k p m -> m #

foldMap :: Monoid m => (a -> m) -> OrdPSQ k p a -> m #

foldr :: (a -> b -> b) -> b -> OrdPSQ k p a -> b #

foldr' :: (a -> b -> b) -> b -> OrdPSQ k p a -> b #

foldl :: (b -> a -> b) -> b -> OrdPSQ k p a -> b #

foldl' :: (b -> a -> b) -> b -> OrdPSQ k p a -> b #

foldr1 :: (a -> a -> a) -> OrdPSQ k p a -> a #

foldl1 :: (a -> a -> a) -> OrdPSQ k p a -> a #

toList :: OrdPSQ k p a -> [a] #

null :: OrdPSQ k p a -> Bool #

length :: OrdPSQ k p a -> Int #

elem :: Eq a => a -> OrdPSQ k p a -> Bool #

maximum :: Ord a => OrdPSQ k p a -> a #

minimum :: Ord a => OrdPSQ k p a -> a #

sum :: Num a => OrdPSQ k p a -> a #

product :: Num a => OrdPSQ k p a -> a #

Traversable (OrdPSQ k p) 
Instance details

Defined in Data.OrdPSQ.Internal

Methods

traverse :: Applicative f => (a -> f b) -> OrdPSQ k p a -> f (OrdPSQ k p b) #

sequenceA :: Applicative f => OrdPSQ k p (f a) -> f (OrdPSQ k p a) #

mapM :: Monad m => (a -> m b) -> OrdPSQ k p a -> m (OrdPSQ k p b) #

sequence :: Monad m => OrdPSQ k p (m a) -> m (OrdPSQ k p a) #

(Ord k, Ord p, Eq v) => Eq (OrdPSQ k p v) 
Instance details

Defined in Data.OrdPSQ.Internal

Methods

(==) :: OrdPSQ k p v -> OrdPSQ k p v -> Bool #

(/=) :: OrdPSQ k p v -> OrdPSQ k p v -> Bool #

(Show k, Show p, Show v) => Show (OrdPSQ k p v) 
Instance details

Defined in Data.OrdPSQ.Internal

Methods

showsPrec :: Int -> OrdPSQ k p v -> ShowS #

show :: OrdPSQ k p v -> String #

showList :: [OrdPSQ k p v] -> ShowS #

(NFData k, NFData p, NFData v) => NFData (OrdPSQ k p v) 
Instance details

Defined in Data.OrdPSQ.Internal

Methods

rnf :: OrdPSQ k p v -> () #

Construction

empty :: OrdPSQ k p v #

O(1) The empty queue.

singleton :: k -> p -> v -> OrdPSQ k p v #

O(1) Build a queue with one element.

fromList :: (Ord k, Ord p) => [(k, p, v)] -> OrdPSQ k p v #

O(n*log n) 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.

Querying

null :: OrdPSQ k p v -> Bool #

O(1) True if the queue is empty.

size :: OrdPSQ k p v -> Int #

O(1) The number of elements in a queue.

member :: Ord k => k -> OrdPSQ k p v -> Bool #

O(log n) Check if a key is present in the the queue.

lookup :: Ord k => k -> OrdPSQ k p v -> Maybe (p, v) #

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

findMin :: OrdPSQ k p v -> Maybe (k, p, v) #

O(1) The element with the lowest priority.

minView :: (Ord k, Ord p) => OrdPSQ k p v -> Maybe (k, p, v, OrdPSQ k p v) #

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

atMostView :: (Ord k, Ord p) => p -> OrdPSQ k p v -> ([(k, p, v)], OrdPSQ 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.

Insertion

insert :: (Ord k, Ord p) => k -> p -> v -> OrdPSQ k p v -> OrdPSQ k p v #

O(log n) 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.

insertView :: (Ord k, Ord p) => k -> p -> v -> OrdPSQ k p v -> (Maybe (p, v), OrdPSQ k p v) #

O(log n) 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.

Deletion

delete :: (Ord k, Ord p) => k -> OrdPSQ k p v -> OrdPSQ k p v #

O(log n) 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.

deleteView :: (Ord k, Ord p) => k -> OrdPSQ k p v -> Maybe (p, v, OrdPSQ k p v) #

O(log n) 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.

Alteration

alter :: (Ord k, Ord p) => (Maybe (p, v) -> (b, Maybe (p, v))) -> k -> OrdPSQ k p v -> (b, OrdPSQ k p v) #

O(log n) 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.

alterMin :: (Ord k, Ord p) => (Maybe (k, p, v) -> (b, Maybe (k, p, v))) -> OrdPSQ k p v -> (b, OrdPSQ k p v) #

O(log n) A variant of alter which works on the element with the minimum priority. Unlike alter, this variant also allows you to change the key of the element.

Mapping

map :: (k -> p -> v -> w) -> OrdPSQ k p v -> OrdPSQ k p w #

O(n) Modify every value in the queue.

unsafeMapMonotonic :: (k -> p -> v -> (q, w)) -> OrdPSQ k p v -> OrdPSQ 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.

Folding

toList :: OrdPSQ 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.

toAscList :: OrdPSQ k p v -> [(k, p, v)] #

O(n) Convert to an ascending list.

keys :: OrdPSQ k p v -> [k] #

O(n) Obtain the list of present keys in the queue.

fold' :: (k -> p -> v -> a -> a) -> a -> OrdPSQ 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.