Portability | portable (Haskell 2010) |
---|---|
Stability | provisional |
Maintainer | niswegmann@gmail.com |
For details of the implementation of MurmurHash3, see the following webpages:
Documentation
Type class for computing hash generators from values.
Making custom data types instantiate Hashable
is straightforward; given
the following tree data structure:
data Tree a = Tip | Bin a (Tree a) (Tree a)
...we make it instantiate Hashable
like this:
instance Hashable a => Hashable (Tree a) where hashGen Tip = salt 0x0 hashGen (Bin x l r) = hashGen x `combine` hashGen l `combine` hashGen r
For sum data types such as Either
we typically want to avoid that
Left "foo"
hashes to the same hash as
Right "foo"
...hence we add some salt
for each constructor:
instance (Hashable a, Hashable b) => Hashable (Either a b) where hashGen (Left x) = salt 0x1 `combine` hashGen x hashGen (Right y) = salt 0x2 `combine` hashGen y
Hashable Bool | |
Hashable Char | |
Hashable Double | |
Hashable Float | |
Hashable Int | |
Hashable Int8 | |
Hashable Int16 | |
Hashable Int32 | |
Hashable Int64 | |
Hashable Integer | |
Hashable Word | |
Hashable Word8 | |
Hashable Word16 | |
Hashable Word32 | |
Hashable Word64 | |
Hashable () | |
Hashable a => Hashable [a] | |
(Hashable a, Integral a) => Hashable (Ratio a) | |
(Hashable a, RealFloat a) => Hashable (Complex a) | |
Hashable a => Hashable (Maybe a) | |
(Hashable a, Hashable b) => Hashable (Either a b) | |
(Hashable a, Hashable b) => Hashable (a, b) | |
(Hashable a, Ix i) => Hashable (Array i a) | |
(Hashable a, Hashable b, Hashable c) => Hashable (a, b, c) | |
(Hashable a, Hashable b, Hashable c, Hashable d) => Hashable (a, b, c, d) |
A hash generator is a function that maps a hash state into a new hash state. The internal representation of hash states is kept transparent.