@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;
    }

    // Check value length first
    int valueBufferIndex = (valueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET;
    int startOffsetInValueBuffer;
    if ((previousValueEndOffset - 1) >>> VALUE_BUFFER_SHIFT_OFFSET != valueBufferIndex) {
      // The first value in the value buffer
      if ((valueEndOffset & VALUE_BUFFER_MASK) != inputValueLength) {
        return false;
      }
      startOffsetInValueBuffer = 0;
    } else {
      // Not the first value in the value buffer
      if (valueEndOffset - previousValueEndOffset != inputValueLength) {
        return false;
      }
      startOffsetInValueBuffer = previousValueEndOffset & VALUE_BUFFER_MASK;
    }

    // Value length matches, check value
    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;
    }
  }
@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]));
        }
      }
    }
  }