Skip to content

Commit 61eb586

Browse files
oberblastmeistersjakobi
authored andcommitted
add to strict HashMap
1 parent 8e02578 commit 61eb586

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

Data/HashMap/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ update f = Exts.inline alter (>>= f)
12731273
-- 'lookup' k ('alter' f k m) = f ('lookup' k m)
12741274
-- @
12751275
alter :: (Eq k, Hashable k) => (Maybe v -> Maybe v) -> k -> HashMap k v -> HashMap k v
1276-
alter f k = alter' f (hash k) k
1276+
alter f k = Exts.inline alter' f (hash k) k
12771277
{-# INLINABLE alter #-}
12781278

12791279
alter' :: Eq k => (Maybe v -> Maybe v) -> Hash -> k -> HashMap k v -> HashMap k v

Data/HashMap/Internal/Strict.hs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ adjust f k0 m0 = go h0 k0 0 m0
299299
-- (if it is in the map). If @(f x)@ is 'Nothing', the element is deleted.
300300
-- If it is @('Just' y)@, the key @k@ is bound to the new value @y@.
301301
update :: (Eq k, Hashable k) => (a -> Maybe a) -> k -> HashMap k a -> HashMap k a
302-
update f = alter (>>= f)
302+
update f = Exts.inline alter (>>= f)
303303
{-# INLINABLE update #-}
304304

305305
-- | \(O(\log n)\) The expression @('alter' f k map)@ alters the value @x@ at @k@, or
@@ -311,19 +311,9 @@ update f = alter (>>= f)
311311
-- 'lookup' k ('alter' f k m) = f ('lookup' k m)
312312
-- @
313313
alter :: (Eq k, Hashable k) => (Maybe v -> Maybe v) -> k -> HashMap k v -> HashMap k v
314-
alter f k m =
315-
let !h = hash k
316-
!lookupRes = HM.lookupRecordCollision h k m
317-
in case f (HM.lookupResToMaybe lookupRes) of
318-
Nothing -> case lookupRes of
319-
Absent -> m
320-
Present _ collPos -> HM.deleteKeyExists collPos h k m
321-
Just !v' -> case lookupRes of
322-
Absent -> HM.insertNewKey h k v' m
323-
Present v collPos ->
324-
if v `ptrEq` v'
325-
then m
326-
else HM.insertKeyExists collPos h k v' m
314+
alter f = Exts.inline HM.alter $ \m -> case f m of
315+
Nothing -> Nothing
316+
Just !x -> Just x
327317
{-# INLINABLE alter #-}
328318

329319
-- | \(O(\log n)\) The expression (@'alterF' f k map@) alters the value @x@ at

unordered-containers.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ library
6969
MagicHash,
7070
BangPatterns
7171

72-
-- ghc-options: -Wall -O2 -fwarn-tabs -ferror-spans
73-
ghc-options: -Wall -fwarn-tabs -ferror-spans
72+
ghc-options: -Wall -O2 -fwarn-tabs -ferror-spans
73+
-- ghc-options: -Wall -fwarn-tabs -ferror-spans
7474

7575
-- For dumping the generated code:
7676
-- ghc-options: -ddump-simpl -ddump-stg-final -ddump-cmm -ddump-asm -ddump-to-file

0 commit comments

Comments
 (0)