Skip to content

Commit

Permalink
Don't leave BitmapIndexed with a single Leaf child (issue haskell-uno…
Browse files Browse the repository at this point in the history
  • Loading branch information
michalt committed Oct 10, 2012
1 parent 0b7ef83 commit 74a1314
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Data/HashMap/Base.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -479,7 +479,15 @@ delete k0 m0 = go h0 k0 0 m0
then t then t
else case st' of else case st' of
Empty | A.length ary == 1 -> Empty Empty | A.length ary == 1 -> Empty
| otherwise -> BitmapIndexed (b .&. complement m) (A.delete ary i) | A.length ary == 2 ->
case (i, A.index ary 0, A.index ary 1) of
(0, _, l@(Leaf _ _)) -> l
(1, l@(Leaf _ _), _) -> l
_ -> bIndexed
| otherwise -> bIndexed
where
bIndexed = BitmapIndexed (b .&. complement m) (A.delete ary i)
l@(Leaf _ _) | A.length ary == 1 -> l
_ -> BitmapIndexed b (A.update ary i st') _ -> BitmapIndexed b (A.update ary i st')
where m = mask h s where m = mask h s
i = sparseIndex b m i = sparseIndex b m
Expand Down Expand Up @@ -826,6 +834,11 @@ filterWithKey pred = go
step !ary !mary !b i !j !bi n step !ary !mary !b i !j !bi n
| i >= n = case j of | i >= n = case j of
0 -> return Empty 0 -> return Empty
1 -> do
ch <- A.read mary 0
case ch of
l@(Leaf _ _) -> return l
_ -> BitmapIndexed b <$> trim mary 1
_ -> do _ -> do
ary2 <- trim mary j ary2 <- trim mary j
return $! if j == maxChildren return $! if j == maxChildren
Expand Down

0 comments on commit 74a1314

Please sign in to comment.