{-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-} module Data.Wrapper.PSQ #if 0 ( module Data.Wrapper.PSQ , module Data.PSQueue ) where import Data.PSQueue hiding (foldr, foldl) import qualified Data.PSQueue as PSQueue type PSQKey k = (Ord k) -- | Wrapper over PSQueue-style foldr to implement a psqueues-style interface. fold' :: (Ord k, Ord p) => (k -> p -> () -> a -> a) -> a -> PSQ k p -> a fold' f a q = PSQueue.foldr f' a q where f' (k :-> prio) x = f k prio () x #else ( module Data.Wrapper.PSQ , module HashPSQ ) where import Data.OrdPSQ as OrdPSQ hiding (insert, map, singleton, minView) import qualified Data.OrdPSQ as OrdPSQ import Data.HashPSQ as HashPSQ hiding (insert, map, singleton, minView) import qualified Data.HashPSQ as Q import Data.Hashable type PSQ k p = HashPSQ k p () type Binding k p = (k,p,()) type PSQKey k = (Hashable k, Ord k) pattern (:->) :: k -> p -> Binding k p pattern k :-> p <- (k,p,()) where k :-> p = (k,p,()) key :: Binding k p -> k key (k,p,v) = k {-# INLINE key #-} prio :: Binding k p -> p prio (k,p,v) = p {-# INLINE prio #-} insert :: (PSQKey k, Ord p) => k -> p -> PSQ k p -> PSQ k p insert k p q = Q.insert k p () q {-# INLINE insert #-} insertWith :: (PSQKey k, Ord p) => (p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p insertWith f k p0 q = snd $ Q.alter f' k q where f' (Just (p,())) = ((),Just (f p0 p, ())) f' Nothing = ((),Nothing) {-# INLINE insertWith #-} singleton :: (PSQKey k, Ord p) => k -> p -> PSQ k p singleton k p = Q.singleton k p () {-# INLINE singleton #-} minView :: (PSQKey k, Ord p) => PSQ k p -> Maybe (Binding k p, PSQ k p) minView q = fmap (\(k,p,(),q') -> (k :-> p, q')) $ Q.minView q {-# INLINE minView #-} #endif