Module hash4j

Interface HashStream32

All Superinterfaces:
HashSink
All Known Subinterfaces:
HashStream128, HashStream64

public interface HashStream32
A hash stream computing a 32-bit hash value.
  • Method Details

    • getAsInt

      int getAsInt()
      Returns a 32-bit hash value.
      Returns:
      a 32-bit hash value
    • putByte

      HashStream32 putByte(byte v)
      Description copied from interface: HashSink
      Adds a byte value to the hash computation.
      Specified by:
      putByte in interface HashSink
      Parameters:
      v - the value
      Returns:
      this
    • putBytes

      HashStream32 putBytes(byte[] x)
      Description copied from interface: HashSink
      Adds all elements of a byte array 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);

      Specified by:
      putBytes in interface HashSink
      Parameters:
      x - the array
      Returns:
      this
    • putBytes

      HashStream32 putBytes(byte[] x, int off, int len)
      Description copied from interface: HashSink
      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]);

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

      <T> HashStream32 putBytes(T b, long off, long len, ByteAccess<T> access)
      Description copied from interface: HashSink
      Adds a sequence of bytes to the hash computation.

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

      Specified by:
      putBytes in interface HashSink
      Type Parameters:
      T - the type of the input
      Parameters:
      b - the input
      off - the offset
      len - the length
      access - a strategy to access the bytes of the input
      Returns:
      this
    • putByteArray

      HashStream32 putByteArray(byte[] x)
      Description copied from interface: HashSink
      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);

      Specified by:
      putByteArray in interface HashSink
      Parameters:
      x - the boolean array
      Returns:
      this
    • putBoolean

      HashStream32 putBoolean(boolean v)
      Description copied from interface: HashSink
      Adds a boolean value to the hash computation.

      Equivalent to
      putByte(v ? 1 : 0);

      Specified by:
      putBoolean in interface HashSink
      Parameters:
      v - the value
      Returns:
      this
    • putBooleans

      HashStream32 putBooleans(boolean[] x)
      Description copied from interface: HashSink
      Adds all elements of a boolean array 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:
      putBooleans in interface HashSink
      Parameters:
      x - the array
      Returns:
      this
    • putBooleans

      HashStream32 putBooleans(boolean[] x, int off, int len)
      Description copied from interface: HashSink
      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]);

      Specified by:
      putBooleans in interface HashSink
      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putBooleanArray

      HashStream32 putBooleanArray(boolean[] x)
      Description copied from interface: HashSink
      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);

      Specified by:
      putBooleanArray in interface HashSink
      Parameters:
      x - the boolean array
      Returns:
      this
    • putShort

      HashStream32 putShort(short v)
      Description copied from interface: HashSink
      Adds a short value to the hash computation using little-endian byte order.
      Specified by:
      putShort in interface HashSink
      Parameters:
      v - the value
      Returns:
      this
    • putShorts

      HashStream32 putShorts(short[] x)
      Description copied from interface: HashSink
      Adds all elements of a short array 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);

      Specified by:
      putShorts in interface HashSink
      Parameters:
      x - the array
      Returns:
      this
    • putShorts

      HashStream32 putShorts(short[] x, int off, int len)
      Description copied from interface: HashSink
      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]);

      Specified by:
      putShorts in interface HashSink
      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putShortArray

      HashStream32 putShortArray(short[] x)
      Description copied from interface: HashSink
      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);

      Specified by:
      putShortArray in interface HashSink
      Parameters:
      x - the short array
      Returns:
      this
    • putChar

      HashStream32 putChar(char v)
      Description copied from interface: HashSink
      Adds a char value to the hash computation using little-endian byte order.
      Specified by:
      putChar in interface HashSink
      Parameters:
      v - the value
      Returns:
      this
    • putChars

      HashStream32 putChars(char[] x)
      Description copied from interface: HashSink
      Adds all elements of a char array 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);

      Specified by:
      putChars in interface HashSink
      Parameters:
      x - the array
      Returns:
      this
    • putChars

      HashStream32 putChars(char[] x, int off, int len)
      Description copied from interface: HashSink
      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]);

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

      Description copied from interface: HashSink
      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));

      Specified by:
      putChars in interface HashSink
      Parameters:
      c - a char sequence
      Returns:
      this
    • putCharArray

      HashStream32 putCharArray(char[] x)
      Description copied from interface: HashSink
      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);

      Specified by:
      putCharArray in interface HashSink
      Parameters:
      x - the char array
      Returns:
      this
    • putString

      HashStream32 putString(String s)
      Description copied from interface: HashSink
      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());

      Specified by:
      putString in interface HashSink
      Parameters:
      s - the string
      Returns:
      this
    • putInt

      HashStream32 putInt(int v)
      Description copied from interface: HashSink
      Adds an int value to the hash computation using little-endian byte order.
      Specified by:
      putInt in interface HashSink
      Parameters:
      v - the value
      Returns:
      this
    • putInts

      HashStream32 putInts(int[] x)
      Description copied from interface: HashSink
      Adds all elements of an int array 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);

      Specified by:
      putInts in interface HashSink
      Parameters:
      x - the array
      Returns:
      this
    • putInts

      HashStream32 putInts(int[] x, int off, int len)
      Description copied from interface: HashSink
      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]);

      Specified by:
      putInts in interface HashSink
      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putIntArray

      HashStream32 putIntArray(int[] x)
      Description copied from interface: HashSink
      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);

      Specified by:
      putIntArray in interface HashSink
      Parameters:
      x - the int array
      Returns:
      this
    • putLong

      HashStream32 putLong(long v)
      Description copied from interface: HashSink
      Adds along long value to the hash computation using little-endian byte order.
      Specified by:
      putLong in interface HashSink
      Parameters:
      v - the value
      Returns:
      this
    • putLongs

      HashStream32 putLongs(long[] x)
      Description copied from interface: HashSink
      Adds all elements of a long array 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);

      Specified by:
      putLongs in interface HashSink
      Parameters:
      x - the array
      Returns:
      this
    • putLongs

      HashStream32 putLongs(long[] x, int off, int len)
      Description copied from interface: HashSink
      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]);

      Specified by:
      putLongs in interface HashSink
      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putLongArray

      HashStream32 putLongArray(long[] x)
      Description copied from interface: HashSink
      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);

      Specified by:
      putLongArray in interface HashSink
      Parameters:
      x - the int array
      Returns:
      this
    • putFloat

      HashStream32 putFloat(float v)
      Description copied from interface: HashSink
      Adds a float value to the hash computation using little-endian byte order.

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

      Specified by:
      putFloat in interface HashSink
      Parameters:
      v - the value
      Returns:
      this
    • putFloats

      HashStream32 putFloats(float[] x)
      Description copied from interface: HashSink
      Adds all elements of a float array 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);

      Specified by:
      putFloats in interface HashSink
      Parameters:
      x - the array
      Returns:
      this
    • putFloats

      HashStream32 putFloats(float[] x, int off, int len)
      Description copied from interface: HashSink
      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]);

      Specified by:
      putFloats in interface HashSink
      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putFloatArray

      HashStream32 putFloatArray(float[] x)
      Description copied from interface: HashSink
      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);

      Specified by:
      putFloatArray in interface HashSink
      Parameters:
      x - the float array
      Returns:
      this
    • putDouble

      HashStream32 putDouble(double v)
      Description copied from interface: HashSink
      Adds a double value to the hash computation using little-endian byte order.

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

      Specified by:
      putDouble in interface HashSink
      Parameters:
      v - the value
      Returns:
      this
    • putDoubles

      HashStream32 putDoubles(double[] x)
      Description copied from interface: HashSink
      Adds all elements of a double array 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:
      putDoubles in interface HashSink
      Parameters:
      x - the array
      Returns:
      this
    • putDoubles

      HashStream32 putDoubles(double[] x, int off, int len)
      Description copied from interface: HashSink
      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]);

      Specified by:
      putDoubles in interface HashSink
      Parameters:
      x - the array
      off - the start offset in the array
      len - the number of elements
      Returns:
      this
    • putDoubleArray

      HashStream32 putDoubleArray(double[] x)
      Description copied from interface: HashSink
      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);

      Specified by:
      putDoubleArray in interface HashSink
      Parameters:
      x - the double array
      Returns:
      this
    • putUUID

      HashStream32 putUUID(UUID uuid)
      Description copied from interface: HashSink
      Adds a UUID to the hash computation.

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

      Specified by:
      putUUID in interface HashSink
      Parameters:
      uuid - the UUID
      Returns:
      this
    • put

      <T> HashStream32 put(T obj, HashFunnel<T> funnel)
      Description copied from interface: HashSink
      Adds an object to the hash computation using the given funnel.
      Specified by:
      put in interface HashSink
      Type Parameters:
      T - the type
      Parameters:
      obj - the object
      funnel - the funnel
      Returns:
      this
    • putNullable

      <T> HashStream32 putNullable(T obj, HashFunnel<T> funnel)
      Description copied from interface: HashSink
      Adds a nullable object to the hash computation using the given funnel.
      Specified by:
      putNullable in interface HashSink
      Type Parameters:
      T - the type
      Parameters:
      obj - the nullable object
      funnel - the funnel
      Returns:
      this
    • putUnorderedIterable

      <T> HashStream32 putUnorderedIterable(Iterable<T> data, ToLongFunction<? super T> elementHashFunction)
      Description copied from interface: HashSink
      Adds an unordered Iterable (e.g. Set) to the hash computation.
      Specified by:
      putUnorderedIterable in interface HashSink
      Type Parameters:
      T - the element type
      Parameters:
      data - the iterable
      elementHashFunction - 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
      Adds an unordered Iterable (e.g. Set) to the hash computation.
      Specified by:
      putUnorderedIterable in interface HashSink
      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
    • putUnorderedIterable

      <T> HashStream32 putUnorderedIterable(Iterable<T> data, HashFunnel<? super T> funnel, Hasher64 hasher)
      Description copied from interface: HashSink
      Adds an unordered Iterable (e.g. Set) to the hash computation.
      Specified by:
      putUnorderedIterable in interface HashSink
      Type Parameters:
      T - the element type
      Parameters:
      data - the iterable
      funnel - the funnel
      hasher - a 64-bit hasher
      Returns:
      this
    • putOptional

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

      HashStream32 putOptionalInt(OptionalInt v)
      Description copied from interface: HashSink
      Adds an OptionalInt to the hash computation.
      Specified by:
      putOptionalInt in interface HashSink
      Parameters:
      v - the optional value
      Returns:
      this
    • putOptionalLong

      HashStream32 putOptionalLong(OptionalLong v)
      Description copied from interface: HashSink
      Adds an OptionalLong to the hash computation.
      Specified by:
      putOptionalLong in interface HashSink
      Parameters:
      v - the optional value
      Returns:
      this
    • putOptionalDouble

      HashStream32 putOptionalDouble(OptionalDouble v)
      Description copied from interface: HashSink
      Adds an OptionalDouble to the hash computation.
      Specified by:
      putOptionalDouble in interface HashSink
      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

      <T> int resetAndHashToInt(T obj, HashFunnel<T> funnel)
      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 object
      funnel - 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 using setState(byte[]).

      Returns:
      the state
    • setState

      HashStream32 setState(byte[] state)
      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
      Adds an ordered Iterable (e.g. List) to the hash computation.
      Specified by:
      putOrderedIterable in interface HashSink
      Type Parameters:
      T - the element type
      Parameters:
      data - the iterable
      funnel - the funnel
      Returns:
      this