diff options
Diffstat (limited to 'src/Data/Wrapper/PSQ.hs')
-rw-r--r-- | src/Data/Wrapper/PSQ.hs | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/src/Data/Wrapper/PSQ.hs b/src/Data/Wrapper/PSQ.hs deleted file mode 100644 index 4fdeec67..00000000 --- a/src/Data/Wrapper/PSQ.hs +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | {-# LANGUAGE PatternSynonyms #-} | ||
2 | {-# LANGUAGE CPP #-} | ||
3 | {-# LANGUAGE ConstraintKinds #-} | ||
4 | module Data.Wrapper.PSQ | ||
5 | #if 0 | ||
6 | ( module Data.Wrapper.PSQ , module Data.PSQueue ) where | ||
7 | |||
8 | import Data.PSQueue hiding (foldr, foldl) | ||
9 | import qualified Data.PSQueue as PSQueue | ||
10 | |||
11 | type PSQKey k = (Ord k) | ||
12 | |||
13 | -- | Wrapper over PSQueue-style foldr to implement a psqueues-style interface. | ||
14 | fold' :: (Ord k, Ord p) => (k -> p -> () -> a -> a) -> a -> PSQ k 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.PSQ , module HashPSQ ) where | ||
21 | |||
22 | -- import Data.OrdPSQ as OrdPSQ hiding (insert, map, singleton, minView) | ||
23 | -- import qualified Data.OrdPSQ as OrdPSQ | ||
24 | |||
25 | import Data.Hashable | ||
26 | import qualified Data.HashPSQ as Q | ||
27 | ;import Data.HashPSQ as HashPSQ hiding (insert, map, minView, | ||
28 | singleton) | ||
29 | import Data.Time.Clock.POSIX (POSIXTime) | ||
30 | |||
31 | -- type PSQ' k p v = HashPSQ k p v | ||
32 | type PSQ' = HashPSQ | ||
33 | type PSQ k p = PSQ' k p () | ||
34 | |||
35 | type Binding' k p v = (k,p,v) | ||
36 | type Binding k p = Binding' k p () | ||
37 | |||
38 | type PSQKey k = (Hashable k, Ord k) | ||
39 | |||
40 | pattern (:->) :: k -> p -> Binding k p | ||
41 | pattern k :-> p <- (k,p,_) where k :-> p = (k,p,()) | ||
42 | |||
43 | -- I tried defining (::->) :: (k,v) -> p -> Binding' k p v | ||
44 | -- but no luck... | ||
45 | pattern Binding :: k -> v -> p -> Binding' k p v | ||
46 | pattern Binding k v p <- (k,p,v) where Binding k v p = (k,p,v) | ||
47 | |||
48 | key :: (k,p,v) -> k | ||
49 | key (k,p,v) = k | ||
50 | {-# INLINE key #-} | ||
51 | |||
52 | prio :: (k,p,v) -> p | ||
53 | prio (k,p,v) = p | ||
54 | {-# INLINE prio #-} | ||
55 | |||
56 | insert :: (PSQKey k, Ord p) => k -> p -> PSQ k p -> PSQ k p | ||
57 | insert k p q = Q.insert k p () q | ||
58 | {-# INLINE insert #-} | ||
59 | |||
60 | insert' :: (PSQKey k, Ord p) => k -> v -> p -> PSQ' k p v -> PSQ' k p v | ||
61 | insert' k v p q = Q.insert k p v q | ||
62 | {-# INLINE insert' #-} | ||
63 | |||
64 | insertWith :: (PSQKey k, Ord p) => (p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p | ||
65 | insertWith f k p0 q = snd $ Q.alter f' k q | ||
66 | where | ||
67 | f' (Just (p,())) = ((),Just (f p0 p, ())) | ||
68 | f' Nothing = ((),Just (p0,())) | ||
69 | {-# INLINE insertWith #-} | ||
70 | |||
71 | singleton :: (PSQKey k, Ord p) => k -> p -> PSQ k p | ||
72 | singleton k p = Q.singleton k p () | ||
73 | {-# INLINE singleton #-} | ||
74 | |||
75 | singleton' :: (PSQKey k, Ord p) => k -> v -> p -> PSQ' k p v | ||
76 | singleton' k v p = Q.singleton k p v | ||
77 | {-# INLINE singleton' #-} | ||
78 | |||
79 | |||
80 | minView :: (PSQKey k, Ord p) => PSQ' k p v -> Maybe (Binding' k p v, PSQ' k p v) | ||
81 | minView q = fmap (\(k,p,v,q') -> (Binding k v p, q')) $ Q.minView q | ||
82 | {-# INLINE minView #-} | ||
83 | |||
84 | |||
85 | -- | Utility to convert a 'POSIXTime' delta into microseconds suitable for | ||
86 | -- passing to 'threadDelay'. | ||
87 | toMicroseconds :: POSIXTime -> Int | ||
88 | toMicroseconds = round . (* 1000) . (* 1000) | ||
89 | |||
90 | |||
91 | #endif | ||