Hash

Safe Haskell | Safe-Inferred
Language | Haskell2010

Hash

Contents

- The `HashTable` type
  - Operations on `HashTable`s
- The `Hash` class

Description

Implementation of fixed-size hash tables, with a type class for constructing hash values for structured types.

Synopsis

- data HashTable key val
- new :: (Eq key, Hash key) => Int -> IO (HashTable key val)
- insert :: (Eq key, Hash key) => key -> val -> IO ()
- lookup :: Hash key => key -> IO (Maybe val)
- class Hash a where
  - hash :: a -> Int

# The `HashTable` type

data HashTable key val #

A hash table with keys of type `key` and values of type `val`. The type `key` should be an instance of `Eq`.

## Operations on `HashTable`s

new :: (Eq key, Hash key) => Int -> IO (HashTable key val) #

Builds a new hash table with a given size

insert :: (Eq key, Hash key) => key -> val -> IO () #

Inserts a new element into the hash table

lookup :: Hash key => key -> IO (Maybe val) #

Looks up a key in the hash table, returns ``Just` val` if the key was found, or `Nothing` otherwise.

# The `Hash` class

class Hash a where #

A class of types which can be hashed.

Methods

hash :: a -> Int #

hashes the value of type `a` into an `Int`

#### Instances

Instances details

Hash Float # |
Instance details Defined in Hash Methods hash :: Float -> Int #
Hash Int # |
Instance details Defined in Hash Methods hash :: Int -> Int #
(Hash a, Hash b) => Hash (a, b) # |
Instance details Defined in Hash Methods hash :: (a, b) -> Int #