large-hashable-0.1.1.0: Efficiently hash (large) Haskell values
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.LargeHashable

Description

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 shoud import this module.

Synopsis

Documentation

class LargeHashable a where Source #

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. 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.

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]

Minimal complete definition

Nothing

Methods

updateHash :: a -> LH () Source #

default updateHash :: (GenericLargeHashable (Rep a), Generic a) => a -> LH () Source #

updateHashStable :: a -> LH () Source #

default updateHashStable :: (GenericLargeHashable (Rep a), Generic a) => a -> LH () Source #

Instances

Instances details
LargeHashable Key Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Value Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable CChar Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable CInt Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable CLong Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable CShort Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable CUChar Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable CUInt Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable CULong Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable CUShort Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Void Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Int16 Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Int32 Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Int64 Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Int8 Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Word16 Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Word32 Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Word64 Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Word8 Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable ByteString Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable ByteString Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable ShortByteString Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable IntSet Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Ordering Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Scientific Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Text Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Text Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Day Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable AbsoluteTime Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable DiffTime Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable NominalDiffTime Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable UTCTime Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable UniversalTime Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable LocalTime Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable TimeOfDay Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable TimeZone Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable ZonedTime Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Integer Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable () Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: () -> LH () Source #

updateHashStable :: () -> LH () Source #

LargeHashable Bool Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Char Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Double Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Float Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Int Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable Word Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable v => LargeHashable (KeyMap v) Source # 
Instance details

Defined in Data.LargeHashable.Class

(Integral a, LargeHashable a) => LargeHashable (Ratio a) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: Ratio a -> LH () Source #

updateHashStable :: Ratio a -> LH () Source #

LargeHashable a => LargeHashable (IntMap a) Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable a => LargeHashable (Seq a) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: Seq a -> LH () Source #

updateHashStable :: Seq a -> LH () Source #

LargeHashable a => LargeHashable (Set a) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: Set a -> LH () Source #

updateHashStable :: Set a -> LH () Source #

LargeHashable a => LargeHashable (HashSet a) Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable a => LargeHashable (Vector a) Source # 
Instance details

Defined in Data.LargeHashable.Class

LargeHashable a => LargeHashable (Maybe a) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: Maybe a -> LH () Source #

updateHashStable :: Maybe a -> LH () Source #

LargeHashable a => LargeHashable [a] Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: [a] -> LH () Source #

updateHashStable :: [a] -> LH () Source #

(LargeHashable a, LargeHashable b) => LargeHashable (Either a b) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: Either a b -> LH () Source #

updateHashStable :: Either a b -> LH () Source #

HasResolution a => LargeHashable (Fixed a) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: Fixed a -> LH () Source #

updateHashStable :: Fixed a -> LH () Source #

(LargeHashable k, LargeHashable a) => LargeHashable (Map k a) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: Map k a -> LH () Source #

updateHashStable :: Map k a -> LH () Source #

(LargeHashable a, LargeHashable b) => LargeHashable (Pair a b) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: Pair a b -> LH () Source #

updateHashStable :: Pair a b -> LH () Source #

(LargeHashable k, LargeHashable v) => LargeHashable (HashMap k v) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: HashMap k v -> LH () Source #

updateHashStable :: HashMap k v -> LH () Source #

(LargeHashable a, LargeHashable b) => LargeHashable (a, b) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: (a, b) -> LH () Source #

updateHashStable :: (a, b) -> LH () Source #

(LargeHashable a, LargeHashable b, LargeHashable c) => LargeHashable (a, b, c) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: (a, b, c) -> LH () Source #

updateHashStable :: (a, b, c) -> LH () Source #

(LargeHashable a, LargeHashable b, LargeHashable c, LargeHashable d) => LargeHashable (a, b, c, d) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: (a, b, c, d) -> LH () Source #

updateHashStable :: (a, b, c, d) -> LH () Source #

(LargeHashable a, LargeHashable b, LargeHashable c, LargeHashable d, LargeHashable e) => LargeHashable (a, b, c, d, e) Source # 
Instance details

Defined in Data.LargeHashable.Class

Methods

updateHash :: (a, b, c, d, e) -> LH () Source #

updateHashStable :: (a, b, c, d, e) -> LH () Source #

class LargeHashable' t where Source #

Methods

updateHash' :: LargeHashable a => t a -> LH () Source #

updateHashStable' :: LargeHashable a => t a -> LH () Source #

data LH a Source #

The LH monad (LH stands for "large hash") is used in the definition of hashing functions for arbitrary data types.

Instances

Instances details
Applicative LH Source # 
Instance details

Defined in Data.LargeHashable.Intern

Methods

pure :: a -> LH a #

(<*>) :: LH (a -> b) -> LH a -> LH b #

liftA2 :: (a -> b -> c) -> LH a -> LH b -> LH c #

(*>) :: LH a -> LH b -> LH b #

(<*) :: LH a -> LH b -> LH a #

Functor LH Source # 
Instance details

Defined in Data.LargeHashable.Intern

Methods

fmap :: (a -> b) -> LH a -> LH b #

(<$) :: a -> LH b -> LH a #

Monad LH Source # 
Instance details

Defined in Data.LargeHashable.Intern

Methods

(>>=) :: LH a -> (a -> LH b) -> LH b #

(>>) :: LH a -> LH b -> LH b #

return :: a -> LH a #

data HashAlgorithm h Source #

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.

largeHash :: LargeHashable a => HashAlgorithm h -> a -> h Source #

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&

largeHashStable :: LargeHashable a => HashAlgorithm h -> a -> h Source #

largeHashStable is similar to largeHash, but the hash value is guaranteed to remain stable across releases, even if this causes performance to degrade.

deriveLargeHashableNoCtx :: Name -> Q [Dec] Source #

Derive a LargeHashable instance with no constraints in the context of the instance.

deriveLargeHashableCtx Source #

Arguments

:: Name 
-> ([TypeQ] -> [PredQ])

Function mapping the type variables in the instance head to the additional constraints

-> Q [Dec] 

Derive a LargeHashable instance with extra constraints in the context of the instance.

deriveLargeHashableCustomCtx Source #

Arguments

:: Name 
-> ([TypeQ] -> [PredQ] -> [PredQ])

Function mapping the type variables in the instance head and the constraints that would normally be generated to the constraints that should be generated.

-> Q [Dec] 

Derive a LargeHashable instance with a completely custom instance context.

newtype MD5Hash Source #

Constructors

MD5Hash 

Fields

Instances

Instances details
Read MD5Hash Source # 
Instance details

Defined in Data.LargeHashable.MD5

Show MD5Hash Source # 
Instance details

Defined in Data.LargeHashable.MD5

Eq MD5Hash Source # 
Instance details

Defined in Data.LargeHashable.MD5

Methods

(==) :: MD5Hash -> MD5Hash -> Bool #

(/=) :: MD5Hash -> MD5Hash -> Bool #

Ord MD5Hash Source # 
Instance details

Defined in Data.LargeHashable.MD5