summaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data')
-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