|
delete :: Key -> IntMap a -> IntMap a |
|
delete !k t@(Bin p l r) |
|
| nomatch k p = t |
|
| left k p = binCheckL p (delete k l) r |
|
| otherwise = binCheckR p l (delete k r) |
|
delete k t@(Tip ky _) |
|
| k == ky = Nil |
|
| otherwise = t |
|
delete _k Nil = Nil |
I noticed some code in GHC that performs a bunch of deletions (on the very similar Word64Map) with keys that are most likely absent from the map. So now I'm wondering whether to introduce pointer-checks in Word64Map.delete or to split off a delete_possiblyAbsent version or…
But since Word64Map is derived from IntMap, my first question is: why doesn't IntMap.delete perform these pointer-checks already, even though Map.delete does?
|
delete :: Ord k => k -> Map k a -> Map k a |
|
delete = go |
|
where |
|
go :: Ord k => k -> Map k a -> Map k a |
|
go !_ Tip = Tip |
|
go k t@(Bin _ kx x l r) = |
|
case compare k kx of |
|
LT | l' `ptrEq` l -> t |
|
| otherwise -> balanceR kx x l' r |
|
where !l' = go k l |
|
GT | r' `ptrEq` r -> t |
|
| otherwise -> balanceL kx x l r' |
|
where !r' = go k r |
|
EQ -> glue l r |
|
{-# INLINABLE delete #-} |
containers/containers/src/Data/IntMap/Internal.hs
Lines 966 to 974 in 78da761
I noticed some code in GHC that performs a bunch of deletions (on the very similar
Word64Map) with keys that are most likely absent from the map. So now I'm wondering whether to introduce pointer-checks inWord64Map.deleteor to split off adelete_possiblyAbsentversion or…But since
Word64Mapis derived fromIntMap, my first question is: why doesn'tIntMap.deleteperform these pointer-checks already, even thoughMap.deletedoes?containers/containers/src/Data/Map/Internal.hs
Lines 941 to 955 in 78da761