summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Data/Wrapper/PSQ.hs37
-rw-r--r--src/Network/DHT/Routing.hs4
2 files changed, 29 insertions, 12 deletions
diff --git a/src/Data/Wrapper/PSQ.hs b/src/Data/Wrapper/PSQ.hs
index 2c08011b..7e14008b 100644
--- a/src/Data/Wrapper/PSQ.hs
+++ b/src/Data/Wrapper/PSQ.hs
@@ -1,17 +1,34 @@
1{-# LANGUAGE PatternSynonyms #-} 1{-# LANGUAGE PatternSynonyms #-}
2{-# LANGUAGE CPP #-} 2{-# LANGUAGE CPP #-}
3{-# LANGUAGE ConstraintKinds #-}
3module Data.Wrapper.PSQ 4module Data.Wrapper.PSQ
4#if 0 5#if 0
5 ( module Data.PSQueue ) where ; import Data.PSQueue 6 ( module Data.PSQueue ) where
7
8import Data.PSQueue hiding (foldr, foldl)
9import qualified Data.PSQueue as PSQueue
10
11-- | Wrapper over PSQueue-style foldr to implement a psqueues-style interface.
12fold' :: (Ord k, Ord p) => (k -> p -> () -> a -> a) -> a -> PSQ k p -> a
13fold' f a q = PSQueue.foldr f' a q
14 where
15 f' (k :-> prio) x = f k prio () x
16
6#else 17#else
7 ( module Data.Wrapper.PSQ , module OrdPSQ ) where 18 ( module Data.Wrapper.PSQ , module OrdPSQ ) where
8 19
9import Data.OrdPSQ as OrdPSQ hiding (insert, map, singleton, minView) 20import Data.OrdPSQ as OrdPSQ hiding (insert, map, singleton, minView)
10import qualified Data.OrdPSQ as OrdPSQ 21import qualified Data.OrdPSQ as Q
22
23import Data.HashPSQ as HashPSQ hiding (insert, map, singleton, minView)
24import qualified Data.HashPSQ as HashPSQ
25import Data.Hashable
11 26
12type PSQ k p = OrdPSQ k p () 27type PSQ k p = OrdPSQ k p ()
13type Binding k p = (k,p,()) 28type Binding k p = (k,p,())
14 29
30type PSQKey k = (Ord k)
31
15pattern (:->) :: k -> p -> Binding k p 32pattern (:->) :: k -> p -> Binding k p
16pattern k :-> p <- (k,p,()) where k :-> p = (k,p,()) 33pattern k :-> p <- (k,p,()) where k :-> p = (k,p,())
17 34
@@ -23,23 +40,23 @@ prio :: Binding k p -> p
23prio (k,p,v) = p 40prio (k,p,v) = p
24{-# INLINE prio #-} 41{-# INLINE prio #-}
25 42
26insert :: (Ord k, Ord p) => k -> p -> PSQ k p -> PSQ k p 43insert :: (PSQKey k, Ord p) => k -> p -> PSQ k p -> PSQ k p
27insert k p q = OrdPSQ.insert k p () q 44insert k p q = Q.insert k p () q
28{-# INLINE insert #-} 45{-# INLINE insert #-}
29 46
30insertWith :: (Ord k, Ord p) => (p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p 47insertWith :: (PSQKey k, Ord p) => (p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p
31insertWith f k p0 q = snd $ OrdPSQ.alter f' k q 48insertWith f k p0 q = snd $ Q.alter f' k q
32 where 49 where
33 f' (Just (p,())) = ((),Just (f p0 p, ())) 50 f' (Just (p,())) = ((),Just (f p0 p, ()))
34 f' Nothing = ((),Nothing) 51 f' Nothing = ((),Nothing)
35{-# INLINE insertWith #-} 52{-# INLINE insertWith #-}
36 53
37singleton :: (Ord k, Ord p) => k -> p -> PSQ k p 54singleton :: (PSQKey k, Ord p) => k -> p -> PSQ k p
38singleton k p = OrdPSQ.singleton k p () 55singleton k p = Q.singleton k p ()
39{-# INLINE singleton #-} 56{-# INLINE singleton #-}
40 57
41minView :: (Ord k, Ord p) => PSQ k p -> Maybe (Binding k p, PSQ k p) 58minView :: (PSQKey k, Ord p) => PSQ k p -> Maybe (Binding k p, PSQ k p)
42minView q = fmap (\(k,p,(),q') -> (k :-> p, q')) $ OrdPSQ.minView q 59minView q = fmap (\(k,p,(),q') -> (k :-> p, q')) $ Q.minView q
43{-# INLINE minView #-} 60{-# INLINE minView #-}
44 61
45#endif 62#endif
diff --git a/src/Network/DHT/Routing.hs b/src/Network/DHT/Routing.hs
index 273cf9dc..d380c6f2 100644
--- a/src/Network/DHT/Routing.hs
+++ b/src/Network/DHT/Routing.hs
@@ -248,10 +248,10 @@ instance (Eq ip, Ord (NodeId), Serialize (NodeId), Serialize ip, Serialize u) =>
248 248
249#endif 249#endif
250 250
251psqFromPairList :: (Ord p, Ord k) => [(k, p)] -> OrdPSQ k p () 251psqFromPairList :: (Ord p, Ord k) => [(k, p)] -> PSQ k p
252psqFromPairList xs = PSQ.fromList $ map (\(a,b) -> a :-> b) xs 252psqFromPairList xs = PSQ.fromList $ map (\(a,b) -> a :-> b) xs
253 253
254psqToPairList :: OrdPSQ t t1 () -> [(t, t1)] 254psqToPairList :: PSQ t t1 -> [(t, t1)]
255psqToPairList psq = map (\(a :-> b) -> (a,b)) $ PSQ.toList psq 255psqToPairList psq = map (\(a :-> b) -> (a,b)) $ PSQ.toList psq
256 256
257-- | Update interval, in seconds. 257-- | Update interval, in seconds.