Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions benchmarks/BenchMinPQueue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Test.Tasty.Bench

import qualified KWay.PrioMergeAlg as KWay
import qualified PHeapSort as HS
import qualified Data.PQueue.Prio.Min as P

kWay :: Int -> Int -> Benchmark
kWay i n = bench
Expand All @@ -14,6 +15,17 @@ hSort n = bench
("Heap sort with " ++ show n ++ " elements")
(nf (HS.heapSortRandoms n) $ mkStdGen (-7750349139967535027))

filterQ :: Int -> Benchmark
filterQ n = bench
("filter with " ++ show n ++ " elements")
(whnf (P.drop 1 . P.filterWithKey (>) . (P.fromList :: [(Int, Int)] -> P.MinPQueue Int Int) . take n . randoms) $ mkStdGen 977209486631198655)

partitionQ :: Int -> Benchmark
partitionQ n = bench
("partition with " ++ show n ++ " elements")
(whnf (P.drop 1 . snd . P.partitionWithKey (>) . (P.fromList :: [(Int, Int)] -> P.MinPQueue Int Int) . take n . randoms) $ mkStdGen 781928047937198)


main :: IO ()
main = defaultMain
[ bgroup "heapSort"
Expand All @@ -35,4 +47,18 @@ main = defaultMain
, kWay (2*10^6) 2000
, kWay (4*10^6) 100
]
, bgroup "filter"
[ filterQ (10^3)
, filterQ (10^4)
, filterQ (10^5)
, filterQ (10^6)
, filterQ (3*10^6)
]
, bgroup "partition"
[ partitionQ (10^3)
, partitionQ (10^4)
, partitionQ (10^5)
, partitionQ (10^6)
, partitionQ (3*10^6)
]
]
3 changes: 3 additions & 0 deletions pqueue.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ library
Data.PQueue.Internals.Down
Data.PQueue.Internals.Foldable
Data.PQueue.Prio.Max.Internals
Nattish
if impl(ghc) {
default-extensions: DeriveDataTypeable
}
Expand Down Expand Up @@ -90,11 +91,13 @@ test-suite test
Data.PQueue.Internals.Down
Data.PQueue.Internals.Foldable
Data.PQueue.Prio.Max.Internals
Nattish

Validity.BinomialQueue
Validity.PQueue.Min
Validity.PQueue.Prio.BinomialQueue
Validity.PQueue.Prio.Min
Validity.PQueue.Prio.Max
if impl(ghc) {
default-extensions: DeriveDataTypeable
}
Expand Down
3 changes: 3 additions & 0 deletions src/Data/PQueue/Internals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ fromList :: Ord a => [a] -> MinQueue a
-- comparison per element.
fromList xs = fromBare (BQ.fromList xs)

-- | \(O(n)\). Assumes that the function it is given is (weakly) monotonic, and
-- applies this function to every element of the priority queue, as in 'fmap'.
-- If the function is not monotonic, the result is undefined.
mapU :: (a -> b) -> MinQueue a -> MinQueue b
mapU _ Empty = Empty
mapU f (MinQueue n x ts) = MinQueue n (f x) (BQ.mapU f ts)
Expand Down
16 changes: 0 additions & 16 deletions src/Data/PQueue/Internals/Foldable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,16 @@ module Data.PQueue.Internals.Foldable
, Foldl (..)
, FoldMap (..)
, Foldl' (..)
, IFoldr (..)
, IFoldl (..)
, IFoldMap (..)
, IFoldl' (..)
) where

class Foldr t where
foldr_ :: (a -> b -> b) -> b -> t a -> b

class IFoldr t where
foldrWithKey_ :: (k -> a -> b -> b) -> b -> t k a -> b

class Foldl t where
foldl_ :: (b -> a -> b) -> b -> t a -> b

class IFoldl t where
foldlWithKey_ :: (b -> k -> a -> b) -> b -> t k a -> b

class FoldMap t where
foldMap_ :: Monoid m => (a -> m) -> t a -> m

class IFoldMap t where
foldMapWithKey_ :: Monoid m => (k -> a -> m) -> t k a -> m

class Foldl' t where
foldl'_ :: (b -> a -> b) -> b -> t a -> b

class IFoldl' t where
foldlWithKey'_ :: (b -> k -> a -> b) -> b -> t k a -> b
4 changes: 2 additions & 2 deletions src/Data/PQueue/Min.hs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,6 @@ keysF :: (pRk k a -> rk k) -> Prio.BinomForest pRk k a -> BinomForest rk k
keysF f ts0 = case ts0 of
Prio.Nil -> Nil
Prio.Skip ts' -> Skip $! keysF f' ts'
Prio.Cons (Prio.BinomTree k _ ts) ts'
Prio.Cons (Prio.BinomTree k ts) ts'
-> Cons (BinomTree k (f ts)) $! keysF f' ts'
where f' (Prio.Succ (Prio.BinomTree k _ ts) tss) = Succ (BinomTree k (f ts)) (f tss)
where f' (Prio.Succ (Prio.BinomTree k ts) tss) = Succ (BinomTree k (f ts)) (f tss)
Comment thread
treeowl marked this conversation as resolved.
Loading