Java Code Examples for io.netty.util.internal.PlatformDependent#getByte()

The following examples show how to use io.netty.util.internal.PlatformDependent#getByte() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextInput.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Get next byte from stream.  Do no maintain any line count  Will throw a StreamFinishedPseudoException
 * when the stream has run out of bytes.
 * @return next byte from stream.
 * @throws IOException
 */
public final byte nextCharNoNewLineCheck() throws IOException {

  if (length == -1) {
    throw StreamFinishedPseudoException.INSTANCE;
  }

  if (BoundsChecking.BOUNDS_CHECKING_ENABLED) {
    buffer.checkBytes(bufferPtr - 1, bufferPtr);
  }

  byte byteChar = PlatformDependent.getByte(bStartMinus1 + bufferPtr);

  if (bufferPtr >= length) {
    if (length != -1) {
      updateBuffer();
      bufferPtr--;
    } else {
      throw StreamFinishedPseudoException.INSTANCE;
    }
  }

  bufferPtr++;

  return byteChar;
}
 
Example 2
Source File: ByteFunctionHelpers.java    From Bats with Apache License 2.0 6 votes vote down vote up
private static final int memcmp(final long laddr, int lStart, int lEnd, final byte[] right, int rStart, final int rEnd) {
  int lLen = lEnd - lStart;
  int rLen = rEnd - rStart;
  int n = Math.min(rLen, lLen);
  long lPos = laddr + lStart;
  int rPos = rStart;

  while (n-- != 0) {
    byte leftByte = PlatformDependent.getByte(lPos);
    byte rightByte = right[rPos];
    if (leftByte != rightByte) {
      return ((leftByte & 0xFF) - (rightByte & 0xFF)) > 0 ? 1 : -1;
    }
    lPos++;
    rPos++;
  }

  if (lLen == rLen) {
    return 0;
  }

  return lLen > rLen ? 1 : -1;
}
 
Example 3
Source File: FieldBufferCopier.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private void seekAndCopy(long offsetAddr, int count, int seekTo) {
  final long srcAddr;
  final long dstAddr;
  switch (bufferOrdinal) {
    case NULL_BUFFER_ORDINAL:
      srcAddr = source.getValidityBufferAddress();
      dstAddr = target.getValidityBufferAddress();
      break;
    case VALUE_BUFFER_ORDINAL:
      srcAddr = source.getDataBufferAddress();
      dstAddr = target.getDataBufferAddress();
      break;
    default:
      throw new UnsupportedOperationException("unexpected buffer offset");
  }

  final long maxAddr = offsetAddr + count * STEP_SIZE;
  int targetIndex = seekTo;
  for(; offsetAddr < maxAddr; offsetAddr += STEP_SIZE, targetIndex++){
    final int recordIndex = Short.toUnsignedInt(PlatformDependent.getShort(offsetAddr));
    final int byteValue = PlatformDependent.getByte(srcAddr + (recordIndex >>> 3));
    final int bitVal = ((byteValue >>> (recordIndex & 7)) & 1) << (targetIndex & 7);
    final long addr = dstAddr + (targetIndex >>> 3);
    PlatformDependent.putByte(addr, (byte) (PlatformDependent.getByte(addr) | bitVal));
  }
}
 
