summaryrefslogtreecommitdiff
path: root/src/Data/Wrapper
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-07-19 21:42:17 -0400
committerjoe <joe@jerkface.net>2017-07-19 21:42:17 -0400
commitb3c832ebd86281bfaa4fe6bb88aaacacbed0eadc (patch)
treed8af8a3f24d27938e8e86bdd6d03af0f4187fe91 /src/Data/Wrapper
parent5c9180fa337dc2b87606d573ca3ec044554fa7d0 (diff)
Added a wrapper for IntPSQ.
Diffstat (limited to 'src/Data/Wrapper')
-rw-r--r--src/Data/Wrapper/PSQInt.hs55
1 files changed, 55 insertions, 0 deletions
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 @@
1{-# LANGUAGE PatternSynonyms #-}
2{-# LANGUAGE CPP #-}
3{-# LANGUAGE ConstraintKinds #-}
4module Data.Wrapper.PSQInt
5#if 0
6 ( module Data.Wrapper.PSQInt , module Data.PSQueue ) where
7
8import Data.PSQueue hiding (foldr, foldl, PSQ)
9import qualified Data.PSQueue as PSQueue
10
11type PSQ p = PSQueue.PSQ Int p
12
13-- | Wrapper over PSQueue-style foldr to implement a psqueues-style interface.
14fold' :: (Ord p) => (Int -> p -> () -> a -> a) -> a -> PSQ p -> a
15fold' f a q = PSQueue.foldr f' a q
16 where
17 f' (k :-> prio) x = f k prio () x
18
19#else
20 ( module Data.Wrapper.PSQInt
21 , module IntPSQ
22 , pattern (:->)
23 , key
24 , prio
25 ) where
26
27import Data.Wrapper.PSQ (Binding, pattern (:->), key, prio)
28
29import Data.IntPSQ as IntPSQ hiding (insert, map, singleton, minView)
30import qualified Data.IntPSQ as Q
31
32type PSQ p = IntPSQ p ()
33
34type PSQKey = ()
35
36insert :: (Ord p) => Int -> p -> PSQ p -> PSQ p
37insert k p q = Q.insert k p () q
38{-# INLINE insert #-}
39
40insertWith :: (Ord p) => (p -> p -> p) -> Int -> p -> PSQ p -> PSQ p
41insertWith f k p0 q = snd $ Q.alter f' k q
42 where
43 f' (Just (p,())) = ((),Just (f p0 p, ()))
44 f' Nothing = ((),Nothing)
45{-# INLINE insertWith #-}
46
47singleton :: (Ord p) => Int -> p -> PSQ p
48singleton k p = Q.singleton k p ()
49{-# INLINE singleton #-}
50
51minView :: (Ord p) => PSQ p -> Maybe (Binding Int p, PSQ p)
52minView q = fmap (\(k,p,(),q') -> (k :-> p, q')) $ Q.minView q
53{-# INLINE minView #-}
54
55#endif