From 133087121638a883ff15bc4141425c7df474b92b Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 26 Jul 2017 22:01:09 -0400 Subject: Expose psqueues' auxillary value feature. --- src/Data/Wrapper/PSQ.hs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/Data/Wrapper') diff --git a/src/Data/Wrapper/PSQ.hs b/src/Data/Wrapper/PSQ.hs index 54365a1d..87648e84 100644 --- a/src/Data/Wrapper/PSQ.hs +++ b/src/Data/Wrapper/PSQ.hs @@ -26,19 +26,27 @@ 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 PSQ' k p v = HashPSQ k p v +type PSQ k p = PSQ' k p () + +type Binding' k p v = (k,p,v) +type Binding k p = Binding' 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,()) +pattern k :-> p <- (k,p,_) where k :-> p = (k,p,()) + +-- I tried defining (::->) :: (k,v) -> p -> Binding' k p v +-- but no luck... +pattern Binding :: k -> v -> p -> Binding' k p v +pattern Binding k v p <- (k,p,v) where Binding k v p = (k,p,v) -key :: Binding k p -> k +key :: (k,p,v) -> k key (k,p,v) = k {-# INLINE key #-} -prio :: Binding k p -> p +prio :: (k,p,v) -> p prio (k,p,v) = p {-# INLINE prio #-} @@ -46,6 +54,10 @@ insert :: (PSQKey k, Ord p) => k -> p -> PSQ k p -> PSQ k p insert k p q = Q.insert k p () q {-# INLINE insert #-} +insert' :: (PSQKey k, Ord p) => k -> v -> p -> PSQ' k p v -> PSQ' k p v +insert' k v p q = Q.insert k p v 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 @@ -57,8 +69,8 @@ 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 +minView :: (PSQKey k, Ord p) => PSQ' k p v -> Maybe (Binding' k p v, PSQ' k p v) +minView q = fmap (\(k,p,v,q') -> (Binding k v p, q')) $ Q.minView q {-# INLINE minView #-} #endif -- cgit v1.2.3