Example 4
Source File: MaxAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public void accumulate(final long memoryAddr, final int count) {
  final long maxMemAddr = memoryAddr + count * WIDTH_ORDINAL;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();

  int incomingIndex = 0;
  for(long ordinalAddr = memoryAddr; ordinalAddr < maxMemAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++){
    java.math.BigDecimal newVal = DecimalAccumulatorUtilsNoSpill.getBigDecimal(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
    int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;
    final long maxAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    PlatformDependent.putLong(maxAddr, Double.doubleToLongBits(max(Double.longBitsToDouble(PlatformDependent.getLong(maxAddr)), newVal.doubleValue(), bitVal)));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example 5
Source File: MinAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public void accumulate(final long memoryAddr, final int count) {
  final long maxAddr = memoryAddr + count * 4;
  final long incomingBit = getInput().getValidityBufferAddress();
  final long incomingValue =  getInput().getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;

  int incomingIndex = 0;
  for(long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += 4, incomingIndex++){
    final int newVal = PlatformDependent.getInt(incomingValue + (incomingIndex * WIDTH));
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
    int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;
    final long minAddr = valueAddresses[chunkIndex] + (chunkOffset) * 4;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    PlatformDependent.putInt(minAddr, min(PlatformDependent.getInt(minAddr), newVal, bitVal));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example 6
Source File: FieldBufferCopier6.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(long offsetAddr, int count) {
  if(allocateAsFixed){
    targetAlt.allocateNew(count);
  }
  final long[] srcAddr = this.srcAddrs;
  final long dstAddr;
  switch (bufferOrdinal) {
    case NULL_BUFFER_ORDINAL:
      dstAddr = target.getValidityBufferAddress();
      break;
    case VALUE_BUFFER_ORDINAL:
      dstAddr = target.getDataBufferAddress();
      break;
    default:
      throw new UnsupportedOperationException("unexpected buffer offset");
  }

  final long maxAddr = offsetAddr + count * BUILD_RECORD_LINK_SIZE;
  int targetIndex = 0;
  for(; offsetAddr < maxAddr; offsetAddr += BUILD_RECORD_LINK_SIZE, targetIndex++){
    final int batchIndex = PlatformDependent.getInt(offsetAddr);
    final int batchOffset = Short.toUnsignedInt(PlatformDependent.getShort(offsetAddr + 4));
    final int byteValue = PlatformDependent.getByte(srcAddr[batchIndex] + (batchOffset >>> 3));
    final int bitVal = ((byteValue >>> (batchOffset & 7)) & 1) << (targetIndex & 7);
    final long addr = dstAddr + (targetIndex >>> 3);
    PlatformDependent.putByte(addr, (byte) (PlatformDependent.getByte(addr) | bitVal));
  }
}
 
Example 7
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static int getUnsignedMediumLE(byte[] array, int index) {
    if (UNALIGNED) {
        return (PlatformDependent.getByte(array, index) & 0xff) |
                ((BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes(PlatformDependent.getShort(array, index + 1))
                                          : PlatformDependent.getShort(array, index + 1)) & 0xffff) << 8;
    }
    return PlatformDependent.getByte(array, index) & 0xff |
           (PlatformDependent.getByte(array, index + 1) & 0xff) <<  8 |
           (PlatformDependent.getByte(array, index + 2) & 0xff) << 16;
}
 
Example 8
Source File: QBlockHashTable.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static final boolean memEqual(final long laddr, final long raddr, int len) {
  int n = len;
  long lPos = laddr;
  long rPos = raddr;

  while (n > 7) {
    long leftLong = PlatformDependent.getLong(lPos);
    long rightLong = PlatformDependent.getLong(rPos);
    if (leftLong != rightLong) {
      return false;
    }
    lPos += 8;
    rPos += 8;
    n -= 8;
  }
  while (n > 3) {
    int leftInt = PlatformDependent.getInt(lPos);
    int rightInt = PlatformDependent.getInt(rPos);
    if (leftInt != rightInt) {
      return false;
    }
    lPos += 4;
    rPos += 4;
    n -= 4;
  }
  while (n-- != 0) {
    byte leftByte = PlatformDependent.getByte(lPos);
    byte rightByte = PlatformDependent.getByte(rPos);
    if (leftByte != rightByte) {
      return false;
    }
    lPos++;
    rPos++;
  }
  return true;
}
 
Example 9
Source File: MultiDestCopier.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(long compoundAddr, int srcStart, final int count) {
  copyWatch.start();

  final long[] dstAddrs = this.dstAddrs;

  // skip bytes, but make sure to account for the remaining bits too
  final long srcAddr;
  switch (bufferOrdinal) {
    case NULL_BUFFER_ORDINAL:
      srcAddr = source.getValidityBufferAddress();
      break;
    case VALUE_BUFFER_ORDINAL:
      srcAddr = source.getDataBufferAddress();
      break;
    default:
      throw new UnsupportedOperationException("unexpected buffer offset");
  }

  final long max = compoundAddr + count * OFFSET_SIZE;
  for(; compoundAddr < max; compoundAddr +=OFFSET_SIZE, srcStart++){
    final int compoundIdx = PlatformDependent.getInt(compoundAddr);
    final int batchIdx = compoundIdx >>> 16;
    final int rowIdx = compoundIdx & 65535;

    final int byteValue = PlatformDependent.getByte(srcAddr + (srcStart >>> 3));
    final int bitVal = ((byteValue >>> (srcStart & 7)) & 1) << (rowIdx & 7);
    final long dstAddr = dstAddrs[batchIdx] + (rowIdx >>> 3);
    PlatformDependent.putByte(dstAddr, (byte) (PlatformDependent.getByte(dstAddr) | bitVal));
  }

  copyWatch.stop();
}
 
Example 10
Source File: NdvAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void accumulate(final long memoryAddr, final int count) {
  final long maxAddr = memoryAddr + count * WIDTH_ORDINAL;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final int scale = ((DecimalVector)inputVector).getScale();

  int incomingIndex = 0;
  for (long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++) {
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;

    //incoming record is null, skip it
    if (bitVal == 0) {
      continue;
    }

    java.math.BigDecimal newVal = DecimalAccumulatorUtilsNoSpill.getBigDecimal(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);

    //get the proper chunk from the ordinal
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
    int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;

    final HllAccumHolder ah =  this.accumulators[chunkIndex];
    final HllSketch sketch = ah.getAccums()[chunkOffset];
    sketch.update(newVal.doubleValue());
  }
}
 
Example 11
Source File: PooledUnsafeDirectByteBuf.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
protected int _getUnsignedMedium(int index) {
    long addr = addr(index);
    return (PlatformDependent.getByte(addr) & 0xff) << 16 |
            (PlatformDependent.getByte(addr + 1) & 0xff) << 8 |
            PlatformDependent.getByte(addr + 2) & 0xff;
}
 
Example 12
Source File: SumZeroAccumulators.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long memoryAddr, final int count,
                       final int bitsInChunk, final int chunkOffsetMask) {
  final long maxAddr = memoryAddr + count * PARTITIONINDEX_HTORDINAL_WIDTH;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();
  final int maxValuesPerBatch = super.maxValuesPerBatch;

  for (long partitionAndOrdinalAddr = memoryAddr; partitionAndOrdinalAddr < maxAddr; partitionAndOrdinalAddr += PARTITIONINDEX_HTORDINAL_WIDTH) {
    /* get the hash table ordinal */
    final int tableIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + HTORDINAL_OFFSET);
    /* get the index of data in input vector */
    final int incomingIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + KEYINDEX_OFFSET);
    /* get the corresponding data from input vector -- source data for accumulation */
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    long addressOfInput = incomingValue + (incomingIndex * WIDTH_INPUT);
    long newValLow = PlatformDependent.getLong(addressOfInput) * bitVal;
    long newValHigh =
      PlatformDependent.getLong(addressOfInput + DecimalUtils.LENGTH_OF_LONG) * bitVal;
    /* get the hash table batch index */
    final int chunkIndex = tableIndex >>> bitsInChunk;
    final int chunkOffset = tableIndex & chunkOffsetMask;
    /* get the target address of accumulation vector */
    final long sumAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    /* store the accumulated values at the target location of accumulation vector */
    long curValLow = PlatformDependent.getLong(sumAddr);
    long curValHigh = PlatformDependent.getLong(sumAddr + DecimalUtils.LENGTH_OF_LONG);
    DecimalUtils.addSignedDecimals(sumAddr, newValLow, newValHigh, curValLow, curValHigh);
  }
}
 
Example 13
Source File: FieldBufferCopier4.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(long offsetAddr, int count) {
  if(allocateAsFixed){
    targetAlt.allocateNew(count);
  }
  final long[] srcAddr = this.srcAddrs;
  final long dstAddr;
  switch (bufferOrdinal) {
    case NULL_BUFFER_ORDINAL:
      dstAddr = target.getValidityBufferAddress();
      break;
    case VALUE_BUFFER_ORDINAL:
      dstAddr = target.getDataBufferAddress();
      break;
    default:
      throw new UnsupportedOperationException("unexpected buffer offset");
  }

  final long maxAddr = offsetAddr + count * STEP_SIZE;
  int targetIndex = 0;
  for(; offsetAddr < maxAddr; offsetAddr += STEP_SIZE, targetIndex++){
    final int batchNOFF = PlatformDependent.getInt(offsetAddr);
    final int recordIndex = batchNOFF & MAX_BATCH;
    final int byteValue = PlatformDependent.getByte(srcAddr[batchNOFF >>> BATCH_BITS] + (recordIndex >>> 3));
    final int bitVal = ((byteValue >>> (recordIndex & 7)) & 1) << (targetIndex & 7);
    final long addr = dstAddr + (targetIndex >>> 3);
    PlatformDependent.putByte(addr, (byte) (PlatformDependent.getByte(addr) | bitVal));
  }
}
 
Example 14
Source File: NdvAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void accumulate(final long memoryAddr, final int count) {
  final long maxAddr = memoryAddr + count * 4;
  final long incomingBit = getInput().getValidityBufferAddress();
  final long incomingValue =  getInput().getDataBufferAddress();

  int incomingIndex = 0;
  for(long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += 4, incomingIndex++){
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;

    //incoming record is null, skip it
    if (bitVal == 0) {
      continue;
    }

    final float newVal = Float.intBitsToFloat(PlatformDependent.getInt(incomingValue + (incomingIndex * WIDTH)));

    //get the proper chunk from the ordinal
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
    int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;

    final HllAccumHolder ah =  this.accumulators[chunkIndex];
    final HllSketch sketch = ah.getAccums()[chunkOffset];
    sketch.update(newVal);
  }
}
 
Example 15
Source File: AbstractByteBufPool.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private static int onHeapHashCode(final byte[] bytes, final int offset, final int length) {
   final int intCount = length >>> 1;
   final int byteCount = length & 1;
   int hashCode = 1;
   int arrayIndex = offset;
   for (int i = 0; i < intCount; i++) {
      hashCode = 31 * hashCode + PlatformDependent.getShort(bytes, arrayIndex);
      arrayIndex += 2;
   }
   for (int i = 0; i < byteCount; i++) {
      hashCode = 31 * hashCode + PlatformDependent.getByte(bytes, arrayIndex++);
   }
   return hashCode;
}
 
Example 16
Source File: MinAccumulators.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long memoryAddr, final int count,
                       final int bitsInChunk, final int chunkOffsetMask) {
  final long maxAddr = memoryAddr + count * PARTITIONINDEX_HTORDINAL_WIDTH;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int maxValuesPerBatch = super.maxValuesPerBatch;

  for (long partitionAndOrdinalAddr = memoryAddr; partitionAndOrdinalAddr < maxAddr; partitionAndOrdinalAddr += PARTITIONINDEX_HTORDINAL_WIDTH) {
    /* get the hash table ordinal */
    final int tableIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + HTORDINAL_OFFSET);
    /* get the index of data in input vector */
    final int incomingIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + KEYINDEX_OFFSET);
    /* get the corresponding data from input vector -- source data for accumulation */
    final long newVal = PlatformDependent.getLong(incomingValue + (incomingIndex * WIDTH_INPUT));
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    /* get the hash table batch index */
    final int chunkIndex = tableIndex >>> bitsInChunk;
    final int chunkOffset = tableIndex & chunkOffsetMask;
    /* get the target addresses of accumulation vector */
    final long minAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    /* store the accumulated values(new min or existing) at the target location of accumulation vector */
    PlatformDependent.putLong(minAddr, min(PlatformDependent.getLong(minAddr), newVal, bitVal));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example 17
Source File: ReadOnlyUnsafeDirectByteBuf.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
protected int _getUnsignedMedium(int index) {
    long addr = addr(index);
    return (PlatformDependent.getByte(addr) & 0xff) << 16 |
            (PlatformDependent.getByte(addr + 1) & 0xff) << 8 |
            PlatformDependent.getByte(addr + 2) & 0xff;
}
 
Example 18
Source File: MaxAccumulators.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long memoryAddr, final int count,
                       final int bitsInChunk, final int chunkOffsetMask) {
  final long maxMemAddr = memoryAddr + count * PARTITIONINDEX_HTORDINAL_WIDTH;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int maxValuesPerBatch = super.maxValuesPerBatch;

  for (long partitionAndOrdinalAddr = memoryAddr; partitionAndOrdinalAddr < maxMemAddr; partitionAndOrdinalAddr += PARTITIONINDEX_HTORDINAL_WIDTH) {
    /* get the hash table ordinal */
    final int tableIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + HTORDINAL_OFFSET);
    /* get the index of data in input vector */
    final int incomingIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + KEYINDEX_OFFSET);
    /* get the corresponding data from input vector -- source data for accumulation */
    final float newVal = Float.intBitsToFloat(PlatformDependent.getInt(incomingValue + (incomingIndex * WIDTH_INPUT)));
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    /* get the hash table batch index */
    final int chunkIndex = tableIndex >>> bitsInChunk;
    final int chunkOffset = tableIndex & chunkOffsetMask;
    /* get the target addresses of accumulation vector */
    final long maxAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    /* store the accumulated values(new max or existing) at the target location of accumulation vector */
    PlatformDependent.putInt(maxAddr, Float.floatToRawIntBits(max(Float.intBitsToFloat(PlatformDependent.getInt(maxAddr)), newVal, bitVal)));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example 19
