Data.Hash

data-hash-0.2.0.0: Combinators for building fast hashing functions.

License | BSD-style
Maintainer | jcpetruzza@gmail.com
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell98

Data.Hash

Contents

- The `Hash` type
  - Basic combinators
  - Derived combinators
- The `Hashable` class
- Rolling hashes

Description

Combinators for building fast hashing functions.

Based on the BuzHash algorithm by Robert Uzgalis (see, e.g. "Hashing concepts and the Java programming language" at http://www.serve.net/buz/hash.adt/java.000.html)

Synopsis

- data Hash
- asWord64 :: Hash -> Word64
- hashWord8 :: Word8 -> Hash
- combine :: Hash -> Hash -> Hash
- hashWord16 :: Word16 -> Hash
- hashWord32 :: Word32 -> Hash
- hashWord64 :: Word64 -> Hash
- hashInt :: Int -> Hash
- hashStorable :: Storable a => a -> Hash
- hashFoldable :: (Foldable t, Hashable a) => t a -> Hash
- class Hashable a where
  - hash :: a -> Hash
- module Data.Hash.Rolling

# The `Hash` type

data Hash

A 64-bit hash

Instances

Bounded Hash |
Eq Hash |
Ord Hash |
Show Hash |

asWord64 :: Hash -> Word64

## Basic combinators

hashWord8 :: Word8 -> Hash

combine :: Hash -> Hash -> Hash

`h1 `combine` h2` combines hashes `h1` and `h2` into a new hash.

It is used to generate hash functions for complex types. For example:

    hashPair :: (Hashable a, Hashable b) => (a,b) -> Hash
    hashPair (a,b) = hash a `combine` hash b

## Derived combinators

hashWord16 :: Word16 -> Hash

hashWord32 :: Word32 -> Hash

hashWord64 :: Word64 -> Hash

hashInt :: Int -> Hash

hashStorable :: Storable a => a -> Hash

Observe that, unlike the other functions in this module, `hashStorable` is machine-dependent (the computed hash depends on endianness, etc.).

hashFoldable :: (Foldable t, Hashable a) => t a -> Hash

# The `Hashable` class

class Hashable a where

Methods

hash :: a -> Hash

Instances

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] |
(Integral a, Hashable a) => Hashable (Ratio a) |
Hashable a => Hashable (Maybe a) |
(Hashable a, Hashable b) => Hashable (Either a b) |
(Hashable a, Hashable b) => Hashable (a, b) |
(Hashable a, Hashable b, Hashable c) => Hashable (a, b, c) |
(Hashable a, Hashable b, Hashable c, Hashable d) => Hashable (a, b, c, d) |

# Rolling hashes

module Data.Hash.Rolling