Package org.redisson.misc
Class HighwayHash
java.lang.Object
org.redisson.misc.HighwayHash
HighwayHash algorithm. See
HighwayHash on GitHub
-
Constructor Summary
ConstructorDescriptionHighwayHash
(long[] key) HighwayHash
(long key0, long key1, long key2, long key3) -
Method Summary
Modifier and TypeMethodDescriptionlong[]
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.
-
Constructor Details
-
HighwayHash
public HighwayHash(long key0, long key1, long key2, long key3) - Parameters:
key0
- first 8 bytes of the keykey1
- next 8 bytes of the keykey2
- next 8 bytes of the keykey3
- 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 + 32pos
- 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 longa1
- next 8 bytes in little endian 64-bit longa2
- next 8 bytes in little endian 64-bit longa3
- 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_mod32pos
- position in the array to start reading size_mod32 bytes fromsize_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 bytesoffset
- position of first byte of data to read fromlength
- number of bytes from data to readkey
- 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 bytesoffset
- position of first byte of data to read fromlength
- number of bytes from data to readkey
- 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 bytesoffset
- position of first byte of data to read fromlength
- number of bytes from data to readkey
- 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
-