From 8c34729c62ba64c810fbfa73719ae7f7110c0fbe Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Thu, 26 Apr 2012 20:28:40 -0400 Subject: More laziness. --- Data/Digest/CRC24.hs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'Data') diff --git a/Data/Digest/CRC24.hs b/Data/Digest/CRC24.hs index 4637834..4586177 100644 --- a/Data/Digest/CRC24.hs +++ b/Data/Digest/CRC24.hs @@ -4,12 +4,14 @@ -- (See the LICENSE file). module Data.Digest.CRC24 ( - crc24 + crc24 + , crc24Lazy ) where import Data.Bits (shiftL, (.&.), xor) -import Data.ByteString (ByteString) +import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString as B +import qualified Data.ByteString.Lazy as BL import Data.Word (Word8, Word32) crc24_init :: Word32 @@ -21,5 +23,8 @@ crc24_poly = 0x1864CFB crc24_update :: Word32 -> Word8 -> Word32 crc24_update c b = (last . take 9 $ iterate (\x -> if (shiftL x 1) .&. 0x1000000 == 0x1000000 then shiftL x 1 `xor` crc24_poly else shiftL x 1) (c `xor` shiftL (fromIntegral b) 16)) .&. 0xFFFFFF -crc24 :: ByteString -> Word32 -crc24 bs = B.foldl crc24_update crc24_init bs +crc24 :: B.ByteString -> Word32 +crc24 bs = crc24Lazy . BL.fromChunks $ [bs] + +crc24Lazy :: ByteString -> Word32 +crc24Lazy bs = BL.foldl crc24_update crc24_init bs -- cgit v1.2.3