public final class Hash64 extends Object
This class is an internal implementation detail only intended for use within spectator. It is subject to change without notice.
| Constructor and Description |
|---|
Hash64()
Create a new instance with a seed of zero.
|
Hash64(long seed)
Create a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
long |
compute()
Compute and return the final hash value.
|
long |
computeAndReset()
Compute the final hash value and reset the hash accumulator.
|
static long |
hashBytes(byte[] bytes)
xxHash64 of
bytes with seed 0. |
static long |
hashBytes(byte[] bytes,
int offset,
int length)
xxHash64 of
bytes[offset, offset+length) with seed 0. |
static long |
hashBytes(byte[] bytes,
int offset,
int length,
long seed)
xxHash64 of
bytes[offset, offset+length) with the given seed. |
static long |
hashBytes(byte[] bytes,
long seed)
xxHash64 of
bytes with the given seed. |
static long |
hashInt(int value)
xxHash64 of a single
int value with seed 0. |
static long |
hashInt(int value,
long seed)
xxHash64 of a single
int value with the given seed. |
static long |
hashLong(long value)
xxHash64 of a single
long value with seed 0. |
static long |
hashLong(long value,
long seed)
xxHash64 of a single
long value with the given seed. |
static long |
hashString(CharSequence str)
xxHash64 of the UTF-8 byte sequence of
str with seed 0. |
static long |
hashString(CharSequence str,
long seed)
xxHash64 of the UTF-8 byte sequence of
str with the given seed. |
static int |
reduce(int hash,
int n)
Helper to efficiently reduce hash from to range of
[0, n). |
static int |
reduce(long hash,
int n)
Helper to efficiently reduce hash from to range of
[0, n). |
void |
reset()
Reset so it can be reused for computing another hash.
|
Hash64 |
updateBoolean(boolean value)
Update the hash with the specified boolean value.
|
Hash64 |
updateBooleans(boolean[] values)
Update the hash with the specified boolean values.
|
Hash64 |
updateBooleans(boolean[] values,
int offset,
int length)
Update the hash with the specified boolean values.
|
Hash64 |
updateByte(byte value)
Update the hash with the specified byte value.
|
Hash64 |
updateBytes(byte[] values)
Update the hash with the specified byte values.
|
Hash64 |
updateBytes(byte[] values,
int offset,
int length)
Update the hash with the specified byte values.
|
Hash64 |
updateChar(char value)
Update the hash with the specified character value.
|
Hash64 |
updateChars(char[] values)
Update the hash with the specified character values.
|
Hash64 |
updateChars(char[] values,
int offset,
int length)
Update the hash with the specified character values.
|
Hash64 |
updateDouble(double value)
Update the hash with the specified double value.
|
Hash64 |
updateDoubles(double[] values)
Update the hash with the specified double values.
|
Hash64 |
updateDoubles(double[] values,
int offset,
int length)
Update the hash with the specified double values.
|
Hash64 |
updateFloat(float value)
Update the hash with the specified float value.
|
Hash64 |
updateFloats(float[] values)
Update the hash with the specified float values.
|
Hash64 |
updateFloats(float[] values,
int offset,
int length)
Update the hash with the specified float values.
|
Hash64 |
updateInt(int value)
Update the hash with the specified int value.
|
Hash64 |
updateInts(int[] values)
Update the hash with the specified int values.
|
Hash64 |
updateInts(int[] values,
int offset,
int length)
Update the hash with the specified int values.
|
Hash64 |
updateLong(long value)
Update the hash with the specified long value.
|
Hash64 |
updateLongs(long[] values)
Update the hash with the specified long values.
|
Hash64 |
updateLongs(long[] values,
int offset,
int length)
Update the hash with the specified long values.
|
Hash64 |
updateShort(short value)
Update the hash with the specified short value.
|
Hash64 |
updateShorts(short[] values)
Update the hash with the specified short values.
|
Hash64 |
updateShorts(short[] values,
int offset,
int length)
Update the hash with the specified short values.
|
Hash64 |
updateString(CharSequence str)
Update the hash with the specified character sequence value.
|
public Hash64()
public Hash64(long seed)
public void reset()
public Hash64 updateBoolean(boolean value)
public Hash64 updateBooleans(boolean[] values, int offset, int length)
public Hash64 updateBooleans(boolean[] values)
public Hash64 updateChar(char value)
public Hash64 updateChars(char[] values, int offset, int length)
public Hash64 updateChars(char[] values)
public Hash64 updateString(CharSequence str)
updateBytes(s.getBytes(UTF_8)) bit-for-bit, so output is portable to other
languages that hash UTF-8 bytes.
For short strings (length ≤ ) and any non-String
CharSequence, encodes in-place via a char loop with no transient byte
array. For longer String inputs, falls back to getBytes(UTF_8)
followed by the 8-byte-stride updateBytes path — that one allocates a
transient byte[] (typically JIT-scalar-replaced) but throughput is 2–3× higher on
long strings.
public Hash64 updateByte(byte value)
public Hash64 updateBytes(byte[] values, int offset, int length)
public Hash64 updateBytes(byte[] values)
public Hash64 updateShort(short value)
public Hash64 updateShorts(short[] values, int offset, int length)
public Hash64 updateShorts(short[] values)
public Hash64 updateInt(int value)
public Hash64 updateInts(int[] values, int offset, int length)
public Hash64 updateInts(int[] values)
public Hash64 updateLong(long value)
public Hash64 updateLongs(long[] values, int offset, int length)
public Hash64 updateLongs(long[] values)
public Hash64 updateFloat(float value)
public Hash64 updateFloats(float[] values, int offset, int length)
public Hash64 updateFloats(float[] values)
public Hash64 updateDouble(double value)
public Hash64 updateDoubles(double[] values, int offset, int length)
public Hash64 updateDoubles(double[] values)
public long compute()
public long computeAndReset()
public static long hashLong(long value)
long value with seed 0. Allocation-free.public static long hashLong(long value,
long seed)
long value with the given seed. Allocation-free.public static long hashInt(int value)
int value with seed 0. Allocation-free.public static long hashInt(int value,
long seed)
int value with the given seed. Allocation-free.public static long hashBytes(byte[] bytes)
bytes with seed 0. Allocation-free.public static long hashBytes(byte[] bytes,
long seed)
bytes with the given seed. Allocation-free.public static long hashBytes(byte[] bytes,
int offset,
int length)
bytes[offset, offset+length) with seed 0. Allocation-free.public static long hashBytes(byte[] bytes,
int offset,
int length,
long seed)
bytes[offset, offset+length) with the given seed.
Allocation-free.public static long hashString(CharSequence str)
str with seed 0.
Allocation behavior: a String longer than
chars routes through getBytes(UTF_8) + hashBytes for throughput (allocates
a transient byte[], matches updateString(CharSequence)'s hybrid). All other
inputs — short Strings and any non-String CharSequence
regardless of length — take the inline UTF-8 encoder and allocate nothing. Long
non-String CharSequences pay the inline path's throughput cost
since getBytes is not available on them.
public static long hashString(CharSequence str, long seed)
str with the given seed. See
hashString(CharSequence) for allocation behavior.public static int reduce(long hash,
int n)
[0, n). Based on
fast
alternative to modulo reduction post.public static int reduce(int hash,
int n)
[0, n). Based on
fast
alternative to modulo reduction post.