Skip to content

Commit

Permalink
Fix pre-Semigroup-Monoid stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
meooow25 committed Oct 3, 2024
1 parent e0a2f87 commit fdd057a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions containers/src/Data/IntSet/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,11 +1256,20 @@ foldMap :: Monoid a => (Key -> a) -> IntSet -> a
foldMap f = \t -> -- Use lambda t to be inlinable with one argument only.
case t of
Bin p l r
#if MIN_VERSION_base(4,11,0)
| signBranch p -> go r <> go l -- handle negative numbers
| otherwise -> go l <> go r
#else
| signBranch p -> go r `mappend` go l -- handle negative numbers
| otherwise -> go l `mappend` go r
#endif
_ -> go t
where
#if MIN_VERSION_base(4,11,0)
go (Bin _ l r) = go l <> go r
#else
go (Bin _ l r) = go l `mappend` go r
#endif
go (Tip kx bm) = foldMapBits kx f bm
go Nil = mempty
{-# INLINE foldMap #-}
Expand Down Expand Up @@ -1688,7 +1697,11 @@ foldlBits :: Int -> (a -> Int -> a) -> a -> Nat -> a
foldl'Bits :: Int -> (a -> Int -> a) -> a -> Nat -> a
foldrBits :: Int -> (Int -> a -> a) -> a -> Nat -> a
foldr'Bits :: Int -> (Int -> a -> a) -> a -> Nat -> a
#if MIN_VERSION_base(4,11,0)
foldMapBits :: Semigroup a => Int -> (Int -> a) -> Nat -> a
#else
foldMapBits :: Monoid a => Int -> (Int -> a) -> Nat -> a
#endif
takeWhileAntitoneBits :: Int -> (Int -> Bool) -> Nat -> Nat

{-# INLINE lowestBitSet #-}
Expand Down Expand Up @@ -1758,7 +1771,11 @@ foldMapBits prefix f bitmap = go (prefix + bi0) (bitmap `xor` bitmask0)
bitmask0 = lowestBitMask bitmap
bi0 = countTrailingZeros bitmask0
go !x 0 = f x
#if MIN_VERSION_base(4,11,0)
go !x bm = f x <> go (prefix + bi) (bm `xor` bitmask)
#else
go !x bm = f x `mappend` go (prefix + bi) (bm `xor` bitmask)
#endif
where
bitmask = lowestBitMask bm
bi = countTrailingZeros bitmask
Expand Down Expand Up @@ -1841,7 +1858,11 @@ foldMapBits prefix f bm = go x0 (x0 + 1) ((bm `shiftRL` lb) `shiftRL` 1)
x0 = prefix + lb
go !x !_ 0 = f x
go !x !bi n
#if MIN_VERSION_base(4,11,0)
| n `testBit` 0 = f x <> go bi (bi + 1) (n `shiftRL` 1)
#else
| n `testBit` 0 = f x `mappend` go bi (bi + 1) (n `shiftRL` 1)
#endif
| otherwise = go x (bi + 1) (n `shiftRL` 1)

takeWhileAntitoneBits prefix predicate = foldl'Bits prefix f 0 -- Does not use antitone property
Expand Down

0 comments on commit fdd057a

Please sign in to comment.