hw-bits 0.6.0.0 → 0.7.0.0
raw patch · 24 files changed
+122/−477 lines, 24 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- HaskellWorks.Data.Bits.PopCount: class PopCount v e
- HaskellWorks.Data.Bits.PopCount: popCount :: PopCount v e => e -> v -> Count
- HaskellWorks.Data.Bits.Unmatched: class UnmatchedL0 a
- HaskellWorks.Data.Bits.Unmatched: class UnmatchedL1 a
- HaskellWorks.Data.Bits.Unmatched: class UnmatchedR0 a
- HaskellWorks.Data.Bits.Unmatched: class UnmatchedR1 a
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL0 (Data.Vector.Storable.Vector GHC.Word.Word16)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL0 (Data.Vector.Storable.Vector GHC.Word.Word32)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL0 (Data.Vector.Storable.Vector GHC.Word.Word64)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL0 (Data.Vector.Storable.Vector GHC.Word.Word8)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL0 GHC.Word.Word16
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL0 GHC.Word.Word32
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL0 GHC.Word.Word64
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL0 GHC.Word.Word8
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL1 (Data.Vector.Storable.Vector GHC.Word.Word16)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL1 (Data.Vector.Storable.Vector GHC.Word.Word32)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL1 (Data.Vector.Storable.Vector GHC.Word.Word64)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL1 (Data.Vector.Storable.Vector GHC.Word.Word8)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL1 GHC.Word.Word16
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL1 GHC.Word.Word32
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL1 GHC.Word.Word64
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedL1 GHC.Word.Word8
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR0 (Data.Vector.Storable.Vector GHC.Word.Word16)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR0 (Data.Vector.Storable.Vector GHC.Word.Word32)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR0 (Data.Vector.Storable.Vector GHC.Word.Word64)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR0 (Data.Vector.Storable.Vector GHC.Word.Word8)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR0 GHC.Word.Word16
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR0 GHC.Word.Word32
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR0 GHC.Word.Word64
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR0 GHC.Word.Word8
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR1 (Data.Vector.Storable.Vector GHC.Word.Word16)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR1 (Data.Vector.Storable.Vector GHC.Word.Word32)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR1 (Data.Vector.Storable.Vector GHC.Word.Word64)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR1 (Data.Vector.Storable.Vector GHC.Word.Word8)
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR1 GHC.Word.Word16
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR1 GHC.Word.Word32
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR1 GHC.Word.Word64
- HaskellWorks.Data.Bits.Unmatched: instance HaskellWorks.Data.Bits.Unmatched.UnmatchedR1 GHC.Word.Word8
- HaskellWorks.Data.Bits.Unmatched: unmatchedL0 :: UnmatchedL0 a => a -> Int
- HaskellWorks.Data.Bits.Unmatched: unmatchedL1 :: UnmatchedL1 a => a -> Int
- HaskellWorks.Data.Bits.Unmatched: unmatchedR0 :: UnmatchedR0 a => a -> Int
- HaskellWorks.Data.Bits.Unmatched: unmatchedR1 :: UnmatchedR1 a => a -> Int
Files
- LICENSE +1/−1
- hw-bits.cabal +1/−3
- src/HaskellWorks/Data/Bits.hs +7/−12
- src/HaskellWorks/Data/Bits/AllExcess/AllExcess0.hs +6/−5
- src/HaskellWorks/Data/Bits/AllExcess/AllExcess1.hs +7/−6
- src/HaskellWorks/Data/Bits/BitLength.hs +10/−13
- src/HaskellWorks/Data/Bits/BitParse.hs +10/−14
- src/HaskellWorks/Data/Bits/BitRead.hs +8/−7
- src/HaskellWorks/Data/Bits/BitShow.hs +0/−5
- src/HaskellWorks/Data/Bits/BitWise.hs +14/−18
- src/HaskellWorks/Data/Bits/Broadword.hs +18/−22
- src/HaskellWorks/Data/Bits/ElemFixedBitSize.hs +5/−10
- src/HaskellWorks/Data/Bits/FixedBitSize.hs +2/−8
- src/HaskellWorks/Data/Bits/FromBitTextByteString.hs +21/−20
- src/HaskellWorks/Data/Bits/LoBitsSized.hs +1/−0
- src/HaskellWorks/Data/Bits/Log2.hs +1/−0
- src/HaskellWorks/Data/Bits/PopCount.hs +3/−15
- src/HaskellWorks/Data/Bits/PopCount/PopCount0.hs +1/−6
- src/HaskellWorks/Data/Bits/PopCount/PopCount1.hs +1/−6
- src/HaskellWorks/Data/Bits/Types/Broadword.hs +1/−6
- src/HaskellWorks/Data/Bits/Types/Builtin.hs +1/−6
- src/HaskellWorks/Data/Bits/Unmatched.hs +0/−206
- src/HaskellWorks/Data/Bits/Word.hs +3/−0
- test/HaskellWorks/Data/Bits/UnmatchedSpec.hs +0/−88
LICENSE view
@@ -1,4 +1,4 @@-Copyright John Ky (c) 2016+Copyright John Ky (c) 2017 All rights reserved.
hw-bits.cabal view
@@ -1,5 +1,5 @@ name: hw-bits-version: 0.6.0.0+version: 0.7.0.0 synopsis: Bit manipulation description: Please see README.md homepage: http://github.com/haskell-works/hw-bits#readme@@ -41,7 +41,6 @@ , HaskellWorks.Data.Bits.PopCount.PopCount1 , HaskellWorks.Data.Bits.Types.Broadword , HaskellWorks.Data.Bits.Types.Builtin- , HaskellWorks.Data.Bits.Unmatched , HaskellWorks.Data.Bits.Word build-depends: base >= 4 && < 5 , bytestring@@ -66,7 +65,6 @@ , HaskellWorks.Data.Bits.BitWiseSpec , HaskellWorks.Data.Bits.FromBitTextByteStringSpec , HaskellWorks.Data.Bits.Log2Spec- , HaskellWorks.Data.Bits.UnmatchedSpec build-depends: base >= 4 && < 5 , bytestring , hspec
src/HaskellWorks/Data/Bits.hs view
@@ -1,16 +1,11 @@--- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations. module HaskellWorks.Data.Bits ( module X ) where -import HaskellWorks.Data.Bits.BitLength as X-import HaskellWorks.Data.Bits.BitParse as X-import HaskellWorks.Data.Bits.BitRead as X-import HaskellWorks.Data.Bits.BitShow as X-import HaskellWorks.Data.Bits.BitShown as X-import HaskellWorks.Data.Bits.BitWise as X-import HaskellWorks.Data.Bits.PopCount as X+import HaskellWorks.Data.Bits.BitLength as X+import HaskellWorks.Data.Bits.BitParse as X+import HaskellWorks.Data.Bits.BitRead as X+import HaskellWorks.Data.Bits.BitShow as X+import HaskellWorks.Data.Bits.BitShown as X+import HaskellWorks.Data.Bits.BitWise as X+import HaskellWorks.Data.Bits.PopCount as X
src/HaskellWorks/Data/Bits/AllExcess/AllExcess0.hs view
@@ -2,13 +2,14 @@ module HaskellWorks.Data.Bits.AllExcess.AllExcess0 where -import Data.Word-import qualified Data.Vector.Storable as DVS-import HaskellWorks.Data.Bits.PopCount.PopCount0-import HaskellWorks.Data.Bits.PopCount.PopCount1+import Data.Word+import HaskellWorks.Data.Bits.PopCount.PopCount0+import HaskellWorks.Data.Bits.PopCount.PopCount1 --- TODO Optimise these instances+import qualified Data.Vector.Storable as DVS+ class AllExcess0 a where+ -- | Number of 0-bits minues the number of 1-bits. allExcess0 :: a -> Int instance AllExcess0 [Bool] where
src/HaskellWorks/Data/Bits/AllExcess/AllExcess1.hs view
@@ -2,14 +2,15 @@ module HaskellWorks.Data.Bits.AllExcess.AllExcess1 where -import Data.Word-import qualified Data.Vector as DV-import qualified Data.Vector.Storable as DVS-import HaskellWorks.Data.Bits.PopCount.PopCount0-import HaskellWorks.Data.Bits.PopCount.PopCount1+import Data.Word+import HaskellWorks.Data.Bits.PopCount.PopCount0+import HaskellWorks.Data.Bits.PopCount.PopCount1 --- TODO Optimise these instances+import qualified Data.Vector as DV+import qualified Data.Vector.Storable as DVS+ class AllExcess1 a where+ -- | Number of 1-bits minues the number of 0-bits. allExcess1 :: a -> Int instance AllExcess1 [Bool] where
src/HaskellWorks/Data/Bits/BitLength.hs view
@@ -2,11 +2,6 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} --- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations. module HaskellWorks.Data.Bits.BitLength ( -- * Bit map BitLength(..)@@ -14,18 +9,20 @@ , elemBitEnd ) where -import qualified Data.Vector as DV-import qualified Data.Vector.Storable as DVS-import Data.Word-import HaskellWorks.Data.AtIndex-import HaskellWorks.Data.Naive-import HaskellWorks.Data.Positioning-import Prelude hiding (length)+import Data.Word+import HaskellWorks.Data.AtIndex+import HaskellWorks.Data.Naive+import HaskellWorks.Data.Positioning+import Prelude hiding (length) --- | Number of bits in a value including ones and zeros.+import qualified Data.Vector as DV+import qualified Data.Vector.Storable as DVS+ class BitLength v where+ -- | Number of bits in a value including ones and zeros. bitLength :: v -> Count + -- | Number of bits in a value including ones and zeros as a position. endPosition :: v -> Position endPosition = toPosition . bitLength {-# INLINE endPosition #-}
src/HaskellWorks/Data/Bits/BitParse.hs view
@@ -1,24 +1,20 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE ScopedTypeVariables #-} --- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations. module HaskellWorks.Data.Bits.BitParse ( BitParse(..) ) where -import Control.Applicative-import qualified Data.ByteString as BS-import qualified Data.Vector as DV-import qualified Data.Vector.Storable as DVS-import Data.Word-import GHC.Exts-import HaskellWorks.Data.Bits.BitLength-import HaskellWorks.Data.Bits.BitWise-import HaskellWorks.Data.String.Parse+import Control.Applicative+import Data.Word+import GHC.Exts+import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Bits.BitWise+import HaskellWorks.Data.String.Parse++import qualified Data.ByteString as BS+import qualified Data.Vector as DV+import qualified Data.Vector.Storable as DVS -- | Parsers for bit strings class BitParse a where
src/HaskellWorks/Data/Bits/BitRead.hs view
@@ -6,13 +6,14 @@ ( BitRead(..) ) where -import qualified Data.ByteString as BS-import Data.Maybe-import qualified Data.Vector as DV-import qualified Data.Vector.Storable as DVS-import Data.Word-import HaskellWorks.Data.Bits.BitParse-import HaskellWorks.Data.String.Parse+import Data.Maybe+import Data.Word+import HaskellWorks.Data.Bits.BitParse+import HaskellWorks.Data.String.Parse++import qualified Data.ByteString as BS+import qualified Data.Vector as DV+import qualified Data.Vector.Storable as DVS -- | Bit string reader that produces a value of a type class BitRead a where
src/HaskellWorks/Data/Bits/BitShow.hs view
@@ -1,11 +1,6 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE ScopedTypeVariables #-} --- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations. module HaskellWorks.Data.Bits.BitShow ( BitShow(..) , bitShow
src/HaskellWorks/Data/Bits/BitWise.hs view
@@ -2,11 +2,6 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} --- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations. module HaskellWorks.Data.Bits.BitWise ( -- * Bit map BitWise(..)@@ -14,16 +9,17 @@ , TestBit(..) ) where -import qualified Data.Bits as B-import qualified Data.Vector as DV-import qualified Data.Vector.Storable as DVS-import Data.Word-import HaskellWorks.Data.AtIndex-import HaskellWorks.Data.Bits.BitLength-import HaskellWorks.Data.Naive-import HaskellWorks.Data.Positioning-import Prelude as P+import Data.Word+import HaskellWorks.Data.AtIndex+import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Naive+import HaskellWorks.Data.Positioning+import Prelude as P +import qualified Data.Bits as B+import qualified Data.Vector as DV+import qualified Data.Vector.Storable as DVS+ -- We pervasively use precedence to avoid excessive parentheses, and we use -- the same precedence conventions of the C programming language: arithmetic -- operators come first, ordered in the standard way, followed by shifts,@@ -48,13 +44,13 @@ -- | Class of values that have bit wise logical operations class BitWise a where- -- | Bit wise AND+ -- | Bit-wise AND (.&.) :: a -> a -> a- -- | Bit wise OR+ -- | Bit-wise OR (.|.) :: a -> a -> a- -- | Bit wise XOR+ -- | Bit-wise XOR (.^.) :: a -> a -> a- -- | Bit wise complement+ -- | Bit-wise complement comp :: a -> a -- | Bit-wise value of the given type with all bits set to zero all0s :: a
src/HaskellWorks/Data/Bits/Broadword.hs view
@@ -3,11 +3,6 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} --- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations. module HaskellWorks.Data.Bits.Broadword ( Broadword(..) , broadword@@ -19,10 +14,11 @@ , kBitDiffUnsafe ) where -import qualified Data.Bits as DB-import Data.Word-import HaskellWorks.Data.Bits.BitWise+import Data.Word+import HaskellWorks.Data.Bits.BitWise +import qualified Data.Bits as DB+ newtype Broadword a = Broadword a deriving (Eq, Show) broadword :: Broadword Word64 -> Word64@@ -30,23 +26,23 @@ {-# INLINE broadword #-} l :: Int -> Word64-l 2 = 0x5555555555555555-l 4 = 0x1111111111111111-l 8 = 0x0101010101010101-l 16 = 0x0001000100010001-l 32 = 0x0000000100000001-l 64 = 0x0000000000000001-l k = error ("Invalid h k where k = " ++ show k)+l 2 = 0x5555555555555555+l 4 = 0x1111111111111111+l 8 = 0x0101010101010101+l 16 = 0x0001000100010001+l 32 = 0x0000000100000001+l 64 = 0x0000000000000001+l k = error ("Invalid h k where k = " ++ show k) {-# INLINE l #-} h :: Int -> Word64-h 2 = 0xaaaaaaaaaaaaaaaa-h 4 = 0x8888888888888888-h 8 = 0x8080808080808080-h 16 = 0x8000800080008000-h 32 = 0x8000000080000000-h 64 = 0x8000000000000000-h k = error ("Invalid h k where k = " ++ show k)+h 2 = 0xaaaaaaaaaaaaaaaa+h 4 = 0x8888888888888888+h 8 = 0x8080808080808080+h 16 = 0x8000800080008000+h 32 = 0x8000000080000000+h 64 = 0x8000000000000000+h k = error ("Invalid h k where k = " ++ show k) {-# INLINE h #-} kBitDiff :: Int -> Word64 -> Word64 -> Word64
src/HaskellWorks/Data/Bits/ElemFixedBitSize.hs view
@@ -1,20 +1,15 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeFamilies #-} --- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations.- module HaskellWorks.Data.Bits.ElemFixedBitSize ( ElemFixedBitSize(..) ) where -import qualified Data.Vector as DV-import qualified Data.Vector.Storable as DVS-import Data.Word-import HaskellWorks.Data.Positioning+import Data.Word+import HaskellWorks.Data.Positioning++import qualified Data.Vector as DV+import qualified Data.Vector.Storable as DVS -- | Class of values that have elements of a fixed bit size --
src/HaskellWorks/Data/Bits/FixedBitSize.hs view
@@ -1,15 +1,9 @@--- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations.- module HaskellWorks.Data.Bits.FixedBitSize ( FixedBitSize(..) ) where -import Data.Word-import HaskellWorks.Data.Positioning+import Data.Word+import HaskellWorks.Data.Positioning -- | Class of values that have a fix bit size class FixedBitSize a where
src/HaskellWorks/Data/Bits/FromBitTextByteString.hs view
@@ -1,14 +1,15 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE InstanceSigs #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE InstanceSigs #-} module HaskellWorks.Data.Bits.FromBitTextByteString ( FromBitTextByteString(..) ) where +import Data.Word+import HaskellWorks.Data.Bits+ import qualified Data.ByteString as BS import qualified Data.Vector.Storable as DVS-import Data.Word-import HaskellWorks.Data.Bits class FromBitTextByteString a where -- | Convert a binary byte string to a value of type @a@@ -21,16 +22,16 @@ gen cs = case BS.uncons cs of Just (d, ds) | d == w0 -> gen' 1 0 ds Just (d, ds) | d == w1 -> gen' 1 1 ds- Just (_, ds) -> gen ds- Nothing -> Nothing+ Just (_, ds) -> gen ds+ Nothing -> Nothing gen' :: Int -> Word8 -> BS.ByteString -> Maybe (Word8, BS.ByteString) gen' n w cs | n >= 8 = Just (w, cs) | otherwise = case BS.uncons cs of Just (d, ds) | d == w0 -> gen' (n + 1) (w .|. (0 .<. fromIntegral n)) ds Just (d, ds) | d == w1 -> gen' (n + 1) (w .|. (1 .<. fromIntegral n)) ds- Just (_, ds) -> gen' n w ds- Nothing -> Just (w, cs)+ Just (_, ds) -> gen' n w ds+ Nothing -> Just (w, cs) instance FromBitTextByteString (DVS.Vector Word16) where fromBitTextByteString :: BS.ByteString -> DVS.Vector Word16@@ -39,16 +40,16 @@ gen cs = case BS.uncons cs of Just (d, ds) | d == w0 -> gen' 1 0 ds Just (d, ds) | d == w1 -> gen' 1 1 ds- Just (_, ds) -> gen ds- Nothing -> Nothing+ Just (_, ds) -> gen ds+ Nothing -> Nothing gen' :: Int -> Word16 -> BS.ByteString -> Maybe (Word16, BS.ByteString) gen' n w cs | n >= 16 = Just (w, cs) | otherwise = case BS.uncons cs of Just (d, ds) | d == w0 -> gen' (n + 1) (w .|. (0 .<. fromIntegral n)) ds Just (d, ds) | d == w1 -> gen' (n + 1) (w .|. (1 .<. fromIntegral n)) ds- Just (_, ds) -> gen' n w ds- Nothing -> Just (w, cs)+ Just (_, ds) -> gen' n w ds+ Nothing -> Just (w, cs) instance FromBitTextByteString (DVS.Vector Word32) where fromBitTextByteString :: BS.ByteString -> DVS.Vector Word32@@ -57,16 +58,16 @@ gen cs = case BS.uncons cs of Just (d, ds) | d == w0 -> gen' 1 0 ds Just (d, ds) | d == w1 -> gen' 1 1 ds- Just (_, ds) -> gen ds- Nothing -> Nothing+ Just (_, ds) -> gen ds+ Nothing -> Nothing gen' :: Int -> Word32 -> BS.ByteString -> Maybe (Word32, BS.ByteString) gen' n w cs | n >= 32 = Just (w, cs) | otherwise = case BS.uncons cs of Just (d, ds) | d == w0 -> gen' (n + 1) (w .|. (0 .<. fromIntegral n)) ds Just (d, ds) | d == w1 -> gen' (n + 1) (w .|. (1 .<. fromIntegral n)) ds- Just (_, ds) -> gen' n w ds- Nothing -> Just (w, cs)+ Just (_, ds) -> gen' n w ds+ Nothing -> Just (w, cs) instance FromBitTextByteString (DVS.Vector Word64) where fromBitTextByteString :: BS.ByteString -> DVS.Vector Word64@@ -75,16 +76,16 @@ gen cs = case BS.uncons cs of Just (d, ds) | d == w0 -> gen' 1 0 ds Just (d, ds) | d == w1 -> gen' 1 1 ds- Just (_, ds) -> gen ds- Nothing -> Nothing+ Just (_, ds) -> gen ds+ Nothing -> Nothing gen' :: Int -> Word64 -> BS.ByteString -> Maybe (Word64, BS.ByteString) gen' n w cs | n >= 64 = Just (w, cs) | otherwise = case BS.uncons cs of Just (d, ds) | d == w0 -> gen' (n + 1) (w .|. (0 .<. fromIntegral n)) ds Just (d, ds) | d == w1 -> gen' (n + 1) (w .|. (1 .<. fromIntegral n)) ds- Just (_, ds) -> gen' n w ds- Nothing -> Just (w, cs)+ Just (_, ds) -> gen' n w ds+ Nothing -> Just (w, cs) w0 :: Word8 w0 = 48
src/HaskellWorks/Data/Bits/LoBitsSized.hs view
@@ -7,6 +7,7 @@ import HaskellWorks.Data.Positioning class LoBitsSized a where+ -- | Value with the n least significant bits set to 1. loBitsSized :: Count -> a instance LoBitsSized Word64 where
src/HaskellWorks/Data/Bits/Log2.hs view
@@ -8,6 +8,7 @@ import HaskellWorks.Data.Bits.BitWise class Log2 a where+ -- | Log base of the given value rounded down to the nearest integer log2 :: a -> Int log2_64_tab :: DVS.Vector Int
src/HaskellWorks/Data/Bits/PopCount.hs view
@@ -1,20 +1,8 @@ {-# LANGUAGE MultiParamTypeClasses #-} --- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations. module HaskellWorks.Data.Bits.PopCount- ( -- * Bit map- PopCount(..)- , module X+ ( module X ) where -import HaskellWorks.Data.Bits.PopCount.PopCount0 as X-import HaskellWorks.Data.Bits.PopCount.PopCount1 as X-import HaskellWorks.Data.Positioning--{-# DEPRECATED #-}-class PopCount v e where- popCount :: e -> v -> Count+import HaskellWorks.Data.Bits.PopCount.PopCount0 as X+import HaskellWorks.Data.Bits.PopCount.PopCount1 as X
src/HaskellWorks/Data/Bits/PopCount/PopCount0.hs view
@@ -2,11 +2,6 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} --- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations. module HaskellWorks.Data.Bits.PopCount.PopCount0 ( PopCount0(..) ) where@@ -21,8 +16,8 @@ import HaskellWorks.Data.Positioning import Prelude as P --- | The number of zero bits in the value. class PopCount0 v where+ -- | The number of 0-bits in the value. popCount0 :: v -> Count instance PopCount0 Bool where
src/HaskellWorks/Data/Bits/PopCount/PopCount1.hs view
@@ -1,10 +1,5 @@ {-# LANGUAGE FlexibleInstances #-} --- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations. module HaskellWorks.Data.Bits.PopCount.PopCount1 ( PopCount1(..) ) where@@ -26,8 +21,8 @@ fastWord = Builtin {-# INLINE fastWord #-} --- | The number of one bits in the value. class PopCount1 v where+ -- | The number of 0-bits in the value. popCount1 :: v -> Count instance PopCount1 Bool where
src/HaskellWorks/Data/Bits/Types/Broadword.hs view
@@ -1,14 +1,9 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} --- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations. module HaskellWorks.Data.Bits.Types.Broadword where import Data.Vector.Storable import HaskellWorks.Data.Bits.BitWise --- | Type wrapper to prefer broadword operations+-- | Type wrapper to prefer broadword operations. newtype Broadword a = Broadword a deriving (BitWise, Eq, Show, Storable)
src/HaskellWorks/Data/Bits/Types/Builtin.hs view
@@ -1,14 +1,9 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} --- |--- Copyright: 2016 John Ky--- License: MIT------ Succinct operations. module HaskellWorks.Data.Bits.Types.Builtin where import Data.Vector.Storable import HaskellWorks.Data.Bits.BitWise --- | Type wrapper to prefer builting operations+-- | Type wrapper to prefer builting operations. newtype Builtin a = Builtin a deriving (BitWise, Eq, Show, Storable)
− src/HaskellWorks/Data/Bits/Unmatched.hs
@@ -1,206 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}--module HaskellWorks.Data.Bits.Unmatched- ( UnmatchedL0(..)- , UnmatchedL1(..)- , UnmatchedR0(..)- , UnmatchedR1(..)- ) where--import qualified Data.Vector.Storable as DVS-import Data.Word-import HaskellWorks.Data.Bits.FixedBitSize-import HaskellWorks.Data.Bits.BitWise-import HaskellWorks.Data.Positioning--bitEnd :: FixedBitSize w => w -> Position-bitEnd = toPosition . fixedBitSize-{-# INLINE bitEnd #-}--goL0 :: (TestBit w, FixedBitSize w) => Position -> Int -> w -> Int-goL0 n c w = if 0 <= n && n < bitEnd w- then let delta = if w .?. (bitEnd w - n - 1) then -1 else 1 in goL0 (n + 1) ((c + delta) `max` 0) w- else c-{-# INLINE goL0 #-}--goL1 :: (TestBit w, FixedBitSize w) => Position -> Int -> w -> Int-goL1 n c w = if 0 <= n && n < bitEnd w- then let delta = if w .?. (bitEnd w - n - 1) then 1 else -1 in goL1 (n + 1) ((c + delta) `max` 0) w- else c-{-# INLINE goL1 #-}--goR0 :: (TestBit w, FixedBitSize w) => Position -> Int -> w -> Int-goR0 n c w = if 0 <= n && n < bitEnd w- then let delta = if w .?. n then -1 else 1 in goR0 (n + 1) ((c + delta) `max` 0) w- else c-{-# INLINE goR0 #-}--goR1 :: (TestBit w, FixedBitSize w) => Position -> Int -> w -> Int-goR1 n c w = if 0 <= n && n < bitEnd w- then let delta = if w .?. n then 1 else -1 in goR1 (n + 1) ((c + delta) `max` 0) w- else c-{-# INLINE goR1 #-}--goDVSL0 :: (UnmatchedL0 w, UnmatchedR1 w, DVS.Storable w) => Int -> DVS.Vector w -> Int-goDVSL0 ub v = if DVS.length v == 0- then ub- else let a = DVS.last v in goDVSL0 (unmatchedL0 a + ((ub - unmatchedR1 a) `max` 0)) (DVS.init v)-{-# INLINE goDVSL0 #-}--goDVSL1 :: (UnmatchedL1 w, UnmatchedR0 w, DVS.Storable w) => Int -> DVS.Vector w -> Int-goDVSL1 ub v = if DVS.length v == 0- then ub- else let a = DVS.last v in goDVSL1 (unmatchedL1 a + ((ub - unmatchedR0 a) `max` 0)) (DVS.init v)-{-# INLINE goDVSL1 #-}--goDVSR0 :: (UnmatchedR0 w, UnmatchedL1 w, DVS.Storable w) => Int -> DVS.Vector w -> Int-goDVSR0 ua v = if DVS.length v == 0- then ua- else let b = DVS.head v in goDVSR0 (unmatchedR0 b + ((ua - unmatchedL1 b) `max` 0)) (DVS.tail v)-{-# INLINE goDVSR0 #-}--goDVSR1 :: (UnmatchedR1 w, UnmatchedL0 w, DVS.Storable w) => Int -> DVS.Vector w -> Int-goDVSR1 ub v = if DVS.length v == 0- then ub- else let a = DVS.head v in goDVSR1 (unmatchedR1 a + ((ub - unmatchedL0 a) `max` 0)) (DVS.tail v)-{-# INLINE goDVSR1 #-}--class UnmatchedL0 a where- unmatchedL0 :: a -> Int--class UnmatchedL1 a where- unmatchedL1 :: a -> Int--class UnmatchedR0 a where- unmatchedR0 :: a -> Int--class UnmatchedR1 a where- unmatchedR1 :: a -> Int--instance UnmatchedL0 Word8 where- unmatchedL0 = goL0 0 0- {-# INLINE unmatchedL0 #-}--instance UnmatchedL0 Word16 where- unmatchedL0 = goL0 0 0- {-# INLINE unmatchedL0 #-}--instance UnmatchedL0 Word32 where- unmatchedL0 = goL0 0 0- {-# INLINE unmatchedL0 #-}--instance UnmatchedL0 Word64 where- unmatchedL0 = goL0 0 0- {-# INLINE unmatchedL0 #-}--instance UnmatchedL0 (DVS.Vector Word8) where- unmatchedL0 = goDVSL0 0- {-# INLINE unmatchedL0 #-}--instance UnmatchedL0 (DVS.Vector Word16) where- unmatchedL0 = goDVSL0 0- {-# INLINE unmatchedL0 #-}--instance UnmatchedL0 (DVS.Vector Word32) where- unmatchedL0 = goDVSL0 0- {-# INLINE unmatchedL0 #-}--instance UnmatchedL0 (DVS.Vector Word64) where- unmatchedL0 = goDVSL0 0- {-# INLINE unmatchedL0 #-}--instance UnmatchedL1 Word8 where- unmatchedL1 = goL1 0 0- {-# INLINE unmatchedL1 #-}--instance UnmatchedL1 Word16 where- unmatchedL1 = goL1 0 0- {-# INLINE unmatchedL1 #-}--instance UnmatchedL1 Word32 where- unmatchedL1 = goL1 0 0- {-# INLINE unmatchedL1 #-}--instance UnmatchedL1 Word64 where- unmatchedL1 = goL1 0 0- {-# INLINE unmatchedL1 #-}--instance UnmatchedL1 (DVS.Vector Word8) where- unmatchedL1 = goDVSL1 0- {-# INLINE unmatchedL1 #-}--instance UnmatchedL1 (DVS.Vector Word16) where- unmatchedL1 = goDVSL1 0- {-# INLINE unmatchedL1 #-}--instance UnmatchedL1 (DVS.Vector Word32) where- unmatchedL1 = goDVSL1 0- {-# INLINE unmatchedL1 #-}--instance UnmatchedL1 (DVS.Vector Word64) where- unmatchedL1 = goDVSL1 0- {-# INLINE unmatchedL1 #-}--instance UnmatchedR0 Word8 where- unmatchedR0 = goR0 0 0- {-# INLINE unmatchedR0 #-}--instance UnmatchedR0 Word16 where- unmatchedR0 = goR0 0 0- {-# INLINE unmatchedR0 #-}--instance UnmatchedR0 Word32 where- unmatchedR0 = goR0 0 0- {-# INLINE unmatchedR0 #-}--instance UnmatchedR0 Word64 where- unmatchedR0 = goR0 0 0- {-# INLINE unmatchedR0 #-}--instance UnmatchedR0 (DVS.Vector Word8) where- unmatchedR0 = goDVSR0 0- {-# INLINE unmatchedR0 #-}--instance UnmatchedR0 (DVS.Vector Word16) where- unmatchedR0 = goDVSR0 0- {-# INLINE unmatchedR0 #-}--instance UnmatchedR0 (DVS.Vector Word32) where- unmatchedR0 = goDVSR0 0- {-# INLINE unmatchedR0 #-}--instance UnmatchedR0 (DVS.Vector Word64) where- unmatchedR0 = goDVSR0 0- {-# INLINE unmatchedR0 #-}--instance UnmatchedR1 Word8 where- unmatchedR1 = goR1 0 0- {-# INLINE unmatchedR1 #-}--instance UnmatchedR1 Word16 where- unmatchedR1 = goR1 0 0- {-# INLINE unmatchedR1 #-}--instance UnmatchedR1 Word32 where- unmatchedR1 = goR1 0 0- {-# INLINE unmatchedR1 #-}--instance UnmatchedR1 Word64 where- unmatchedR1 = goR1 0 0- {-# INLINE unmatchedR1 #-}--instance UnmatchedR1 (DVS.Vector Word8) where- unmatchedR1 = goDVSR1 0- {-# INLINE unmatchedR1 #-}--instance UnmatchedR1 (DVS.Vector Word16) where- unmatchedR1 = goDVSR1 0- {-# INLINE unmatchedR1 #-}--instance UnmatchedR1 (DVS.Vector Word32) where- unmatchedR1 = goDVSR1 0- {-# INLINE unmatchedR1 #-}--instance UnmatchedR1 (DVS.Vector Word64) where- unmatchedR1 = goDVSR1 0- {-# INLINE unmatchedR1 #-}
src/HaskellWorks/Data/Bits/Word.hs view
@@ -9,10 +9,13 @@ class WordConcat a where type DoubleWords a+ -- | Concatenate two words in little-endian order of the same size into a+ -- word of twice the size. leConcat :: a -> a -> DoubleWords a class WordSplit a where type HalfWords a+ -- | Split a word equally into two smaller words in little-endian order. leSplit :: a -> (HalfWords a, HalfWords a) instance WordConcat Word8 where
− test/HaskellWorks/Data/Bits/UnmatchedSpec.hs
@@ -1,88 +0,0 @@-{-# LANGUAGE ScopedTypeVariables #-}--module HaskellWorks.Data.Bits.UnmatchedSpec (spec) where--import Data.Vector.Storable as DVS-import Data.Word-import HaskellWorks.Data.Bits.BitWise-import HaskellWorks.Data.Bits.FixedBitSize-import HaskellWorks.Data.Bits.Unmatched-import Test.Hspec-import Test.QuickCheck--{-# ANN module ("HLint: Ignore Redundant do" :: String) #-}--spec :: Spec-spec = describe "HaskellWorks.Data.Bits.UnmatchedSpec" $ do- describe "For Word8" $ do- it "umatchedL0 concatentation" $- property $ \(a :: Word8) (b :: Word8) ->- let c :: Word16 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedL0 a + ((unmatchedL0 b - unmatchedR1 a) `max` 0) `shouldBe` unmatchedL0 c- it "umatchedL1 concatentation" $- property $ \(a :: Word8) (b :: Word8) ->- let c :: Word16 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedL1 a + ((unmatchedL1 b - unmatchedR0 a) `max` 0) `shouldBe` unmatchedL1 c- it "umatchedR0 concatentation" $- property $ \(a :: Word8) (b :: Word8) ->- let c :: Word16 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedR0 b + ((unmatchedR0 a - unmatchedL1 b) `max` 0) `shouldBe` unmatchedR0 c- it "umatchedR1 concatentation" $- property $ \(a :: Word8) (b :: Word8) ->- let c :: Word16 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedR1 b + ((unmatchedR1 a - unmatchedL0 b) `max` 0) `shouldBe` unmatchedR1 c- describe "For Word16" $ do- it "umatchedL0 concatentation" $- property $ \(a :: Word16) (b :: Word16) ->- let c :: Word32 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedL0 a + ((unmatchedL0 b - unmatchedR1 a) `max` 0) `shouldBe` unmatchedL0 c- it "umatchedL1 concatentation" $- property $ \(a :: Word16) (b :: Word16) ->- let c :: Word32 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedL1 a + ((unmatchedL1 b - unmatchedR0 a) `max` 0) `shouldBe` unmatchedL1 c- it "umatchedR0 concatentation" $- property $ \(a :: Word16) (b :: Word16) ->- let c :: Word32 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedR0 b + ((unmatchedR0 a - unmatchedL1 b) `max` 0) `shouldBe` unmatchedR0 c- it "umatchedR1 concatentation" $- property $ \(a :: Word16) (b :: Word16) ->- let c :: Word32 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedR1 b + ((unmatchedR1 a - unmatchedL0 b) `max` 0) `shouldBe` unmatchedR1 c- describe "For Word32" $ do- it "umatchedL0 concatentation" $- property $ \(a :: Word32) (b :: Word32) ->- let c :: Word64 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedL0 a + ((unmatchedL0 b - unmatchedR1 a) `max` 0) `shouldBe` unmatchedL0 c- it "umatchedL1 concatentation" $- property $ \(a :: Word32) (b :: Word32) ->- let c :: Word64 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedL1 a + ((unmatchedL1 b - unmatchedR0 a) `max` 0) `shouldBe` unmatchedL1 c- it "umatchedR0 concatentation" $- property $ \(a :: Word32) (b :: Word32) ->- let c :: Word64 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedR0 b + ((unmatchedR0 a - unmatchedL1 b) `max` 0) `shouldBe` unmatchedR0 c- it "umatchedR1 concatentation" $- property $ \(a :: Word32) (b :: Word32) ->- let c :: Word64 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedR1 b + ((unmatchedR1 a - unmatchedL0 b) `max` 0) `shouldBe` unmatchedR1 c- describe "For (DVS.Vector Word8)" $ do- it "umatchedL0 concatentation" $- property $ \(a :: Word8) (b :: Word8) ->- let c = DVS.fromList [a, b] in- let d :: Word16 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedL0 d `shouldBe` unmatchedL0 c- it "umatchedL1 concatentation" $- property $ \(a :: Word8) (b :: Word8) ->- let c = DVS.fromList [a, b] in- let d :: Word16 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedL1 d `shouldBe` unmatchedL1 c- it "umatchedR0 concatentation" $- property $ \(a :: Word8) (b :: Word8) ->- let c = DVS.fromList [a, b] in- let d :: Word16 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedR0 d `shouldBe` unmatchedR0 c- it "umatchedR1 concatentation" $- property $ \(a :: Word8) (b :: Word8) ->- let c = DVS.fromList [a, b] in- let d :: Word16 = (fromIntegral a) .|. (fromIntegral b .<. fixedBitSize b) in- unmatchedR1 d `shouldBe` unmatchedR1 c