Skip to content

Commit 147b05f

Browse files
committed
Fix size tracking in 'filterMapAuxInternal'
Because values are bound to 'sz' often in the many local functions used in 'filterMapAuxInternal', some shadowing occured that caused the size calculated to be incorrect. This commit renames those variables to avoid collisions.
1 parent bbcb840 commit 147b05f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Data/HashMap/Base.hs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1295,30 +1295,30 @@ filterMapAuxInternal onLeaf onColl = go 0
12951295
go !sz (Full ary) = filterA sz ary fullNodeMask
12961296
go !sz (Collision h ary) = filterC sz ary h
12971297

1298-
filterA sz ary0 b0 =
1298+
filterA sze ary0 b0 =
12991299
let !n = A.length ary0
13001300
in runST $ do
13011301
mary <- A.new_ n
1302-
step ary0 mary b0 0 0 1 n sz
1302+
step ary0 mary b0 0 0 1 n sze
13031303
where
13041304
step :: A.Array (Tree k v1) -> A.MArray s (Tree k v2)
13051305
-> Bitmap -> Int -> Int -> Bitmap -> Int -> Int
13061306
-> ST s (A.Sized (Tree k v2))
13071307
step !ary !mary !b i !j !bi n !siz
13081308
| i >= n = case j of
1309-
0 -> return (A.Sized siz Empty)
1309+
0 -> return $! A.Sized siz Empty
13101310
1 -> do
13111311
ch <- A.read mary 0
13121312
case ch of
1313-
t | isLeafOrCollision t -> return (A.Sized siz t)
1313+
t | isLeafOrCollision t -> return $! A.Sized siz t
13141314
_ -> A.Sized siz . BitmapIndexed b <$> trim mary 1
13151315
_ -> do
13161316
ary2 <- trim mary j
13171317
return . A.Sized siz $! if j == maxChildren
13181318
then Full ary2
13191319
else BitmapIndexed b ary2
1320-
| bi .&. b == 0 = step ary mary b i j (bi `unsafeShiftL` 1) n sz
1321-
| otherwise = case go sz (A.index ary i) of
1320+
| bi .&. b == 0 = step ary mary b i j (bi `unsafeShiftL` 1) n siz
1321+
| otherwise = case go siz (A.index ary i) of
13221322
A.Sized dsz Empty -> step ary mary (b .&. complement bi) (i+1) j
13231323
(bi `unsafeShiftL` 1) n dsz
13241324
A.Sized dsz t -> do A.write mary j t
@@ -1334,18 +1334,18 @@ filterMapAuxInternal onLeaf onColl = go 0
13341334
step :: A.Array (Leaf k v1) -> A.MArray s (Leaf k v2)
13351335
-> Int -> Int -> Int -> Int
13361336
-> ST s (A.Sized (Tree k v2))
1337-
step !ary !mary i !j n !sz
1337+
step !ary !mary i !j n !sze
13381338
| i >= n = case j of
1339-
0 -> return (A.Sized sz Empty)
1339+
0 -> return (A.Sized sze Empty)
13401340
1 -> do l <- A.read mary 0
1341-
return $! (A.Sized sz (Leaf h l))
1341+
return . A.Sized sze $! Leaf h l
13421342
_ | i == j -> do ary2 <- A.unsafeFreeze mary
1343-
return $! (A.Sized sz (Collision h ary2))
1343+
return . A.Sized sze $! Collision h ary2
13441344
| otherwise -> do ary2 <- trim mary j
1345-
return $! (A.Sized sz (Collision h ary2))
1345+
return . A.Sized sze $! Collision h ary2
13461346
| Just el <- onColl (A.index ary i)
1347-
= A.write mary j el >> step ary mary (i+1) (j+1) n (sz + 1)
1348-
| otherwise = step ary mary (i+1) j n sz
1347+
= A.write mary j el >> step ary mary (i+1) (j+1) n (sze + 1)
1348+
| otherwise = step ary mary (i+1) j n sze
13491349
{-# INLINE filterMapAuxInternal #-}
13501350

13511351
-- | /O(n)/ Filter this map by retaining only elements which values

0 commit comments

Comments
 (0)