module Foundation.Hashing.Hasher
( Hasher(..)
) where
import Foundation.Internal.Base
import Foundation.Array (UArray)
import qualified Foundation.Array.Unboxed as A
import Data.Bits
import qualified Prelude
class Hasher st where
type HashResult st
type HashInitParam st
hashNew :: st
hashNewParam :: HashInitParam st -> st
hashEnd :: st -> HashResult st
hashMix8 :: Word8 -> st -> st
hashMix16 :: Word16 -> st -> st
hashMix16 w st = hashMix8 w2 $ hashMix8 w1 st
where (# !w1, !w2 #) = unWord16 w
hashMix32 :: Word32 -> st -> st
hashMix32 w st = hashMix8 w4 $ hashMix8 w3 $ hashMix8 w2 $ hashMix8 w1 st
where (# !w1, !w2, !w3, !w4 #) = unWord32 w
hashMix64 :: Word64 -> st -> st
hashMix64 w st = hashMix32 w2 $ hashMix32 w1 st
where (# !w1, !w2 #) = unWord64_32 w
hashMixBytes :: A.PrimType e => UArray e -> st -> st
hashMixBytes ba st = A.foldl' (flip hashMix8) st (A.unsafeRecast ba)
unWord16 :: Word16 -> (# Word8, Word8 #)
unWord16 w = (# Prelude.fromIntegral (w `unsafeShiftR` 8)
, Prelude.fromIntegral w #)
unWord32 :: Word32 -> (# Word8, Word8, Word8, Word8 #)
unWord32 w = (# Prelude.fromIntegral (w `unsafeShiftR` 24)
, Prelude.fromIntegral (w `unsafeShiftR` 16)
, Prelude.fromIntegral (w `unsafeShiftR` 8)
, Prelude.fromIntegral w #)
unWord64_32 :: Word64 -> (# Word32, Word32 #)
unWord64_32 w = (# Prelude.fromIntegral (w `unsafeShiftR` 32)
, Prelude.fromIntegral w #)