module TensorFlow.CRC32C
( crc32c
, crc32cLBS
, crc32cUpdate
, crc32cMasked
, crc32cLBSMasked
, crc32cMask
, crc32cUnmask
) where
import Data.Bits (rotateL, rotateR)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import Data.Digest.CRC32C (crc32c, crc32c_update)
import Data.List (foldl')
import Data.Word (Word32)
crc32cUpdate :: Word32 -> B.ByteString -> Word32
crc32cUpdate :: Word32 -> ByteString -> Word32
crc32cUpdate = Word32 -> ByteString -> Word32
crc32c_update
crc32cLBS :: BL.ByteString -> Word32
crc32cLBS :: ByteString -> Word32
crc32cLBS = (Word32 -> ByteString -> Word32)
-> Word32 -> [ByteString] -> Word32
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Word32 -> ByteString -> Word32
crc32cUpdate 0 ([ByteString] -> Word32)
-> (ByteString -> [ByteString]) -> ByteString -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> [ByteString]
BL.toChunks
crc32cMask :: Word32 -> Word32
crc32cMask :: Word32 -> Word32
crc32cMask x :: Word32
x = Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
rotateR Word32
x 15 Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ Word32
maskDelta
crc32cUnmask :: Word32 -> Word32
crc32cUnmask :: Word32 -> Word32
crc32cUnmask x :: Word32
x = Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
rotateL (Word32
x Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
maskDelta) 15
crc32cMasked :: B.ByteString -> Word32
crc32cMasked :: ByteString -> Word32
crc32cMasked = Word32 -> Word32
crc32cMask (Word32 -> Word32)
-> (ByteString -> Word32) -> ByteString -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Word32
crc32c
crc32cLBSMasked :: BL.ByteString -> Word32
crc32cLBSMasked :: ByteString -> Word32
crc32cLBSMasked = Word32 -> Word32
crc32cMask (Word32 -> Word32)
-> (ByteString -> Word32) -> ByteString -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Word32
crc32cLBS
maskDelta :: Word32
maskDelta :: Word32
maskDelta = 0xa282ead8