Book Image

Haskell Data Analysis Cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis Cookbook

By: Nishant Shukla

Overview of this book

Table of Contents (19 chapters)
Haskell Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Running MurmurHash, a simple but speedy hashing algorithm


Sometimes, the priority of a hashing function should be in maximizing its computation speed. The MurmurHash algorithm exists for this reason. When dealing with massive data sets, speed is essential.

Tip

There are negative qualities of a fast hashing algorithm. If hashing algorithm A is 10 times faster than hashing algorithm B, then it's also 10 times faster to stumble upon the content used to create a digest with A than with B using a random content search. A hashing algorithm should be fast, but not so fast as to impact the security of the algorithm.

Getting ready

Install the Murmur hashing algorithm from Cabal as follows:

$ cabal install murmur-hash

How to do it…

  1. Import the Murmur hashing algorithm as follows:

    import Data.Digest.Murmur32
  2. Define a custom data type and implement an instance to use Murmur as follows:

    data Point = Point Int Int
      instance (Hashable32 Point) where 
      hash32Add (Point x y) h = x `hash32Add` (y `hash32Add` h...