Skip to content

Commit e680073

Browse files
committed
Replace tuples with strict datatype
This commit changes the recursive helpers in functions that modify a hashmap's size to return a 'Sized' value (with strict fields) instead of the base tuples.
1 parent d551025 commit e680073

File tree

3 files changed

+186
-182
lines changed

3 files changed

+186
-182
lines changed

Data/HashMap/Array.hs

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Data.HashMap.Array
1010
, RunRes (..)
1111
, RunResA
1212
, RunResM
13+
, Sized (..)
1314

1415
-- * Creation
1516
, new
@@ -316,12 +317,17 @@ updateWith' :: Array e -> Int -> (e -> e) -> Array e
316317
updateWith' ary idx f = update ary idx $! f (index ary idx)
317318
{-# INLINE updateWith' #-}
318319

320+
-- | Helper datatype used in 'updateWithInternal''. Used when a change in
321+
-- a value's size must be returned along with the value itself (typically
322+
-- a hashmap).
323+
data Sized a = Sized {-# UNPACK #-} !Int !a
324+
319325
-- | /O(n)/ Update the element at the given positio in this array, by
320326
-- applying a function to it. Evaluates the element to WHNF before
321327
-- inserting it into the array.
322-
updateWithInternal' :: Array e -> Int -> (e -> (Int, e)) -> RunResA e
328+
updateWithInternal' :: Array e -> Int -> (e -> Sized e) -> RunResA e
323329
updateWithInternal' ary idx f =
324-
let !(!sz, !e) = f (index ary idx)
330+
let Sized sz e = f (index ary idx)
325331
in RunRes sz (update ary idx e)
326332
{-# INLINE updateWithInternal' #-}
327333

0 commit comments

Comments
 (0)