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