Module hash4j

Interface Hasher32

All Known Subinterfaces:
Hasher128, Hasher64

public interface Hasher32
A 32-bit hash function.

Instances are immutable. Therefore, it is safe to use a single instance across multiple threads and for multiple hash calculations.

  • Method Summary

    Modifier and Type
    Method
    Description
    int
    The size of the hash value in bits.
    int
    hashBytesToInt(byte[] input)
    Hashes a byte array to a 32-bit integer value.
    int
    hashBytesToInt(byte[] input, int off, int len)
    Hashes a byte array to a 32-bit integer value.
    <T> int
    hashBytesToInt(T input, long off, long len, ByteAccess<T> access)
    Hashes a sequence of bytes to a 32-bit int value
    int
    Hashes a CharSequence to a 32-bit int value.
    int
    hashIntIntIntToInt(int v1, int v2, int v3)
    Hashes/Mixes three 32-bit int values into a 32-bit int value.
    int
    hashIntIntToInt(int v1, int v2)
    Hashes/Mixes two 32-bit int values into a 32-bit int value.
    int
    hashIntLongToInt(int v1, long v2)
    Hashes/Mixes a 32-bit int value and a 64-bit long value into a 32-bit int value.
    int
    hashIntToInt(int v)
    Hashes a 32-bit int value into a 32-bit int value.
    int
    hashLongIntToInt(long v1, int v2)
    Hashes/Mixes a 64-bit long value and a 32-bit int value into a 32-bit int value.
    int
    hashLongLongLongToInt(long v1, long v2, long v3)
    Hashes/Mixes three 64-bit long values into a 32-bit int value.
    int
    hashLongLongToInt(long v1, long v2)
    Hashes/Mixes two 64-bit long values into a 32-bit int value.
    int
    hashLongToInt(long v)
    Hashes a 64-bit long value into a 32-bit int value.
    Starts a hash stream.
    hashStreamFromState(byte[] state)
    Reconstructs a hash stream from a given state.
    <T> int
    hashToInt(T obj, HashFunnel<T> funnel)
    Hashes an object to a 32-bit integer value.
  • Method Details

    • hashStream

      HashStream32 hashStream()
      Starts a hash stream.
      Returns:
      a new HashStream32 instance
    • hashStreamFromState

      HashStream32 hashStreamFromState(byte[] state)
      Reconstructs a hash stream from a given state.

      The behavior is undefined, if the given state was not created by a hash stream of a hasher that is equal to this hasher.

      Returns:
      a new HashStream32 instance
    • hashToInt

      <T> int hashToInt(T obj, HashFunnel<T> funnel)
      Hashes an object to a 32-bit integer value.
      Type Parameters:
      T - the type
      Parameters:
      obj - the object
      funnel - the funnel
      Returns:
      the hash value
    • hashBytesToInt

      int hashBytesToInt(byte[] input)
      Hashes a byte array to a 32-bit integer value.

      Equivalent to hashBytesToInt(input, 0, input.length).

      Parameters:
      input - the byte array
      Returns:
      the hash value
    • hashBytesToInt

      int hashBytesToInt(byte[] input, int off, int len)
      Hashes a byte array to a 32-bit integer value.

      Equivalent to hashToInt(input, (b, f) -> f.putBytes(b, off, len)).

      Parameters:
      input - the byte array
      off - the offset
      len - the length
      Returns:
      the hash value
    • hashBytesToInt

      <T> int hashBytesToInt(T input, long off, long len, ByteAccess<T> access)
      Hashes a sequence of bytes to a 32-bit int value
      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:
      the hash value
    • hashCharsToInt

      int hashCharsToInt(CharSequence input)
      Hashes a CharSequence to a 32-bit int value.

      Equivalent to hashToInt(input, (c, f) -> f.putChars(c)).

      Parameters:
      input - the char sequence
      Returns:
      the hash value
    • hashIntToInt

      int hashIntToInt(int v)
      Hashes a 32-bit int value into a 32-bit int value.

      Equivalent to hashStream().putInt(v).getAsInt();

      Parameters:
      v - value
      Returns:
      the hash value
    • hashIntIntToInt

      int hashIntIntToInt(int v1, int v2)
      Hashes/Mixes two 32-bit int values into a 32-bit int value.

      Equivalent to hashStream().putInt(v1).putInt(v2).getAsInt();

      Parameters:
      v1 - first value
      v2 - second value
      Returns:
      the hash value
    • hashIntIntIntToInt

      int hashIntIntIntToInt(int v1, int v2, int v3)
      Hashes/Mixes three 32-bit int values into a 32-bit int value.

      Equivalent to hashStream().putInt(v1).putInt(v2).putInt(v3).getAsInt();

      Parameters:
      v1 - first value
      v2 - second value
      v3 - third value
      Returns:
      the hash value
    • hashIntLongToInt

      int hashIntLongToInt(int v1, long v2)
      Hashes/Mixes a 32-bit int value and a 64-bit long value into a 32-bit int value.

      Equivalent to hashStream().putInt(v1).putLong(v2).getAsInt();

      Parameters:
      v1 - first value
      v2 - second value
      Returns:
      the hash value
    • hashLongToInt

      int hashLongToInt(long v)
      Hashes a 64-bit long value into a 32-bit int value.

      Equivalent to hashStream().putLong(v).getAsInt();

      Parameters:
      v - value
      Returns:
      the hash value
    • hashLongLongToInt

      int hashLongLongToInt(long v1, long v2)
      Hashes/Mixes two 64-bit long values into a 32-bit int value.

      Equivalent to hashStream().putLong(v1).putLong(v2).getAsInt();

      Parameters:
      v1 - first value
      v2 - second value
      Returns:
      the hash value
    • hashLongLongLongToInt

      int hashLongLongLongToInt(long v1, long v2, long v3)
      Hashes/Mixes three 64-bit long values into a 32-bit int value.

      Equivalent to hashStream().putLong(v1).putLong(v2).putLong(v3).getAsInt();

      Parameters:
      v1 - first value
      v2 - second value
      v3 - third value
      Returns:
      the hash value
    • hashLongIntToInt

      int hashLongIntToInt(long v1, int v2)
      Hashes/Mixes a 64-bit long value and a 32-bit int value into a 32-bit int value.

      Equivalent to hashStream().putLong(v1).putInt(v2).getAsInt();

      Parameters:
      v1 - first value
      v2 - second value
      Returns:
      the hash value
    • getHashBitSize

      int getHashBitSize()
      The size of the hash value in bits.
      Returns:
      the size of the hash value in bits