diff options
author | joe <joe@jerkface.net> | 2017-07-26 22:01:09 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-07-26 22:01:09 -0400 |
commit | 133087121638a883ff15bc4141425c7df474b92b (patch) | |
tree | 305896448fc295f33600207a7818afeedfc3ff54 /src/Data/Wrapper | |
parent | dd6ce8958a9589111f2eef98633fbc9b510647e4 (diff) |
Expose psqueues' auxillary value feature.
Diffstat (limited to 'src/Data/Wrapper')
-rw-r--r-- | src/Data/Wrapper/PSQ.hs | 26 |
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) | |||
26 | import qualified Data.HashPSQ as Q | 26 | import qualified Data.HashPSQ as Q |
27 | import Data.Hashable | 27 | import Data.Hashable |
28 | 28 | ||
29 | type PSQ k p = HashPSQ k p () | 29 | type PSQ' k p v = HashPSQ k p v |
30 | type Binding k p = (k,p,()) | 30 | type PSQ k p = PSQ' k p () |
31 | |||
32 | type Binding' k p v = (k,p,v) | ||
33 | type Binding k p = Binding' k p () | ||
31 | 34 | ||
32 | type PSQKey k = (Hashable k, Ord k) | 35 | type PSQKey k = (Hashable k, Ord k) |
33 | 36 | ||
34 | pattern (:->) :: k -> p -> Binding k p | 37 | pattern (:->) :: k -> p -> Binding k p |
35 | pattern k :-> p <- (k,p,()) where k :-> p = (k,p,()) | 38 | pattern 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... | ||
42 | pattern Binding :: k -> v -> p -> Binding' k p v | ||
43 | pattern Binding k v p <- (k,p,v) where Binding k v p = (k,p,v) | ||
36 | 44 | ||
37 | key :: Binding k p -> k | 45 | key :: (k,p,v) -> k |
38 | key (k,p,v) = k | 46 | key (k,p,v) = k |
39 | {-# INLINE key #-} | 47 | {-# INLINE key #-} |
40 | 48 | ||
41 | prio :: Binding k p -> p | 49 | prio :: (k,p,v) -> p |
42 | prio (k,p,v) = p | 50 | prio (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 | |||
46 | insert k p q = Q.insert k p () q | 54 | insert k p q = Q.insert k p () q |
47 | {-# INLINE insert #-} | 55 | {-# INLINE insert #-} |
48 | 56 | ||
57 | insert' :: (PSQKey k, Ord p) => k -> v -> p -> PSQ' k p v -> PSQ' k p v | ||
58 | insert' k v p q = Q.insert k p v q | ||
59 | {-# INLINE insert' #-} | ||
60 | |||
49 | insertWith :: (PSQKey k, Ord p) => (p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p | 61 | insertWith :: (PSQKey k, Ord p) => (p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p |
50 | insertWith f k p0 q = snd $ Q.alter f' k q | 62 | insertWith 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 | |||
57 | singleton k p = Q.singleton k p () | 69 | singleton k p = Q.singleton k p () |
58 | {-# INLINE singleton #-} | 70 | {-# INLINE singleton #-} |
59 | 71 | ||
60 | minView :: (PSQKey k, Ord p) => PSQ k p -> Maybe (Binding k p, PSQ k p) | 72 | minView :: (PSQKey k, Ord p) => PSQ' k p v -> Maybe (Binding' k p v, PSQ' k p v) |
61 | minView q = fmap (\(k,p,(),q') -> (k :-> p, q')) $ Q.minView q | 73 | minView 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 |