-- | Compute a partial checksum, yielding a value suitable to be passed to
-- computeChecksum.
computePartialChecksum :: Word32 -> S.ByteString -> Word32
computePartialChecksum base b = result
 where
  !n' = S.length b

  !result
    | odd n'    = step most hi 0
    | otherwise = most
    where hi    = S.unsafeIndex b (n'-1)

  !most         = loop (fromIntegral base) 0

  loop !acc off
    | off < n   = loop (step acc hi lo) (off + 2)
    | otherwise = acc
    where hi    = S.unsafeIndex b off
          lo    = S.unsafeIndex b (off+1)
          n     = clearBit n' 0
computePartialChecksum :: Word32 -> S.ByteString -> Word32
computePartialChecksum base b = result
 where
  !n' = S.length b

  !result
    | odd n'    = step most hi 0
    | otherwise = most
    where hi    = S.unsafeIndex b (n'-1)

  !most         = loop (fromIntegral base) 0

  loop !acc off
    | off < n   = loop (step acc hi lo) (off + 2)
    | otherwise = acc
    where hi    = S.unsafeIndex b off
          lo    = S.unsafeIndex b (off+1)
          n     = clearBit n' 0
computePartialChecksum base b = result
 where
  !n' = S.length b

  !result
    | odd n'    = step most hi 0
    | otherwise = most
    where hi    = S.unsafeIndex b (n'-1)

  !most         = loop (fromIntegral base) 0

  loop !acc off
    | off < n   = loop (step acc hi lo) (off + 2)
    | otherwise = acc
    where hi    = S.unsafeIndex b off
          lo    = S.unsafeIndex b (off+1)
          n     = clearBit n' 0