The hash functions are available as classes in the de.greenrobot.common.hash package. They implement the java.util.zip.Checksum interface, and are thus straight forward to use.

Utility classes

Hash and checksum functions usually only accept bytes as input. Our class PrimitiveDataChecksum transforms shorts, ints, longs, Strings, and arrays on the fly to bytes. It’s a wrapper around Java’s Checksum interface and can thus be used with all of our hash function classes (or Java’s Adler32/CRC32).

The class CombinedChecksum takes two Checksum objects (preferably 32 bit) and combines their hashes into a 64 bit hash. CombinedChecksum implements Checksum itself. This class can be useful to work around flaws in hashing functions, or to make collision attacks harder.

Getting hashes on the fly with streaming

FNV-1a hash functions

FNV is a popular hash function and one of the easiest to implement. Our implementation produces the same hashes as the C reference (unit tested). Because of the byte-per-byte algorithm, it’s not the fastest on today’s processors.

Classes: FNV32 and FNV64

Speed (i7-3720QM) FNV32: 737 MB/s

Speed (i7-3720QM) FNV64: 785 MB/s

SMHasher quality: mediocre (a couple of flaws)

FNVJ hash functions

These are some experimental custom hash functions, sacrificing quality to perform very fast. They might be an alternative if your use case does not have strict requirements. When in doubt, stick to Murmur3A or Murmur3F.

Classes: FNVJ32 and FNVJ64

Speed (i7-3720QM) FNVJ32: 3128 MB/s

Speed (i7-3720QM) FNVJ64: 5879 MB/s

SMHasher quality: bad (lots of flaws, only FNVJ32 ported and tested)

Murmur3 hash functions

Murmur3 hash functions are fast and produce high quality hashes. You cannot make a wrong choice here.