From 68e24da1b9a97f0095fe71eda03a6acb7779b32d Mon Sep 17 00:00:00 2001 From: Soumik Sarkar Date: Sun, 14 Jan 2024 05:45:42 +0530 Subject: [PATCH] Make IntMap split, splitLookup strict in the key (#982) Currently, the key is ignored for an empty map. All IntMap and IntSet functions taking a key are strict in the key. This allows the Int to be unboxed. --- containers/changelog.md | 9 +++++++++ containers/src/Data/IntMap/Internal.hs | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/containers/changelog.md b/containers/changelog.md index db7213a54..acf59fa59 100644 --- a/containers/changelog.md +++ b/containers/changelog.md @@ -1,5 +1,14 @@ # Changelog for [`containers` package](http://github.com/haskell/containers) +## Next release + +### Breaking changes + +* `Data.IntMap.Lazy.split`, `Data.IntMap.Strict.split`, + `Data.IntMap.Lazy.splitLookup` and `Data.IntMap.Strict.splitLookup` are now + strict in the key. Previously, the key was ignored for an empty map. + (Soumik Sarkar) + ## 0.7 ### Breaking changes diff --git a/containers/src/Data/IntMap/Internal.hs b/containers/src/Data/IntMap/Internal.hs index 0195a22a1..4a4b7107d 100644 --- a/containers/src/Data/IntMap/Internal.hs +++ b/containers/src/Data/IntMap/Internal.hs @@ -2815,7 +2815,7 @@ split k t = _ -> case go k t of (lt :*: gt) -> (lt, gt) where - go k' t'@(Bin p m l r) + go !k' t'@(Bin p m l r) | nomatch k' p m = if k' > p then t' :*: Nil else Nil :*: t' | zero k' m = case go k' l of (lt :*: gt) -> lt :*: bin p m gt r | otherwise = case go k' r of (lt :*: gt) -> bin p m l lt :*: gt @@ -2857,7 +2857,7 @@ splitLookup k t = _ -> go k t of SplitLookup lt fnd gt -> (lt, fnd, gt) where - go k' t'@(Bin p m l r) + go !k' t'@(Bin p m l r) | nomatch k' p m = if k' > p then SplitLookup t' Nothing Nil