io.netty.util.internal.PlatformDependent#putShort ( )源码实例Demo

下面列出了io.netty.util.internal.PlatformDependent#putShort ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bats   文件: DrillBuf.java
@Override
public ByteBuf writeShort(int value) {
  BoundsChecking.ensureWritable(this, 2);
  PlatformDependent.putShort(addr(writerIndex), (short) value);
  writerIndex += 2;
  return this;
}
 
源代码2 项目: Bats   文件: DrillBuf.java
@Override
public ByteBuf writeChar(int value) {
  BoundsChecking.ensureWritable(this, 2);
  PlatformDependent.putShort(addr(writerIndex), (short) value);
  writerIndex += 2;
  return this;
}
 
源代码3 项目: dremio-oss   文件: TestCopierRoundTrip.java
@Test
public void bigintRoundtrip(){
  final int count = 1024;
  try(
      BigIntVector in = new BigIntVector("in", allocator);
      BigIntVector out = new BigIntVector("out", allocator);
      ){

    in.allocateNew(count);

    for(int i = 0; i < count; i++){
      if(i % 5 == 0){
        in.setSafe(i, i);
      }
    }
    in.setValueCount(count);

    List<FieldBufferCopier> copiers = FieldBufferCopier.getCopiers(ImmutableList.<FieldVector>of(in), ImmutableList.<FieldVector>of(out));
    try(
        final SelectionVector2 sv2 = new SelectionVector2(allocator);
        ){

      sv2.allocateNew(count);
      // create full sv2.
      int x = 0;
      for(long mem = sv2.memoryAddress(); mem < sv2.memoryAddress() + count * 2; mem+=2){
        PlatformDependent.putShort(mem, (short) (char) x);
        x++;
      }
      sv2.setRecordCount(count);
      copy(copiers, sv2);

      out.setValueCount(count);
      for(int i =0; i < count; i++){
        assertEquals(in.getObject(i), out.getObject(i));
      }
    }
  }
}
 
源代码4 项目: netty-4.1.22   文件: UnsafeByteBufUtil.java
static void setShort(long address, int value) {
    if (UNALIGNED) {
        PlatformDependent.putShort(
                address, BIG_ENDIAN_NATIVE_ORDER ? (short) value : Short.reverseBytes((short) value));
    } else {
        PlatformDependent.putByte(address, (byte) (value >>> 8));
        PlatformDependent.putByte(address + 1, (byte) value);
    }
}
 
源代码5 项目: netty-4.1.22   文件: UnsafeByteBufUtil.java
static void setMedium(long address, int value) {
    PlatformDependent.putByte(address, (byte) (value >>> 16));
    if (UNALIGNED) {
        PlatformDependent.putShort(address + 1, BIG_ENDIAN_NATIVE_ORDER ? (short) value
                                                                        : Short.reverseBytes((short) value));
    } else {
        PlatformDependent.putByte(address + 1, (byte) (value >>> 8));
        PlatformDependent.putByte(address + 2, (byte) value);
    }
}
 
源代码6 项目: netty-4.1.22   文件: UnsafeByteBufUtil.java
static void setMediumLE(long address, int value) {
    PlatformDependent.putByte(address, (byte) value);
    if (UNALIGNED) {
        PlatformDependent.putShort(address + 1, BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes((short) (value >>> 8))
                                                                        : (short) (value >>> 8));
    } else {
        PlatformDependent.putByte(address + 1, (byte) (value >>> 8));
        PlatformDependent.putByte(address + 2, (byte) (value >>> 16));
    }
}
 
源代码7 项目: netty-4.1.22   文件: UnsafeByteBufUtil.java
static void setShort(byte[] array, int index, int value) {
    if (UNALIGNED) {
        PlatformDependent.putShort(array, index,
                                   BIG_ENDIAN_NATIVE_ORDER ? (short) value : Short.reverseBytes((short) value));
    } else {
        PlatformDependent.putByte(array, index, (byte) (value >>> 8));
        PlatformDependent.putByte(array, index + 1, (byte) value);
    }
}
 
源代码8 项目: netty-4.1.22   文件: UnsafeByteBufUtil.java
static void setShortLE(byte[] array, int index, int value) {
    if (UNALIGNED) {
        PlatformDependent.putShort(array, index,
                                   BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes((short) value) : (short) value);
    } else {
        PlatformDependent.putByte(array, index, (byte) value);
        PlatformDependent.putByte(array, index + 1, (byte) (value >>> 8));
    }
}
 
源代码9 项目: tajo   文件: CompactRowBlockWriter.java
@Override
public void endRow() {
  long rowHeaderPos = recordStartAddr();
  // curOffset is equivalent to a byte length of this row.
  PlatformDependent.putInt(rowHeaderPos, curOffset);
  rowHeaderPos += SizeOf.SIZE_OF_INT;

  //set null flags
  byte [] flags = nullFlags.toArray();
  PlatformDependent.putShort(rowHeaderPos, (short) flags.length);
  rowHeaderPos += SizeOf.SIZE_OF_SHORT;
  PlatformDependent.copyMemory(flags, 0, rowHeaderPos, flags.length);

  rowBlock.setRows(rowBlock.rows() + 1);
}
 
