@Test public void testGetNextSetBitOffset() throws IOException { int[] setBitOffsets = new int[NUM_ITERATIONS]; int bitOffset = RANDOM.nextInt(10); for (int i = 0; i < NUM_ITERATIONS; i++) { setBitOffsets[i] = bitOffset; bitOffset += RANDOM.nextInt(10) + 1; } int dataBufferSize = setBitOffsets[NUM_ITERATIONS - 1] / Byte.SIZE + 1; try (PinotDataBuffer dataBuffer = getEmptyDataBuffer(dataBufferSize); PinotDataBitSet dataBitSet = new PinotDataBitSet(dataBuffer)) { for (int i = 0; i < NUM_ITERATIONS; i++) { dataBitSet.setBit(setBitOffsets[i]); } for (int i = 0; i < NUM_ITERATIONS - 1; i++) { assertEquals(dataBitSet .getNextSetBitOffset(setBitOffsets[i] + RANDOM.nextInt(setBitOffsets[i + 1] - setBitOffsets[i]) + 1), setBitOffsets[i + 1]); } for (int i = 0; i < NUM_ITERATIONS - 100; i++) { int n = RANDOM.nextInt(100) + 1; assertEquals(dataBitSet .getNextNthSetBitOffset(setBitOffsets[i] + RANDOM.nextInt(setBitOffsets[i + 1] - setBitOffsets[i]) + 1, n), setBitOffsets[i + n]); } } }
public int getNextSetBitOffset(int bitOffset) { int byteOffset = bitOffset / Byte.SIZE; int bitOffsetInFirstByte = bitOffset % Byte.SIZE; int firstByte = (_dataBuffer.getByte(byteOffset) << bitOffsetInFirstByte) & BYTE_MASK; if (firstByte != 0) { return bitOffset + FIRST_BIT_SET[firstByte]; } while (true) { int currentByte = _dataBuffer.getByte(++byteOffset) & BYTE_MASK; if (currentByte != 0) { return (byteOffset * Byte.SIZE) | FIRST_BIT_SET[currentByte]; } } }
PinotDataBitSet implements Closeable { public int getNextSetBitOffset(int bitOffset) { int byteOffset = bitOffset / Byte.SIZE; int bitOffsetInFirstByte = bitOffset % Byte.SIZE; int firstByte = (_dataBuffer.getByte(byteOffset) << bitOffsetInFirstByte) & BYTE_MASK; if (firstByte != 0) { return bitOffset + FIRST_BIT_SET[firstByte]; } while (true) { int currentByte = _dataBuffer.getByte(++byteOffset) & BYTE_MASK; if (currentByte != 0) { return (byteOffset * Byte.SIZE) | FIRST_BIT_SET[currentByte]; } } } }
PinotDataBitSet implements Closeable { public int getNextSetBitOffset(int bitOffset) { int byteOffset = bitOffset / Byte.SIZE; int bitOffsetInFirstByte = bitOffset % Byte.SIZE; int firstByte = (_dataBuffer.getByte(byteOffset) << bitOffsetInFirstByte) & BYTE_MASK; if (firstByte != 0) { return bitOffset + FIRST_BIT_SET[firstByte]; } while (true) { int currentByte = _dataBuffer.getByte(++byteOffset) & BYTE_MASK; if (currentByte != 0) { return (byteOffset * Byte.SIZE) | FIRST_BIT_SET[currentByte]; } } } PinotDataBitSet(PinotDataBuffer dataBuffer); }
PinotDataBitSet implements Closeable { public int getNextSetBitOffset(int bitOffset) { int byteOffset = bitOffset / Byte.SIZE; int bitOffsetInFirstByte = bitOffset % Byte.SIZE; int firstByte = (_dataBuffer.getByte(byteOffset) << bitOffsetInFirstByte) & BYTE_MASK; if (firstByte != 0) { return bitOffset + FIRST_BIT_SET[firstByte]; } while (true) { int currentByte = _dataBuffer.getByte(++byteOffset) & BYTE_MASK; if (currentByte != 0) { return (byteOffset * Byte.SIZE) | FIRST_BIT_SET[currentByte]; } } } PinotDataBitSet(PinotDataBuffer dataBuffer); static int getNumBitsPerValue(int maxValue); int readInt(int index, int numBitsPerValue); void readInt(int startIndex, int numBitsPerValue, int length, int[] buffer); void writeInt(int index, int numBitsPerValue, int value); void writeInt(int startIndex, int numBitsPerValue, int length, int[] values); void setBit(int bitOffset); void unsetBit(int bitOffset); int getNextSetBitOffset(int bitOffset); int getNextNthSetBitOffset(int bitOffset, int n); @Override void close(); }
PinotDataBitSet implements Closeable { public int getNextSetBitOffset(int bitOffset) { int byteOffset = bitOffset / Byte.SIZE; int bitOffsetInFirstByte = bitOffset % Byte.SIZE; int firstByte = (_dataBuffer.getByte(byteOffset) << bitOffsetInFirstByte) & BYTE_MASK; if (firstByte != 0) { return bitOffset + FIRST_BIT_SET[firstByte]; } while (true) { int currentByte = _dataBuffer.getByte(++byteOffset) & BYTE_MASK; if (currentByte != 0) { return (byteOffset * Byte.SIZE) | FIRST_BIT_SET[currentByte]; } } } PinotDataBitSet(PinotDataBuffer dataBuffer); static int getNumBitsPerValue(int maxValue); int readInt(int index, int numBitsPerValue); void readInt(int startIndex, int numBitsPerValue, int length, int[] buffer); void writeInt(int index, int numBitsPerValue, int value); void writeInt(int startIndex, int numBitsPerValue, int length, int[] values); void setBit(int bitOffset); void unsetBit(int bitOffset); int getNextSetBitOffset(int bitOffset); int getNextNthSetBitOffset(int bitOffset, int n); @Override void close();  }