-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Bindings to the C implementation the xxHash algorithm
--   
--   Bindings to the C implementation the xxHash algorithm. xxHash provides
--   32-bit and 64-bit extremely fast non-cryptographic hash functions.
@package xxhash-ffi
@version 0.2.0.0


-- | This module provides FFI imports to the C reference library at
--   <a>https://github.com/Cyan4973/xxHash</a>.
--   
--   This binding keeps the intermediate state for stream processing in an
--   <a>MutableByteArray#</a> on the managed GHC heap. All foreign imports
--   use unsafe call semantics. Therefore, it is possible to use either
--   unpinned or pinned <a>MutableByteArray#</a> since GHC's garbage
--   collector doesn't move the either kind during an unsafe foreign call.
--   However GHCi &lt;8.4 may replace unsafe foreign calls with safe
--   foreign calls in the bytecode interpreter. Consequently, unpinned
--   'MutableByteArray#s' may be moved by the garbage collector during
--   foreign calls which obviously breaks this code. So extra care should
--   be taken when loading this code into the bytecode interpreter.
module Data.Digest.XXHash.FFI.C
c_xxh64 :: Ptr a -> CSize -> CULLong -> IO CULLong
c_xxh32 :: Ptr a -> CSize -> CUInt -> IO CUInt

-- | Intermediate state for computing a XXH32 using segmentation or
--   streams.
type XXH32State = MutableByteArray# RealWorld

-- | 'allocaXXH32State f' temporarily allocates a <a>XXH32State</a> and
--   passes it to the function <tt>f</tt>.
allocaXXH32State :: (XXH32State -> IO a) -> IO a
c_xxh32_copyState :: XXH32State -> XXH32State -> IO ()
c_xxh32_reset :: XXH32State -> CUInt -> IO ()
c_xxh32_update :: XXH32State -> Ptr a -> CSize -> IO ()
c_xxh32_digest :: XXH32State -> IO CUInt

-- | Intermediate state for computing a XXH64 using segmentation or
--   streams.
type XXH64State = MutableByteArray# RealWorld

-- | 'allocaXXH64State f' temporarily allocates a <a>XXH64State</a> and
--   passes it to the function <tt>f</tt>.
allocaXXH64State :: (XXH64State -> IO a) -> IO a
c_xxh64_copyState :: XXH64State -> XXH64State -> IO ()
c_xxh64_reset :: XXH64State -> CULLong -> IO ()
c_xxh64_update :: XXH64State -> Ptr a -> CSize -> IO ()
c_xxh64_digest :: XXH64State -> IO CULLong


-- | This module provides bindings to the xxHash64 and the xxHash32
--   algorithm.
--   
--   The C implementation used is directly taken from
--   <a>https://github.com/Cyan4973/xxHash</a>.
module Data.Digest.XXHash.FFI

-- | Class for hashable data types.
--   
--   Not that all standard instances are specialized using the
--   <tt>SPECIALIZE</tt> pragma.
class XXHash t

-- | Calculate the 32-bit xxHash using a given seed.
xxh32 :: XXHash t => t -> Word32 -> Word32

-- | Calculate the 64-bit xxHash using a given seed.
xxh64 :: XXHash t => t -> Word64 -> Word64
instance Data.Digest.XXHash.FFI.XXHash Data.ByteString.Internal.ByteString
instance Data.Digest.XXHash.FFI.XXHash Data.ByteString.Lazy.Internal.ByteString
