Module hash4j

Interface PackedArray.PackedArrayHandler

Enclosing class:
PackedArray

public static interface PackedArray.PackedArrayHandler
A handler for a packed array with predefined element size.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    clear(byte[] array)
    Sets all components of the given packed array to 0.
    byte[]
    create(int length)
    Creates a byte array that can store a packed array having the given number of components.
    byte[]
    create(PackedArray.IndexedLongValueProvider valueProvider, int length)
    Returns a byte array that represents a packed array having the given number of components.
    long
    get(byte[] array, int idx)
    Returns the value of a component in a packed array.
    int
    The number of bits of a single component.
    int
    numBytes(int length)
    Returns the number of bytes needed to store a packed array having the given number of components.
    int
    numEqualComponents(byte[] array1, byte[] array2, int length)
    Returns the number of equal components of two packed arrays with given length.
    readIterator(byte[] array, int length)
    Returns a PackedArray.PackedArrayReadIterator to read the values of all components in sequential order.
    long
    set(byte[] array, int idx, long value)
    Sets a component in a packed array to the given value and returns the previous value.
    long
    update(byte[] array, int idx, long value, LongBinaryOperator operator)
    Updates a component in a packed array using the given value and a binary operator that computes the update value from the previous value and the given value.
  • Method Details

    • numBytes

      int numBytes(int length)
      Returns the number of bytes needed to store a packed array having the given number of components.
      Parameters:
      length - the length of the packed array
      Returns:
      the number of bytes
    • create

      byte[] create(int length)
      Creates a byte array that can store a packed array having the given number of components.

      All components of the byte array are initially 0, which also corresponds to 0 values in the packed array.

      Parameters:
      length - the length of the packed array
      Returns:
      a byte array representing the packed array
    • create

      byte[] create(PackedArray.IndexedLongValueProvider valueProvider, int length)
      Returns a byte array that represents a packed array having the given number of components. The initial values are taken from the given PackedArray.IndexedLongValueProvider.
      Parameters:
      valueProvider - a value provider
      length - the length of the packed array
      Returns:
      a byte array representing the packed array
    • get

      long get(byte[] array, int idx)
      Returns the value of a component in a packed array.

      If the given index is not valid, the behavior of this function is undefined.

      Parameters:
      array - a byte array representing the packed array
      idx - the index of the component
      Returns:
      the value of the component
    • set

      long set(byte[] array, int idx, long value)
      Sets a component in a packed array to the given value and returns the previous value.

      Only the lowest getBitSize() bits of the given value are used for setting the new value.

      If the given index is not valid, the behavior of this function is undefined.

      Parameters:
      array - a byte array representing the packed array
      idx - the index of the component
      value - the new value
      Returns:
      the previous value of the component
    • update

      long update(byte[] array, int idx, long value, LongBinaryOperator operator)
      Updates a component in a packed array using the given value and a binary operator that computes the update value from the previous value and the given value.

      The given operator will get the old value of the component as first argument and the given value as second argument. Only the lowest getBitSize() bits of the result are used for setting the new value.

      If the given index is not valid, the behavior of this function is undefined.

      Parameters:
      array - a byte array representing the packed array
      idx - the index of the component
      value - a value
      operator - a binary operator
      Returns:
      the previous value of the component
      Throws:
      NullPointerException - if operator is null
    • getBitSize

      int getBitSize()
      The number of bits of a single component.
      Returns:
      the number of bits
    • numEqualComponents

      int numEqualComponents(byte[] array1, byte[] array2, int length)
      Returns the number of equal components of two packed arrays with given length.

      If the arrays have been initialized using create(int) with a different length than the given length, the behavior of this method is not defined.

      Parameters:
      array1 - the first packed array
      array2 - the second packed array
      length - the total number of components
      Returns:
      the number of equal components
    • clear

      void clear(byte[] array)
      Sets all components of the given packed array to 0.
      Parameters:
      array - a packed array
    • readIterator

      PackedArray.PackedArrayReadIterator readIterator(byte[] array, int length)
      Returns a PackedArray.PackedArrayReadIterator to read the values of all components in sequential order.
      Parameters:
      array - the packed array
      length - the number of components of the packed array
      Returns:
      a read iterator
      Throws:
      NullPointerException - if array is null