diff --git a/Data/HashMap/Base.hs b/Data/HashMap/Base.hs index 4424661d..c246c44e 100644 --- a/Data/HashMap/Base.hs +++ b/Data/HashMap/Base.hs @@ -1295,30 +1295,30 @@ filterMapAuxInternal onLeaf onColl = go 0 go !sz (Full ary) = filterA sz ary fullNodeMask go !sz (Collision h ary) = filterC sz ary h - filterA sz ary0 b0 = + filterA sze ary0 b0 = let !n = A.length ary0 in runST $ do mary <- A.new_ n - step ary0 mary b0 0 0 1 n sz + step ary0 mary b0 0 0 1 n sze where step :: A.Array (Tree k v1) -> A.MArray s (Tree k v2) -> Bitmap -> Int -> Int -> Bitmap -> Int -> Int -> ST s (A.Sized (Tree k v2)) step !ary !mary !b i !j !bi n !siz | i >= n = case j of - 0 -> return (A.Sized siz Empty) + 0 -> return $! A.Sized siz Empty 1 -> do ch <- A.read mary 0 case ch of - t | isLeafOrCollision t -> return (A.Sized siz t) + t | isLeafOrCollision t -> return $! A.Sized siz t _ -> A.Sized siz . BitmapIndexed b <$> trim mary 1 _ -> do ary2 <- trim mary j return . A.Sized siz $! if j == maxChildren then Full ary2 else BitmapIndexed b ary2 - | bi .&. b == 0 = step ary mary b i j (bi `unsafeShiftL` 1) n sz - | otherwise = case go sz (A.index ary i) of + | bi .&. b == 0 = step ary mary b i j (bi `unsafeShiftL` 1) n siz + | otherwise = case go siz (A.index ary i) of A.Sized dsz Empty -> step ary mary (b .&. complement bi) (i+1) j (bi `unsafeShiftL` 1) n dsz A.Sized dsz t -> do A.write mary j t @@ -1334,18 +1334,18 @@ filterMapAuxInternal onLeaf onColl = go 0 step :: A.Array (Leaf k v1) -> A.MArray s (Leaf k v2) -> Int -> Int -> Int -> Int -> ST s (A.Sized (Tree k v2)) - step !ary !mary i !j n !sz + step !ary !mary i !j n !sze | i >= n = case j of - 0 -> return (A.Sized sz Empty) + 0 -> return (A.Sized sze Empty) 1 -> do l <- A.read mary 0 - return $! (A.Sized sz (Leaf h l)) + return . A.Sized sze $! Leaf h l _ | i == j -> do ary2 <- A.unsafeFreeze mary - return $! (A.Sized sz (Collision h ary2)) + return . A.Sized sze $! Collision h ary2 | otherwise -> do ary2 <- trim mary j - return $! (A.Sized sz (Collision h ary2)) + return . A.Sized sze $! Collision h ary2 | Just el <- onColl (A.index ary i) - = A.write mary j el >> step ary mary (i+1) (j+1) n (sz + 1) - | otherwise = step ary mary (i+1) j n sz + = A.write mary j el >> step ary mary (i+1) (j+1) n (sze + 1) + | otherwise = step ary mary (i+1) j n sze {-# INLINE filterMapAuxInternal #-} -- | /O(n)/ Filter this map by retaining only elements which values