data-hash-0.2.0.1: 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
- module Data.Hash.Rolling

# The `Hash` type

data Hash #

A 64-bit hash

Instances

Bounded Hash # |
Methods minBound :: Hash # maxBound :: Hash #
Eq Hash # |
Methods (==) :: Hash -> Hash -> Bool # (/=) :: Hash -> Hash -> Bool #
Ord Hash # |
Methods compare :: Hash -> Hash -> Ordering # (<) :: Hash -> Hash -> Bool # (<=) :: Hash -> Hash -> Bool # (>) :: Hash -> Hash -> Bool # (>=) :: Hash -> Hash -> Bool # max :: Hash -> Hash -> Hash # min :: Hash -> Hash -> Hash #
Show Hash # |
Methods showsPrec :: Int -> Hash -> ShowS # show :: Hash -> String # showList :: [Hash] -> ShowS #

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 #

Minimal complete definition

hash

Methods

hash :: a -> Hash #

Instances

Hashable Bool # |
Methods hash :: Bool -> Hash #
Hashable Char # |
Methods hash :: Char -> Hash #
Hashable Double # |
Methods hash :: Double -> Hash #
Hashable Float # |
Methods hash :: Float -> Hash #
Hashable Int # |
Methods hash :: Int -> Hash #
Hashable Int8 # |
Methods hash :: Int8 -> Hash #
Hashable Int16 # |
Methods hash :: Int16 -> Hash #
Hashable Int32 # |
Methods hash :: Int32 -> Hash #
Hashable Int64 # |
Methods hash :: Int64 -> Hash #
Hashable Integer # |
Methods hash :: Integer -> Hash #
Hashable Word # |
Methods hash :: Word -> Hash #
Hashable Word8 # |
Methods hash :: Word8 -> Hash #
Hashable Word16 # |
Methods hash :: Word16 -> Hash #
Hashable Word32 # |
Methods hash :: Word32 -> Hash #
Hashable Word64 # |
Methods hash :: Word64 -> Hash #
Hashable () # |
Methods hash :: () -> Hash #
Hashable a => Hashable [a] # |
Methods hash :: [a] -> Hash #
Hashable a => Hashable (Maybe a) # |
Methods hash :: Maybe a -> Hash #
(Integral a, Hashable a) => Hashable (Ratio a) # |
Methods hash :: Ratio a -> Hash #
(Hashable a, Hashable b) => Hashable (Either a b) # |
Methods hash :: Either a b -> Hash #
(Hashable a, Hashable b) => Hashable (a, b) # |
Methods hash :: (a, b) -> Hash #
(Hashable a, Hashable b, Hashable c) => Hashable (a, b, c) # |
Methods hash :: (a, b, c) -> Hash #
(Hashable a, Hashable b, Hashable c, Hashable d) => Hashable (a, b, c, d) # |
Methods hash :: (a, b, c, d) -> Hash #

# Rolling hashes

module Data.Hash.Rolling