Repository navigation
Conversation
Use a strict pair in the go helpers and force the rebuilt set before wrapping it in Just. Fixes haskell#1251.
|
How does this compare to |
Check for the empty set first and return Just right away, with the tree walk in NOINLINE minViewSure/maxViewSure helpers, like IntMap's minViewWithKey/minViewWithKeySure. minView and maxView are INLINE, so callers like deleteMin can avoid the Maybe and the pair.
|
Good point, thanks. I've updated the PR to follow IntMap's design, which is also what the issue suggested: With |
|
Is this patch LLM-generated? |
|
Well, no, I'm not a bot and it's a PR I've implemented and designed. However, of course I use AI to understand concepts and review my work. |
| _ -> Just $ case maxViewSure t of result :*: t' -> (result, t') | ||
| {-# INLINE maxView #-} | ||
|
|
||
| maxViewSure :: IntSet -> StrictPair Key IntSet |
There was a problem hiding this comment.
Looks good overall, but instead of StrictPair we should have View type like for IntMap:
containers/containers/src/Data/IntMap/Internal.hs
Line 2393 in c9c0c88
This makes a difference for GHC <9.4, documented here:
containers/containers/src/Data/IntSet/Internal.hs
Lines 1811 to 1815 in c9c0c88
Fixes #1251.
minViewandmaxViewnow follow IntMap'sminViewWithKey/minViewWithKeySuredesign, as suggested in the issue: they check for the empty set first and returnJustright away, with the tree walk inNOINLINEminViewSure/maxViewSurehelpers. The helpers return aStrictPairinstead of a lazy tuple (IntMap uses itsViewtype, but IntSet has no values), so the rebuilt set is constructed right away instead of being left as a thunk.With
minView/maxViewmarkedINLINE, callers likedeleteMinavoid theMaybeand the pair entirely. Core fordeleteMin(GHC 9.10.3):Benchmarks (
intset-benchmarks, GHC 9.10.3, aarch64-osx):intset-propertiespasses.