Skip to content

Commit

Permalink
Remove redundant guards
Browse files Browse the repository at this point in the history
  • Loading branch information
rockbmb committed Oct 12, 2017
1 parent e680073 commit 7d190bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
10 changes: 4 additions & 6 deletions Data/HashMap/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ instance (Eq k, Eq v) => Eq (HashMap k v) where

equal :: (k -> k' -> Bool) -> (v -> v' -> Bool)
-> HashMap k v -> HashMap k' v' -> Bool
equal eqk eqv (HashMap s1 t1) (HashMap s2 t2)
| s1 == s2 = go (toList' t1 []) (toList' t2 [])
| otherwise = False
equal eqk eqv (HashMap s1 t1) (HashMap s2 t2) =
(s1 == s2) && go (toList' t1 []) (toList' t2 [])
where
-- If the two trees are the same, then their lists of 'Leaf's and
-- 'Collision's read from left to right should be the same (modulo the
Expand Down Expand Up @@ -329,9 +328,8 @@ cmp cmpk cmpv (HashMap _ t1) (HashMap _ t2) =

-- Same as 'equal' but doesn't compare the values.
equalKeys :: (k -> k' -> Bool) -> HashMap k v -> HashMap k' v' -> Bool
equalKeys eq (HashMap s1 t1) (HashMap s2 t2)
| s1 == s2 = go (toList' t1 []) (toList' t2 [])
| otherwise = False
equalKeys eq (HashMap s1 t1) (HashMap s2 t2) =
(s1 == s2) && go (toList' t1 []) (toList' t2 [])
where
go (Leaf k1 l1 : tl1) (Leaf k2 l2 : tl2)
| k1 == k2 && leafEq l1 l2
Expand Down
24 changes: 13 additions & 11 deletions Data/HashMap/Strict.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ insertWithInternal f k0 v0 m0 = go h0 k0 v0 0 m0
| hy == h = if ky == k
then A.Sized 0 (leaf h k (f x y))
else A.Sized 1 (x `seq` (collision h l (L k x)))
| otherwise = A.Sized 0 (x `seq` runST (two s h k x hy ky y))
| otherwise = A.Sized 1 (x `seq` runST (two s h k x hy ky y))
go h k x s (BitmapIndexed b ary)
| b .&. m == 0 =
let ary' = A.insert ary i $! leaf h k x
Expand Down Expand Up @@ -210,37 +210,39 @@ unsafeInsertWithInternal
unsafeInsertWithInternal f k0 v0 m0 = runST (go h0 k0 v0 0 m0)
where
h0 = hash k0
go !h !k x !_ Empty = return $! A.Sized 1 (leaf h k x)
go !h !k x !_ Empty = return . A.Sized 1 $! leaf h k x
go h k x s (Leaf hy l@(L ky y))
| hy == h = if ky == k
then return $! A.Sized 0 (leaf h k (f x y))
then return . A.Sized 0 $! leaf h k (f x y)
else do
let l' = x `seq` (L k x)
return $! A.Sized 1 (collision h l l')
| otherwise = (x `seq` two s h k x hy ky y) >>= return . A.Sized 1
return . A.Sized 1 $! collision h l l'
| otherwise = do
twoHM <- x `seq` two s h k x hy ky y
return . A.Sized 1 $! twoHM
go h k x s t@(BitmapIndexed b ary)
| b .&. m == 0 = do
ary' <- A.insertM ary i $! leaf h k x
return $! A.Sized 1 (bitmapIndexedOrFull (b .|. m) ary')
return . A.Sized 1 $! bitmapIndexedOrFull (b .|. m) ary'
| otherwise = do
st <- A.indexM ary i
A.Sized sz st' <- go h k x (s+bitsPerSubkey) st
A.unsafeUpdateM ary i st'
return (A.Sized sz t)
A.unsafeUpdateM ary i $! st'
return . A.Sized sz $! t
where m = mask h s
i = sparseIndex b m
go h k x s t@(Full ary) = do
st <- A.indexM ary i
A.Sized sz st' <- go h k x (s+bitsPerSubkey) st
A.unsafeUpdateM ary i st'
return (A.Sized sz t)
A.unsafeUpdateM ary i $! st'
return . A.Sized sz $! t
where i = index h s
go h k x s t@(Collision hy v)
| h == hy =
let !start = A.length v
!newV = updateOrSnocWith f k x v
!end = A.length newV
in return $! A.Sized (end - start) (Collision h newV)
in return . A.Sized (end - start) $! Collision h newV
| otherwise = go h k x s $ BitmapIndexed (mask hy s) (A.singleton t)
{-# INLINABLE unsafeInsertWithInternal #-}

Expand Down

0 comments on commit 7d190bd

Please sign in to comment.