Skip to content

Commit 1ee67ea

Browse files
.
1 parent d9a50d7 commit 1ee67ea

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

Data/HashMap/Internal.hs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,30 +1840,28 @@ intersectionArrayBy f !b1 !b2 !ary1 !ary2
18401840
| b1 .&. b2 == 0 = Empty
18411841
| otherwise = runST $ do
18421842
mary <- A.new_ $ popCount bIntersect
1843-
-- iterate over nonzero bits of b1 .|. b2
1844-
let go !i !i1 !i2 !b !bFinal
1843+
-- iterate over nonzero bits of b1 .&. b2
1844+
let go !i !b !bFinal
18451845
| b == 0 = pure (i, bFinal)
1846-
| testBit $ b1 .&. b2 = do
1846+
| otherwise = do
18471847
x1 <- A.indexM ary1 i1
18481848
x2 <- A.indexM ary2 i2
18491849
case f x1 x2 of
1850-
Empty -> go i (i1 + 1) (i2 + 1) b' (bFinal .&. complement m)
1850+
Empty -> go i b' (bFinal .&. complement m)
18511851
_ -> do
18521852
A.write mary i $! f x1 x2
1853-
go (i + 1) (i1 + 1) (i2 + 1) b' bFinal
1854-
| testBit b1 = go i (i1 + 1) i2 b' bFinal
1855-
| otherwise = go i i1 (i2 + 1) b' bFinal
1853+
go (i + 1) b' bFinal
18561854
where
18571855
m = 1 `unsafeShiftL` countTrailingZeros b
1858-
testBit x = x .&. m /= 0
1856+
i1 = sparseIndex b1 m
1857+
i2 = sparseIndex b2 m
18591858
b' = b .&. complement m
1860-
(len, bFinal) <- go 0 0 0 bCombined bIntersect
1859+
(len, bFinal) <- go 0 bIntersect bIntersect
18611860
case len of
18621861
0 -> pure Empty
18631862
1 -> A.read mary 0
18641863
_ -> bitmapIndexedOrFull bFinal <$> (A.unsafeFreeze =<< A.shrink mary len)
18651864
where
1866-
bCombined = b1 .|. b2
18671865
bIntersect = b1 .&. b2
18681866
{-# INLINE intersectionArrayBy #-}
18691867

0 commit comments

Comments
 (0)