From 4c9bdf60a1b90ec25d999deba494f581c59a8a7e Mon Sep 17 00:00:00 2001 From: meooow25 Date: Tue, 29 Oct 2024 03:42:10 +0530 Subject: [PATCH] Remove the Nat synonym --- containers/src/Data/IntMap/Internal.hs | 6 ----- containers/src/Data/IntSet/Internal.hs | 35 ++++++++++++-------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/containers/src/Data/IntMap/Internal.hs b/containers/src/Data/IntMap/Internal.hs index e6b68cd24..fe0e5c622 100644 --- a/containers/src/Data/IntMap/Internal.hs +++ b/containers/src/Data/IntMap/Internal.hs @@ -263,9 +263,6 @@ module Data.IntMap.Internal ( , showTree , showTreeWith - -- * Internal types - , Nat - -- * Utility , link , linkKey @@ -333,9 +330,6 @@ import Text.Read import qualified Control.Category as Category --- A "Nat" is a natural machine word (an unsigned Int) -type Nat = Word - {-------------------------------------------------------------------- Types --------------------------------------------------------------------} diff --git a/containers/src/Data/IntSet/Internal.hs b/containers/src/Data/IntSet/Internal.hs index 5c01ab5fe..af87654ea 100644 --- a/containers/src/Data/IntSet/Internal.hs +++ b/containers/src/Data/IntSet/Internal.hs @@ -241,9 +241,6 @@ import Data.Functor.Identity (Identity(..)) infixl 9 \\{-This comment teaches CPP correct behaviour -} --- A "Nat" is a natural machine word (an unsigned Int) -type Nat = Word - {-------------------------------------------------------------------- Operators --------------------------------------------------------------------} @@ -1678,18 +1675,18 @@ bitmapOf x = bitmapOfSuffix (suffixOf x) The signatures of methods in question are placed after this comment. ----------------------------------------------------------------------} -lowestBitSet :: Nat -> Int -highestBitSet :: Nat -> Int -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 +lowestBitSet :: Word -> Int +highestBitSet :: Word -> Int +foldlBits :: Int -> (a -> Int -> a) -> a -> Word -> a +foldl'Bits :: Int -> (a -> Int -> a) -> a -> Word -> a +foldrBits :: Int -> (Int -> a -> a) -> a -> Word -> a +foldr'Bits :: Int -> (Int -> a -> a) -> a -> Word -> a #if MIN_VERSION_base(4,11,0) -foldMapBits :: Semigroup a => Int -> (Int -> a) -> Nat -> a +foldMapBits :: Semigroup a => Int -> (Int -> a) -> Word -> a #else -foldMapBits :: Monoid a => Int -> (Int -> a) -> Nat -> a +foldMapBits :: Monoid a => Int -> (Int -> a) -> Word -> a #endif -takeWhileAntitoneBits :: Int -> (Int -> Bool) -> Nat -> Nat +takeWhileAntitoneBits :: Int -> (Int -> Bool) -> Word -> Word {-# INLINE lowestBitSet #-} {-# INLINE highestBitSet #-} @@ -1702,7 +1699,7 @@ takeWhileAntitoneBits :: Int -> (Int -> Bool) -> Nat -> Nat #if defined(__GLASGOW_HASKELL__) -lowestBitMask :: Nat -> Nat +lowestBitMask :: Word -> Word lowestBitMask x = x .&. negate x {-# INLINE lowestBitMask #-} @@ -1710,16 +1707,16 @@ lowestBitSet x = countTrailingZeros x highestBitSet x = WORD_SIZE_IN_BITS - 1 - countLeadingZeros x --- Reverse the order of bits in the Nat. -revNat :: Nat -> Nat +-- Reverse the order of bits in the Word. +revWord :: Word -> Word #if WORD_SIZE_IN_BITS==32 -revNat x1 = case ((x1 `shiftRL` 1) .&. 0x55555555) .|. ((x1 .&. 0x55555555) `shiftLL` 1) of +revWord x1 = case ((x1 `shiftRL` 1) .&. 0x55555555) .|. ((x1 .&. 0x55555555) `shiftLL` 1) of x2 -> case ((x2 `shiftRL` 2) .&. 0x33333333) .|. ((x2 .&. 0x33333333) `shiftLL` 2) of x3 -> case ((x3 `shiftRL` 4) .&. 0x0F0F0F0F) .|. ((x3 .&. 0x0F0F0F0F) `shiftLL` 4) of x4 -> case ((x4 `shiftRL` 8) .&. 0x00FF00FF) .|. ((x4 .&. 0x00FF00FF) `shiftLL` 8) of x5 -> ( x5 `shiftRL` 16 ) .|. ( x5 `shiftLL` 16); #else -revNat x1 = case ((x1 `shiftRL` 1) .&. 0x5555555555555555) .|. ((x1 .&. 0x5555555555555555) `shiftLL` 1) of +revWord x1 = case ((x1 `shiftRL` 1) .&. 0x5555555555555555) .|. ((x1 .&. 0x5555555555555555) `shiftLL` 1) of x2 -> case ((x2 `shiftRL` 2) .&. 0x3333333333333333) .|. ((x2 .&. 0x3333333333333333) `shiftLL` 2) of x3 -> case ((x3 `shiftRL` 4) .&. 0x0F0F0F0F0F0F0F0F) .|. ((x3 .&. 0x0F0F0F0F0F0F0F0F) `shiftLL` 4) of x4 -> case ((x4 `shiftRL` 8) .&. 0x00FF00FF00FF00FF) .|. ((x4 .&. 0x00FF00FF00FF00FF) `shiftLL` 8) of @@ -1740,14 +1737,14 @@ foldl'Bits prefix f z bitmap = go bitmap z where !bitmask = lowestBitMask bm !bi = countTrailingZeros bitmask -foldrBits prefix f z bitmap = go (revNat bitmap) z +foldrBits prefix f z bitmap = go (revWord bitmap) z where go 0 acc = acc go bm acc = go (bm `xor` bitmask) ((f $! (prefix+(WORD_SIZE_IN_BITS-1)-bi)) acc) where !bitmask = lowestBitMask bm !bi = countTrailingZeros bitmask -foldr'Bits prefix f z bitmap = go (revNat bitmap) z +foldr'Bits prefix f z bitmap = go (revWord bitmap) z where go 0 acc = acc go bm !acc = go (bm `xor` bitmask) ((f $! (prefix+(WORD_SIZE_IN_BITS-1)-bi)) acc) where !bitmask = lowestBitMask bm