源代码10 项目: netty-4.1.22   文件: UnsafeByteBufUtil.java
static void setMediumLE(byte[] array, int index, int value) {
    PlatformDependent.putByte(array, index, (byte) value);
    if (UNALIGNED) {
        PlatformDependent.putShort(array, index + 1,
                                   BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes((short) (value >>> 8))
                                                           : (short) (value >>> 8));
    } else {
        PlatformDependent.putByte(array, index + 1, (byte) (value >>> 8));
        PlatformDependent.putByte(array, index + 2, (byte) (value >>> 16));
    }
}
 
源代码11 项目: dremio-oss   文件: TestCopierRoundTrip.java
@Test
public void bigintAppend(){
  final int count = 1024;
  try(
    BigIntVector in = new BigIntVector("in", allocator);
    BigIntVector out = new BigIntVector("out", allocator);
  ){

    in.allocateNew(count);

    for(int i = 0; i < count; i++){
      if(i % 5 == 0){
        in.setSafe(i, i);
      }
    }
    in.setValueCount(count);

    List<FieldBufferCopier> copiers = FieldBufferCopier.getCopiers(ImmutableList.<FieldVector>of(in), ImmutableList.<FieldVector>of(out));
    try(
      final SelectionVector2 sv2 = new SelectionVector2(allocator);
    ){

      sv2.allocateNew(count / 2);
      // set alternate elements.
      int x = 0;
      for(long mem = sv2.memoryAddress(); mem < sv2.memoryAddress() + count; mem+=2){
        PlatformDependent.putShort(mem, (short) (char) x);
        x += 2;
      }
      sv2.setRecordCount(count/2);
      append(copiers, sv2);

      out.setValueCount(count / 2);
      for(int i =0; i < count / 2; i++){
        assertEquals(in.getObject(i * 2), out.getObject(i));
      }
    }
  }
}
 
源代码12 项目: dremio-oss   文件: TestCopierRoundTrip.java
@Test
public void intAppend(){
  final int count = 1024;
  try(
    IntVector in = new IntVector("in", allocator);
    IntVector out = new IntVector("out", allocator);
  ){

    in.allocateNew(count);
    for(int i = 0; i < count; i++){
      if(i % 5 == 0){
        in.setSafe(i, i);
      }
    }
    in.setValueCount(count);

    List<FieldBufferCopier> copiers = FieldBufferCopier.getCopiers(ImmutableList.<FieldVector>of(in), ImmutableList.<FieldVector>of(out));
    try(
      final SelectionVector2 sv2 = new SelectionVector2(allocator);
    ){

      sv2.allocateNew(count / 2);
      // set alternate elements.
      int x = 0;
      for(long mem = sv2.memoryAddress(); mem < sv2.memoryAddress() + count; mem+=2){
        PlatformDependent.putShort(mem, (short) (char) x);
        x += 2;
      }
      sv2.setRecordCount(count/2);

      append(copiers, sv2);

      out.setValueCount(count / 2);
      for(int i =0; i < count / 2; i++){
        assertEquals(in.getObject(i * 2), out.getObject(i));
      }
    }
  }
}
 
源代码13 项目: Bats   文件: DrillBuf.java
@Override
public ByteBuf setShort(int index, int value) {
  chk(index, 2);
  PlatformDependent.putShort(addr(index), (short) value);
  return this;
}
 
源代码14 项目: Bats   文件: DrillBuf.java
@Override
public ByteBuf setChar(int index, int value) {
  chk(index, 2);
  PlatformDependent.putShort(addr(index), (short) value);
  return this;
}
 
源代码15 项目: Bats   文件: UnsafeDirectLittleEndian.java
private void _setShort(int index, int value) {
  PlatformDependent.putShort(addr(index), (short) value);
}
 
源代码16 项目: netty-4.1.22   文件: UnsafeDirectSwappedByteBuf.java
@Override
protected void _setShort(AbstractByteBuf wrapped, int index, short value) {
    PlatformDependent.putShort(addr(wrapped, index), value);
}
 
源代码17 项目: netty-4.1.22   文件: UnsafeHeapSwappedByteBuf.java
@Override
protected void _setShort(AbstractByteBuf wrapped, int index, short value) {
    PlatformDependent.putShort(wrapped.array(), idx(wrapped, index), value);
}
 
