Module hash4j

Interface ByteAccess<T>

Type Parameters:
T - the type of the data object

public interface ByteAccess<T>
Strategy to access contiguous bytes of a data object.

It is recommended to override the default implementations of at least getInt(Object, long) and getLong(Object, long) for best performance.

  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    copyToByteArray(T data, long idx, byte[] array, int off, int len)
    Copies a given number of bytes from the data object into a given byte[] array.
    byte
    getByte(T data, long idx)
    Returns the byte at a certain position from the given data object as byte.
    default int
    getByteAsUnsignedInt(T data, long idx)
    Returns the byte at a certain position from the given data object as non-negative int.
    default long
    getByteAsUnsignedLong(T data, long idx)
    Returns the byte at a certain position from the given data object as non-negative long.
    default int
    getInt(T data, long idx)
    Returns 4 subsequent bytes starting at a certain position from the given data object as int.
    default long
    getIntAsUnsignedLong(T data, long idx)
    Returns 4 subsequent bytes starting at a certain position from the given data object as non-negative long.
    default long
    getLong(T data, long idx)
    Returns 8 subsequent bytes starting at a certain position from the given data object as long.
  • Method Details

    • getByte

      byte getByte(T data, long idx)
      Returns the byte at a certain position from the given data object as byte.
      Parameters:
      data - the data object
      idx - the index
      Returns:
      the byte
    • getByteAsUnsignedInt

      default int getByteAsUnsignedInt(T data, long idx)
      Returns the byte at a certain position from the given data object as non-negative int.

      This is equivalent to getByte(data, idx) & 0xFF.

      Parameters:
      data - the data object
      idx - the index
      Returns:
      the byte as non-negative long
    • getByteAsUnsignedLong

      default long getByteAsUnsignedLong(T data, long idx)
      Returns the byte at a certain position from the given data object as non-negative long.

      This is equivalent to getByte(data, idx) & 0xFFL.

      Parameters:
      data - the data object
      idx - the index
      Returns:
      the byte as non-negative long
    • getInt

      default int getInt(T data, long idx)
      Returns 4 subsequent bytes starting at a certain position from the given data object as int.

      This is equivalent to (getByte(data, idx) & 0xFF) | ((getByte(data, idx + 1) & 0xFF) << 8) | ((getByte(data, idx + 2) & 0xFF) << 16) | ((int)getByte(data, idx+3) << 24).

      Parameters:
      data - the data object
      idx - the index of the first byte
      Returns:
      4 bytes as integer
    • getIntAsUnsignedLong

      default long getIntAsUnsignedLong(T data, long idx)
      Returns 4 subsequent bytes starting at a certain position from the given data object as non-negative long.

      This is equivalent to getInt(data, idx) & 0xFFFFFFFFL.

      Parameters:
      data - the data object
      idx - the index of the first byte
      Returns:
      4 bytes as non-negative long
    • getLong

      default long getLong(T data, long idx)
      Returns 8 subsequent bytes starting at a certain position from the given data object as long.

      This is equivalent to getIntUnsigned(data, idx) | ((long) getInt(data, idx + 4) << 32).

      Parameters:
      data - the data object
      idx - the index of the first byte
      Returns:
      8 bytes as long
    • copyToByteArray

      default void copyToByteArray(T data, long idx, byte[] array, int off, int len)
      Copies a given number of bytes from the data object into a given byte[] array.

      This is equivalent to for(int i = 0; i < len; ++i) array[off + i] = getByte(data, idx + i).

      Parameters:
      data - the data object
      idx - the index of the first byte
      array - the target byte array
      off - the target offset
      len - the number of bytes