@Test public void testGet() 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(Arrays.equals(offHeapMutableBytesStore.get(index), _values[index])); } } }
@SuppressWarnings("Duplicates") public byte[] get(int index) { 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); if (previousValueEndOffset == valueEndOffset) { return EMPTY_BYTES; } int valueBufferIndex = (valueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET; int startOffsetInValueBuffer; int valueLength; if ((previousValueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET != valueBufferIndex) { startOffsetInValueBuffer = 0; valueLength = valueEndOffset & VALUE_BUFFER_MASK; } else { startOffsetInValueBuffer = previousValueEndOffset & VALUE_BUFFER_MASK; valueLength = valueEndOffset - previousValueEndOffset; } byte[] value = new byte[valueLength]; _valueBuffers.get(valueBufferIndex).copyTo(startOffsetInValueBuffer, value); return value; }
OffHeapMutableBytesStore implements Closeable { @SuppressWarnings("Duplicates") public byte[] get(int index) { 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); if (previousValueEndOffset == valueEndOffset) { return EMPTY_BYTES; } int valueBufferIndex = (valueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET; int startOffsetInValueBuffer; int valueLength; if ((previousValueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET != valueBufferIndex) { startOffsetInValueBuffer = 0; valueLength = valueEndOffset & VALUE_BUFFER_MASK; } else { startOffsetInValueBuffer = previousValueEndOffset & VALUE_BUFFER_MASK; valueLength = valueEndOffset - previousValueEndOffset; } byte[] value = new byte[valueLength]; _valueBuffers.get(valueBufferIndex).copyTo(startOffsetInValueBuffer, value); return value; } }
OffHeapMutableBytesStore implements Closeable { @SuppressWarnings("Duplicates") public byte[] get(int index) { 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); if (previousValueEndOffset == valueEndOffset) { return EMPTY_BYTES; } int valueBufferIndex = (valueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET; int startOffsetInValueBuffer; int valueLength; if ((previousValueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET != valueBufferIndex) { startOffsetInValueBuffer = 0; valueLength = valueEndOffset & VALUE_BUFFER_MASK; } else { startOffsetInValueBuffer = previousValueEndOffset & VALUE_BUFFER_MASK; valueLength = valueEndOffset - previousValueEndOffset; } byte[] value = new byte[valueLength]; _valueBuffers.get(valueBufferIndex).copyTo(startOffsetInValueBuffer, value); return value; } OffHeapMutableBytesStore(PinotDataBufferMemoryManager memoryManager, String allocationContext); }
OffHeapMutableBytesStore implements Closeable { @SuppressWarnings("Duplicates") public byte[] get(int index) { 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); if (previousValueEndOffset == valueEndOffset) { return EMPTY_BYTES; } int valueBufferIndex = (valueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET; int startOffsetInValueBuffer; int valueLength; if ((previousValueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET != valueBufferIndex) { startOffsetInValueBuffer = 0; valueLength = valueEndOffset & VALUE_BUFFER_MASK; } else { startOffsetInValueBuffer = previousValueEndOffset & VALUE_BUFFER_MASK; valueLength = valueEndOffset - previousValueEndOffset; } byte[] value = new byte[valueLength]; _valueBuffers.get(valueBufferIndex).copyTo(startOffsetInValueBuffer, value); return value; } 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 byte[] get(int index) { 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); if (previousValueEndOffset == valueEndOffset) { return EMPTY_BYTES; } int valueBufferIndex = (valueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET; int startOffsetInValueBuffer; int valueLength; if ((previousValueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET != valueBufferIndex) { startOffsetInValueBuffer = 0; valueLength = valueEndOffset & VALUE_BUFFER_MASK; } else { startOffsetInValueBuffer = previousValueEndOffset & VALUE_BUFFER_MASK; valueLength = valueEndOffset - previousValueEndOffset; } byte[] value = new byte[valueLength]; _valueBuffers.get(valueBufferIndex).copyTo(startOffsetInValueBuffer, value); return value; } 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();  }