源代码18 项目: dremio-oss   文件: TestCopierRoundTrip.java
@Test
public void varcharRoundtrip(){
  final int count = 1024;
  try(
      VarCharVector in = new VarCharVector("in", allocator);
      VarCharVector out = new VarCharVector("out", allocator);
      ){

    in.allocateNew(count * 8, count);

    for(int i = 0; i < count; i++){
      if(i % 5 == 0){
        byte[] data = ("hello-" + i).getBytes(Charsets.UTF_8);
        in.setSafe(i, data, 0, data.length);
      }
    }
    in.setValueCount(count);

    List<FieldBufferCopier> copiers = FieldBufferCopier.getCopiers(ImmutableList.<FieldVector>of(in), ImmutableList.<FieldVector>of(out));
    try(
        final SelectionVector2 sv2 = new SelectionVector2(allocator);
        ){

      sv2.allocateNew(count);
      // create full sv2.
      int x = 0;
      for(long mem = sv2.memoryAddress(); mem < sv2.memoryAddress() + count * 2; mem+=2){
        PlatformDependent.putShort(mem, (short) (char) x);
        x++;
      }

      sv2.setRecordCount(count);
      copy(copiers, sv2);

      out.setValueCount(count);
      for(int i =0; i < count; i++){
        assertEquals(in.getObject(i), out.getObject(i));
      }
    }
  }
}
 
源代码19 项目: dremio-oss   文件: VectorizedHashJoinOperator.java
private void setLinks(long indexAddr, final int buildBatch, final int records){
  for(int incomingRecordIndex = 0; incomingRecordIndex < records; incomingRecordIndex++, indexAddr+=4){

    final int hashTableIndex = PlatformDependent.getInt(indexAddr);

    if(hashTableIndex == -1){
      continue;
    }

    if (hashTableIndex > maxHashTableIndex) {
      maxHashTableIndex = hashTableIndex;
    }
    /* Use the global index returned by the hash table, to store
     * the current record index and batch index. This will be used
     * later when we probe and find a match.
     */


    /* set the current record batch index and the index
     * within the batch at the specified keyIndex. The keyIndex
     * denotes the global index where the key for this record is
     * stored in the hash table
     */
    int hashTableBatch  = hashTableIndex >>> 16;
    int hashTableOffset = hashTableIndex & BATCH_MASK;

    ArrowBuf startIndex;
    try {
      startIndex = startIndices.get(hashTableBatch);
    } catch (IndexOutOfBoundsException e){
      UserException.Builder b = UserException.functionError()
        .message("Index out of bounds in VectorizedHashJoin. Index = %d, size = %d", hashTableBatch, startIndices.size())
        .addContext("incomingRecordIndex=%d, hashTableIndex=%d", incomingRecordIndex, hashTableIndex);
      if (debugInsertion) {
        b.addContext(table.traceReport());
      }
      throw b.build(logger);
    }
    final long startIndexMemStart = startIndex.memoryAddress() + hashTableOffset * HashTable.BUILD_RECORD_LINK_SIZE;

    // If head of the list is empty, insert current index at this position
    final int linkBatch = PlatformDependent.getInt(startIndexMemStart);
    if (linkBatch == INDEX_EMPTY) {
      PlatformDependent.putInt(startIndexMemStart, buildBatch);
      PlatformDependent.putShort(startIndexMemStart + 4, (short) incomingRecordIndex);
    } else {
      /* Head of this list is not empty, if the first link
       * is empty insert there
       */
      hashTableBatch = linkBatch;
      hashTableOffset = Short.toUnsignedInt(PlatformDependent.getShort(startIndexMemStart + 4));

      final ArrowBuf firstLink = buildInfoList.get(hashTableBatch).getLinks();
      final long firstLinkMemStart = firstLink.memoryAddress() + hashTableOffset * HashTable.BUILD_RECORD_LINK_SIZE;

      final int firstLinkBatch = PlatformDependent.getInt(firstLinkMemStart);

      if (firstLinkBatch == INDEX_EMPTY) {
        PlatformDependent.putInt(firstLinkMemStart, buildBatch);
        PlatformDependent.putShort(firstLinkMemStart + 4, (short) incomingRecordIndex);
      } else {
        /* Insert the current value as the first link and
         * make the current first link as its next
         */
        final int firstLinkOffset = Short.toUnsignedInt(PlatformDependent.getShort(firstLinkMemStart + 4));

        final ArrowBuf nextLink = buildInfoList.get(buildBatch).getLinks();
        final long nextLinkMemStart = nextLink.memoryAddress() + incomingRecordIndex * HashTable.BUILD_RECORD_LINK_SIZE;

        PlatformDependent.putInt(nextLinkMemStart, firstLinkBatch);
        PlatformDependent.putShort(nextLinkMemStart + 4, (short) firstLinkOffset);

        // As the existing (batch, offset) pair is moved out of firstLink into nextLink,
        // now put the new (batch, offset) in the firstLink
        PlatformDependent.putInt(firstLinkMemStart, buildBatch);
        PlatformDependent.putShort(firstLinkMemStart + 4, (short) incomingRecordIndex);
      }
    }
  }
}
 
源代码20 项目: Bats   文件: DrillBuf.java
/**
 * Copy a short value to the dest+destIndex
 *
 * @param dest destination byte array
 * @param destIndex destination index
 * @param value a short value
 */
public static void putShort(byte[] dest, int destIndex, short value) {
  check(destIndex, SHORT_NUM_BYTES, dest.length);
  PlatformDependent.putShort(dest, destIndex, value);
}