-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Labels
Description
Can we expose the tooling around LookupRes from proper public modules, so we can improve the instance like this?
type instance IxValue (HashMap k a) = a
instance (Eq k, Hashable k) => Ixed (HashMap k a) where
- ix k f m = case HashMap.lookup k m of
- Just v -> f v <&> \v' -> HashMap.insert k v' m
- Nothing -> pure m
+ ix k f m = case HashMap.Internal.lookupRecordCollision h k m of
+ HashMap.Internal.Present v i ->
+ f v <&> \v' -> HashMap.Internal.insertKeyExists i h k v' m
+ HashMap.Internal.Absent -> pure m
+ where h = HashMap.Internal.hash k
{-# INLINE ix #-}For now, I suspect that even an implementation via ixAt (i.e. alterF) might be more efficient than the current one.