digest 0.0.0.5 → 0.0.0.6
raw patch · 3 files changed
+30/−18 lines, 3 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Data.Digest.Adler32: adler32Update :: (Adler32 a) => Word32 -> a -> Word32
+ Data.Digest.CRC32: crc32Update :: (CRC32 a) => Word32 -> a -> Word32
Files
- Data/Digest/Adler32.hsc +14/−8
- Data/Digest/CRC32.hsc +14/−8
- digest.cabal +2/−2
Data/Digest/Adler32.hsc view
@@ -13,7 +13,7 @@ ------------------------------------------------------------ module Data.Digest.Adler32 ( - Adler32, adler32 + Adler32, adler32, adler32Update ) where import Foreign @@ -32,22 +32,28 @@ class Adler32 a where -- | Compute Adler32 checksum adler32 :: a -> Word32 + adler32 = adler32Update 0 + -- | Given the Adler32 checksum of a string, compute Adler32 of its + -- concatenation with another string (t.i., incrementally update the + -- Adler32 hash value). + adler32Update :: Word32 -> a -> Word32 + instance Adler32 S.ByteString where - adler32 = adler32_s + adler32Update = adler32_s_update instance Adler32 L.ByteString where - adler32 = adler32_l + adler32Update = adler32_l_update instance Adler32 [Word8] where - adler32 = adler32 . L.pack + adler32Update n = (adler32Update n) . L.pack -adler32_s :: S.ByteString -> Word32 -adler32_s s = adler32_l (LI.Chunk s LI.Empty) +adler32_s_update :: Word32 -> S.ByteString -> Word32 +adler32_s_update n s = adler32_l_update n (LI.Chunk s LI.Empty) -adler32_l :: L.ByteString -> Word32 -adler32_l = LI.foldlChunks updateAdler 0 +adler32_l_update :: Word32 -> L.ByteString -> Word32 +adler32_l_update n = LI.foldlChunks updateAdler n where updateAdler adler bs = fromIntegral $ adler32_c (fromIntegral adler) buf (fromIntegral len) where (ptr, offset, len) = BI.toForeignPtr bs buf = (unsafeForeignPtrToPtr ptr) `plusPtr` offset
Data/Digest/CRC32.hsc view
@@ -13,7 +13,7 @@ ------------------------------------------------------------ module Data.Digest.CRC32 ( - CRC32, crc32 + CRC32, crc32, crc32Update ) where import Foreign @@ -32,22 +32,28 @@ class CRC32 a where -- | Compute CRC32 checksum crc32 :: a -> Word32 + crc32 = crc32Update 0 + -- | Given the CRC32 checksum of a string, compute CRC32 of its + -- concatenation with another string (t.i., incrementally update + -- the CRC32 hash value) + crc32Update :: Word32 -> a -> Word32 + instance CRC32 S.ByteString where - crc32 = crc32_s + crc32Update = crc32_s_update instance CRC32 L.ByteString where - crc32 = crc32_l + crc32Update = crc32_l_update instance CRC32 [Word8] where - crc32 = crc32 . L.pack + crc32Update n = (crc32Update n) . L.pack -crc32_s :: S.ByteString -> Word32 -crc32_s s = crc32_l (LI.Chunk s LI.Empty) +crc32_s_update :: Word32 -> S.ByteString -> Word32 +crc32_s_update n s = crc32_l_update n (LI.Chunk s LI.Empty) -crc32_l :: L.ByteString -> Word32 -crc32_l = LI.foldlChunks updateCRC 0 +crc32_l_update :: Word32 -> L.ByteString -> Word32 +crc32_l_update n = LI.foldlChunks updateCRC n where updateCRC crc bs = fromIntegral $ crc32_c (fromIntegral crc) buf (fromIntegral len) where (ptr, offset, len) = BI.toForeignPtr bs buf = (unsafeForeignPtrToPtr ptr) `plusPtr` offset
digest.cabal view
@@ -1,6 +1,6 @@ name: digest-version: 0.0.0.5-copyright: (c) 2008 Eugene Kirpichov+version: 0.0.0.6+copyright: (c) 2009 Eugene Kirpichov license: BSD3 license-file: LICENSE author: Eugene Kirpichov <ekirpichov@gmail.com>