java.lang.Object
org.apache.arrow.vector.BitVectorHelper
Helper class for performing generic operations on a bit vector buffer. External use of this class
is not recommended.
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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
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 atindex
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
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
Set the bit at provided index to 0.
-
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
Set the bit at provided index to 1.- Parameters:
validityBuffer
- validity buffer of the vectorindex
- index to be set
-
unsetBit
Set the bit at provided index to 0.- Parameters:
validityBuffer
- validity buffer of the vectorindex
- index to be set
-
setValidityBit
Set the bit at a given index to provided value (1 or 0).- Parameters:
validityBuffer
- validity buffer of the vectorindex
- index to be setvalue
- 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 vectorallocator
- allocator for the buffervalueCount
- number of values to allocate/setindex
- index to be setvalue
- value to set- Returns:
- ArrowBuf
-
get
Check if a bit at a given index is set or not.- Parameters:
buffer
- buffer to checkindex
- 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
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 vectorvalueCount
- 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
Returns the byte at index from data right-shifted by offset. -
getBitsFromNextByte
Returns the byte atindex
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 countsourceValidityBuffer
- The source validity buffer that will have its position copied if there is a mix of null and non-null valuesallocator
- 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.
-