@Test public void testEqualsValueAt() throws Exception { try (OffHeapMutableBytesStore offHeapMutableBytesStore = new OffHeapMutableBytesStore(_memoryManager, null)) { for (int i = 0; i < NUM_VALUES; i++) { offHeapMutableBytesStore.add(_values[i]); } for (int i = 0; i < NUM_VALUES; i++) { int index = RANDOM.nextInt(NUM_VALUES); assertTrue(offHeapMutableBytesStore.equalsValueAt(index, _values[index])); if (!Arrays.equals(_values[index], _values[0])) { assertFalse(offHeapMutableBytesStore.equalsValueAt(0, _values[index])); assertFalse(offHeapMutableBytesStore.equalsValueAt(index, _values[0])); } } } }
@SuppressWarnings("Duplicates") public boolean equalsValueAt(int index, byte[] valueToCompare) { assert index < _numValues; int offsetBufferIndex = index >>> OFFSET_BUFFER_SHIFT_OFFSET; PinotDataBuffer offsetBuffer = _offsetBuffers.get(offsetBufferIndex); int offsetIndex = index & OFFSET_BUFFER_MASK; int previousValueEndOffset = offsetBuffer.getInt(offsetIndex << 2); int valueEndOffset = offsetBuffer.getInt((offsetIndex + 1) << 2); int inputValueLength = valueToCompare.length; if (previousValueEndOffset == valueEndOffset) { return inputValueLength == 0; } int valueBufferIndex = (valueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET; int startOffsetInValueBuffer; if ((previousValueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET != valueBufferIndex) { if ((valueEndOffset & VALUE_BUFFER_MASK) != inputValueLength) { return false; } startOffsetInValueBuffer = 0; } else { if (valueEndOffset - previousValueEndOffset != inputValueLength) { return false; } startOffsetInValueBuffer = previousValueEndOffset & VALUE_BUFFER_MASK; } PinotDataBuffer valueBuffer = _valueBuffers.get(valueBufferIndex); if (inputValueLength <= PinotDataBuffer.BULK_BYTES_PROCESSING_THRESHOLD) { for (int i = 0; i < inputValueLength; i++) { if (valueToCompare[i] != valueBuffer.getByte(startOffsetInValueBuffer + i)) { return false; } } return true; } else { byte[] value = new byte[inputValueLength]; valueBuffer.copyTo(startOffsetInValueBuffer, value); for (int i = 0; i < inputValueLength; i++) { if (valueToCompare[i] != value[i]) { return false; } } return true; } }
OffHeapMutableBytesStore implements Closeable { @SuppressWarnings("Duplicates") public boolean equalsValueAt(int index, byte[] valueToCompare) { assert index < _numValues; int offsetBufferIndex = index >>> OFFSET_BUFFER_SHIFT_OFFSET; PinotDataBuffer offsetBuffer = _offsetBuffers.get(offsetBufferIndex); int offsetIndex = index & OFFSET_BUFFER_MASK; int previousValueEndOffset = offsetBuffer.getInt(offsetIndex << 2); int valueEndOffset = offsetBuffer.getInt((offsetIndex + 1) << 2); int inputValueLength = valueToCompare.length; if (previousValueEndOffset == valueEndOffset) { return inputValueLength == 0; } int valueBufferIndex = (valueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET; int startOffsetInValueBuffer; if ((previousValueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET != valueBufferIndex) { if ((valueEndOffset & VALUE_BUFFER_MASK) != inputValueLength) { return false; } startOffsetInValueBuffer = 0; } else { if (valueEndOffset - previousValueEndOffset != inputValueLength) { return false; } startOffsetInValueBuffer = previousValueEndOffset & VALUE_BUFFER_MASK; } PinotDataBuffer valueBuffer = _valueBuffers.get(valueBufferIndex); if (inputValueLength <= PinotDataBuffer.BULK_BYTES_PROCESSING_THRESHOLD) { for (int i = 0; i < inputValueLength; i++) { if (valueToCompare[i] != valueBuffer.getByte(startOffsetInValueBuffer + i)) { return false; } } return true; } else { byte[] value = new byte[inputValueLength]; valueBuffer.copyTo(startOffsetInValueBuffer, value); for (int i = 0; i < inputValueLength; i++) { if (valueToCompare[i] != value[i]) { return false; } } return true; } } }
OffHeapMutableBytesStore implements Closeable { @SuppressWarnings("Duplicates") public boolean equalsValueAt(int index, byte[] valueToCompare) { assert index < _numValues; int offsetBufferIndex = index >>> OFFSET_BUFFER_SHIFT_OFFSET; PinotDataBuffer offsetBuffer = _offsetBuffers.get(offsetBufferIndex); int offsetIndex = index & OFFSET_BUFFER_MASK; int previousValueEndOffset = offsetBuffer.getInt(offsetIndex << 2); int valueEndOffset = offsetBuffer.getInt((offsetIndex + 1) << 2); int inputValueLength = valueToCompare.length; if (previousValueEndOffset == valueEndOffset) { return inputValueLength == 0; } int valueBufferIndex = (valueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET; int startOffsetInValueBuffer; if ((previousValueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET != valueBufferIndex) { if ((valueEndOffset & VALUE_BUFFER_MASK) != inputValueLength) { return false; } startOffsetInValueBuffer = 0; } else { if (valueEndOffset - previousValueEndOffset != inputValueLength) { return false; } startOffsetInValueBuffer = previousValueEndOffset & VALUE_BUFFER_MASK; } PinotDataBuffer valueBuffer = _valueBuffers.get(valueBufferIndex); if (inputValueLength <= PinotDataBuffer.BULK_BYTES_PROCESSING_THRESHOLD) { for (int i = 0; i < inputValueLength; i++) { if (valueToCompare[i] != valueBuffer.getByte(startOffsetInValueBuffer + i)) { return false; } } return true; } else { byte[] value = new byte[inputValueLength]; valueBuffer.copyTo(startOffsetInValueBuffer, value); for (int i = 0; i < inputValueLength; i++) { if (valueToCompare[i] != value[i]) { return false; } } return true; } } OffHeapMutableBytesStore(PinotDataBufferMemoryManager memoryManager, String allocationContext); }
OffHeapMutableBytesStore implements Closeable { @SuppressWarnings("Duplicates") public boolean equalsValueAt(int index, byte[] valueToCompare) { assert index < _numValues; int offsetBufferIndex = index >>> OFFSET_BUFFER_SHIFT_OFFSET; PinotDataBuffer offsetBuffer = _offsetBuffers.get(offsetBufferIndex); int offsetIndex = index & OFFSET_BUFFER_MASK; int previousValueEndOffset = offsetBuffer.getInt(offsetIndex << 2); int valueEndOffset = offsetBuffer.getInt((offsetIndex + 1) << 2); int inputValueLength = valueToCompare.length; if (previousValueEndOffset == valueEndOffset) { return inputValueLength == 0; } int valueBufferIndex = (valueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET; int startOffsetInValueBuffer; if ((previousValueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET != valueBufferIndex) { if ((valueEndOffset & VALUE_BUFFER_MASK) != inputValueLength) { return false; } startOffsetInValueBuffer = 0; } else { if (valueEndOffset - previousValueEndOffset != inputValueLength) { return false; } startOffsetInValueBuffer = previousValueEndOffset & VALUE_BUFFER_MASK; } PinotDataBuffer valueBuffer = _valueBuffers.get(valueBufferIndex); if (inputValueLength <= PinotDataBuffer.BULK_BYTES_PROCESSING_THRESHOLD) { for (int i = 0; i < inputValueLength; i++) { if (valueToCompare[i] != valueBuffer.getByte(startOffsetInValueBuffer + i)) { return false; } } return true; } else { byte[] value = new byte[inputValueLength]; valueBuffer.copyTo(startOffsetInValueBuffer, value); for (int i = 0; i < inputValueLength; i++) { if (valueToCompare[i] != value[i]) { return false; } } return true; } } OffHeapMutableBytesStore(PinotDataBufferMemoryManager memoryManager, String allocationContext); int add(byte[] value); @SuppressWarnings("Duplicates") byte[] get(int index); @SuppressWarnings("Duplicates") boolean equalsValueAt(int index, byte[] valueToCompare); int getNumValues(); int getTotalBufferSize(); @Override void close(); }
OffHeapMutableBytesStore implements Closeable { @SuppressWarnings("Duplicates") public boolean equalsValueAt(int index, byte[] valueToCompare) { assert index < _numValues; int offsetBufferIndex = index >>> OFFSET_BUFFER_SHIFT_OFFSET; PinotDataBuffer offsetBuffer = _offsetBuffers.get(offsetBufferIndex); int offsetIndex = index & OFFSET_BUFFER_MASK; int previousValueEndOffset = offsetBuffer.getInt(offsetIndex << 2); int valueEndOffset = offsetBuffer.getInt((offsetIndex + 1) << 2); int inputValueLength = valueToCompare.length; if (previousValueEndOffset == valueEndOffset) { return inputValueLength == 0; } int valueBufferIndex = (valueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET; int startOffsetInValueBuffer; if ((previousValueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET != valueBufferIndex) { if ((valueEndOffset & VALUE_BUFFER_MASK) != inputValueLength) { return false; } startOffsetInValueBuffer = 0; } else { if (valueEndOffset - previousValueEndOffset != inputValueLength) { return false; } startOffsetInValueBuffer = previousValueEndOffset & VALUE_BUFFER_MASK; } PinotDataBuffer valueBuffer = _valueBuffers.get(valueBufferIndex); if (inputValueLength <= PinotDataBuffer.BULK_BYTES_PROCESSING_THRESHOLD) { for (int i = 0; i < inputValueLength; i++) { if (valueToCompare[i] != valueBuffer.getByte(startOffsetInValueBuffer + i)) { return false; } } return true; } else { byte[] value = new byte[inputValueLength]; valueBuffer.copyTo(startOffsetInValueBuffer, value); for (int i = 0; i < inputValueLength; i++) { if (valueToCompare[i] != value[i]) { return false; } } return true; } } OffHeapMutableBytesStore(PinotDataBufferMemoryManager memoryManager, String allocationContext); int add(byte[] value); @SuppressWarnings("Duplicates") byte[] get(int index); @SuppressWarnings("Duplicates") boolean equalsValueAt(int index, byte[] valueToCompare); int getNumValues(); int getTotalBufferSize(); @Override void close();  }