Class HighwayHash

java.lang.Object
org.redisson.misc.HighwayHash

public final class HighwayHash extends Object
HighwayHash algorithm. See HighwayHash on GitHub
  • Constructor Summary

    Constructors
    Constructor
    Description
    HighwayHash(long[] key)
     
    HighwayHash(long key0, long key1, long key2, long key3)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long[]
    Computes the hash value after all bytes were processed.
    long[]
    Computes the hash value after all bytes were processed.
    long
    Computes the hash value after all bytes were processed.
    static long[]
    hash128(byte[] data, int offset, int length, long[] key)
    NOTE: The 128-bit HighwayHash algorithm is not yet frozen and subject to change.
    static long[]
    hash256(byte[] data, int offset, int length, long[] key)
    NOTE: The 256-bit HighwayHash algorithm is not yet frozen and subject to change.
    static long
    hash64(byte[] data, int offset, int length, long[] key)
    NOTE: The 64-bit HighwayHash algorithm is declared stable and no longer subject to change.
    void
    update(long a0, long a1, long a2, long a3)
    Updates the hash with 32 bytes of data given as 4 longs.
    void
    updatePacket(byte[] packet, int pos)
    Updates the hash with 32 bytes of data.
    void
    updateRemainder(byte[] bytes, int pos, int size_mod32)
    Updates the hash with the last 1 to 31 bytes of the data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HighwayHash

      public HighwayHash(long key0, long key1, long key2, long key3)
      Parameters:
      key0 - first 8 bytes of the key
      key1 - next 8 bytes of the key
      key2 - next 8 bytes of the key
      key3 - last 8 bytes of the key
    • HighwayHash

      public HighwayHash(long[] key)
      Parameters:
      key - array of size 4 with the key to initialize the hash with
  • Method Details

    • updatePacket

      public void updatePacket(byte[] packet, int pos)
      Updates the hash with 32 bytes of data. If you can read 4 long values from your data efficiently, prefer using update() instead for more speed.
      Parameters:
      packet - data array which has a length of at least pos + 32
      pos - position in the array to read the first of 32 bytes from
    • update

      public void update(long a0, long a1, long a2, long a3)
      Updates the hash with 32 bytes of data given as 4 longs. This function is more efficient than updatePacket when you can use it.
      Parameters:
      a0 - first 8 bytes in little endian 64-bit long
      a1 - next 8 bytes in little endian 64-bit long
      a2 - next 8 bytes in little endian 64-bit long
      a3 - last 8 bytes in little endian 64-bit long
    • updateRemainder

      public void updateRemainder(byte[] bytes, int pos, int size_mod32)
      Updates the hash with the last 1 to 31 bytes of the data. You must use updatePacket first per 32 bytes of the data, if and only if 1 to 31 bytes of the data are not processed after that, updateRemainder must be used for those final bytes.
      Parameters:
      bytes - data array which has a length of at least pos + size_mod32
      pos - position in the array to start reading size_mod32 bytes from
      size_mod32 - the amount of bytes to read
    • finalize64

      public long finalize64()
      Computes the hash value after all bytes were processed. Invalidates the state. NOTE: The 64-bit HighwayHash algorithm is declared stable and no longer subject to change.
      Returns:
      64-bit hash
    • finalize128

      public long[] finalize128()
      Computes the hash value after all bytes were processed. Invalidates the state. NOTE: The 128-bit HighwayHash algorithm is not yet frozen and subject to change.
      Returns:
      array of size 2 containing 128-bit hash
    • finalize256

      public long[] finalize256()
      Computes the hash value after all bytes were processed. Invalidates the state. NOTE: The 256-bit HighwayHash algorithm is not yet frozen and subject to change.
      Returns:
      array of size 4 containing 256-bit hash
    • hash64

      public static long hash64(byte[] data, int offset, int length, long[] key)
      NOTE: The 64-bit HighwayHash algorithm is declared stable and no longer subject to change.
      Parameters:
      data - array with data bytes
      offset - position of first byte of data to read from
      length - number of bytes from data to read
      key - array of size 4 with the key to initialize the hash with
      Returns:
      64-bit hash for the given data
    • hash128

      public static long[] hash128(byte[] data, int offset, int length, long[] key)
      NOTE: The 128-bit HighwayHash algorithm is not yet frozen and subject to change.
      Parameters:
      data - array with data bytes
      offset - position of first byte of data to read from
      length - number of bytes from data to read
      key - array of size 4 with the key to initialize the hash with
      Returns:
      array of size 2 containing 128-bit hash for the given data
    • hash256

      public static long[] hash256(byte[] data, int offset, int length, long[] key)
      NOTE: The 256-bit HighwayHash algorithm is not yet frozen and subject to change.
      Parameters:
      data - array with data bytes
      offset - position of first byte of data to read from
      length - number of bytes from data to read
      key - array of size 4 with the key to initialize the hash with
      Returns:
      array of size 4 containing 256-bit hash for the given data