Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shrink in filterMapAux #433

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Data/HashMap/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2100,9 +2100,9 @@ filterMapAux onLeaf onColl = go
ch <- A.read mary 0
case ch of
t | isLeafOrCollision t -> return t
_ -> BitmapIndexed b <$> A.trim mary 1
_ -> BitmapIndexed b <$> (A.unsafeFreeze =<< A.shrink mary 1)
_ -> do
ary2 <- A.trim mary j
ary2 <- A.unsafeFreeze =<< A.shrink mary j
return $! if j == maxChildren
then Full ary2
else BitmapIndexed b ary2
Expand All @@ -2129,7 +2129,7 @@ filterMapAux onLeaf onColl = go
return $! Leaf h l
_ | i == j -> do ary2 <- A.unsafeFreeze mary
return $! Collision h ary2
| otherwise -> do ary2 <- A.trim mary j
| otherwise -> do ary2 <- A.unsafeFreeze =<< A.shrink mary j
return $! Collision h ary2
| Just el <- onColl $! A.index ary i
= A.write mary j el >> step ary mary (i+1) (j+1) n
Expand Down
7 changes: 1 addition & 6 deletions Data/HashMap/Internal/Array.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ module Data.HashMap.Internal.Array
, insertM
, delete
, sameArray1
, trim

, unsafeFreeze
, unsafeThaw
, unsafeSameArray
, run
, copy
, copyM
, cloneM

-- * Folds
, foldl
Expand Down Expand Up @@ -318,11 +318,6 @@ cloneM _mary@(MArray mary#) _off@(I# off#) _len@(I# len#) =
case cloneSmallMutableArray# mary# off# len# s of
(# s', mary'# #) -> (# s', MArray mary'# #)

-- | Create a new array of the @n@ first elements of @mary@.
trim :: MArray s a -> Int -> ST s (Array a)
trim mary n = cloneM mary 0 n >>= unsafeFreeze
{-# INLINE trim #-}

-- | \(O(n)\) Insert an element at the given position in this array,
-- increasing its size by one.
insert :: Array e -> Int -> e -> Array e
Expand Down