With greenrobot-essentials hash functions, we provide a set of highly performant non-cryptographic Java hash functions in an easy-to-use way:
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 classesHash 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 streamingBecause all hash classes implement Checksum, you can use Java’s CheckedInputStream and CheckedOutputStream. They calculate the checksum (hash) of read/written data on the fly.
FNV-1a hash functionsFNV 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.
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.
Murmur3 hash functions are fast and produce high quality hashes. You cannot make a wrong choice here.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4