Home

Awesome

Jenkins Hash

A Java implementation of Bob Jenkins' hash for non-cryptographic purposes. This implementaion can yield 32-bit and 64-bit hash values and can be used for hashtable lookups.

The algorithm implemented here is ideal for 32-bit architectures.

What is Jenkins hash?

Jenkins hash is a general purpose hash algorithm created by Bob Jenkins. It takes an input of variable length and processes chunks of 12-bytes each and outputs a hash value as int (32 bits) or long (64 bits).

Advantages over other hash algorithms:

  1. Uniform distribution of hashes
  2. Very good <a href="http://en.wikipedia.org/wiki/Strict_Avalanche_Criterion">avalanche effect</a>
  3. Faster than most hash algorithms in terms of number of instructions used in hash calculation.

Usage

String message = "";
JenkinsHash jh = new JenkinsHash();
int pc = jh.hash32(message.getBytes());

System.out.println(Integer.toHexString(pc));

References