-
--- given the checksum of bytes from index: startIdx to endIdx, find
--- the checksum for the block from (startIdx + 1 .. endIdx + 1)
-rollingChecksumUpdate :: Word32 -> Word8 -> Word8 -> Integer -> Integer -> Word32
-rollingChecksumUpdate oldChecksum old new strtIdx endIdx =
- let b_Old = (oldChecksum `shiftR` 16) .&. 0xff
- a_Old = (oldChecksum .&. 0xff)
- a_New = (a_Old - (fromIntegral old) + (fromIntegral new)) `mod` m
- b_New = (b_Old - ((fromIntegral endIdx) - (fromIntegral strtIdx) + 1) * (fromIntegral old) + a_New) `mod` m
- m = 2^16
- in
- a_New `mod` m + (b_New `mod` m) * m