From b3c832ebd86281bfaa4fe6bb88aaacacbed0eadc Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 19 Jul 2017 21:42:17 -0400 Subject: Added a wrapper for IntPSQ. --- src/Data/Wrapper/PSQInt.hs | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/Data/Wrapper/PSQInt.hs (limited to 'src/Data/Wrapper') diff --git a/src/Data/Wrapper/PSQInt.hs b/src/Data/Wrapper/PSQInt.hs new file mode 100644 index 00000000..c61b7ab6 --- /dev/null +++ b/src/Data/Wrapper/PSQInt.hs @@ -0,0 +1,55 @@ +{-# 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 -- cgit v1.2.3