Class CommonHashes


  • public final class CommonHashes
    extends java.lang.Object
    Static methods to obtain commonly-used hash functions. Note that a suitable provider JAR must be made available on the class path. This class does not have direct access to specific implementations; it simply constructs the hash parameters and uses the Hashes class to search for a provider.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static IncrementalIntHash crc32()
      Returns an incremental stateless hash function implementing the CRC-32 checksum algorithm.
      static IncrementalIntHash crc32c()
      Returns an incremental stateless hash function implementing the CRC-32C checksum algorithm.
      static IncrementalLongHash crc64()
      Returns an incremental stateless hash function implementing the CRC-64 checksum algorithm.
      static StatefulHash md5()
      Returns a hash function implementing the MD5 algorithm (128 bits).
      static StatefulHash murmur3_128()
      Returns a hash function implementing the MurmurHash3 algorithm, 128-bit x64 variant, with a seed of 0.
      static StatefulHash murmur3_128​(int seed)
      Returns a hash function implementing the MurmurHash3 algorithm, 128-bit x64 variant, with the given seed value.
      static StatelessIntHash murmur3_32()
      Returns a hash function implementing the MurmurHash3 algorithm, 32-bit x86 variant, with a seed of 0.
      static StatelessIntHash murmur3_32​(int seed)
      Returns a hash function implementing the MurmurHash3 algorithm, 32-bit x86 variant, with the given seed value
      static StatefulHash sha1()
      Returns a hash function implementing the SHA-1 algorithm (160 bits).
      static StatefulHash sha256()
      Returns a hash function implementing the SHA-256 algorithm (256 bits).
      static StatefulHash sha384()
      Returns a hash function implementing the SHA-384 algorithm (384 bits).
      static StatefulHash sha512()
      Returns a hash function implementing the SHA-512 algorithm (512 bits).
      static StatelessLongHash sipHash24()
      Returns a hash function implementing the SipHash-2-4 algorithm (64 bits) with the default seed, 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F.
      static StatelessLongHash sipHash24​(long seedLow, long seedHigh)
      Returns a hash function implementing the SipHash-2-4 algorithm (64 bits) with the given seed value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • crc32

        public static IncrementalIntHash crc32()
        Returns an incremental stateless hash function implementing the CRC-32 checksum algorithm.
        Returns:
        a CRC-32 stateless incremental integer hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • crc32c

        public static IncrementalIntHash crc32c()
        Returns an incremental stateless hash function implementing the CRC-32C checksum algorithm.
        Returns:
        a CRC-32C stateless incremental integer hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • crc64

        public static IncrementalLongHash crc64()
        Returns an incremental stateless hash function implementing the CRC-64 checksum algorithm.
        Returns:
        a CRC-64 stateless incremental long integer hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • murmur3_32

        public static StatelessIntHash murmur3_32()
        Returns a hash function implementing the MurmurHash3 algorithm, 32-bit x86 variant, with a seed of 0.
        Returns:
        a MurmurHash3 32-bit/x86 stateless integer hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • murmur3_32

        public static StatelessIntHash murmur3_32​(int seed)
        Returns a hash function implementing the MurmurHash3 algorithm, 32-bit x86 variant, with the given seed value
        Parameters:
        seed - the 32-bit seed value
        Returns:
        a MurmurHash3 32-bit/x86 stateless integer hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • murmur3_128

        public static StatefulHash murmur3_128()
        Returns a hash function implementing the MurmurHash3 algorithm, 128-bit x64 variant, with a seed of 0.
        Returns:
        a MurmurHash3 128-bit/x64 stateful hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • murmur3_128

        public static StatefulHash murmur3_128​(int seed)
        Returns a hash function implementing the MurmurHash3 algorithm, 128-bit x64 variant, with the given seed value.
        Parameters:
        seed - the 32-bit seed value
        Returns:
        a MurmurHash3 128-bit/x64 stateful hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • sipHash24

        public static StatelessLongHash sipHash24()
        Returns a hash function implementing the SipHash-2-4 algorithm (64 bits) with the default seed, 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F.
        Returns:
        a SipHash-2-4 stateless long integer hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • sipHash24

        public static StatelessLongHash sipHash24​(long seedLow,
                                                  long seedHigh)
        Returns a hash function implementing the SipHash-2-4 algorithm (64 bits) with the given seed value.
        Parameters:
        seedLow - the low-order 64 bits of the seed
        seedHigh - the high-order 64 bits of the seed
        Returns:
        a SipHash-2-4 stateless long integer hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • md5

        public static StatefulHash md5()
        Returns a hash function implementing the MD5 algorithm (128 bits).
        Returns:
        an MD5 stateful hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • sha1

        public static StatefulHash sha1()
        Returns a hash function implementing the SHA-1 algorithm (160 bits).
        Returns:
        a SHA-1 stateful hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • sha256

        public static StatefulHash sha256()
        Returns a hash function implementing the SHA-256 algorithm (256 bits).
        Returns:
        a SHA-256 stateful hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • sha384

        public static StatefulHash sha384()
        Returns a hash function implementing the SHA-384 algorithm (384 bits).
        Returns:
        a SHA-384 stateful hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available
      • sha512

        public static StatefulHash sha512()
        Returns a hash function implementing the SHA-512 algorithm (512 bits).
        Returns:
        a SHA-512 stateful hash
        Throws:
        java.lang.UnsupportedOperationException - if no provider is available