Skip to content

Commit

Permalink
[#10] Add mergeAll-based version of applyMerge
Browse files Browse the repository at this point in the history
Implement applyMerge in terms of mergeAll from data-ordlist, to provide
a point of comparison for benchmarking.
  • Loading branch information
pgujjula committed May 10, 2024
1 parent 7652550 commit 9ff2b7f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apply-merge.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ test-suite apply-merge-tests
ApplyMerge.DoublyLinkedList
ApplyMerge.IntMap
ApplyMerge.IntSet
ApplyMerge.MergeAll
Data.DoublyLinkedList.STRef
Data.List.ApplyMerge
Data.List.NonEmpty.ApplyMerge
Expand All @@ -63,6 +64,7 @@ test-suite apply-merge-tests
Test.ApplyMerge.DoublyLinkedList
Test.ApplyMerge.IntMap
Test.ApplyMerge.IntSet
Test.ApplyMerge.MergeAll
Test.Data.DoublyLinkedList.STRef
Test.Data.List.ApplyMerge
Test.Data.PQueue.Prio.Min.Mutable
Expand All @@ -73,6 +75,7 @@ test-suite apply-merge-tests
build-depends:
base >=4.16 && <4.17 || >=4.17 && <4.18 || >=4.18 && <4.19 || >=4.19 && <4.20
, containers ==0.6.*
, data-ordlist ==0.4.*
, pqueue >=1.4 && <1.5 || >=1.5 && <1.6
, reflection ==2.1.*
, tasty >=1.4 && <1.5 || >=1.5 && <1.6
Expand All @@ -90,6 +93,7 @@ benchmark apply-merge-benchmarks
ApplyMerge.DoublyLinkedList
ApplyMerge.IntMap
ApplyMerge.IntSet
ApplyMerge.MergeAll
Data.DoublyLinkedList.STRef
Data.List.ApplyMerge
Data.List.NonEmpty.ApplyMerge
Expand All @@ -104,6 +108,7 @@ benchmark apply-merge-benchmarks
build-depends:
base >=4.16 && <4.17 || >=4.17 && <4.18 || >=4.18 && <4.19 || >=4.19 && <4.20
, containers ==0.6.*
, data-ordlist ==0.4.*
, pqueue >=1.4 && <1.5 || >=1.5 && <1.6
, reflection ==2.1.*
, tasty-bench ==0.3.*
Expand Down
2 changes: 2 additions & 0 deletions bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Main (main) where
import ApplyMerge.DoublyLinkedList qualified
import ApplyMerge.IntMap qualified
import ApplyMerge.IntSet qualified
import ApplyMerge.MergeAll qualified
import Bench.Data.DoublyLinkedList.STRef qualified
import Bench.PriorityQueue.MinPQueue qualified
import Bench.PriorityQueue.MinPQueue.Mutable qualified
Expand All @@ -20,6 +21,7 @@ main =
ApplyMerge.DoublyLinkedList.applyMerge,
benchCommon "IntMap" ApplyMerge.IntMap.applyMerge,
benchCommon "IntSet" ApplyMerge.IntSet.applyMerge,
benchCommon "MergeAll" ApplyMerge.MergeAll.applyMerge,
Bench.Data.DoublyLinkedList.STRef.benchmarks,
Bench.PriorityQueue.MinPQueue.benchmarks,
Bench.PriorityQueue.MinPQueue.Mutable.benchmarks
Expand Down
2 changes: 2 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ tests:
main: Main.hs
dependencies:
- containers ^>= {0.6}
- data-ordlist ^>= {0.4}
- pqueue ^>= {1.4, 1.5}
- reflection ^>= {2.1}
- tasty ^>= {1.4, 1.5}
Expand All @@ -81,6 +82,7 @@ benchmarks:
main: Main.hs
dependencies:
- containers ^>= {0.6}
- data-ordlist ^>= {0.4}
- pqueue ^>= {1.4, 1.5}
- reflection ^>= {2.1}
- tasty-bench ^>= {0.3}
Expand Down
10 changes: 10 additions & 0 deletions src/ApplyMerge/MergeAll.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- SPDX-FileCopyrightText: Copyright Preetham Gujjula
-- SPDX-License-Identifier: BSD-3-Clause
module ApplyMerge.MergeAll (applyMerge) where

import Data.List.Ordered (mergeAll)

applyMerge :: (Ord c) => (a -> b -> c) -> [a] -> [b] -> [c]
applyMerge _ [] _ = []
applyMerge f xs ys =
mergeAll (map (\y -> map (`f` y) xs) ys)
2 changes: 2 additions & 0 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Main (main) where
import Test.ApplyMerge.DoublyLinkedList qualified (tests)
import Test.ApplyMerge.IntMap qualified (tests)
import Test.ApplyMerge.IntSet qualified (tests)
import Test.ApplyMerge.MergeAll qualified (tests)
import Test.Data.DoublyLinkedList.STRef qualified (tests)
import Test.Data.List.ApplyMerge qualified (tests)
import Test.Data.PQueue.Prio.Min.Mutable qualified (tests)
Expand All @@ -21,6 +22,7 @@ tests =
[ Test.ApplyMerge.DoublyLinkedList.tests,
Test.ApplyMerge.IntMap.tests,
Test.ApplyMerge.IntSet.tests,
Test.ApplyMerge.MergeAll.tests,
Test.Data.List.ApplyMerge.tests,
Test.Data.DoublyLinkedList.STRef.tests,
Test.Data.PQueue.Prio.Min.Mutable.tests
Expand Down
25 changes: 25 additions & 0 deletions test/Test/ApplyMerge/MergeAll.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- SPDX-FileCopyrightText: Copyright Preetham Gujjula
-- SPDX-License-Identifier: BSD-3-Clause
module Test.ApplyMerge.MergeAll
( tests,
)
where

import ApplyMerge.MergeAll (applyMerge)
import Test.ApplyMerge.Common
( basicTest,
blockTest,
maxTest,
skewedTest,
)
import Test.Tasty (TestTree, testGroup)

tests :: TestTree
tests =
testGroup
"ApplyMerge.MergeAll"
[ basicTest applyMerge,
skewedTest applyMerge,
blockTest applyMerge,
maxTest applyMerge
]

0 comments on commit 9ff2b7f

Please sign in to comment.