in vector/src/main/java/org/apache/arrow/vector/BitVectorHelper.java [231:289]
public static boolean checkAllBitsEqualTo(
final ArrowBuf validityBuffer, final int valueCount, final boolean checkOneBits) {
if (valueCount == 0) {
return true;
}
final int sizeInBytes = getValidityBufferSize(valueCount);
// boundary check
validityBuffer.checkBytes(0, sizeInBytes);
// If value count is not a multiple of 8, then calculate number of used bits in the last byte
final int remainder = valueCount % 8;
final int fullBytesCount = remainder == 0 ? sizeInBytes : sizeInBytes - 1;
// the integer number to compare against
final int intToCompare = checkOneBits ? -1 : 0;
int index = 0;
while (index + 8 <= fullBytesCount) {
long longValue = MemoryUtil.getLong(validityBuffer.memoryAddress() + index);
if (longValue != (long) intToCompare) {
return false;
}
index += 8;
}
if (index + 4 <= fullBytesCount) {
int intValue = MemoryUtil.getInt(validityBuffer.memoryAddress() + index);
if (intValue != intToCompare) {
return false;
}
index += 4;
}
while (index < fullBytesCount) {
byte byteValue = MemoryUtil.getByte(validityBuffer.memoryAddress() + index);
if (byteValue != (byte) intToCompare) {
return false;
}
index += 1;
}
// handling with the last bits
if (remainder != 0) {
byte byteValue = MemoryUtil.getByte(validityBuffer.memoryAddress() + sizeInBytes - 1);
byte mask = (byte) ((1 << remainder) - 1);
byteValue = (byte) (byteValue & mask);
if (checkOneBits) {
if ((mask & byteValue) != mask) {
return false;
}
} else {
if (byteValue != (byte) 0) {
return false;
}
}
}
return true;
}