packages feed

castagnoli 0.2.0.1 → 0.2.0.2

raw patch · 6 files changed

+84/−73 lines, 6 filessetup-changednew-uploaderPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for castagnoli +## 0.2.0.2 -- 2024-02-01++* Update package metadata.+ ## 0.2.0.1 -- 2023-08-22  * Allow newer primitive
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
castagnoli.cabal view
@@ -1,40 +1,44 @@-cabal-version: 2.2-name: castagnoli-version: 0.2.0.1-synopsis: Portable CRC-32C-description: Portable implementation of CRC-32C.-homepage: https://github.com/andrewthad/castagnoli-bug-reports: https://github.com/andrewthad/castagnoli/issues-license: BSD-3-Clause-license-file: LICENSE-author: Andrew Martin-maintainer: andrew.thaddeus@gmail.com-copyright: 2019 Andrew Martin-category: Data-extra-source-files: CHANGELOG.md+cabal-version:   2.2+name:            castagnoli+version:         0.2.0.2+synopsis:        Portable CRC-32C+description:     Portable implementation of CRC-32C.+homepage:        https://github.com/byteverse/castagnoli+bug-reports:     https://github.com/byteverse/castagnoli/issues+license:         BSD-3-Clause+license-file:    LICENSE+author:          Andrew Martin+maintainer:      amartin@layer3com.com+copyright:       2019 Andrew Martin+category:        Data+extra-doc-files: CHANGELOG.md  library-  exposed-modules:-    Crc32c-  other-modules:-    Crc32c.Table+  exposed-modules:  Crc32c+  other-modules:    Crc32c.Table   build-depends:-    , base >=4.12.0.0 && <5-    , primitive >=0.7 && <0.10-    , byteslice >=0.1.1 && <0.3-  hs-source-dirs: src-  ghc-options: -O2 -Wall+    , base       >=4.12.0.0 && <5+    , byteslice  >=0.1.1    && <0.3+    , primitive  >=0.7      && <0.10++  hs-source-dirs:   src+  ghc-options:      -O2 -Wall   default-language: Haskell2010  test-suite test-  type: exitcode-stdio-1.0-  hs-source-dirs: test-  main-is: Main.hs+  type:             exitcode-stdio-1.0+  hs-source-dirs:   test+  main-is:          Main.hs   build-depends:     , base     , bytestring     , castagnoli-    , text     , primitive-  ghc-options: -Wall -O2+    , text++  ghc-options:      -Wall -O2   default-language: Haskell2010++source-repository head+  type:     git+  location: git://github.com/byteverse/castagnoli.git
src/Crc32c.hs view
@@ -1,5 +1,5 @@-{-# language BangPatterns #-}-{-# language TypeApplications #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE TypeApplications #-}  module Crc32c   ( bytes@@ -7,21 +7,22 @@   , chunks   ) where +import Control.Monad.Primitive (PrimMonad, PrimState) import Crc32c.Table (table)-import Data.Word (Word8,Word32)-import Data.Bytes.Types (Bytes(Bytes),MutableBytes(MutableBytes))-import Control.Monad.Primitive (PrimState,PrimMonad)-import Data.Bits (shiftR,xor)-import Data.Bytes.Chunks (Chunks(ChunksCons,ChunksNil))+import Data.Bits (shiftR, xor)+import Data.Bytes.Chunks (Chunks (ChunksCons, ChunksNil))+import Data.Bytes.Types (Bytes (Bytes), MutableBytes (MutableBytes)) import qualified Data.Primitive.ByteArray as PM import qualified Data.Primitive.Ptr as PM+import Data.Word (Word32, Word8)  -- | Compute the checksum of a slice of bytes. bytes :: Word32 -> Bytes -> Word32 bytes !acc0 (Bytes arr off len) =-  let go !acc !ix !end = if ix < end-        then go (step acc (PM.indexByteArray arr ix)) (ix + 1) end-        else acc+  let go !acc !ix !end =+        if ix < end+          then go (step acc (PM.indexByteArray arr ix)) (ix + 1) end+          else acc    in xor 0xFFFFFFFF (go (xor acc0 0xFFFFFFFF) off (off + len))  chunks :: Word32 -> Chunks -> Word32@@ -31,17 +32,19 @@    in chunks acc' xs  -- | Compute the checksum of a slice of mutable bytes.-mutableBytes :: PrimMonad m-  => Word32-  -> MutableBytes (PrimState m)-  -> m Word32-{-# inlineable mutableBytes #-}+mutableBytes ::+  (PrimMonad m) =>+  Word32 ->+  MutableBytes (PrimState m) ->+  m Word32+{-# INLINEABLE mutableBytes #-} mutableBytes acc0 (MutableBytes arr off len) = do-  let go !acc !ix !end = if ix < end-        then do-          w <- PM.readByteArray arr ix-          go (step acc w) (ix + 1) end-        else pure acc+  let go !acc !ix !end =+        if ix < end+          then do+            w <- PM.readByteArray arr ix+            go (step acc w) (ix + 1) end+          else pure acc   r <- go (xor acc0 0xFFFFFFFF) off (off + len)   pure (xor 0xFFFFFFFF r) @@ -56,7 +59,7 @@ -- x            in go (bytes acc (Bytes b 0 (PM.sizeofByteArray b))) (ix + 1) end -- x         else acc -- x    in go acc0 off (off + len)--- x +-- x -- x -- | Compute the checksum of a slice into an mutable array of -- x -- unsliced byte arrays. -- x mutableByteArrays :: PrimMonad m@@ -73,9 +76,10 @@ -- x    in go acc0 off (off + len)  step :: Word32 -> Word8 -> Word32-step !acc !w = xor-  (scramble (xor (fromIntegral @Word32 @Word8 acc) w))-  (shiftR acc 8)+step !acc !w =+  xor+    (scramble (xor (fromIntegral @Word32 @Word8 acc) w))+    (shiftR acc 8)  scramble :: Word8 -> Word32 scramble w = PM.indexOffPtr table (fromIntegral @Word8 @Int w)
src/Crc32c/Table.hs view
@@ -1,12 +1,12 @@-{-# language CPP #-}-{-# language MagicHash #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE MagicHash #-}  module Crc32c.Table   ( table   ) where  import Data.Word (Word32)-import GHC.Ptr (Ptr(Ptr))+import GHC.Ptr (Ptr (Ptr))  #include "MachDeps.h" 
test/Main.hs view
@@ -1,24 +1,25 @@-import Crc32c (bytes,byteArrays) import Control.Monad (when)-import Data.Primitive (ByteArray)-import Data.Word (Word8)+import Crc32c (bytes)  import qualified GHC.Exts as Exts  main :: IO () main = do-  let sample1 = Exts.fromList-        [0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39]+  let sample1 =+        Exts.fromList+          [0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39]   let expected1 = 0xe3069283   let actual1 = bytes 0 sample1-  when (actual1 /= expected1) $ fail $-    "ex1: expected " ++ show expected1 ++ " but got " ++ show actual1-  let sample2 = Exts.fromList-        [ (Exts.fromList [0x31 :: Word8,0x32,0x33]) :: ByteArray-        , (Exts.fromList [0x34 :: Word8,0x35,0x36,0x37,0x38,0x39])-        ]-  let expected2 = 0xe3069283-  let actual2 = byteArrays 0 sample2-  when (actual2 /= expected2) $ fail $-    "ex2: expected " ++ show expected2 ++ " but got " ++ show actual2-  +  when (actual1 /= expected1) $+    fail $+      "ex1: expected " ++ show expected1 ++ " but got " ++ show actual1++-- Commented out the test case below because Crc32c.byteArrays isn't currently defined.+-- let sample2 = Exts.fromList+--       [ (Exts.fromList [0x31 :: Word8,0x32,0x33]) :: ByteArray+--       , (Exts.fromList [0x34 :: Word8,0x35,0x36,0x37,0x38,0x39])+--       ]+-- let expected2 = 0xe3069283+-- let actual2 = byteArrays 0 sample2+-- when (actual2 /= expected2) $ fail $+--   "ex2: expected " ++ show expected2 ++ " but got " ++ show actual2