Skip to content

Commit d56eb40

Browse files
authored
Enhance parallel building (#58)
Move the `keysQueue` implementation out of `Data.PQueue.Internals`. This allows that module to build in parallel with `Data.PQueue.Prio.Internals`. It looks like [Cabal can't yet make use of this](haskell/cabal#976), but work to make it do so is under way.
1 parent 07f77f1 commit d56eb40

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/Data/PQueue/Internals.hs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ module Data.PQueue.Internals (
3737
foldrU,
3838
foldlU,
3939
-- traverseU,
40-
keysQueue,
4140
seqSpine,
4241
unions
4342
) where
@@ -48,8 +47,6 @@ import Data.Foldable (foldl')
4847
import Data.Semigroup (Semigroup(..), stimesMonoid)
4948
#endif
5049

51-
import qualified Data.PQueue.Prio.Internals as Prio
52-
5350
#ifdef __GLASGOW_HASKELL__
5451
import Data.Data
5552
import Text.Read (Lexeme(Ident), lexP, parens, prec,
@@ -690,19 +687,6 @@ seqSpineF Nil z = z
690687
seqSpineF (Skip ts') z = seqSpineF ts' z
691688
seqSpineF (Cons _ ts') z = seqSpineF ts' z
692689

693-
-- | Constructs a priority queue out of the keys of the specified 'Prio.MinPQueue'.
694-
keysQueue :: Prio.MinPQueue k a -> MinQueue k
695-
keysQueue Prio.Empty = Empty
696-
keysQueue (Prio.MinPQ n k _ ts) = MinQueue n k (keysF (const Zero) ts)
697-
698-
keysF :: (pRk k a -> rk k) -> Prio.BinomForest pRk k a -> BinomForest rk k
699-
keysF f ts0 = case ts0 of
700-
Prio.Nil -> Nil
701-
Prio.Skip ts' -> Skip (keysF f' ts')
702-
Prio.Cons (Prio.BinomTree k _ ts) ts'
703-
-> Cons (BinomTree k (f ts)) (keysF f' ts')
704-
where f' (Prio.Succ (Prio.BinomTree k _ ts) tss) = Succ (BinomTree k (f ts)) (f tss)
705-
706690
class NFRank rk where
707691
rnfRk :: NFData a => rk a -> ()
708692

src/Data/PQueue/Min.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import Data.Semigroup (Semigroup((<>)))
9191
import qualified Data.List as List
9292

9393
import Data.PQueue.Internals
94+
import qualified Data.PQueue.Prio.Internals as Prio
9495

9596
#ifdef __GLASGOW_HASKELL__
9697
import GHC.Exts (build)
@@ -213,3 +214,16 @@ fromDescList xs = foldl' (flip insertMinQ') empty xs
213214
-- | Equivalent to 'toListU'.
214215
elemsU :: MinQueue a -> [a]
215216
elemsU = toListU
217+
218+
-- | Constructs a priority queue out of the keys of the specified 'Prio.MinPQueue'.
219+
keysQueue :: Prio.MinPQueue k a -> MinQueue k
220+
keysQueue Prio.Empty = Empty
221+
keysQueue (Prio.MinPQ n k _ ts) = MinQueue n k (keysF (const Zero) ts)
222+
223+
keysF :: (pRk k a -> rk k) -> Prio.BinomForest pRk k a -> BinomForest rk k
224+
keysF f ts0 = case ts0 of
225+
Prio.Nil -> Nil
226+
Prio.Skip ts' -> Skip (keysF f' ts')
227+
Prio.Cons (Prio.BinomTree k _ ts) ts'
228+
-> Cons (BinomTree k (f ts)) (keysF f' ts')
229+
where f' (Prio.Succ (Prio.BinomTree k _ ts) tss) = Succ (BinomTree k (f ts)) (f tss)

0 commit comments

Comments
 (0)