| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Data.PerfectHash.Hashing
Description
Implements the specialized hash function for this perfect hashing algorithm.
C code that makes use of the perfect hash table output must exactly
re-implement this hash function.
Synopsis
- primeFNV :: Int
- class ToHashableChunks a where
- toHashableChunks :: a -> [Hash]
- hash :: ToHashableChunks a => Nonce -> a -> Hash
Constants
This choice of prime number 0x01000193 was taken from the Python implementation
on Steve Hanov's page.
Class instances
class ToHashableChunks a where Source #
Mechanism for a key to be decomposed into units processable by the FNV-1a hashing algorithm.
Methods
toHashableChunks :: a -> [Hash] Source #
Instances
| ToHashableChunks Int Source # | |
Defined in Data.PerfectHash.Hashing Methods toHashableChunks :: Int -> [Hash] Source # | |
| ToHashableChunks String Source # | |
Defined in Data.PerfectHash.Hashing Methods toHashableChunks :: String -> [Hash] Source # | |
| ToHashableChunks Text Source # | |
Defined in Data.PerfectHash.Hashing Methods toHashableChunks :: Text -> [Hash] Source # | |
Main functions
Arguments
| :: ToHashableChunks a | |
| => Nonce | nonce |
| -> a | key |
| -> Hash |
The interface is comparable to the
hashWithSalt
function from the hashable package.
Uses the "FNV-1a" algorithm from the FNV website:
hash = offset_basis
for each octet_of_data to be hashed
hash = hash xor octet_of_data
hash = hash * FNV_prime
return hash