Module hash4j

Interface HashSink

All Known Subinterfaces:
com.dynatrace.hash4j.hashing.HashStream, HashStream128, HashStream32, HashStream64

public interface HashSink
A sink that accepts various data types contributing to the hash computation.
  • Method Details

    • putByte

      HashSink putByte(byte v)
      Adds a byte value to the hash computation.
      Parameters:
      v - the value
      Returns:
      this
    • putBytes

      HashSink putBytes(byte[] x)
      Adds all elements of a byte array to the hash computation.

      Unlike 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);

      Parameters:
      x - the array
      Returns:
      this
    • putBytes

      HashSink putBytes(byte[] x, int off, int len)
      Adds len elements of the given byte array to the hash computation.

      Equivalent to
      for (int i = 0; i < len; i++) putByte(x[off + i]);

      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putBytes

      <T> HashSink putBytes(T input, long off, long len, ByteAccess<T> access)
      Adds a sequence of bytes to the hash computation.

      Equivalent to
      for (int i = 0; i < len; i++) putByte(access.getByte(input, off + i));

      Type Parameters:
      T - the type of the input
      Parameters:
      input - the input
      off - the offset
      len - the length
      access - a strategy to access the bytes of the input
      Returns:
      this
    • putByteArray

      HashSink putByteArray(byte[] x)
      Adds a byte array 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);

      Parameters:
      x - the boolean array
      Returns:
      this
    • putBoolean

      HashSink putBoolean(boolean v)
      Adds a boolean value to the hash computation.

      Equivalent to
      putByte(v ? 1 : 0);

      Parameters:
      v - the value
      Returns:
      this
    • putBooleans

      HashSink putBooleans(boolean[] x)
      Adds all elements of a boolean array to the hash computation.

      Unlike 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);

      Parameters:
      x - the array
      Returns:
      this
    • putBooleans

      HashSink putBooleans(boolean[] x, int off, int len)
      Adds len elements of the given boolean array to the hash computation.

      Equivalent to
      for (int i = 0; i < len; i++) putBoolean(x[off + i]);

      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putBooleanArray

      HashSink putBooleanArray(boolean[] x)
      Adds a boolean array 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);

      Parameters:
      x - the boolean array
      Returns:
      this
    • putShort

      HashSink putShort(short v)
      Adds a short value to the hash computation using little-endian byte order.
      Parameters:
      v - the value
      Returns:
      this
    • putShorts

      HashSink putShorts(short[] x)
      Adds all elements of a short array to the hash computation.

      Unlike 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);

      Parameters:
      x - the array
      Returns:
      this
    • putShorts

      HashSink putShorts(short[] x, int off, int len)
      Adds len elements of the given short array to the hash computation.

      Equivalent to
      for (int i = 0; i < len; i++) putShort(x[off + i]);

      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putShortArray

      HashSink putShortArray(short[] x)
      Adds a short array 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);

      Parameters:
      x - the short array
      Returns:
      this
    • putChar

      HashSink putChar(char v)
      Adds a char value to the hash computation using little-endian byte order.
      Parameters:
      v - the value
      Returns:
      this
    • putChars

      HashSink putChars(char[] x)
      Adds all elements of a char array to the hash computation.

      Unlike 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);

      Parameters:
      x - the array
      Returns:
      this
    • putChars

      HashSink putChars(char[] x, int off, int len)
      Adds len elements of the given char array to the hash computation.

      Equivalent to
      for (int i = 0; i < len; i++) putChar(x[off + i]);

      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putChars

      HashSink putChars(CharSequence c)
      Adds 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));

      Parameters:
      c - a char sequence
      Returns:
      this
    • putCharArray

      HashSink putCharArray(char[] x)
      Adds a char array 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);

      Parameters:
      x - the char array
      Returns:
      this
    • putString

      HashSink putString(String s)
      Adds 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());

      Parameters:
      s - the string
      Returns:
      this
    • putInt

      HashSink putInt(int v)
      Adds an int value to the hash computation using little-endian byte order.
      Parameters:
      v - the value
      Returns:
      this
    • putInts

      HashSink putInts(int[] x)
      Adds all elements of an int array to the hash computation.

      Unlike 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);

      Parameters:
      x - the array
      Returns:
      this
    • putInts

      HashSink putInts(int[] x, int off, int len)
      Adds len elements of the given int array to the hash computation.

      Equivalent to
      for (int i = 0; i < len; i++) putInt(x[off + i]);

      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putIntArray

      HashSink putIntArray(int[] x)
      Adds an int array 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);

      Parameters:
      x - the int array
      Returns:
      this
    • putLong

      HashSink putLong(long v)
      Adds along long value to the hash computation using little-endian byte order.
      Parameters:
      v - the value
      Returns:
      this
    • putLongs

      HashSink putLongs(long[] x)
      Adds all elements of a long array to the hash computation.

      Unlike 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);

      Parameters:
      x - the array
      Returns:
      this
    • putLongs

      HashSink putLongs(long[] x, int off, int len)
      Adds len elements of the given long array to the hash computation.

      Equivalent to
      for (int i = 0; i < len; i++) putLong(x[off + i]);

      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putLongArray

      HashSink putLongArray(long[] x)
      Adds a long array 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);

      Parameters:
      x - the int array
      Returns:
      this
    • putFloat

      HashSink putFloat(float v)
      Adds a float value to the hash computation using little-endian byte order.

      Equivalent to
      putInt(Float.floatToRawIntBits(v));

      Parameters:
      v - the value
      Returns:
      this
    • putFloats

      HashSink putFloats(float[] x)
      Adds all elements of a float array to the hash computation.

      Unlike 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);

      Parameters:
      x - the array
      Returns:
      this
    • putFloats

      HashSink putFloats(float[] x, int off, int len)
      Adds len elements of the given float array to the hash computation.

      Equivalent to
      for (int i = 0; i < len; i++) putFloat(x[off + i]);

      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putFloatArray

      HashSink putFloatArray(float[] x)
      Adds a float array 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);

      Parameters:
      x - the float array
      Returns:
      this
    • putDouble

      HashSink putDouble(double v)
      Adds a double value to the hash computation using little-endian byte order.

      Equivalent to
      putLong(Double.doubleToRawLongBits(v));

      Parameters:
      v - the value
      Returns:
      this
    • putDoubles

      HashSink putDoubles(double[] x)
      Adds all elements of a double array to the hash computation.

      Unlike 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);

      Parameters:
      x - the array
      Returns:
      this
    • putDoubles

      HashSink putDoubles(double[] x, int off, int len)
      Adds len elements of the given double array to the hash computation.

      Equivalent to
      for (int i = 0; i < len; i++) putDouble(x[off + i]);

      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putDoubleArray

      HashSink putDoubleArray(double[] x)
      Adds a double array 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);

      Parameters:
      x - the double array
      Returns:
      this
    • putUUID

      HashSink putUUID(UUID uuid)
      Adds a UUID to the hash computation.

      Equivalent to
      putLong(uuid.getLeastSignificantBits()).putLong(uuid.getMostSignificantBits());

      Parameters:
      uuid - the UUID
      Returns:
      this
    • put

      <T> HashSink put(T obj, HashFunnel<T> funnel)
      Adds an object to the hash computation using the given funnel.
      Type Parameters:
      T - the type
      Parameters:
      obj - the object
      funnel - the funnel
      Returns:
      this
    • putNullable

      <T> HashSink putNullable(T obj, HashFunnel<T> funnel)
      Adds a nullable object to the hash computation using the given funnel.
      Type Parameters:
      T - the type
      Parameters:
      obj - the nullable object
      funnel - the funnel
      Returns:
      this
    • putOrderedIterable

      <T> HashSink putOrderedIterable(Iterable<T> data, HashFunnel<? super T> funnel)
      Adds an ordered Iterable (e.g. List) to the hash computation.
      Type Parameters:
      T - the element type
      Parameters:
      data - the iterable
      funnel - the funnel
      Returns:
      this
    • putUnorderedIterable

      <T> HashSink putUnorderedIterable(Iterable<T> data, ToLongFunction<? super T> elementHashFunction)
      Adds an unordered Iterable (e.g. Set) to the hash computation.
      Type Parameters:
      T - the element type
      Parameters:
      data - the iterable
      elementHashFunction - 64-bit hash function used for individual elements
      Returns:
      this
      Throws:
      OutOfMemoryError - if the allocation of a long array, that is able to keep a 64-bit hash for each element in the Iterable, fails
    • putUnorderedIterable

      <T> HashSink putUnorderedIterable(Iterable<T> data, HashFunnel<? super T> funnel, HashStream64 hashStream)
      Adds an unordered Iterable (e.g. Set) to the hash computation.
      Type Parameters:
      T - the element type
      Parameters:
      data - the iterable
      funnel - the funnel
      hashStream - 64-bit hash stream used for individual elements, must be a different instance than this HashSink
      Returns:
      this
      Throws:
      OutOfMemoryError - if the allocation of a long array, that is able to keep a 64-bit hash for each element in the Iterable, fails
      IllegalArgumentException - if the hash stream is equal to this HashSink
    • putUnorderedIterable

      <T> HashSink putUnorderedIterable(Iterable<T> data, HashFunnel<? super T> funnel, Hasher64 hasher)
      Adds an unordered Iterable (e.g. Set) to the hash computation.
      Type Parameters:
      T - the element type
      Parameters:
      data - the iterable
      funnel - the funnel
      hasher - a 64-bit hasher
      Returns:
      this
      Throws:
      OutOfMemoryError - if the allocation of a long array, that is able to keep a 64-bit hash for each element in the Iterable, fails
    • putOptional

      <T> HashSink putOptional(Optional<T> obj, HashFunnel<? super T> funnel)
      Adds an optional object to the hash computation using the given funnel.
      Type Parameters:
      T - the type
      Parameters:
      obj - the optional object
      funnel - the funnel
      Returns:
      this
    • putOptionalInt

      HashSink putOptionalInt(OptionalInt v)
      Adds an OptionalInt to the hash computation.
      Parameters:
      v - the optional value
      Returns:
      this
    • putOptionalLong

      HashSink putOptionalLong(OptionalLong v)
      Adds an OptionalLong to the hash computation.
      Parameters:
      v - the optional value
      Returns:
      this
    • putOptionalDouble

      HashSink putOptionalDouble(OptionalDouble v)
      Adds an OptionalDouble to the hash computation.
      Parameters:
      v - the optional value
      Returns:
      this