Skip to content

Tweak Array.deleteM #360

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

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 6 additions & 6 deletions Data/HashMap/Internal/Array.hs
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,13 @@ delete ary idx = runST (deleteM ary idx)
-- | /O(n)/ Delete an element at the given position in this array,
-- decreasing its size by one.
deleteM :: Array e -> Int -> ST s (Array e)
deleteM ary idx = do
deleteM ary0 idx = do
CHECK_BOUNDS("deleteM", count, idx)
do mary <- new_ (count-1)
copy ary 0 mary 0 idx
copy ary (idx+1) mary idx (count-(idx+1))
unsafeFreeze mary
where !count = length ary
do mary0 <- unsafeThaw ary0
mary1 <- cloneM mary0 0 (count-1)
copy ary0 (idx+1) mary1 idx (count-(idx+1))
unsafeFreeze mary1
where !count = length ary0
{-# INLINE deleteM #-}

map :: (a -> b) -> Array a -> Array b
Expand Down