-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Efficiently hash (large) Haskell values -- -- Please see README.md @package large-hashable @version 0.1.2.0 -- | Generic, low-level data types for hashing. This is an internal module. -- -- You should only import this module if you write your own hash -- algorithm or if you need access to low-level hashing functions when -- defining instances of LargeHash. -- -- Regular users should not import this module. Import -- LargeHashable instead. module Data.LargeHashable.Intern -- | Functions for updating an intermediate hash value. The functions live -- in the IO monad because they are typically implemented via FFI. data HashUpdates HashUpdates :: {-# NOUNPACK #-} !Ptr Word8 -> Int -> IO () -> {-# NOUNPACK #-} !Word8 -> IO () -> {-# NOUNPACK #-} !Word16 -> IO () -> {-# NOUNPACK #-} !Word32 -> IO () -> {-# NOUNPACK #-} !Word64 -> IO () -> HashUpdates -- | adds a byte array to the hash [hu_updatePtr] :: HashUpdates -> {-# NOUNPACK #-} !Ptr Word8 -> Int -> IO () [hu_updateUChar] :: HashUpdates -> {-# NOUNPACK #-} !Word8 -> IO () [hu_updateUShort] :: HashUpdates -> {-# NOUNPACK #-} !Word16 -> IO () [hu_updateUInt] :: HashUpdates -> {-# NOUNPACK #-} !Word32 -> IO () [hu_updateULong] :: HashUpdates -> {-# NOUNPACK #-} !Word64 -> IO () -- | The interface for a hashing algorithm. The interface contains a simple -- run function, which is used to update the hash with all values needed, -- and the outputs the resulting hash. data HashAlgorithm h HashAlgorithm :: {-# NOUNPACK #-} !(HashUpdates -> IO ()) -> IO h -> {-# NOUNPACK #-} !h -> h -> h -> {-# NOUNPACK #-} !HashUpdates -> h -> IO () -> HashAlgorithm h [ha_run] :: HashAlgorithm h -> {-# NOUNPACK #-} !(HashUpdates -> IO ()) -> IO h [ha_xor] :: HashAlgorithm h -> {-# NOUNPACK #-} !h -> h -> h [ha_updateHash] :: HashAlgorithm h -> {-# NOUNPACK #-} !HashUpdates -> h -> IO () -- | The LH monad (LH stands for "large hash") is used in the -- definition of hashing functions for arbitrary data types. data LH a hashUpdates :: LH HashUpdates -- | Perform an IO action in the LH monad. Use with care, do -- not perform arbitrary IO operation with this function! Only use -- it for calling functions of the HashUpdates datatype. ioInLH :: IO a -> LH a -- | Runs a LH computation and returns the resulting hash. runLH :: HashAlgorithm h -> LH () -> h updateXorHash :: [LH ()] -> LH () instance GHC.Base.Functor Data.LargeHashable.Intern.LH instance GHC.Base.Applicative Data.LargeHashable.Intern.LH instance GHC.Base.Monad Data.LargeHashable.Intern.LH -- | This module defines the central type class LargeHashable of -- this package. module Data.LargeHashable.Class -- | A type class for computing hashes (i.e. MD5, SHA256, ...) from haskell -- values. -- -- The laws of this typeclass are the following: -- --
    --
  1. If two values are equal according to ==, then the finally -- computed hashes must also be equal according to ==. However it -- is not required that the hashes of inequal values have to be inequal. -- Also note that an instance of LargeHashable does not require a -- instance of Eq. Using any sane algorithm the chance of a -- collision should be 1 / n where n is the number of different hashes -- possible.
  2. --
  3. If two values are inequal according to ==, then the -- probability of a hash collision is 1/n, where n is the number of -- possible hashes produced by the underlying hash algorithm.
  4. --
-- -- A rule of thumb: hash all information that you would also need for -- serializing/deserializing values of your datatype. For instance, when -- hashing lists, you would not only hash the list elements but also the -- length of the list. Consider the following datatype -- --
--   data Foo = Foo [Int] [Int]
--   
-- -- We now write an instance for LargeHashable like this -- --
--   instance LargeHashable Foo where
--       updateHash (Foo l1 l2) = updateHash l1 >> updateHash l2
--   
-- -- If we did not hash the length of a list, then the following two values -- of Foo would produce identical hashes: -- --
--   Foo [1,2,3] []
--   Foo [1] [2,3]
--   
class LargeHashable a updateHash :: LargeHashable a => a -> LH () updateHash :: (LargeHashable a, GenericLargeHashable (Rep a), Generic a) => a -> LH () updateHashStable :: LargeHashable a => a -> LH () updateHashStable :: (LargeHashable a, GenericLargeHashable (Rep a), Generic a) => a -> LH () -- | largeHash is the central function of this package. For a given -- value it computes a Hash using the given -- HashAlgorithm. The library tries to keep the hash values for -- LargeHashable instances provided by library stable across -- releases, but there is no guarantee. See @largeHashStable& largeHash :: LargeHashable a => HashAlgorithm h -> a -> h -- | largeHashStable is similar to largeHash, but the hash -- value is guaranteed to remain stable across releases, even if this -- causes performance to degrade. largeHashStable :: LargeHashable a => HashAlgorithm h -> a -> h class LargeHashable' t updateHash' :: (LargeHashable' t, LargeHashable a) => t a -> LH () updateHashStable' :: (LargeHashable' t, LargeHashable a) => t a -> LH () genericUpdateHash :: (Generic a, GenericLargeHashable (Rep a)) => a -> LH () updateHashList :: forall a. (a -> LH ()) -> [a] -> LH () instance (Data.LargeHashable.Class.GenericLargeHashable f, Data.LargeHashable.Class.GenericLargeHashableSum g) => Data.LargeHashable.Class.GenericLargeHashable (f GHC.Generics.:+: g) instance (Data.LargeHashable.Class.GenericLargeHashable f, Data.LargeHashable.Class.GenericLargeHashableSum g) => Data.LargeHashable.Class.GenericLargeHashableSum (f GHC.Generics.:+: g) instance Data.LargeHashable.Class.GenericLargeHashable f => Data.LargeHashable.Class.GenericLargeHashableSum (GHC.Generics.M1 i t f) instance Data.LargeHashable.Class.LargeHashable Data.Text.Internal.Text instance Data.LargeHashable.Class.LargeHashable Data.Text.Internal.Lazy.Text instance Data.LargeHashable.Class.LargeHashable Data.ByteString.Internal.Type.ByteString instance Data.LargeHashable.Class.LargeHashable Data.ByteString.Lazy.Internal.ByteString instance Data.LargeHashable.Class.LargeHashable Data.ByteString.Short.Internal.ShortByteString instance Data.LargeHashable.Class.LargeHashable GHC.Types.Int instance Data.LargeHashable.Class.LargeHashable GHC.Int.Int8 instance Data.LargeHashable.Class.LargeHashable GHC.Int.Int16 instance Data.LargeHashable.Class.LargeHashable GHC.Int.Int32 instance Data.LargeHashable.Class.LargeHashable GHC.Int.Int64 instance Data.LargeHashable.Class.LargeHashable GHC.Types.Word instance Data.LargeHashable.Class.LargeHashable GHC.Word.Word8 instance Data.LargeHashable.Class.LargeHashable GHC.Word.Word16 instance Data.LargeHashable.Class.LargeHashable GHC.Word.Word32 instance Data.LargeHashable.Class.LargeHashable GHC.Word.Word64 instance Data.LargeHashable.Class.LargeHashable Foreign.C.Types.CChar instance Data.LargeHashable.Class.LargeHashable Foreign.C.Types.CShort instance Data.LargeHashable.Class.LargeHashable Foreign.C.Types.CInt instance Data.LargeHashable.Class.LargeHashable Foreign.C.Types.CLong instance Data.LargeHashable.Class.LargeHashable Foreign.C.Types.CUChar instance Data.LargeHashable.Class.LargeHashable Foreign.C.Types.CUShort instance Data.LargeHashable.Class.LargeHashable Foreign.C.Types.CUInt instance Data.LargeHashable.Class.LargeHashable Foreign.C.Types.CULong instance Data.LargeHashable.Class.LargeHashable GHC.Types.Char instance Data.LargeHashable.Class.LargeHashable GHC.Num.Integer.Integer instance Data.LargeHashable.Class.LargeHashable GHC.Types.Double instance Data.LargeHashable.Class.LargeHashable GHC.Types.Float instance Data.Fixed.HasResolution a => Data.LargeHashable.Class.LargeHashable (Data.Fixed.Fixed a) instance Data.LargeHashable.Class.LargeHashable GHC.Types.Bool instance Data.LargeHashable.Class.LargeHashable a => Data.LargeHashable.Class.LargeHashable [a] instance Data.LargeHashable.Class.LargeHashable a => Data.LargeHashable.Class.LargeHashable (Data.Set.Internal.Set a) instance Data.LargeHashable.Class.LargeHashable Data.IntSet.Internal.IntSet instance Data.LargeHashable.Class.LargeHashable a => Data.LargeHashable.Class.LargeHashable (Data.HashSet.Internal.HashSet a) instance (Data.LargeHashable.Class.LargeHashable k, Data.LargeHashable.Class.LargeHashable a) => Data.LargeHashable.Class.LargeHashable (Data.Map.Internal.Map k a) instance Data.LargeHashable.Class.LargeHashable a => Data.LargeHashable.Class.LargeHashable (Data.IntMap.Internal.IntMap a) instance (Data.LargeHashable.Class.LargeHashable k, Data.LargeHashable.Class.LargeHashable v) => Data.LargeHashable.Class.LargeHashable (Data.HashMap.Internal.HashMap k v) instance (Data.LargeHashable.Class.LargeHashable a, Data.LargeHashable.Class.LargeHashable b) => Data.LargeHashable.Class.LargeHashable (a, b) instance (Data.LargeHashable.Class.LargeHashable a, Data.LargeHashable.Class.LargeHashable b, Data.LargeHashable.Class.LargeHashable c) => Data.LargeHashable.Class.LargeHashable (a, b, c) instance (Data.LargeHashable.Class.LargeHashable a, Data.LargeHashable.Class.LargeHashable b, Data.LargeHashable.Class.LargeHashable c, Data.LargeHashable.Class.LargeHashable d) => Data.LargeHashable.Class.LargeHashable (a, b, c, d) instance (Data.LargeHashable.Class.LargeHashable a, Data.LargeHashable.Class.LargeHashable b, Data.LargeHashable.Class.LargeHashable c, Data.LargeHashable.Class.LargeHashable d, Data.LargeHashable.Class.LargeHashable e) => Data.LargeHashable.Class.LargeHashable (a, b, c, d, e) instance Data.LargeHashable.Class.LargeHashable a => Data.LargeHashable.Class.LargeHashable (GHC.Maybe.Maybe a) instance (Data.LargeHashable.Class.LargeHashable a, Data.LargeHashable.Class.LargeHashable b) => Data.LargeHashable.Class.LargeHashable (Data.Either.Either a b) instance Data.LargeHashable.Class.LargeHashable () instance Data.LargeHashable.Class.LargeHashable GHC.Types.Ordering instance (GHC.Real.Integral a, Data.LargeHashable.Class.LargeHashable a) => Data.LargeHashable.Class.LargeHashable (GHC.Real.Ratio a) instance Data.LargeHashable.Class.LargeHashable Data.Time.Clock.Internal.AbsoluteTime.AbsoluteTime instance Data.LargeHashable.Class.LargeHashable Data.Time.Clock.Internal.DiffTime.DiffTime instance Data.LargeHashable.Class.LargeHashable Data.Time.Clock.Internal.NominalDiffTime.NominalDiffTime instance Data.LargeHashable.Class.LargeHashable Data.Time.LocalTime.Internal.LocalTime.LocalTime instance Data.LargeHashable.Class.LargeHashable Data.Time.LocalTime.Internal.ZonedTime.ZonedTime instance Data.LargeHashable.Class.LargeHashable Data.Time.LocalTime.Internal.TimeOfDay.TimeOfDay instance Data.LargeHashable.Class.LargeHashable Data.Time.LocalTime.Internal.TimeZone.TimeZone instance Data.LargeHashable.Class.LargeHashable Data.Time.Clock.Internal.UTCTime.UTCTime instance Data.LargeHashable.Class.LargeHashable Data.Time.Calendar.Days.Day instance Data.LargeHashable.Class.LargeHashable Data.Time.Clock.Internal.UniversalTime.UniversalTime instance Data.LargeHashable.Class.LargeHashable a => Data.LargeHashable.Class.LargeHashable (Data.Vector.Vector a) instance (Data.LargeHashable.Class.LargeHashable a, Data.LargeHashable.Class.LargeHashable b) => Data.LargeHashable.Class.LargeHashable (Data.Strict.Tuple.Pair a b) instance Data.LargeHashable.Class.LargeHashable Data.Scientific.Scientific instance Data.LargeHashable.Class.LargeHashable Data.Aeson.Types.Internal.Value instance Data.LargeHashable.Class.LargeHashable Data.Aeson.Key.Key instance Data.LargeHashable.Class.LargeHashable v => Data.LargeHashable.Class.LargeHashable (Data.Aeson.KeyMap.KeyMap v) instance Data.LargeHashable.Class.LargeHashable GHC.Base.Void instance Data.LargeHashable.Class.LargeHashable a => Data.LargeHashable.Class.LargeHashable (Data.Sequence.Internal.Seq a) instance Data.LargeHashable.Class.GenericLargeHashable GHC.Generics.U1 instance Data.LargeHashable.Class.LargeHashable c => Data.LargeHashable.Class.GenericLargeHashable (GHC.Generics.K1 i c) instance Data.LargeHashable.Class.GenericLargeHashable GHC.Generics.V1 instance (Data.LargeHashable.Class.GenericLargeHashable f, Data.LargeHashable.Class.GenericLargeHashable g) => Data.LargeHashable.Class.GenericLargeHashable (f GHC.Generics.:*: g) instance Data.LargeHashable.Class.GenericLargeHashable f => Data.LargeHashable.Class.GenericLargeHashable (GHC.Generics.M1 i t f) -- | Efficient representation for small bytearrays with 128 or 256 bits. module Data.LargeHashable.LargeWord data Word128 Word128 :: !Word64 -> !Word64 -> Word128 [w128_first] :: Word128 -> !Word64 [w128_second] :: Word128 -> !Word64 data Word256 Word256 :: !Word128 -> !Word128 -> Word256 [w256_first] :: Word256 -> !Word128 [w256_second] :: Word256 -> !Word128 -- | Converts a ByteString into a Word128. Only the first -- 16 bytes are taken into account, the rest is ignored. bsToW128 :: ByteString -> Word128 w128ToBs :: Word128 -> ByteString -- | Converts a ByteString into a Word256. Only the first -- 32 bytes are taken into account, the rest is ignored. bsToW256 :: ByteString -> Word256 w256ToBs :: Word256 -> ByteString xorW128 :: Word128 -> Word128 -> Word128 xorW256 :: Word256 -> Word256 -> Word256 instance Data.Data.Data Data.LargeHashable.LargeWord.Word128 instance GHC.Generics.Generic Data.LargeHashable.LargeWord.Word128 instance GHC.Classes.Ord Data.LargeHashable.LargeWord.Word128 instance GHC.Classes.Eq Data.LargeHashable.LargeWord.Word128 instance GHC.Read.Read Data.LargeHashable.LargeWord.Word128 instance GHC.Show.Show Data.LargeHashable.LargeWord.Word128 instance Data.Data.Data Data.LargeHashable.LargeWord.Word256 instance GHC.Generics.Generic Data.LargeHashable.LargeWord.Word256 instance GHC.Classes.Ord Data.LargeHashable.LargeWord.Word256 instance GHC.Classes.Eq Data.LargeHashable.LargeWord.Word256 instance GHC.Read.Read Data.LargeHashable.LargeWord.Word256 instance GHC.Show.Show Data.LargeHashable.LargeWord.Word256 -- | An implementation of HashAlgorithm for MD5 -- (https:/www.ietf.orgrfc/rfc1321.txt). module Data.LargeHashable.MD5 newtype MD5Hash MD5Hash :: Word128 -> MD5Hash [unMD5Hash] :: MD5Hash -> Word128 md5HashAlgorithm :: HashAlgorithm MD5Hash runMD5 :: LH () -> MD5Hash instance GHC.Classes.Ord Data.LargeHashable.MD5.MD5Hash instance GHC.Classes.Eq Data.LargeHashable.MD5.MD5Hash instance GHC.Show.Show Data.LargeHashable.MD5.MD5Hash instance GHC.Read.Read Data.LargeHashable.MD5.MD5Hash module Data.LargeHashable.TH deriveLargeHashable :: Name -> Q [Dec] -- | Derive a LargeHashable instance with extra constraints in the -- context of the instance. deriveLargeHashableCtx :: Name -> ([TypeQ] -> [PredQ]) -> Q [Dec] -- | Derive a LargeHashable instance with no constraints in the -- context of the instance. deriveLargeHashableNoCtx :: Name -> Q [Dec] -- | Derive a LargeHashable instance with a completely custom -- instance context. deriveLargeHashableCustomCtx :: Name -> ([TypeQ] -> [PredQ] -> [PredQ]) -> Q [Dec] -- | This is the top-level module of LargeHashable, a library for -- efficiently hashing any Haskell data type using a hash algorithm like -- MD5, SHA256 etc. -- -- Normal users should import this module. module Data.LargeHashable -- | A type class for computing hashes (i.e. MD5, SHA256, ...) from haskell -- values. -- -- The laws of this typeclass are the following: -- --
    --
  1. If two values are equal according to ==, then the finally -- computed hashes must also be equal according to ==. However it -- is not required that the hashes of inequal values have to be inequal. -- Also note that an instance of LargeHashable does not require a -- instance of Eq. Using any sane algorithm the chance of a -- collision should be 1 / n where n is the number of different hashes -- possible.
  2. --
  3. If two values are inequal according to ==, then the -- probability of a hash collision is 1/n, where n is the number of -- possible hashes produced by the underlying hash algorithm.
  4. --
-- -- A rule of thumb: hash all information that you would also need for -- serializing/deserializing values of your datatype. For instance, when -- hashing lists, you would not only hash the list elements but also the -- length of the list. Consider the following datatype -- --
--   data Foo = Foo [Int] [Int]
--   
-- -- We now write an instance for LargeHashable like this -- --
--   instance LargeHashable Foo where
--       updateHash (Foo l1 l2) = updateHash l1 >> updateHash l2
--   
-- -- If we did not hash the length of a list, then the following two values -- of Foo would produce identical hashes: -- --
--   Foo [1,2,3] []
--   Foo [1] [2,3]
--   
class LargeHashable a updateHash :: LargeHashable a => a -> LH () updateHash :: (LargeHashable a, GenericLargeHashable (Rep a), Generic a) => a -> LH () updateHashStable :: LargeHashable a => a -> LH () updateHashStable :: (LargeHashable a, GenericLargeHashable (Rep a), Generic a) => a -> LH () class LargeHashable' t updateHash' :: (LargeHashable' t, LargeHashable a) => t a -> LH () updateHashStable' :: (LargeHashable' t, LargeHashable a) => t a -> LH () -- | The LH monad (LH stands for "large hash") is used in the -- definition of hashing functions for arbitrary data types. data LH a -- | The interface for a hashing algorithm. The interface contains a simple -- run function, which is used to update the hash with all values needed, -- and the outputs the resulting hash. data HashAlgorithm h -- | largeHash is the central function of this package. For a given -- value it computes a Hash using the given -- HashAlgorithm. The library tries to keep the hash values for -- LargeHashable instances provided by library stable across -- releases, but there is no guarantee. See @largeHashStable& largeHash :: LargeHashable a => HashAlgorithm h -> a -> h -- | largeHashStable is similar to largeHash, but the hash -- value is guaranteed to remain stable across releases, even if this -- causes performance to degrade. largeHashStable :: LargeHashable a => HashAlgorithm h -> a -> h deriveLargeHashable :: Name -> Q [Dec] -- | Derive a LargeHashable instance with no constraints in the -- context of the instance. deriveLargeHashableNoCtx :: Name -> Q [Dec] -- | Derive a LargeHashable instance with extra constraints in the -- context of the instance. deriveLargeHashableCtx :: Name -> ([TypeQ] -> [PredQ]) -> Q [Dec] -- | Derive a LargeHashable instance with a completely custom -- instance context. deriveLargeHashableCustomCtx :: Name -> ([TypeQ] -> [PredQ] -> [PredQ]) -> Q [Dec] newtype MD5Hash MD5Hash :: Word128 -> MD5Hash [unMD5Hash] :: MD5Hash -> Word128 md5HashAlgorithm :: HashAlgorithm MD5Hash runMD5 :: LH () -> MD5Hash