From d9159028e812f2855558ba183d3c11040d98e408 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Fri, 7 Sep 2018 23:27:49 -0400 Subject: Added some minor helper utiltities to PSQ and Network.Tox.Session. --- src/Data/Wrapper/PSQ.hs | 13 +++++++++++-- src/Data/Wrapper/PSQInt.hs | 6 ++---- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src/Data/Wrapper') diff --git a/src/Data/Wrapper/PSQ.hs b/src/Data/Wrapper/PSQ.hs index 5d32e16c..745e556b 100644 --- a/src/Data/Wrapper/PSQ.hs +++ b/src/Data/Wrapper/PSQ.hs @@ -22,9 +22,11 @@ fold' f a q = PSQueue.foldr f' a q -- import Data.OrdPSQ as OrdPSQ hiding (insert, map, singleton, minView) -- import qualified Data.OrdPSQ as OrdPSQ -import Data.HashPSQ as HashPSQ hiding (insert, map, singleton, minView) -import qualified Data.HashPSQ as Q import Data.Hashable +import qualified Data.HashPSQ as Q + ;import Data.HashPSQ as HashPSQ hiding (insert, map, minView, + singleton) +import Data.Time.Clock.POSIX (POSIXTime) type PSQ' k p v = HashPSQ k p v type PSQ k p = PSQ' k p () @@ -78,4 +80,11 @@ minView :: (PSQKey k, Ord p) => PSQ' k p v -> Maybe (Binding' k p v, PSQ' k p v) minView q = fmap (\(k,p,v,q') -> (Binding k v p, q')) $ Q.minView q {-# INLINE minView #-} + +-- | Utility to convert a 'POSIXTime' delta into microseconds suitable for +-- passing to 'threadDelay'. +toMicroseconds :: POSIXTime -> Int +toMicroseconds = round . (* 1000) . (* 1000) + + #endif diff --git a/src/Data/Wrapper/PSQInt.hs b/src/Data/Wrapper/PSQInt.hs index c61b7ab6..5badb8b2 100644 --- a/src/Data/Wrapper/PSQInt.hs +++ b/src/Data/Wrapper/PSQInt.hs @@ -19,12 +19,10 @@ fold' f a q = PSQueue.foldr f' a q #else ( module Data.Wrapper.PSQInt , module IntPSQ - , pattern (:->) - , key - , prio + , module Data.Wrapper.PSQ ) where -import Data.Wrapper.PSQ (Binding, pattern (:->), key, prio) +import Data.Wrapper.PSQ (Binding, pattern (:->), key, prio, toMicroseconds) import Data.IntPSQ as IntPSQ hiding (insert, map, singleton, minView) import qualified Data.IntPSQ as Q -- cgit v1.2.3