summaryrefslogtreecommitdiff
path: root/src/Data/Wrapper
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-07-26 22:01:09 -0400
committerjoe <joe@jerkface.net>2017-07-26 22:01:09 -0400
commit133087121638a883ff15bc4141425c7df474b92b (patch)
tree305896448fc295f33600207a7818afeedfc3ff54 /src/Data/Wrapper
parentdd6ce8958a9589111f2eef98633fbc9b510647e4 (diff)
Expose psqueues' auxillary value feature.
Diffstat (limited to 'src/Data/Wrapper')
-rw-r--r--src/Data/Wrapper/PSQ.hs26
1 files changed, 19 insertions, 7 deletions
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)
26import qualified Data.HashPSQ as Q 26import qualified Data.HashPSQ as Q
27import Data.Hashable 27import Data.Hashable
28 28
29type PSQ k p = HashPSQ k p () 29type PSQ' k p v = HashPSQ k p v
30type Binding k p = (k,p,()) 30type PSQ k p = PSQ' k p ()
31
32type Binding' k p v = (k,p,v)
33type Binding k p = Binding' k p ()
31 34
32type PSQKey k = (Hashable k, Ord k) 35type PSQKey k = (Hashable k, Ord k)
33 36
34pattern (:->) :: k -> p -> Binding k p 37pattern (:->) :: k -> p -> Binding k p
35pattern k :-> p <- (k,p,()) where k :-> p = (k,p,()) 38pattern k :-> p <- (k,p,_) where k :-> p = (k,p,())
39
40-- I tried defining (::->) :: (k,v) -> p -> Binding' k p v
41-- but no luck...
42pattern Binding :: k -> v -> p -> Binding' k p v
43pattern Binding k v p <- (k,p,v) where Binding k v p = (k,p,v)
36 44
37key :: Binding k p -> k 45key :: (k,p,v) -> k
38key (k,p,v) = k 46key (k,p,v) = k
39{-# INLINE key #-} 47{-# INLINE key #-}
40 48
41prio :: Binding k p -> p 49prio :: (k,p,v) -> p
42prio (k,p,v) = p 50prio (k,p,v) = p
43{-# INLINE prio #-} 51{-# INLINE prio #-}
44 52
@@ -46,6 +54,10 @@ insert :: (PSQKey k, Ord p) => k -> p -> PSQ k p -> PSQ k p
46insert k p q = Q.insert k p () q 54insert k p q = Q.insert k p () q
47{-# INLINE insert #-} 55{-# INLINE insert #-}
48 56
57insert' :: (PSQKey k, Ord p) => k -> v -> p -> PSQ' k p v -> PSQ' k p v
58insert' k v p q = Q.insert k p v q
59{-# INLINE insert' #-}
60
49insertWith :: (PSQKey k, Ord p) => (p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p 61insertWith :: (PSQKey k, Ord p) => (p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p
50insertWith f k p0 q = snd $ Q.alter f' k q 62insertWith f k p0 q = snd $ Q.alter f' k q
51 where 63 where
@@ -57,8 +69,8 @@ singleton :: (PSQKey k, Ord p) => k -> p -> PSQ k p
57singleton k p = Q.singleton k p () 69singleton k p = Q.singleton k p ()
58{-# INLINE singleton #-} 70{-# INLINE singleton #-}
59 71
60minView :: (PSQKey k, Ord p) => PSQ k p -> Maybe (Binding k p, PSQ k p) 72minView :: (PSQKey k, Ord p) => PSQ' k p v -> Maybe (Binding' k p v, PSQ' k p v)
61minView q = fmap (\(k,p,(),q') -> (k :-> p, q')) $ Q.minView q 73minView q = fmap (\(k,p,v,q') -> (Binding k v p, q')) $ Q.minView q
62{-# INLINE minView #-} 74{-# INLINE minView #-}
63 75
64#endif 76#endif