diff options
author | joe <joe@jerkface.net> | 2017-07-19 21:42:17 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-07-19 21:42:17 -0400 |
commit | b3c832ebd86281bfaa4fe6bb88aaacacbed0eadc (patch) | |
tree | d8af8a3f24d27938e8e86bdd6d03af0f4187fe91 | |
parent | 5c9180fa337dc2b87606d573ca3ec044554fa7d0 (diff) |
Added a wrapper for IntPSQ.
-rw-r--r-- | src/Data/Wrapper/PSQInt.hs | 55 |
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 #-} | ||
4 | module Data.Wrapper.PSQInt | ||
5 | #if 0 | ||
6 | ( module Data.Wrapper.PSQInt , module Data.PSQueue ) where | ||
7 | |||
8 | import Data.PSQueue hiding (foldr, foldl, PSQ) | ||
9 | import qualified Data.PSQueue as PSQueue | ||
10 | |||
11 | type PSQ p = PSQueue.PSQ Int p | ||
12 | |||
13 | -- | Wrapper over PSQueue-style foldr to implement a psqueues-style interface. | ||
14 | fold' :: (Ord p) => (Int -> p -> () -> a -> a) -> a -> PSQ p -> a | ||
15 | fold' 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 | |||
27 | import Data.Wrapper.PSQ (Binding, pattern (:->), key, prio) | ||
28 | |||
29 | import Data.IntPSQ as IntPSQ hiding (insert, map, singleton, minView) | ||
30 | import qualified Data.IntPSQ as Q | ||
31 | |||
32 | type PSQ p = IntPSQ p () | ||
33 | |||
34 | type PSQKey = () | ||
35 | |||
36 | insert :: (Ord p) => Int -> p -> PSQ p -> PSQ p | ||
37 | insert k p q = Q.insert k p () q | ||
38 | {-# INLINE insert #-} | ||
39 | |||
40 | insertWith :: (Ord p) => (p -> p -> p) -> Int -> p -> PSQ p -> PSQ p | ||
41 | insertWith 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 | |||
47 | singleton :: (Ord p) => Int -> p -> PSQ p | ||
48 | singleton k p = Q.singleton k p () | ||
49 | {-# INLINE singleton #-} | ||
50 | |||
51 | minView :: (Ord p) => PSQ p -> Maybe (Binding Int p, PSQ p) | ||
52 | minView q = fmap (\(k,p,(),q') -> (k :-> p, q')) $ Q.minView q | ||
53 | {-# INLINE minView #-} | ||
54 | |||
55 | #endif | ||