{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnboxedTuples #-}
module Data.Hash.FNV1
(
Fnv164Hash(..)
, Fnv164Context
, fnv164Initialize
, fnv164Update
, fnv164Finalize
, fnv164
, Fnv1a64Hash(..)
, Fnv1a64Context
, fnv1a64Initialize
, fnv1a64Update
, fnv1a64Finalize
, fnv1a64
, Fnv132Hash(..)
, Fnv132Context
, fnv132Initialize
, fnv132Update
, fnv132Finalize
, fnv132
, Fnv1a32Hash(..)
, Fnv1a32Context
, fnv1a32Initialize
, fnv1a32Update
, fnv1a32Finalize
, fnv1a32
, Fnv1Hash(..)
, Fnv1Context
, fnv1Initialize
, fnv1Update
, fnv1Finalize
, fnv1
, Fnv1aHash(..)
, Fnv1aContext
, fnv1aInitialize
, fnv1aUpdate
, fnv1aFinalize
, fnv1a
, module Data.Hash.Class.Pure
, fnv1_64
, fnv1_64_
, fnv1a_64
, fnv1a_64_
, fnv1_32
, fnv1_32_
, fnv1a_32
, fnv1a_32_
, fnv1_host
, fnv1_host_
, fnv1Primitive
, fnv1Primitive_
, fnv1a_host
, fnv1a_host_
, fnv1aPrimitive
, fnv1aPrimitive_
, fnvPrime
, fnvPrime32
, fnvPrime64
, fnvOffsetBasis
, fnvOffsetBasis32
, fnvOffsetBasis64
) where
import Control.Monad
import Data.Bits
import Data.Word
import Foreign.Ptr
import Foreign.Storable
import GHC.Exts
import GHC.IO
import Data.Hash.Class.Pure
newtype Fnv164Context = Fnv164Context Word64
newtype Fnv164Hash = Fnv164Hash Word64
deriving (Int -> Fnv164Hash -> ShowS
[Fnv164Hash] -> ShowS
Fnv164Hash -> String
(Int -> Fnv164Hash -> ShowS)
-> (Fnv164Hash -> String)
-> ([Fnv164Hash] -> ShowS)
-> Show Fnv164Hash
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Fnv164Hash] -> ShowS
$cshowList :: [Fnv164Hash] -> ShowS
show :: Fnv164Hash -> String
$cshow :: Fnv164Hash -> String
showsPrec :: Int -> Fnv164Hash -> ShowS
$cshowsPrec :: Int -> Fnv164Hash -> ShowS
Show, Fnv164Hash -> Fnv164Hash -> Bool
(Fnv164Hash -> Fnv164Hash -> Bool)
-> (Fnv164Hash -> Fnv164Hash -> Bool) -> Eq Fnv164Hash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Fnv164Hash -> Fnv164Hash -> Bool
$c/= :: Fnv164Hash -> Fnv164Hash -> Bool
== :: Fnv164Hash -> Fnv164Hash -> Bool
$c== :: Fnv164Hash -> Fnv164Hash -> Bool
Eq, Eq Fnv164Hash
Eq Fnv164Hash
-> (Fnv164Hash -> Fnv164Hash -> Ordering)
-> (Fnv164Hash -> Fnv164Hash -> Bool)
-> (Fnv164Hash -> Fnv164Hash -> Bool)
-> (Fnv164Hash -> Fnv164Hash -> Bool)
-> (Fnv164Hash -> Fnv164Hash -> Bool)
-> (Fnv164Hash -> Fnv164Hash -> Fnv164Hash)
-> (Fnv164Hash -> Fnv164Hash -> Fnv164Hash)
-> Ord Fnv164Hash
Fnv164Hash -> Fnv164Hash -> Bool
Fnv164Hash -> Fnv164Hash -> Ordering
Fnv164Hash -> Fnv164Hash -> Fnv164Hash
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Fnv164Hash -> Fnv164Hash -> Fnv164Hash
$cmin :: Fnv164Hash -> Fnv164Hash -> Fnv164Hash
max :: Fnv164Hash -> Fnv164Hash -> Fnv164Hash
$cmax :: Fnv164Hash -> Fnv164Hash -> Fnv164Hash
>= :: Fnv164Hash -> Fnv164Hash -> Bool
$c>= :: Fnv164Hash -> Fnv164Hash -> Bool
> :: Fnv164Hash -> Fnv164Hash -> Bool
$c> :: Fnv164Hash -> Fnv164Hash -> Bool
<= :: Fnv164Hash -> Fnv164Hash -> Bool
$c<= :: Fnv164Hash -> Fnv164Hash -> Bool
< :: Fnv164Hash -> Fnv164Hash -> Bool
$c< :: Fnv164Hash -> Fnv164Hash -> Bool
compare :: Fnv164Hash -> Fnv164Hash -> Ordering
$ccompare :: Fnv164Hash -> Fnv164Hash -> Ordering
$cp1Ord :: Eq Fnv164Hash
Ord)
fnv164Initialize :: Fnv164Context
fnv164Initialize :: Fnv164Context
fnv164Initialize = Word64 -> Fnv164Context
Fnv164Context Word64
fnvOffsetBasis64
{-# INLINE fnv164Initialize #-}
fnv164Update :: Fnv164Context -> Ptr Word8 -> Int -> IO Fnv164Context
fnv164Update :: Fnv164Context -> Ptr Word8 -> Int -> IO Fnv164Context
fnv164Update (Fnv164Context !Word64
ctx) !Ptr Word8
ptr !Int
n =
Word64 -> Fnv164Context
Fnv164Context (Word64 -> Fnv164Context) -> IO Word64 -> IO Fnv164Context
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Ptr Word8 -> Int -> Word64 -> IO Word64
fnv1_64_ Ptr Word8
ptr Int
n Word64
ctx
{-# INLINE fnv164Update #-}
fnv164Finalize :: Fnv164Context -> Fnv164Hash
fnv164Finalize :: Fnv164Context -> Fnv164Hash
fnv164Finalize (Fnv164Context !Word64
ctx) = Word64 -> Fnv164Hash
Fnv164Hash Word64
ctx
{-# INLINE fnv164Finalize #-}
fnv164 :: Ptr Word8 -> Int -> IO Fnv164Hash
fnv164 :: Ptr Word8 -> Int -> IO Fnv164Hash
fnv164 !Ptr Word8
ptr !Int
n = Fnv164Context -> Fnv164Hash
fnv164Finalize (Fnv164Context -> Fnv164Hash) -> IO Fnv164Context -> IO Fnv164Hash
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Fnv164Context -> Ptr Word8 -> Int -> IO Fnv164Context
fnv164Update Fnv164Context
fnv164Initialize Ptr Word8
ptr Int
n
{-# INLINE fnv164 #-}
instance IncrementalHash Fnv164Hash where
type Context Fnv164Hash = Fnv164Context
update :: Context Fnv164Hash -> Ptr Word8 -> Int -> IO (Context Fnv164Hash)
update = Context Fnv164Hash -> Ptr Word8 -> Int -> IO (Context Fnv164Hash)
Fnv164Context -> Ptr Word8 -> Int -> IO Fnv164Context
fnv164Update
finalize :: Context Fnv164Hash -> Fnv164Hash
finalize = Context Fnv164Hash -> Fnv164Hash
Fnv164Context -> Fnv164Hash
fnv164Finalize
{-# INLINE update #-}
{-# INLINE finalize #-}
instance Hash Fnv164Hash where
initialize :: Context Fnv164Hash
initialize = Context Fnv164Hash
Fnv164Context
fnv164Initialize
{-# INLINE initialize #-}
newtype Fnv1a64Context = Fnv1a64Context Word64
newtype Fnv1a64Hash = Fnv1a64Hash Word64
deriving (Int -> Fnv1a64Hash -> ShowS
[Fnv1a64Hash] -> ShowS
Fnv1a64Hash -> String
(Int -> Fnv1a64Hash -> ShowS)
-> (Fnv1a64Hash -> String)
-> ([Fnv1a64Hash] -> ShowS)
-> Show Fnv1a64Hash
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Fnv1a64Hash] -> ShowS
$cshowList :: [Fnv1a64Hash] -> ShowS
show :: Fnv1a64Hash -> String
$cshow :: Fnv1a64Hash -> String
showsPrec :: Int -> Fnv1a64Hash -> ShowS
$cshowsPrec :: Int -> Fnv1a64Hash -> ShowS
Show, Fnv1a64Hash -> Fnv1a64Hash -> Bool
(Fnv1a64Hash -> Fnv1a64Hash -> Bool)
-> (Fnv1a64Hash -> Fnv1a64Hash -> Bool) -> Eq Fnv1a64Hash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Fnv1a64Hash -> Fnv1a64Hash -> Bool
$c/= :: Fnv1a64Hash -> Fnv1a64Hash -> Bool
== :: Fnv1a64Hash -> Fnv1a64Hash -> Bool
$c== :: Fnv1a64Hash -> Fnv1a64Hash -> Bool
Eq, Eq Fnv1a64Hash
Eq Fnv1a64Hash
-> (Fnv1a64Hash -> Fnv1a64Hash -> Ordering)
-> (Fnv1a64Hash -> Fnv1a64Hash -> Bool)
-> (Fnv1a64Hash -> Fnv1a64Hash -> Bool)
-> (Fnv1a64Hash -> Fnv1a64Hash -> Bool)
-> (Fnv1a64Hash -> Fnv1a64Hash -> Bool)
-> (Fnv1a64Hash -> Fnv1a64Hash -> Fnv1a64Hash)
-> (Fnv1a64Hash -> Fnv1a64Hash -> Fnv1a64Hash)
-> Ord Fnv1a64Hash
Fnv1a64Hash -> Fnv1a64Hash -> Bool
Fnv1a64Hash -> Fnv1a64Hash -> Ordering
Fnv1a64Hash -> Fnv1a64Hash -> Fnv1a64Hash
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Fnv1a64Hash -> Fnv1a64Hash -> Fnv1a64Hash
$cmin :: Fnv1a64Hash -> Fnv1a64Hash -> Fnv1a64Hash
max :: Fnv1a64Hash -> Fnv1a64Hash -> Fnv1a64Hash
$cmax :: Fnv1a64Hash -> Fnv1a64Hash -> Fnv1a64Hash
>= :: Fnv1a64Hash -> Fnv1a64Hash -> Bool
$c>= :: Fnv1a64Hash -> Fnv1a64Hash -> Bool
> :: Fnv1a64Hash -> Fnv1a64Hash -> Bool
$c> :: Fnv1a64Hash -> Fnv1a64Hash -> Bool
<= :: Fnv1a64Hash -> Fnv1a64Hash -> Bool
$c<= :: Fnv1a64Hash -> Fnv1a64Hash -> Bool
< :: Fnv1a64Hash -> Fnv1a64Hash -> Bool
$c< :: Fnv1a64Hash -> Fnv1a64Hash -> Bool
compare :: Fnv1a64Hash -> Fnv1a64Hash -> Ordering
$ccompare :: Fnv1a64Hash -> Fnv1a64Hash -> Ordering
$cp1Ord :: Eq Fnv1a64Hash
Ord)
fnv1a64Initialize :: Fnv1a64Context
fnv1a64Initialize :: Fnv1a64Context
fnv1a64Initialize = Word64 -> Fnv1a64Context
Fnv1a64Context Word64
fnvOffsetBasis64
{-# INLINE fnv1a64Initialize #-}
fnv1a64Update :: Fnv1a64Context -> Ptr Word8 -> Int -> IO Fnv1a64Context
fnv1a64Update :: Fnv1a64Context -> Ptr Word8 -> Int -> IO Fnv1a64Context
fnv1a64Update (Fnv1a64Context !Word64
ctx) !Ptr Word8
ptr !Int
n =
Word64 -> Fnv1a64Context
Fnv1a64Context (Word64 -> Fnv1a64Context) -> IO Word64 -> IO Fnv1a64Context
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Ptr Word8 -> Int -> Word64 -> IO Word64
fnv1a_64_ Ptr Word8
ptr Int
n Word64
ctx
{-# INLINE fnv1a64Update #-}
fnv1a64Finalize :: Fnv1a64Context -> Fnv1a64Hash
fnv1a64Finalize :: Fnv1a64Context -> Fnv1a64Hash
fnv1a64Finalize (Fnv1a64Context !Word64
ctx) = Word64 -> Fnv1a64Hash
Fnv1a64Hash Word64
ctx
{-# INLINE fnv1a64Finalize #-}
fnv1a64 :: Ptr Word8 -> Int -> IO Fnv1a64Hash
fnv1a64 :: Ptr Word8 -> Int -> IO Fnv1a64Hash
fnv1a64 !Ptr Word8
ptr !Int
n = Fnv1a64Context -> Fnv1a64Hash
fnv1a64Finalize (Fnv1a64Context -> Fnv1a64Hash)
-> IO Fnv1a64Context -> IO Fnv1a64Hash
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Fnv1a64Context -> Ptr Word8 -> Int -> IO Fnv1a64Context
fnv1a64Update Fnv1a64Context
fnv1a64Initialize Ptr Word8
ptr Int
n
{-# INLINE fnv1a64 #-}
instance IncrementalHash Fnv1a64Hash where
type Context Fnv1a64Hash = Fnv1a64Context
update :: Context Fnv1a64Hash -> Ptr Word8 -> Int -> IO (Context Fnv1a64Hash)
update = Context Fnv1a64Hash -> Ptr Word8 -> Int -> IO (Context Fnv1a64Hash)
Fnv1a64Context -> Ptr Word8 -> Int -> IO Fnv1a64Context
fnv1a64Update
finalize :: Context Fnv1a64Hash -> Fnv1a64Hash
finalize = Context Fnv1a64Hash -> Fnv1a64Hash
Fnv1a64Context -> Fnv1a64Hash
fnv1a64Finalize
{-# INLINE update #-}
{-# INLINE finalize #-}
instance Hash Fnv1a64Hash where
initialize :: Context Fnv1a64Hash
initialize = Context Fnv1a64Hash
Fnv1a64Context
fnv1a64Initialize
{-# INLINE initialize #-}
newtype Fnv132Context = Fnv132Context Word32
newtype Fnv132Hash = Fnv132Hash Word32
deriving (Int -> Fnv132Hash -> ShowS
[Fnv132Hash] -> ShowS
Fnv132Hash -> String
(Int -> Fnv132Hash -> ShowS)
-> (Fnv132Hash -> String)
-> ([Fnv132Hash] -> ShowS)
-> Show Fnv132Hash
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Fnv132Hash] -> ShowS
$cshowList :: [Fnv132Hash] -> ShowS
show :: Fnv132Hash -> String
$cshow :: Fnv132Hash -> String
showsPrec :: Int -> Fnv132Hash -> ShowS
$cshowsPrec :: Int -> Fnv132Hash -> ShowS
Show, Fnv132Hash -> Fnv132Hash -> Bool
(Fnv132Hash -> Fnv132Hash -> Bool)
-> (Fnv132Hash -> Fnv132Hash -> Bool) -> Eq Fnv132Hash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Fnv132Hash -> Fnv132Hash -> Bool
$c/= :: Fnv132Hash -> Fnv132Hash -> Bool
== :: Fnv132Hash -> Fnv132Hash -> Bool
$c== :: Fnv132Hash -> Fnv132Hash -> Bool
Eq, Eq Fnv132Hash
Eq Fnv132Hash
-> (Fnv132Hash -> Fnv132Hash -> Ordering)
-> (Fnv132Hash -> Fnv132Hash -> Bool)
-> (Fnv132Hash -> Fnv132Hash -> Bool)
-> (Fnv132Hash -> Fnv132Hash -> Bool)
-> (Fnv132Hash -> Fnv132Hash -> Bool)
-> (Fnv132Hash -> Fnv132Hash -> Fnv132Hash)
-> (Fnv132Hash -> Fnv132Hash -> Fnv132Hash)
-> Ord Fnv132Hash
Fnv132Hash -> Fnv132Hash -> Bool
Fnv132Hash -> Fnv132Hash -> Ordering
Fnv132Hash -> Fnv132Hash -> Fnv132Hash
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Fnv132Hash -> Fnv132Hash -> Fnv132Hash
$cmin :: Fnv132Hash -> Fnv132Hash -> Fnv132Hash
max :: Fnv132Hash -> Fnv132Hash -> Fnv132Hash
$cmax :: Fnv132Hash -> Fnv132Hash -> Fnv132Hash
>= :: Fnv132Hash -> Fnv132Hash -> Bool
$c>= :: Fnv132Hash -> Fnv132Hash -> Bool
> :: Fnv132Hash -> Fnv132Hash -> Bool
$c> :: Fnv132Hash -> Fnv132Hash -> Bool
<= :: Fnv132Hash -> Fnv132Hash -> Bool
$c<= :: Fnv132Hash -> Fnv132Hash -> Bool
< :: Fnv132Hash -> Fnv132Hash -> Bool
$c< :: Fnv132Hash -> Fnv132Hash -> Bool
compare :: Fnv132Hash -> Fnv132Hash -> Ordering
$ccompare :: Fnv132Hash -> Fnv132Hash -> Ordering
$cp1Ord :: Eq Fnv132Hash
Ord)
fnv132Initialize :: Fnv132Context
fnv132Initialize :: Fnv132Context
fnv132Initialize = Word32 -> Fnv132Context
Fnv132Context Word32
fnvOffsetBasis32
{-# INLINE fnv132Initialize #-}
fnv132Update :: Fnv132Context -> Ptr Word8 -> Int -> IO Fnv132Context
fnv132Update :: Fnv132Context -> Ptr Word8 -> Int -> IO Fnv132Context
fnv132Update (Fnv132Context !Word32
ctx) !Ptr Word8
ptr !Int
n =
Word32 -> Fnv132Context
Fnv132Context (Word32 -> Fnv132Context) -> IO Word32 -> IO Fnv132Context
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Ptr Word8 -> Int -> Word32 -> IO Word32
fnv1_32_ Ptr Word8
ptr Int
n Word32
ctx
{-# INLINE fnv132Update #-}
fnv132Finalize :: Fnv132Context -> Fnv132Hash
fnv132Finalize :: Fnv132Context -> Fnv132Hash
fnv132Finalize (Fnv132Context !Word32
ctx) = Word32 -> Fnv132Hash
Fnv132Hash Word32
ctx
{-# INLINE fnv132Finalize #-}
fnv132 :: Ptr Word8 -> Int -> IO Fnv132Hash
fnv132 :: Ptr Word8 -> Int -> IO Fnv132Hash
fnv132 !Ptr Word8
ptr !Int
n = Fnv132Context -> Fnv132Hash
fnv132Finalize (Fnv132Context -> Fnv132Hash) -> IO Fnv132Context -> IO Fnv132Hash
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Fnv132Context -> Ptr Word8 -> Int -> IO Fnv132Context
fnv132Update Fnv132Context
fnv132Initialize Ptr Word8
ptr Int
n
{-# INLINE fnv132 #-}
instance IncrementalHash Fnv132Hash where
type Context Fnv132Hash = Fnv132Context
update :: Context Fnv132Hash -> Ptr Word8 -> Int -> IO (Context Fnv132Hash)
update = Context Fnv132Hash -> Ptr Word8 -> Int -> IO (Context Fnv132Hash)
Fnv132Context -> Ptr Word8 -> Int -> IO Fnv132Context
fnv132Update
finalize :: Context Fnv132Hash -> Fnv132Hash
finalize = Context Fnv132Hash -> Fnv132Hash
Fnv132Context -> Fnv132Hash
fnv132Finalize
{-# INLINE update #-}
{-# INLINE finalize #-}
instance Hash Fnv132Hash where
initialize :: Context Fnv132Hash
initialize = Context Fnv132Hash
Fnv132Context
fnv132Initialize
{-# INLINE initialize #-}
newtype Fnv1a32Context = Fnv1a32Context Word32
newtype Fnv1a32Hash = Fnv1a32Hash Word32
deriving (Int -> Fnv1a32Hash -> ShowS
[Fnv1a32Hash] -> ShowS
Fnv1a32Hash -> String
(Int -> Fnv1a32Hash -> ShowS)
-> (Fnv1a32Hash -> String)
-> ([Fnv1a32Hash] -> ShowS)
-> Show Fnv1a32Hash
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Fnv1a32Hash] -> ShowS
$cshowList :: [Fnv1a32Hash] -> ShowS
show :: Fnv1a32Hash -> String
$cshow :: Fnv1a32Hash -> String
showsPrec :: Int -> Fnv1a32Hash -> ShowS
$cshowsPrec :: Int -> Fnv1a32Hash -> ShowS
Show, Fnv1a32Hash -> Fnv1a32Hash -> Bool
(Fnv1a32Hash -> Fnv1a32Hash -> Bool)
-> (Fnv1a32Hash -> Fnv1a32Hash -> Bool) -> Eq Fnv1a32Hash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Fnv1a32Hash -> Fnv1a32Hash -> Bool
$c/= :: Fnv1a32Hash -> Fnv1a32Hash -> Bool
== :: Fnv1a32Hash -> Fnv1a32Hash -> Bool
$c== :: Fnv1a32Hash -> Fnv1a32Hash -> Bool
Eq, Eq Fnv1a32Hash
Eq Fnv1a32Hash
-> (Fnv1a32Hash -> Fnv1a32Hash -> Ordering)
-> (Fnv1a32Hash -> Fnv1a32Hash -> Bool)
-> (Fnv1a32Hash -> Fnv1a32Hash -> Bool)
-> (Fnv1a32Hash -> Fnv1a32Hash -> Bool)
-> (Fnv1a32Hash -> Fnv1a32Hash -> Bool)
-> (Fnv1a32Hash -> Fnv1a32Hash -> Fnv1a32Hash)
-> (Fnv1a32Hash -> Fnv1a32Hash -> Fnv1a32Hash)
-> Ord Fnv1a32Hash
Fnv1a32Hash -> Fnv1a32Hash -> Bool
Fnv1a32Hash -> Fnv1a32Hash -> Ordering
Fnv1a32Hash -> Fnv1a32Hash -> Fnv1a32Hash
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Fnv1a32Hash -> Fnv1a32Hash -> Fnv1a32Hash
$cmin :: Fnv1a32Hash -> Fnv1a32Hash -> Fnv1a32Hash
max :: Fnv1a32Hash -> Fnv1a32Hash -> Fnv1a32Hash
$cmax :: Fnv1a32Hash -> Fnv1a32Hash -> Fnv1a32Hash
>= :: Fnv1a32Hash -> Fnv1a32Hash -> Bool
$c>= :: Fnv1a32Hash -> Fnv1a32Hash -> Bool
> :: Fnv1a32Hash -> Fnv1a32Hash -> Bool
$c> :: Fnv1a32Hash -> Fnv1a32Hash -> Bool
<= :: Fnv1a32Hash -> Fnv1a32Hash -> Bool
$c<= :: Fnv1a32Hash -> Fnv1a32Hash -> Bool
< :: Fnv1a32Hash -> Fnv1a32Hash -> Bool
$c< :: Fnv1a32Hash -> Fnv1a32Hash -> Bool
compare :: Fnv1a32Hash -> Fnv1a32Hash -> Ordering
$ccompare :: Fnv1a32Hash -> Fnv1a32Hash -> Ordering
$cp1Ord :: Eq Fnv1a32Hash
Ord)
fnv1a32Initialize :: Fnv1a32Context
fnv1a32Initialize :: Fnv1a32Context
fnv1a32Initialize = Word32 -> Fnv1a32Context
Fnv1a32Context Word32
fnvOffsetBasis32
{-# INLINE fnv1a32Initialize #-}
fnv1a32Update :: Fnv1a32Context -> Ptr Word8 -> Int -> IO Fnv1a32Context
fnv1a32Update :: Fnv1a32Context -> Ptr Word8 -> Int -> IO Fnv1a32Context
fnv1a32Update (Fnv1a32Context !Word32
ctx) !Ptr Word8
ptr !Int
n =
Word32 -> Fnv1a32Context
Fnv1a32Context (Word32 -> Fnv1a32Context) -> IO Word32 -> IO Fnv1a32Context
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Ptr Word8 -> Int -> Word32 -> IO Word32
fnv1a_32_ Ptr Word8
ptr Int
n Word32
ctx
{-# INLINE fnv1a32Update #-}
fnv1a32Finalize :: Fnv1a32Context -> Fnv1a32Hash
fnv1a32Finalize :: Fnv1a32Context -> Fnv1a32Hash
fnv1a32Finalize (Fnv1a32Context !Word32
ctx) = Word32 -> Fnv1a32Hash
Fnv1a32Hash Word32
ctx
{-# INLINE fnv1a32Finalize #-}
fnv1a32 :: Ptr Word8 -> Int -> IO Fnv1a32Hash
fnv1a32 :: Ptr Word8 -> Int -> IO Fnv1a32Hash
fnv1a32 !Ptr Word8
ptr !Int
n = Fnv1a32Context -> Fnv1a32Hash
fnv1a32Finalize (Fnv1a32Context -> Fnv1a32Hash)
-> IO Fnv1a32Context -> IO Fnv1a32Hash
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Fnv1a32Context -> Ptr Word8 -> Int -> IO Fnv1a32Context
fnv1a32Update Fnv1a32Context
fnv1a32Initialize Ptr Word8
ptr Int
n
{-# INLINE fnv1a32 #-}
instance IncrementalHash Fnv1a32Hash where
type Context Fnv1a32Hash = Fnv1a32Context
update :: Context Fnv1a32Hash -> Ptr Word8 -> Int -> IO (Context Fnv1a32Hash)
update = Context Fnv1a32Hash -> Ptr Word8 -> Int -> IO (Context Fnv1a32Hash)
Fnv1a32Context -> Ptr Word8 -> Int -> IO Fnv1a32Context
fnv1a32Update
finalize :: Context Fnv1a32Hash -> Fnv1a32Hash
finalize = Context Fnv1a32Hash -> Fnv1a32Hash
Fnv1a32Context -> Fnv1a32Hash
fnv1a32Finalize
{-# INLINE update #-}
{-# INLINE finalize #-}
instance Hash Fnv1a32Hash where
initialize :: Context Fnv1a32Hash
initialize = Context Fnv1a32Hash
Fnv1a32Context
fnv1a32Initialize
{-# INLINE initialize #-}
newtype Fnv1Context = Fnv1Context Word
newtype Fnv1Hash = Fnv1Hash Word
deriving (Int -> Fnv1Hash -> ShowS
[Fnv1Hash] -> ShowS
Fnv1Hash -> String
(Int -> Fnv1Hash -> ShowS)
-> (Fnv1Hash -> String) -> ([Fnv1Hash] -> ShowS) -> Show Fnv1Hash
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Fnv1Hash] -> ShowS
$cshowList :: [Fnv1Hash] -> ShowS
show :: Fnv1Hash -> String
$cshow :: Fnv1Hash -> String
showsPrec :: Int -> Fnv1Hash -> ShowS
$cshowsPrec :: Int -> Fnv1Hash -> ShowS
Show, Fnv1Hash -> Fnv1Hash -> Bool
(Fnv1Hash -> Fnv1Hash -> Bool)
-> (Fnv1Hash -> Fnv1Hash -> Bool) -> Eq Fnv1Hash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Fnv1Hash -> Fnv1Hash -> Bool
$c/= :: Fnv1Hash -> Fnv1Hash -> Bool
== :: Fnv1Hash -> Fnv1Hash -> Bool
$c== :: Fnv1Hash -> Fnv1Hash -> Bool
Eq, Eq Fnv1Hash
Eq Fnv1Hash
-> (Fnv1Hash -> Fnv1Hash -> Ordering)
-> (Fnv1Hash -> Fnv1Hash -> Bool)
-> (Fnv1Hash -> Fnv1Hash -> Bool)
-> (Fnv1Hash -> Fnv1Hash -> Bool)
-> (Fnv1Hash -> Fnv1Hash -> Bool)
-> (Fnv1Hash -> Fnv1Hash -> Fnv1Hash)
-> (Fnv1Hash -> Fnv1Hash -> Fnv1Hash)
-> Ord Fnv1Hash
Fnv1Hash -> Fnv1Hash -> Bool
Fnv1Hash -> Fnv1Hash -> Ordering
Fnv1Hash -> Fnv1Hash -> Fnv1Hash
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Fnv1Hash -> Fnv1Hash -> Fnv1Hash
$cmin :: Fnv1Hash -> Fnv1Hash -> Fnv1Hash
max :: Fnv1Hash -> Fnv1Hash -> Fnv1Hash
$cmax :: Fnv1Hash -> Fnv1Hash -> Fnv1Hash
>= :: Fnv1Hash -> Fnv1Hash -> Bool
$c>= :: Fnv1Hash -> Fnv1Hash -> Bool
> :: Fnv1Hash -> Fnv1Hash -> Bool
$c> :: Fnv1Hash -> Fnv1Hash -> Bool
<= :: Fnv1Hash -> Fnv1Hash -> Bool
$c<= :: Fnv1Hash -> Fnv1Hash -> Bool
< :: Fnv1Hash -> Fnv1Hash -> Bool
$c< :: Fnv1Hash -> Fnv1Hash -> Bool
compare :: Fnv1Hash -> Fnv1Hash -> Ordering
$ccompare :: Fnv1Hash -> Fnv1Hash -> Ordering
$cp1Ord :: Eq Fnv1Hash
Ord)
fnv1Initialize :: Fnv1Context
fnv1Initialize :: Fnv1Context
fnv1Initialize = Word -> Fnv1Context
Fnv1Context Word
fnvOffsetBasis
{-# INLINE fnv1Initialize #-}
fnv1Update :: Fnv1Context -> Ptr Word8 -> Int -> IO Fnv1Context
fnv1Update :: Fnv1Context -> Ptr Word8 -> Int -> IO Fnv1Context
fnv1Update (Fnv1Context !Word
ctx) !Ptr Word8
ptr !Int
n =
Word -> Fnv1Context
Fnv1Context (Word -> Fnv1Context) -> IO Word -> IO Fnv1Context
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Ptr Word8 -> Int -> Word -> IO Word
fnv1_host_ Ptr Word8
ptr Int
n Word
ctx
{-# INLINE fnv1Update #-}
fnv1Finalize :: Fnv1Context -> Fnv1Hash
fnv1Finalize :: Fnv1Context -> Fnv1Hash
fnv1Finalize (Fnv1Context !Word
ctx) = Word -> Fnv1Hash
Fnv1Hash Word
ctx
{-# INLINE fnv1Finalize #-}
fnv1 :: Ptr Word8 -> Int -> IO Fnv1Hash
fnv1 :: Ptr Word8 -> Int -> IO Fnv1Hash
fnv1 !Ptr Word8
ptr !Int
n = Fnv1Context -> Fnv1Hash
fnv1Finalize (Fnv1Context -> Fnv1Hash) -> IO Fnv1Context -> IO Fnv1Hash
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Fnv1Context -> Ptr Word8 -> Int -> IO Fnv1Context
fnv1Update Fnv1Context
fnv1Initialize Ptr Word8
ptr Int
n
{-# INLINE fnv1 #-}
instance IncrementalHash Fnv1Hash where
type Context Fnv1Hash = Fnv1Context
update :: Context Fnv1Hash -> Ptr Word8 -> Int -> IO (Context Fnv1Hash)
update = Context Fnv1Hash -> Ptr Word8 -> Int -> IO (Context Fnv1Hash)
Fnv1Context -> Ptr Word8 -> Int -> IO Fnv1Context
fnv1Update
finalize :: Context Fnv1Hash -> Fnv1Hash
finalize = Context Fnv1Hash -> Fnv1Hash
Fnv1Context -> Fnv1Hash
fnv1Finalize
{-# INLINE update #-}
{-# INLINE finalize #-}
instance Hash Fnv1Hash where
initialize :: Context Fnv1Hash
initialize = Context Fnv1Hash
Fnv1Context
fnv1Initialize
{-# INLINE initialize #-}
newtype Fnv1aContext = Fnv1aContext Word
newtype Fnv1aHash = Fnv1aHash Word
deriving (Int -> Fnv1aHash -> ShowS
[Fnv1aHash] -> ShowS
Fnv1aHash -> String
(Int -> Fnv1aHash -> ShowS)
-> (Fnv1aHash -> String)
-> ([Fnv1aHash] -> ShowS)
-> Show Fnv1aHash
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Fnv1aHash] -> ShowS
$cshowList :: [Fnv1aHash] -> ShowS
show :: Fnv1aHash -> String
$cshow :: Fnv1aHash -> String
showsPrec :: Int -> Fnv1aHash -> ShowS
$cshowsPrec :: Int -> Fnv1aHash -> ShowS
Show, Fnv1aHash -> Fnv1aHash -> Bool
(Fnv1aHash -> Fnv1aHash -> Bool)
-> (Fnv1aHash -> Fnv1aHash -> Bool) -> Eq Fnv1aHash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Fnv1aHash -> Fnv1aHash -> Bool
$c/= :: Fnv1aHash -> Fnv1aHash -> Bool
== :: Fnv1aHash -> Fnv1aHash -> Bool
$c== :: Fnv1aHash -> Fnv1aHash -> Bool
Eq, Eq Fnv1aHash
Eq Fnv1aHash
-> (Fnv1aHash -> Fnv1aHash -> Ordering)
-> (Fnv1aHash -> Fnv1aHash -> Bool)
-> (Fnv1aHash -> Fnv1aHash -> Bool)
-> (Fnv1aHash -> Fnv1aHash -> Bool)
-> (Fnv1aHash -> Fnv1aHash -> Bool)
-> (Fnv1aHash -> Fnv1aHash -> Fnv1aHash)
-> (Fnv1aHash -> Fnv1aHash -> Fnv1aHash)
-> Ord Fnv1aHash
Fnv1aHash -> Fnv1aHash -> Bool
Fnv1aHash -> Fnv1aHash -> Ordering
Fnv1aHash -> Fnv1aHash -> Fnv1aHash
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Fnv1aHash -> Fnv1aHash -> Fnv1aHash
$cmin :: Fnv1aHash -> Fnv1aHash -> Fnv1aHash
max :: Fnv1aHash -> Fnv1aHash -> Fnv1aHash
$cmax :: Fnv1aHash -> Fnv1aHash -> Fnv1aHash
>= :: Fnv1aHash -> Fnv1aHash -> Bool
$c>= :: Fnv1aHash -> Fnv1aHash -> Bool
> :: Fnv1aHash -> Fnv1aHash -> Bool
$c> :: Fnv1aHash -> Fnv1aHash -> Bool
<= :: Fnv1aHash -> Fnv1aHash -> Bool
$c<= :: Fnv1aHash -> Fnv1aHash -> Bool
< :: Fnv1aHash -> Fnv1aHash -> Bool
$c< :: Fnv1aHash -> Fnv1aHash -> Bool
compare :: Fnv1aHash -> Fnv1aHash -> Ordering
$ccompare :: Fnv1aHash -> Fnv1aHash -> Ordering
$cp1Ord :: Eq Fnv1aHash
Ord)
fnv1aInitialize :: Fnv1aContext
fnv1aInitialize :: Fnv1aContext
fnv1aInitialize = Word -> Fnv1aContext
Fnv1aContext Word
fnvOffsetBasis
{-# INLINE fnv1aInitialize #-}
fnv1aUpdate :: Fnv1aContext -> Ptr Word8 -> Int -> IO Fnv1aContext
fnv1aUpdate :: Fnv1aContext -> Ptr Word8 -> Int -> IO Fnv1aContext
fnv1aUpdate (Fnv1aContext !Word
ctx) !Ptr Word8
ptr !Int
n =
Word -> Fnv1aContext
Fnv1aContext (Word -> Fnv1aContext) -> IO Word -> IO Fnv1aContext
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Ptr Word8 -> Int -> Word -> IO Word
fnv1a_host_ Ptr Word8
ptr Int
n Word
ctx
{-# INLINE fnv1aUpdate #-}
fnv1aFinalize :: Fnv1aContext -> Fnv1aHash
fnv1aFinalize :: Fnv1aContext -> Fnv1aHash
fnv1aFinalize (Fnv1aContext !Word
ctx) = Word -> Fnv1aHash
Fnv1aHash Word
ctx
{-# INLINE fnv1aFinalize #-}
fnv1a :: Ptr Word8 -> Int -> IO Fnv1aHash
fnv1a :: Ptr Word8 -> Int -> IO Fnv1aHash
fnv1a !Ptr Word8
ptr !Int
n = Fnv1aContext -> Fnv1aHash
fnv1aFinalize (Fnv1aContext -> Fnv1aHash) -> IO Fnv1aContext -> IO Fnv1aHash
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Fnv1aContext -> Ptr Word8 -> Int -> IO Fnv1aContext
fnv1aUpdate Fnv1aContext
fnv1aInitialize Ptr Word8
ptr Int
n
{-# INLINE fnv1a #-}
instance IncrementalHash Fnv1aHash where
type Context Fnv1aHash = Fnv1aContext
update :: Context Fnv1aHash -> Ptr Word8 -> Int -> IO (Context Fnv1aHash)
update = Context Fnv1aHash -> Ptr Word8 -> Int -> IO (Context Fnv1aHash)
Fnv1aContext -> Ptr Word8 -> Int -> IO Fnv1aContext
fnv1aUpdate
finalize :: Context Fnv1aHash -> Fnv1aHash
finalize = Context Fnv1aHash -> Fnv1aHash
Fnv1aContext -> Fnv1aHash
fnv1aFinalize
{-# INLINE update #-}
{-# INLINE finalize #-}
instance Hash Fnv1aHash where
initialize :: Context Fnv1aHash
initialize = Context Fnv1aHash
Fnv1aContext
fnv1aInitialize
{-# INLINE initialize #-}
fnvPrime32 :: Word32
fnvPrime32 :: Word32
fnvPrime32 = Word32
0x01000193
{-# INLINE fnvPrime32 #-}
fnvPrime64 :: Word64
fnvPrime64 :: Word64
fnvPrime64 = Word64
0x100000001b3
{-# INLINE fnvPrime64 #-}
fnvOffsetBasis32 :: Word32
fnvOffsetBasis32 :: Word32
fnvOffsetBasis32 = Word32
0x811c9dc5
{-# INLINE fnvOffsetBasis32 #-}
fnvOffsetBasis64 :: Word64
fnvOffsetBasis64 :: Word64
fnvOffsetBasis64 = Word64
0xcbf29ce484222325
{-# INLINE fnvOffsetBasis64 #-}
fnvPrime :: Word
#if defined(x86_64_HOST_ARCH)
fnvPrime :: Word
fnvPrime = Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
fnvPrime64
#elif defined(i386_HOST_ARCH)
fnvPrime = fromIntegral fvnPrime32
#else
fnvPrime = error "fnvPrime: unsupported hardware platform"
#endif
{-# INLINE fnvPrime #-}
fnvOffsetBasis :: Word
#if defined(x86_64_HOST_ARCH)
fnvOffsetBasis :: Word
fnvOffsetBasis = Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
fnvOffsetBasis64
#elif defined(i386_HOST_ARCH)
fnvOffsetBasis = fromIntegral fnvOffsetBasis32
#else
fnvOffsetBasis = error "fnvOffsetBasis: unsupported hardware platform"
#endif
{-# INLINE fnvOffsetBasis #-}
fnv1_64 :: Ptr Word8 -> Int -> IO Word64
fnv1_64 :: Ptr Word8 -> Int -> IO Word64
fnv1_64 !Ptr Word8
ptr !Int
n = Ptr Word8 -> Int -> Word64 -> IO Word64
fnv1_64_ Ptr Word8
ptr Int
n Word64
fnvOffsetBasis64
{-# INLINE fnv1_64 #-}
fnv1_64_ :: Ptr Word8 -> Int -> Word64 -> IO Word64
fnv1_64_ :: Ptr Word8 -> Int -> Word64 -> IO Word64
fnv1_64_ !Ptr Word8
ptr !Int
n !Word64
a = Word64 -> Int -> IO Word64
loop Word64
a Int
0
where
loop :: Word64 -> Int -> IO Word64
loop !Word64
acc !Int
i
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n = Word64 -> IO Word64
forall (m :: * -> *) a. Monad m => a -> m a
return Word64
acc
| Bool
otherwise = do
!Word8
x <- Ptr Word8 -> Int -> IO Word8
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff @Word8 Ptr Word8
ptr Int
i
Word64 -> Int -> IO Word64
loop ((Word64
fnvPrime64 Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
* Word64
acc) Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
x) (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
{-# INLINE fnv1_64_ #-}
fnv1a_64 :: Ptr Word8 -> Int -> IO Word64
fnv1a_64 :: Ptr Word8 -> Int -> IO Word64
fnv1a_64 !Ptr Word8
ptr !Int
n = Ptr Word8 -> Int -> Word64 -> IO Word64
fnv1a_64_ Ptr Word8
ptr Int
n Word64
fnvOffsetBasis64
{-# INLINE fnv1a_64 #-}
fnv1a_64_ :: Ptr Word8 -> Int -> Word64 -> IO Word64
fnv1a_64_ :: Ptr Word8 -> Int -> Word64 -> IO Word64
fnv1a_64_ !Ptr Word8
ptr !Int
n !Word64
a = Word64 -> Int -> IO Word64
loop Word64
a Int
0
where
loop :: Word64 -> Int -> IO Word64
loop !Word64
acc !Int
i
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n = Word64 -> IO Word64
forall (m :: * -> *) a. Monad m => a -> m a
return Word64
acc
| Bool
otherwise = do
!Word8
x <- Ptr Word8 -> Int -> IO Word8
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff @Word8 Ptr Word8
ptr Int
i
Word64 -> Int -> IO Word64
loop (Word64
fnvPrime64 Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
* (Word64
acc Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
x)) (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
{-# INLINE fnv1a_64_ #-}
fnv1_32 :: Ptr Word8 -> Int -> IO Word32
fnv1_32 :: Ptr Word8 -> Int -> IO Word32
fnv1_32 !Ptr Word8
ptr !Int
n = Ptr Word8 -> Int -> Word32 -> IO Word32
fnv1_32_ Ptr Word8
ptr Int
n Word32
fnvOffsetBasis32
{-# INLINE fnv1_32 #-}
fnv1_32_ :: Ptr Word8 -> Int -> Word32 -> IO Word32
fnv1_32_ :: Ptr Word8 -> Int -> Word32 -> IO Word32
fnv1_32_ !Ptr Word8
ptr !Int
n !Word32
a = Word32 -> Int -> IO Word32
loop Word32
a Int
0
where
loop :: Word32 -> Int -> IO Word32
loop !Word32
acc !Int
i
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n = Word32 -> IO Word32
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
acc
| Bool
otherwise = do
!Word8
x <- Ptr Word8 -> Int -> IO Word8
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff @Word8 Ptr Word8
ptr Int
i
Word32 -> Int -> IO Word32
loop ((Word32
fnvPrime32 Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
* Word32
acc) Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
x) (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
{-# INLINE fnv1_32_ #-}
fnv1a_32 :: Ptr Word8 -> Int -> IO Word32
fnv1a_32 :: Ptr Word8 -> Int -> IO Word32
fnv1a_32 !Ptr Word8
ptr !Int
n = Ptr Word8 -> Int -> Word32 -> IO Word32
fnv1a_32_ Ptr Word8
ptr Int
n Word32
fnvOffsetBasis32
{-# INLINE fnv1a_32 #-}
fnv1a_32_ :: Ptr Word8 -> Int -> Word32 -> IO Word32
fnv1a_32_ :: Ptr Word8 -> Int -> Word32 -> IO Word32
fnv1a_32_ !Ptr Word8
ptr !Int
n Word32
a = Word32 -> Int -> IO Word32
loop Word32
a Int
0
where
loop :: Word32 -> Int -> IO Word32
loop !Word32
acc !Int
i
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n = Word32 -> IO Word32
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
acc
| Bool
otherwise = do
!Word8
x <- Ptr Word8 -> Int -> IO Word8
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff @Word8 Ptr Word8
ptr Int
i
Word32 -> Int -> IO Word32
loop (Word32
fnvPrime32 Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
* (Word32
acc Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
`xor` Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
x)) (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
{-# INLINE fnv1a_32_ #-}
fnv1_host :: Ptr Word8 -> Int -> IO Word
fnv1_host :: Ptr Word8 -> Int -> IO Word
fnv1_host (Ptr Addr#
addr) (I# Int#
n) = (State# RealWorld -> (# State# RealWorld, Word #)) -> IO Word
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, Word #)) -> IO Word)
-> (State# RealWorld -> (# State# RealWorld, Word #)) -> IO Word
forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s -> case Addr# -> Int# -> State# RealWorld -> (# State# RealWorld, Word# #)
forall tok. Addr# -> Int# -> State# tok -> (# State# tok, Word# #)
fnv1Primitive Addr#
addr Int#
n State# RealWorld
s of
(# State# RealWorld
s1, Word#
w #) -> (# State# RealWorld
s1, Word# -> Word
W# Word#
w #)
{-# INlINE fnv1_host #-}
fnv1_host_ :: Ptr Word8 -> Int -> Word -> IO Word
fnv1_host_ :: Ptr Word8 -> Int -> Word -> IO Word
fnv1_host_ (Ptr Addr#
addr) (I# Int#
n) (W# Word#
a) = (State# RealWorld -> (# State# RealWorld, Word #)) -> IO Word
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, Word #)) -> IO Word)
-> (State# RealWorld -> (# State# RealWorld, Word #)) -> IO Word
forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s -> case Addr#
-> Int#
-> Word#
-> State# RealWorld
-> (# State# RealWorld, Word# #)
forall tok.
Addr# -> Int# -> Word# -> State# tok -> (# State# tok, Word# #)
fnv1Primitive_ Addr#
addr Int#
n Word#
a State# RealWorld
s of
(# State# RealWorld
s1, Word#
w #) -> (# State# RealWorld
s1, Word# -> Word
W# Word#
w #)
{-# INlINE fnv1_host_ #-}
fnv1Primitive :: Addr# -> Int# -> State# tok -> (# State# tok, Word# #)
fnv1Primitive :: Addr# -> Int# -> State# tok -> (# State# tok, Word# #)
fnv1Primitive !Addr#
addr !Int#
n !State# tok
tok = Addr# -> Int# -> Word# -> State# tok -> (# State# tok, Word# #)
forall tok.
Addr# -> Int# -> Word# -> State# tok -> (# State# tok, Word# #)
fnv1Primitive_ Addr#
addr Int#
n Word#
o State# tok
tok
where
!(W# Word#
o) = Word
fnvOffsetBasis
{-# INLINE fnv1Primitive #-}
fnv1Primitive_ :: Addr# -> Int# -> Word# -> State# tok -> (# State# tok, Word# #)
fnv1Primitive_ :: Addr# -> Int# -> Word# -> State# tok -> (# State# tok, Word# #)
fnv1Primitive_ !Addr#
addr !Int#
n !Word#
a State# tok
tok = case Word# -> Int# -> State# tok -> (# State# tok, Word# #)
loop Word#
a Int#
0# State# tok
tok of
(# State# tok
tok1, Word#
w #) -> (# State# tok
tok1, Word#
w #)
where
loop :: Word# -> Int# -> State# tok -> (# State# tok, Word# #)
loop !Word#
acc !Int#
i !State# tok
s = case Int#
i Int# -> Int# -> Int#
==# Int#
n of
Int#
1# -> (# State# tok
s, Word#
acc #)
Int#
_ -> case Addr# -> Int# -> State# tok -> (# State# tok, Word# #)
forall tok. Addr# -> Int# -> State# tok -> (# State# tok, Word# #)
readWord8OffAddr# Addr#
addr Int#
i State# tok
s of
(# State# tok
s1, Word#
w #) -> Word# -> Int# -> State# tok -> (# State# tok, Word# #)
loop
((Word#
p Word# -> Word# -> Word#
`timesWord#` Word#
acc) Word# -> Word# -> Word#
`xor#` Word# -> Word#
word8ToWord# Word#
w)
(Int#
i Int# -> Int# -> Int#
+# Int#
1#)
State# tok
s1
!(W# Word#
p) = Word
fnvPrime
{-# INLINE fnv1Primitive_ #-}
fnv1a_host :: Ptr Word8 -> Int -> IO Word
fnv1a_host :: Ptr Word8 -> Int -> IO Word
fnv1a_host (Ptr Addr#
addr) (I# Int#
n) = (State# RealWorld -> (# State# RealWorld, Word #)) -> IO Word
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, Word #)) -> IO Word)
-> (State# RealWorld -> (# State# RealWorld, Word #)) -> IO Word
forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s -> case Addr# -> Int# -> State# RealWorld -> (# State# RealWorld, Word# #)
forall tok. Addr# -> Int# -> State# tok -> (# State# tok, Word# #)
fnv1aPrimitive Addr#
addr Int#
n State# RealWorld
s of
(# State# RealWorld
s1, Word#
w #) -> (# State# RealWorld
s1, Word# -> Word
W# Word#
w #)
{-# INlINE fnv1a_host #-}
fnv1a_host_ :: Ptr Word8 -> Int -> Word -> IO Word
fnv1a_host_ :: Ptr Word8 -> Int -> Word -> IO Word
fnv1a_host_ (Ptr Addr#
addr) (I# Int#
n) (W# Word#
a) = (State# RealWorld -> (# State# RealWorld, Word #)) -> IO Word
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO ((State# RealWorld -> (# State# RealWorld, Word #)) -> IO Word)
-> (State# RealWorld -> (# State# RealWorld, Word #)) -> IO Word
forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s -> case Addr#
-> Int#
-> Word#
-> State# RealWorld
-> (# State# RealWorld, Word# #)
forall tok.
Addr# -> Int# -> Word# -> State# tok -> (# State# tok, Word# #)
fnv1aPrimitive_ Addr#
addr Int#
n Word#
a State# RealWorld
s of
(# State# RealWorld
s1, Word#
w #) -> (# State# RealWorld
s1, Word# -> Word
W# Word#
w #)
{-# INlINE fnv1a_host_ #-}
fnv1aPrimitive :: Addr# -> Int# -> State# tok -> (# State# tok, Word# #)
fnv1aPrimitive :: Addr# -> Int# -> State# tok -> (# State# tok, Word# #)
fnv1aPrimitive !Addr#
addr !Int#
n !State# tok
tok = Addr# -> Int# -> Word# -> State# tok -> (# State# tok, Word# #)
forall tok.
Addr# -> Int# -> Word# -> State# tok -> (# State# tok, Word# #)
fnv1aPrimitive_ Addr#
addr Int#
n Word#
o State# tok
tok
where
!(W# Word#
o) = Word
fnvOffsetBasis
{-# INLINE fnv1aPrimitive #-}
fnv1aPrimitive_ :: Addr# -> Int# -> Word# -> State# tok -> (# State# tok, Word# #)
fnv1aPrimitive_ :: Addr# -> Int# -> Word# -> State# tok -> (# State# tok, Word# #)
fnv1aPrimitive_ !Addr#
addr !Int#
n !Word#
a State# tok
tok = case Word# -> Int# -> State# tok -> (# State# tok, Word# #)
loop Word#
a Int#
0# State# tok
tok of
(# State# tok
tok1, Word#
w #) -> (# State# tok
tok1, Word#
w #)
where
loop :: Word# -> Int# -> State# tok -> (# State# tok, Word# #)
loop !Word#
acc !Int#
i !State# tok
s = case Int#
i Int# -> Int# -> Int#
==# Int#
n of
Int#
1# -> (# State# tok
s, Word#
acc #)
Int#
_ -> case Addr# -> Int# -> State# tok -> (# State# tok, Word# #)
forall tok. Addr# -> Int# -> State# tok -> (# State# tok, Word# #)
readWord8OffAddr# Addr#
addr Int#
i State# tok
s of
(# State# tok
s1, Word#
w #) ->
let !acc' :: Word#
acc' = Word#
p Word# -> Word# -> Word#
`timesWord#` (Word#
acc Word# -> Word# -> Word#
`xor#` Word# -> Word#
word8ToWord# Word#
w)
!n' :: Int#
n' = Int#
i Int# -> Int# -> Int#
+# Int#
1#
in Word# -> Int# -> State# tok -> (# State# tok, Word# #)
loop Word#
acc' Int#
n' State# tok
s1
!(W# Word#
p) = Word
fnvPrime
{-# INLINE fnv1aPrimitive_ #-}
#if !MIN_VERSION_base(4,16,0)
word8ToWord# :: Word# -> Word#
word8ToWord# :: Word# -> Word#
word8ToWord# Word#
a = Word#
a
{-# INLINE word8ToWord# #-}
#endif