Skip to content

Commit 1c118c4

Browse files
cleanup
1 parent 5a439cc commit 1c118c4

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

Data/HashMap/Internal.hs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,10 @@ unionWithKey f = go 0
15911591
ary' = update32With' ary2 i $ \st2 -> go (s+bitsPerSubkey) t1 st2
15921592
in Full ary'
15931593

1594+
leafHashCode (Leaf h _) = h
1595+
leafHashCode (Collision h _) = h
1596+
leafHashCode _ = error "leafHashCode"
1597+
15941598
goDifferentHash s h1 h2 t1 t2
15951599
| m1 == m2 = BitmapIndexed m1 (A.singleton $! goDifferentHash (s+bitsPerSubkey) h1 h2 t1 t2)
15961600
| m1 < m2 = BitmapIndexed (m1 .|. m2) (A.pair t1 t2)
@@ -1866,7 +1870,7 @@ intersectionArrayBy f !b1 !b2 !ary1 !ary2 = do
18661870
intersectionCollisions :: Eq k => (k -> v1 -> v2 -> (# v3 #)) -> A.Array (Leaf k v1) -> A.Array (Leaf k v2) -> ST s (Int, A.MArray s (Leaf k v3))
18671871
intersectionCollisions f ary1 ary2 = do
18681872
mary2 <- A.thaw ary2 0 $ A.length ary2
1869-
mary <- A.new_ $ A.length ary1 + A.length ary2
1873+
mary <- A.new_ $ min (A.length ary1) (A.length ary2)
18701874
let go i j
18711875
| i >= A.length ary1 || j >= A.lengthM mary2 = pure j
18721876
| otherwise = do
@@ -2382,12 +2386,6 @@ ptrEq :: a -> a -> Bool
23822386
ptrEq x y = Exts.isTrue# (Exts.reallyUnsafePtrEquality# x y ==# 1#)
23832387
{-# INLINE ptrEq #-}
23842388

2385-
leafHashCode :: HashMap k v -> Hash
2386-
leafHashCode (Leaf h _) = h
2387-
leafHashCode (Collision h _) = h
2388-
leafHashCode _ = error "leafHashCode"
2389-
{-# INLINE leafHashCode #-}
2390-
23912389
------------------------------------------------------------------------
23922390
-- IsList instance
23932391
instance (Eq k, Hashable k) => Exts.IsList (HashMap k v) where

benchmarks/Benchmarks.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,17 @@ main = do
318318
[ bench "Int" $ whnf (HM.union hmi) hmi2
319319
, bench "ByteString" $ whnf (HM.union hmbs) hmbsSubset
320320
]
321+
322+
, bgroup "intersection"
323+
[ bench "Int" $ whnf (HM.intersection hmi) hmi2
324+
, bench "ByteString" $ whnf (HM.intersection hmbs) hmbsSubset
325+
]
321326

322327
-- Transformations
323328
, bench "map" $ whnf (HM.map (\ v -> v + 1)) hmi
324329

325330
-- * Difference and intersection
326331
, bench "difference" $ whnf (HM.difference hmi) hmi2
327-
, bench "intersection" $ whnf (HM.intersection hmi) hmi2
328332

329333
-- Folds
330334
, bench "foldl'" $ whnf (HM.foldl' (+) 0) hmi

tests/Properties/HashMapLazy.hs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import Control.Applicative (Const (..))
1818
import Control.Monad (guard)
1919
import Data.Bifoldable
2020
import Data.Function (on)
21-
import Debug.Trace (traceId)
2221
import Data.Functor.Identity (Identity (..))
2322
import Data.Hashable (Hashable (hashWithSalt))
2423
import Data.Ord (comparing)
@@ -252,15 +251,7 @@ pSubmapDifference m1 m2 = HM.isSubmapOf (HM.difference m1 m2) m1
252251

253252
pNotSubmapDifference :: HashMap Key Int -> HashMap Key Int -> Property
254253
pNotSubmapDifference m1 m2 =
255-
not (HM.null (HM.intersection m1 m2)) ==> do
256-
257-
let
258-
res = HM.intersection m1 m2
259-
res' = M.intersection (M.fromList $ HM.toList m1) (M.fromList $ HM.toList m2)
260-
-- !_ = traceId $ "res: " ++ show res
261-
-- !_ = traceId $ "res': " ++ show res'
262-
-- !_ = traceId $ "m1: " ++ show m1
263-
-- !_ = traceId $ "m2: " ++ show m2
254+
not (HM.null (HM.intersection m1 m2)) ==>
264255
not (HM.isSubmapOf m1 (HM.difference m1 m2))
265256

266257
pSubmapDelete :: HashMap Key Int -> Property
@@ -334,9 +325,6 @@ pIntersection xs ys =
334325
`eq_` HM.intersection (HM.fromList xs)
335326
$ ys
336327

337-
intersectionBad :: Assertion
338-
intersectionBad = pIntersection [(-20, 0), (0, 0)] [(0, 0), (20, 0)] @? "should be true"
339-
340328
pIntersectionWith :: [(Key, Int)] -> [(Key, Int)] -> Bool
341329
pIntersectionWith xs ys = M.intersectionWith (-) (M.fromList xs) `eq_`
342330
HM.intersectionWith (-) (HM.fromList xs) $ ys
@@ -547,7 +535,6 @@ tests =
547535
[ testProperty "difference" pDifference
548536
, testProperty "differenceWith" pDifferenceWith
549537
, testProperty "intersection" pIntersection
550-
, testCase "intersectionBad" intersectionBad
551538
, testProperty "intersectionWith" pIntersectionWith
552539
, testProperty "intersectionWithKey" pIntersectionWithKey
553540
]

0 commit comments

Comments
 (0)