- All Superinterfaces:
HashSink
- All Known Subinterfaces:
HashStream128,HashStream64
-
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates a copy of this hash stream.intgetAsInt()Returns a 32-bit hash value.intThe size of the hash value in bits.Returns a reference of the underlying hasher.byte[]getState()Returns the state of the hash stream.<T> HashStream32put(T obj, HashFunnel<T> funnel) Adds an object to the hash computation using the given funnel.putBoolean(boolean v) Adds abooleanvalue to the hash computation.putBooleanArray(boolean[] x) Adds abooleanarray to the hash computation.putBooleans(boolean[] x) Adds all elements of abooleanarray to the hash computation.putBooleans(boolean[] x, int off, int len) Addslenelements of the givenbooleanarray to the hash computation.putByte(byte v) Adds abytevalue to the hash computation.putByteArray(byte[] x) Adds abytearray to the hash computation.putBytes(byte[] x) Adds all elements of abytearray to the hash computation.putBytes(byte[] x, int off, int len) Addslenelements of the givenbytearray to the hash computation.<T> HashStream32putBytes(T b, long off, long len, ByteAccess<T> access) Adds a sequence of bytes to the hash computation.putChar(char v) Adds acharvalue to the hash computation using little-endian byte order.putCharArray(char[] x) Adds achararray to the hash computation.putChars(char[] x) Adds all elements of achararray to the hash computation.putChars(char[] x, int off, int len) Addslenelements of the givenchararray to the hash computation.Adds chars to the hash computation.putDouble(double v) Adds adoublevalue to the hash computation using little-endian byte order.putDoubleArray(double[] x) Adds adoublearray to the hash computation.putDoubles(double[] x) Adds all elements of adoublearray to the hash computation.putDoubles(double[] x, int off, int len) Addslenelements of the givendoublearray to the hash computation.putFloat(float v) Adds afloatvalue to the hash computation using little-endian byte order.putFloatArray(float[] x) Adds afloatarray to the hash computation.putFloats(float[] x) Adds all elements of afloatarray to the hash computation.putFloats(float[] x, int off, int len) Addslenelements of the givenfloatarray to the hash computation.putInt(int v) Adds anintvalue to the hash computation using little-endian byte order.putIntArray(int[] x) Adds anintarray to the hash computation.putInts(int[] x) Adds all elements of anintarray to the hash computation.putInts(int[] x, int off, int len) Addslenelements of the givenintarray to the hash computation.putLong(long v) Adds alonglongvalue to the hash computation using little-endian byte order.putLongArray(long[] x) Adds alongarray to the hash computation.putLongs(long[] x) Adds all elements of alongarray to the hash computation.putLongs(long[] x, int off, int len) Addslenelements of the givenlongarray to the hash computation.<T> HashStream32putNullable(T obj, HashFunnel<T> funnel) Adds a nullable object to the hash computation using the given funnel.<T> HashStream32putOptional(Optional<T> obj, HashFunnel<? super T> funnel) Adds an optional object to the hash computation using the given funnel.Adds anOptionalDoubleto the hash computation.Adds anOptionalIntto the hash computation.Adds anOptionalLongto the hash computation.<T> com.dynatrace.hash4j.hashing.HashStreamputOrderedIterable(Iterable<T> data, HashFunnel<? super T> funnel) Adds an orderedIterable(e.g.putShort(short v) Adds ashortvalue to the hash computation using little-endian byte order.putShortArray(short[] x) Adds ashortarray to the hash computation.putShorts(short[] x) Adds all elements of ashortarray to the hash computation.putShorts(short[] x, int off, int len) Addslenelements of the givenshortarray to the hash computation.Adds a string to the hash computation.<T> HashStream32putUnorderedIterable(Iterable<T> data, HashFunnel<? super T> funnel, Hasher64 hasher) Adds an unorderedIterable(e.g.<T> HashStream32putUnorderedIterable(Iterable<T> data, HashFunnel<? super T> funnel, HashStream64 hashStream) Adds an unorderedIterable(e.g.<T> HashStream32putUnorderedIterable(Iterable<T> data, ToLongFunction<? super T> elementHashFunction) Adds an unorderedIterable(e.g.Adds aUUIDto the hash computation.reset()Resets the hash stream.<T> intresetAndHashToInt(T obj, HashFunnel<T> funnel) Resets this hash stream and returns a 32-bit hash value of the given object using the given funnel.setState(byte[] state) Sets the state of the hash stream.
-
Method Details
-
getAsInt
int getAsInt()Returns a 32-bit hash value.- Returns:
- a 32-bit hash value
-
putByte
Description copied from interface:HashSinkAdds abytevalue to the hash computation. -
putBytes
Description copied from interface:HashSinkAdds all elements of abytearray to the hash computation.Unlike
HashSink.putByteArray(byte[])this method does not add the length of the array.If the array has variable length, and it is just one of many variable-length fields of the object for which a hash value is calculated, it is highly recommended to also incorporate the length of the array to improve the hash quality and decrease the chance of hash collisions.
Equivalent to
putBytes(x, 0, x.length); -
putBytes
Description copied from interface:HashSinkAddslenelements of the givenbytearray to the hash computation.Equivalent to
for (int i = 0; i < len; i++) putByte(x[off + i]); -
putBytes
Description copied from interface:HashSinkAdds a sequence of bytes to the hash computation.Equivalent to
for (int i = 0; i < len; i++) putByte(access.getByte(input, off + i)); -
putByteArray
Description copied from interface:HashSinkAdds abytearray to the hash computation.This method includes the length information. In this way,
hashSink.putByteArray(new byte[]{1, 2}).putByteArray(new byte[]{3})and
hashSink.putByteArray(new byte[]{1}).putByteArray(new byte[]{2, 3})will be different contributions to the hash value computation.
Equivalent to
putBytes(x).putInt(x.length);- Specified by:
putByteArrayin interfaceHashSink- Parameters:
x- the boolean array- Returns:
- this
-
putBoolean
Description copied from interface:HashSinkAdds abooleanvalue to the hash computation.Equivalent to
putByte(v ? 1 : 0);- Specified by:
putBooleanin interfaceHashSink- Parameters:
v- the value- Returns:
- this
-
putBooleans
Description copied from interface:HashSinkAdds all elements of abooleanarray to the hash computation.Unlike
HashSink.putBooleanArray(boolean[])this method does not add the length of the array.If the array has variable length, and it is just one of many variable-length fields of the object for which a hash value is calculated, it is highly recommended to also incorporate the length of the array to improve the hash quality and decrease the chance of hash collisions.
Equivalent to
putBooleans(x, 0, x.length);- Specified by:
putBooleansin interfaceHashSink- Parameters:
x- the array- Returns:
- this
-
putBooleans
Description copied from interface:HashSinkAddslenelements of the givenbooleanarray to the hash computation.Equivalent to
for (int i = 0; i < len; i++) putBoolean(x[off + i]);- Specified by:
putBooleansin interfaceHashSink- Parameters:
x- the arrayoff- the start offset in the arraylen- the number of elements- Returns:
- this
-
putBooleanArray
Description copied from interface:HashSinkAdds abooleanarray to the hash computation.This method includes the length information. In this way,
hashSink.putBooleanArray(new boolean[]{true, false}).putBooleanArray(new boolean[]{true})and
hashSink.putBooleanArray(new boolean[]{true}).putBooleanArray(new boolean[]{false, true})will be different contributions to the hash value computation.
Equivalent to
putBooleans(x).putInt(x.length);- Specified by:
putBooleanArrayin interfaceHashSink- Parameters:
x- the boolean array- Returns:
- this
-
putShort
Description copied from interface:HashSinkAdds ashortvalue to the hash computation using little-endian byte order. -
putShorts
Description copied from interface:HashSinkAdds all elements of ashortarray to the hash computation.Unlike
HashSink.putShortArray(short[])this method does not add the length of the array.If the array has variable length, and it is just one of many variable-length fields of the object for which a hash value is calculated, it is highly recommended to also incorporate the length of the array to improve the hash quality and decrease the chance of hash collisions.
Equivalent to
putShorts(x, 0, x.length); -
putShorts
Description copied from interface:HashSinkAddslenelements of the givenshortarray to the hash computation.Equivalent to
for (int i = 0; i < len; i++) putShort(x[off + i]); -
putShortArray
Description copied from interface:HashSinkAdds ashortarray to the hash computation.This method includes the length information. In this way,
hashSink.putShortArray(new short[]{1, 2}).putShortArray(new short[]{3})and
hashSink.putShortArray(new short[]{1}).putShortArray(new short[]{2, 3})will be different contributions to the hash value computation.
Equivalent to
putShorts(x).putInt(x.length);- Specified by:
putShortArrayin interfaceHashSink- Parameters:
x- the short array- Returns:
- this
-
putChar
Description copied from interface:HashSinkAdds acharvalue to the hash computation using little-endian byte order. -
putChars
Description copied from interface:HashSinkAdds all elements of achararray to the hash computation.Unlike
HashSink.putCharArray(char[])this method does not add the length of the array.If the array has variable length, and it is just one of many variable-length fields of the object for which a hash value is calculated, it is highly recommended to also incorporate the length of the array to improve the hash quality and decrease the chance of hash collisions.
Equivalent to
putChars(x, 0, x.length); -
putChars
Description copied from interface:HashSinkAddslenelements of the givenchararray to the hash computation.Equivalent to
for (int i = 0; i < len; i++) putChar(x[off + i]); -
putChars
Description copied from interface:HashSinkAdds chars to the hash computation.This method does not include the length information. In this way,
hashSink.putChars("AB").putChars("C")and
hashSink.putChars("A").putChars("BC")will be equivalent contributions to the hash value computation.
Equivalent to
for (int i = 0; i < s.length(); ++i) putChar(s.charAt(i)); -
putCharArray
Description copied from interface:HashSinkAdds achararray to the hash computation.This method includes the length information. In this way,
hashSink.putCharArray(new char[]{'A', 'B'}).putCharArray(new char[]{'C'})and
hashSink.putCharArray(new char[]{'A'}).putCharArray(new char[]{'B', 'C'})will be different contributions to the hash value computation.
Equivalent to
putChars(x).putInt(x.length);- Specified by:
putCharArrayin interfaceHashSink- Parameters:
x- the char array- Returns:
- this
-
putString
Description copied from interface:HashSinkAdds a string to the hash computation.This method includes the length information. In this way,
hashSink.putString("AB").putString("C")and
hashSink.putString("A").putString("BC")will be different contributions to the hash value computation.
Equivalent to
putChars(s).putInt(s.length()); -
putInt
Description copied from interface:HashSinkAdds anintvalue to the hash computation using little-endian byte order. -
putInts
Description copied from interface:HashSinkAdds all elements of anintarray to the hash computation.Unlike
HashSink.putIntArray(int[])this method does not add the length of the array.If the array has variable length, and it is just one of many variable-length fields of the object for which a hash value is calculated, it is highly recommended to also incorporate the length of the array to improve the hash quality and decrease the chance of hash collisions.
Equivalent to
putInts(x, 0, x.length); -
putInts
Description copied from interface:HashSinkAddslenelements of the givenintarray to the hash computation.Equivalent to
for (int i = 0; i < len; i++) putInt(x[off + i]); -
putIntArray
Description copied from interface:HashSinkAdds anintarray to the hash computation.This method includes the length information. In this way,
hashSink.putIntArray(new int[]{1, 2}).putIntArray(new int[]{3})and
hashSink.putIntArray(new int[]{1}).putIntArray(new int[]{2, 3})will be different contributions to the hash value computation.
Equivalent to
putInts(x).putInt(x.length);- Specified by:
putIntArrayin interfaceHashSink- Parameters:
x- the int array- Returns:
- this
-
putLong
Description copied from interface:HashSinkAdds alonglongvalue to the hash computation using little-endian byte order. -
putLongs
Description copied from interface:HashSinkAdds all elements of alongarray to the hash computation.Unlike
HashSink.putLongArray(long[])this method does not add the length of the array.If the array has variable length, and it is just one of many variable-length fields of the object for which a hash value is calculated, it is highly recommended to also incorporate the length of the array to improve the hash quality and decrease the chance of hash collisions.
Equivalent to
putLongs(x, 0, x.length); -
putLongs
Description copied from interface:HashSinkAddslenelements of the givenlongarray to the hash computation.Equivalent to
for (int i = 0; i < len; i++) putLong(x[off + i]); -
putLongArray
Description copied from interface:HashSinkAdds alongarray to the hash computation.This method includes the length information. In this way,
hashSink.putLongArray(new long[]{1, 2}).putLongArray(new long[]{3})and
hashSink.putLongArray(new long[]{1}).putLongArray(new long[]{2, 3})will be different contributions to the hash value computation.
Equivalent to
putLongs(x).putInt(x.length);- Specified by:
putLongArrayin interfaceHashSink- Parameters:
x- the int array- Returns:
- this
-
putFloat
Description copied from interface:HashSinkAdds afloatvalue to the hash computation using little-endian byte order.Equivalent to
putInt(Float.floatToRawIntBits(v)); -
putFloats
Description copied from interface:HashSinkAdds all elements of afloatarray to the hash computation.Unlike
HashSink.putFloatArray(float[])this method does not add the length of the array.If the array has variable length, and it is just one of many variable-length fields of the object for which a hash value is calculated, it is highly recommended to also incorporate the length of the array to improve the hash quality and decrease the chance of hash collisions.
Equivalent to
putFloats(x, 0, x.length); -
putFloats
Description copied from interface:HashSinkAddslenelements of the givenfloatarray to the hash computation.Equivalent to
for (int i = 0; i < len; i++) putFloat(x[off + i]); -
putFloatArray
Description copied from interface:HashSinkAdds afloatarray to the hash computation.This method includes the length information. In this way,
hashSink.putFloatArray(new float[]{1, 2}).putFloatArray(new float[]{3})and
hashSink.putFloatArray(new float[]{1}).putFloatArray(new float[]{2, 3})will be different contributions to the hash value computation.
Equivalent to
putFloats(x).putInt(x.length);- Specified by:
putFloatArrayin interfaceHashSink- Parameters:
x- the float array- Returns:
- this
-
putDouble
Description copied from interface:HashSinkAdds adoublevalue to the hash computation using little-endian byte order.Equivalent to
putLong(Double.doubleToRawLongBits(v)); -
putDoubles
Description copied from interface:HashSinkAdds all elements of adoublearray to the hash computation.Unlike
HashSink.putDoubleArray(double[])this method does not add the length of the array.If the array has variable length, and it is just one of many variable-length fields of the object for which a hash value is calculated, it is highly recommended to also incorporate the length of the array to improve the hash quality and decrease the chance of hash collisions.
Equivalent to
putDoubles(x, 0, x.length);- Specified by:
putDoublesin interfaceHashSink- Parameters:
x- the array- Returns:
- this
-
putDoubles
Description copied from interface:HashSinkAddslenelements of the givendoublearray to the hash computation.Equivalent to
for (int i = 0; i < len; i++) putDouble(x[off + i]);- Specified by:
putDoublesin interfaceHashSink- Parameters:
x- the arrayoff- the start offset in the arraylen- the number of elements- Returns:
- this
-
putDoubleArray
Description copied from interface:HashSinkAdds adoublearray to the hash computation.This method includes the length information. In this way,
hashSink.putDoubleArray(new double[]{1, 2}).putDoubleArray(new double[]{3})and
hashSink.putDoubleArray(new double[]{1}).putDoubleArray(new double[]{2, 3})will be different contributions to the hash value computation.
Equivalent to
putDoubles(x).putInt(x.length);- Specified by:
putDoubleArrayin interfaceHashSink- Parameters:
x- the double array- Returns:
- this
-
putUUID
Description copied from interface:HashSinkAdds aUUIDto the hash computation.Equivalent to
putLong(uuid.getLeastSignificantBits()).putLong(uuid.getMostSignificantBits()); -
put
Description copied from interface:HashSinkAdds an object to the hash computation using the given funnel. -
putNullable
Description copied from interface:HashSinkAdds a nullable object to the hash computation using the given funnel.- Specified by:
putNullablein interfaceHashSink- Type Parameters:
T- the type- Parameters:
obj- the nullable objectfunnel- the funnel- Returns:
- this
-
putUnorderedIterable
<T> HashStream32 putUnorderedIterable(Iterable<T> data, ToLongFunction<? super T> elementHashFunction) Description copied from interface:HashSink- Specified by:
putUnorderedIterablein interfaceHashSink- Type Parameters:
T- the element type- Parameters:
data- the iterableelementHashFunction- 64-bit hash function used for individual elements- Returns:
- this
-
putUnorderedIterable
<T> HashStream32 putUnorderedIterable(Iterable<T> data, HashFunnel<? super T> funnel, HashStream64 hashStream) Description copied from interface:HashSink- Specified by:
putUnorderedIterablein interfaceHashSink- Type Parameters:
T- the element type- Parameters:
data- the iterablefunnel- the funnelhashStream- 64-bit hash stream used for individual elements, must be a different instance than thisHashSink- Returns:
- this
-
putUnorderedIterable
<T> HashStream32 putUnorderedIterable(Iterable<T> data, HashFunnel<? super T> funnel, Hasher64 hasher) Description copied from interface:HashSink- Specified by:
putUnorderedIterablein interfaceHashSink- Type Parameters:
T- the element type- Parameters:
data- the iterablefunnel- the funnelhasher- a 64-bit hasher- Returns:
- this
-
putOptional
Description copied from interface:HashSinkAdds an optional object to the hash computation using the given funnel.- Specified by:
putOptionalin interfaceHashSink- Type Parameters:
T- the type- Parameters:
obj- the optional objectfunnel- the funnel- Returns:
- this
-
putOptionalInt
Description copied from interface:HashSinkAdds anOptionalIntto the hash computation.- Specified by:
putOptionalIntin interfaceHashSink- Parameters:
v- the optional value- Returns:
- this
-
putOptionalLong
Description copied from interface:HashSinkAdds anOptionalLongto the hash computation.- Specified by:
putOptionalLongin interfaceHashSink- Parameters:
v- the optional value- Returns:
- this
-
putOptionalDouble
Description copied from interface:HashSinkAdds anOptionalDoubleto the hash computation.- Specified by:
putOptionalDoublein interfaceHashSink- Parameters:
v- the optional value- Returns:
- this
-
reset
HashStream32 reset()Resets the hash stream.This allows to reuse this instance for new hash computations.
- Returns:
- this
-
copy
HashStream32 copy()Creates a copy of this hash stream.This allows to save the current state for reuse, without new hash computations.
Equivalent to
getHasher().hashStreamFromState(getState()).- Returns:
- new instance
-
resetAndHashToInt
Resets this hash stream and returns a 32-bit hash value of the given object using the given funnel.Equivalent to
funnel.put(obj, reset()); return getAsInt();- Type Parameters:
T- the type- Parameters:
obj- the objectfunnel- the funnel- Returns:
- a 32-bit hash value
-
getHasher
Hasher32 getHasher()Returns a reference of the underlying hasher.- Returns:
- a reference to the underlying hasher
-
getState
byte[] getState()Returns the state of the hash stream.The state allows to continue the processing after creating a new instance using the
hashStreamFromState(byte[])of the corresponding hasher instance or initializing an existing instance usingsetState(byte[]).- Returns:
- the state
-
setState
Sets the state of the hash stream.The behavior is undefined, if the given state was not created by a hash stream of a hasher that is equal to
getHasher().- Parameters:
state- the state- Returns:
- a reference to the underlying hasher
-
getHashBitSize
int getHashBitSize()The size of the hash value in bits.- Returns:
- the size of the hash value in bits
-
putOrderedIterable
<T> com.dynatrace.hash4j.hashing.HashStream putOrderedIterable(Iterable<T> data, HashFunnel<? super T> funnel) Description copied from interface:HashSink- Specified by:
putOrderedIterablein interfaceHashSink- Type Parameters:
T- the element type- Parameters:
data- the iterablefunnel- the funnel- Returns:
- this
-