Source File: ByteFunctionHelpers.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static final int memcmp(final long laddr, int lStart, int lEnd, final long raddr, int rStart, final int rEnd) {
  int lLen = lEnd - lStart;
  int rLen = rEnd - rStart;
  int n = Math.min(rLen, lLen);
  long lPos = laddr + lStart;
  long rPos = raddr + rStart;

  while (n > 7) {
    long leftLong = PlatformDependent.getLong(lPos);
    long rightLong = PlatformDependent.getLong(rPos);
    if (leftLong != rightLong) {
      return UnsignedLongs.compare(Long.reverseBytes(leftLong), Long.reverseBytes(rightLong));
    }
    lPos += 8;
    rPos += 8;
    n -= 8;
  }

  while (n-- != 0) {
    byte leftByte = PlatformDependent.getByte(lPos);
    byte rightByte = PlatformDependent.getByte(rPos);
    if (leftByte != rightByte) {
      return ((leftByte & 0xFF) - (rightByte & 0xFF)) > 0 ? 1 : -1;
    }
    lPos++;
    rPos++;
  }

  if (lLen == rLen) {
    return 0;
  }

  return lLen > rLen ? 1 : -1;

}
 
Example 20
Source File: Pivots.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private static void pivotVariableLengths(
    final List<VectorPivotDef> fields,
    final FixedBlockVector targetFixed,
    final VariableBlockVector targetVariable,
    final int count) {
  final int dataWidth = targetFixed.getBlockWidth() - LBlockHashTable.VAR_OFFSET_SIZE;
  final int fieldCount = fields.size();
  final long[] bitAddresses = new long[fieldCount];
  final long[] offsetAddresses = new long[fieldCount];
  final long[] dataAddresses = new long[fieldCount];
  final int[] nullByteOffset = new int[fieldCount];
  final int[] nullBitOffset = new int[fieldCount];
  long targetFixedAddress = targetFixed.getMemoryAddress();

  int i = 0;
  long totalData = 0;
  for(VectorPivotDef vpd : fields){

    nullByteOffset[i] = vpd.getNullByteOffset();
    nullBitOffset[i] = vpd.getNullBitOffset();

    List<ArrowBuf> buffers = vpd.getIncomingVector().getFieldBuffers();
    Preconditions.checkArgument(buffers.size() == 3, "A variable length vector should have three field buffers. %s has %s buffers.", Describer.describe(vpd.getIncomingVector().getField()), buffers.size());

    // convert to bit offsets. Overflows shouldn't exist since no system (yet) has memory of Long.MAX_VALUE / 8
    bitAddresses[i] = buffers.get(0).memoryAddress() * 8;

    offsetAddresses[i] = buffers.get(1).memoryAddress();

    ArrowBuf dataBuf = buffers.get(2);
    totalData += dataBuf.writerIndex();
    dataAddresses[i] = dataBuf.memoryAddress();
    i++;
  }

  Preconditions.checkArgument(totalData < Integer.MAX_VALUE);
  targetVariable.ensureAvailableDataSpace(((int) totalData) + 4 * fields.size() * count + (LBlockHashTable.VAR_LENGTH_SIZE * count));

  final int blockWidth = targetFixed.getBlockWidth();


  long varOffsetAddress = targetFixedAddress + dataWidth;
  long startingVariableAddr = targetVariable.getMemoryAddress();
  long targetVariableAddr = targetVariable.getMemoryAddress();

  for(int record = 0; record < count; record++){

    int varLen = 0;

    // write the starting position of the variable width data.
    PlatformDependent.putInt(varOffsetAddress, (int) (targetVariableAddr - startingVariableAddr));
    final long varLenAddress = targetVariableAddr;
    targetVariableAddr += LBlockHashTable.VAR_LENGTH_SIZE; // we'll write length last.

    for(int field = 0; field < fieldCount; field++){

      final long offsetAddress = offsetAddresses[field];
      final long startAndEnd = PlatformDependent.getLong(offsetAddress);
      final int firstOffset = (int) startAndEnd;
      final int secondOffset = (int) (startAndEnd >> 32);
      final long len = secondOffset - firstOffset;

      // update bit address.
      final long bitAddress = bitAddresses[field];
      final int bitVal = (PlatformDependent.getByte(bitAddress >>> 3) >>> (bitAddress & 7)) & 1;
      long targetNullByteAddress = targetFixedAddress + nullByteOffset[field];
      PlatformDependent.putInt(targetNullByteAddress, PlatformDependent.getInt(targetNullByteAddress) | (bitVal << nullBitOffset[field]));

      // update length.
      final int copyLength = (int) (bitVal * len);
      PlatformDependent.putInt(targetVariableAddr, copyLength);
      targetVariableAddr += 4;
      varLen += 4;

      // copy data
      final long dataAddress = dataAddresses[field];
      final long srcDataStart = dataAddress + firstOffset;
      Copier.copy(srcDataStart, targetVariableAddr, copyLength);

      // update pointers.
      targetVariableAddr += copyLength;
      varLen += copyLength;
      offsetAddresses[field] += 4;
      bitAddresses[field]++;
    }

    // set total varlen in fixed block.
    PlatformDependent.putInt(varLenAddress, varLen);
    varOffsetAddress += blockWidth;
    targetFixedAddress += blockWidth;
  }
}