diff --git a/containers-tests/tests/IntSetValidity.hs b/containers-tests/tests/IntSetValidity.hs index 5d341eff2..cc792b023 100644 --- a/containers-tests/tests/IntSetValidity.hs +++ b/containers-tests/tests/IntSetValidity.hs @@ -7,7 +7,6 @@ import Data.IntSet.Internal import Data.List (intercalate) import Numeric (showHex) import Test.Tasty.QuickCheck (Property, counterexample, property, (.&&.)) -import Utils.Containers.Internal.BitUtil (bitcount) {-------------------------------------------------------------------- Assertions diff --git a/containers/src/Data/IntSet/Internal.hs b/containers/src/Data/IntSet/Internal.hs index 572fc4e38..24a04c328 100644 --- a/containers/src/Data/IntSet/Internal.hs +++ b/containers/src/Data/IntSet/Internal.hs @@ -367,7 +367,7 @@ size :: IntSet -> Int size = go 0 where go !acc (Bin _ l r) = go (go acc l) r - go acc (Tip _ bm) = acc + bitcount 0 bm + go acc (Tip _ bm) = acc + popCount bm go acc Nil = acc -- | \(O(\min(n,W))\). Is the value a member of the set? diff --git a/containers/src/Utils/Containers/Internal/BitUtil.hs b/containers/src/Utils/Containers/Internal/BitUtil.hs index df876c4f4..05a7a21fb 100644 --- a/containers/src/Utils/Containers/Internal/BitUtil.hs +++ b/containers/src/Utils/Containers/Internal/BitUtil.hs @@ -1,7 +1,4 @@ {-# LANGUAGE CPP #-} -#if __GLASGOW_HASKELL__ -{-# LANGUAGE MagicHash #-} -#endif #if !defined(TESTING) && defined(__GLASGOW_HASKELL__) {-# LANGUAGE Safe #-} #endif @@ -31,38 +28,16 @@ -- closely. module Utils.Containers.Internal.BitUtil - ( bitcount - , highestBitMask + ( highestBitMask , shiftLL , shiftRL , wordSize ) where -import Data.Bits (popCount, unsafeShiftL, unsafeShiftR +import Data.Bits (unsafeShiftL, unsafeShiftR , countLeadingZeros, finiteBitSize ) - -{---------------------------------------------------------------------- - [bitcount] as posted by David F. Place to haskell-cafe on April 11, 2006, - based on the code on - http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan, - where the following source is given: - Published in 1988, the C Programming Language 2nd Ed. (by Brian W. - Kernighan and Dennis M. Ritchie) mentions this in exercise 2-9. On April - 19, 2006 Don Knuth pointed out to me that this method "was first published - by Peter Wegner in CACM 3 (1960), 322. (Also discovered independently by - Derrick Lehmer and published in 1964 in a book edited by Beckenbach.)" -----------------------------------------------------------------------} - -bitcount :: Int -> Word -> Int -bitcount a x = a + popCount x -{-# INLINE bitcount #-} - --- The highestBitMask implementation is based on --- http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 --- which has been put in the public domain. - -- | Return a word where only the highest bit is set. highestBitMask :: Word -> Word highestBitMask w = shiftLL 1 (wordSize - 1 - countLeadingZeros w)