packages feed

pqueue-1.4.1.2 / Data / PQueue / Prio / Max / Internals.hs

{-# LANGUAGE CPP #-}module Data.PQueue.Prio.Max.Internals whereimport Control.DeepSeq (NFData(rnf))import Data.Traversable (Traversable(traverse))import Data.Foldable (Foldable(foldr, foldl))import Data.Functor ((<$>))# if __GLASGOW_HASKELL__import Data.Data (Data, Typeable)# endifimport Prelude hiding (foldr, foldl)import Data.PQueue.Prio.Internals (MinPQueue)newtype Down a = Down {unDown :: a}# if __GLASGOW_HASKELL__  deriving (Eq, Data, Typeable)# else  deriving (Eq)# endif-- | A priority queue where values of type @a@ are annotated with keys of type @k@.-- The queue supports extracting the element with maximum key.newtype MaxPQueue k a = MaxPQ (MinPQueue (Down k) a)# if __GLASGOW_HASKELL__  deriving (Eq, Ord, Data, Typeable)# else  deriving (Eq, Ord)# endifinstance (NFData k, NFData a) => NFData (MaxPQueue k a) where  rnf (MaxPQ q) = rnf qinstance NFData a => NFData (Down a) where  rnf (Down a) = rnf ainstance Ord a => Ord (Down a) where  Down a `compare` Down b = b `compare` a  Down a <= Down b = b <= ainstance Functor Down where  fmap f (Down a) = Down (f a)instance Foldable Down where  foldr f z (Down a) = a `f` z  foldl f z (Down a) = z `f` ainstance Traversable Down where  traverse f (Down a) = Down <$> f a