Class BitVectorHelper

java.lang.Object
org.apache.arrow.vector.BitVectorHelper

public class BitVectorHelper extends Object
Helper class for performing generic operations on a bit vector buffer. External use of this class is not recommended.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    bitIndex(int absoluteBitIndex)
    Get the relative index of bit within the byte in validity buffer.
    static int
    bitIndex(long absoluteBitIndex)
    Get the relative index of bit within the byte in validity buffer.
    static int
    byteIndex(int absoluteBitIndex)
    Get the index of byte corresponding to bit index in validity buffer.
    static long
    byteIndex(long absoluteBitIndex)
    Get the index of byte corresponding to bit index in validity buffer.
    static boolean
    checkAllBitsEqualTo(ArrowBuf validityBuffer, int valueCount, boolean checkOneBits)
    Tests if all bits in a validity buffer are equal 0 or 1, according to the specified parameter.
    static void
    concatBits(ArrowBuf input1, int numBits1, ArrowBuf input2, int numBits2, ArrowBuf output)
    Concat two validity buffers.
    static int
    get(ArrowBuf buffer, int index)
    Check if a bit at a given index is set or not.
    static byte
    getBitsFromCurrentByte(ArrowBuf data, int index, int offset)
    Returns the byte at index from data right-shifted by offset.
    static byte
    getBitsFromNextByte(ArrowBuf data, int index, int offset)
    Returns the byte at index from left-shifted by (8 - offset).
    static int
    getNullCount(ArrowBuf validityBuffer, int valueCount)
    Given a validity buffer, find the number of bits that are not set.
    static int
    getValidityBufferSize(int valueCount)
    Compute the size of validity buffer required to manage a given number of elements in a vector.
    static ArrowBuf
    loadValidityBuffer(ArrowFieldNode fieldNode, ArrowBuf sourceValidityBuffer, BufferAllocator allocator)
    Returns a new buffer if the source validity buffer is either all null or all not-null, otherwise returns a buffer pointing to the same memory as source.
    static void
    setBit(ArrowBuf validityBuffer, long index)
    Set the bit at provided index to 1.
    static void
    setValidityBit(ArrowBuf validityBuffer, int index, int value)
    Set the bit at a given index to provided value (1 or 0).
    static ArrowBuf
    setValidityBit(ArrowBuf validityBuffer, BufferAllocator allocator, int valueCount, int index, int value)
    Set the bit at a given index to provided value (1 or 0).
    static void
    unsetBit(ArrowBuf validityBuffer, int index)
    Set the bit at provided index to 0.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • byteIndex

      public static long byteIndex(long absoluteBitIndex)
      Get the index of byte corresponding to bit index in validity buffer.
    • bitIndex

      public static int bitIndex(long absoluteBitIndex)
      Get the relative index of bit within the byte in validity buffer.
    • byteIndex

      public static int byteIndex(int absoluteBitIndex)
      Get the index of byte corresponding to bit index in validity buffer.
    • bitIndex

      public static int bitIndex(int absoluteBitIndex)
      Get the relative index of bit within the byte in validity buffer.
    • setBit

      public static void setBit(ArrowBuf validityBuffer, long index)
      Set the bit at provided index to 1.
      Parameters:
      validityBuffer - validity buffer of the vector
      index - index to be set
    • unsetBit

      public static void unsetBit(ArrowBuf validityBuffer, int index)
      Set the bit at provided index to 0.
      Parameters:
      validityBuffer - validity buffer of the vector
      index - index to be set
    • setValidityBit

      public static void setValidityBit(ArrowBuf validityBuffer, int index, int value)
      Set the bit at a given index to provided value (1 or 0).
      Parameters:
      validityBuffer - validity buffer of the vector
      index - index to be set
      value - value to set
    • setValidityBit

      public static ArrowBuf setValidityBit(ArrowBuf validityBuffer, BufferAllocator allocator, int valueCount, int index, int value)
      Set the bit at a given index to provided value (1 or 0). Internally takes care of allocating the buffer if the caller didn't do so.
      Parameters:
      validityBuffer - validity buffer of the vector
      allocator - allocator for the buffer
      valueCount - number of values to allocate/set
      index - index to be set
      value - value to set
      Returns:
      ArrowBuf
    • get

      public static int get(ArrowBuf buffer, int index)
      Check if a bit at a given index is set or not.
      Parameters:
      buffer - buffer to check
      index - index of the buffer
      Returns:
      1 if bit is set, 0 otherwise.
    • getValidityBufferSize

      public static int getValidityBufferSize(int valueCount)
      Compute the size of validity buffer required to manage a given number of elements in a vector.
      Parameters:
      valueCount - number of elements in the vector
      Returns:
      buffer size
    • getNullCount

      public static int getNullCount(ArrowBuf validityBuffer, int valueCount)
      Given a validity buffer, find the number of bits that are not set. This is used to compute the number of null elements in a nullable vector.
      Parameters:
      validityBuffer - validity buffer of the vector
      valueCount - number of values in the vector
      Returns:
      number of bits not set.
    • checkAllBitsEqualTo

      public static boolean checkAllBitsEqualTo(ArrowBuf validityBuffer, int valueCount, boolean checkOneBits)
      Tests if all bits in a validity buffer are equal 0 or 1, according to the specified parameter.
      Parameters:
      validityBuffer - the validity buffer.
      valueCount - the bit count.
      checkOneBits - if set to true, the method checks if all bits are equal to 1; otherwise, it checks if all bits are equal to 0.
      Returns:
      true if all bits are 0 or 1 according to the parameter, and false otherwise.
    • getBitsFromCurrentByte

      public static byte getBitsFromCurrentByte(ArrowBuf data, int index, int offset)
      Returns the byte at index from data right-shifted by offset.
    • getBitsFromNextByte

      public static byte getBitsFromNextByte(ArrowBuf data, int index, int offset)
      Returns the byte at index from left-shifted by (8 - offset).
    • loadValidityBuffer

      public static ArrowBuf loadValidityBuffer(ArrowFieldNode fieldNode, ArrowBuf sourceValidityBuffer, BufferAllocator allocator)
      Returns a new buffer if the source validity buffer is either all null or all not-null, otherwise returns a buffer pointing to the same memory as source.
      Parameters:
      fieldNode - The fieldNode containing the null count
      sourceValidityBuffer - The source validity buffer that will have its position copied if there is a mix of null and non-null values
      allocator - The allocator to use for creating a new buffer if necessary.
      Returns:
      A new buffer that is either allocated or points to the same memory as sourceValidityBuffer.
    • concatBits

      public static void concatBits(ArrowBuf input1, int numBits1, ArrowBuf input2, int numBits2, ArrowBuf output)
      Concat two validity buffers.
      Parameters:
      input1 - the first validity buffer.
      numBits1 - the number of bits in the first validity buffer.
      input2 - the second validity buffer.
      numBits2 - the number of bits in the second validity buffer.
      output - the output validity buffer. It can be the same one as the first input. The caller must make sure the output buffer has enough capacity.