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

The following examples show how to use io.netty.util.internal.PlatformDependent#getLong() . 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: 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 * 4;
  final long incomaxgBit = getInput().getValidityBufferAddress();
  final long incomaxgValue =  getInput().getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;

  int incomaxgIndex = 0;
  for(long ordinalAddr = memoryAddr; ordinalAddr < maxMemAddr; ordinalAddr += 4, incomaxgIndex++){

    final long newVal = PlatformDependent.getLong(incomaxgValue + (incomaxgIndex * WIDTH));
    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) * 8;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitVal = (PlatformDependent.getByte(incomaxgBit + ((incomaxgIndex >>> 3))) >>> (incomaxgIndex & 7)) & 1;
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    PlatformDependent.putLong(maxAddr, max(PlatformDependent.getLong(maxAddr), newVal, bitVal));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example 2
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 3
Source File: SumZeroAccumulatorsNoSpill.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 long maxAddr = memoryAddr + count * 4;
  final long incomingBit = getInput().getValidityBufferAddress();
  final long incomingValue =  getInput().getDataBufferAddress();
  final long[] valueAddresses = this.valueAddresses;

  int incomingIndex = 0;
  for(long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += 4, incomingIndex++){
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    final long newVal = PlatformDependent.getLong(incomingValue + (incomingIndex * WIDTH)) * bitVal;
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    final long sumAddr = valueAddresses[tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK] + (tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK) * 8;
    PlatformDependent.putLong(sumAddr, PlatformDependent.getLong(sumAddr) + newVal);
  }
}
 
Example 4
Source File: MinAccumulatorsNoSpill.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 long maxAddr = 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;

  int incomingIndex = 0;
  for(long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++){
    final long newVal = PlatformDependent.getLong(incomingValue + (incomingIndex * WIDTH_INPUT));
    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) * 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);
    // first 4 bytes are the number of days (in little endian, that's the bottom 32 bits)
    // second 4 bytes are the number of milliseconds (in little endian, that's the top 32 bits)
    final int newDays = (int) newVal;
    final int newMillis = (int)(newVal >>> 32);
    // To compare the pairs of day/milli, we swap them, with days getting the most significant bits
    // The incoming value is updated to either be MAX (if incoming is null), or keep as is (if the value is not null)
    final long newSwappedVal = ((((long)newDays) << 32) | newMillis) * bitVal + Long.MAX_VALUE * (bitVal ^ 1);
    final long minVal = PlatformDependent.getLong(minAddr);
    final int minDays = (int) minVal;
    final int minMillis = (int)(minVal >>> 32);
    final long minSwappedVal = (((long)minDays) << 32) | minMillis;
    PlatformDependent.putLong(minAddr, (minSwappedVal < newSwappedVal) ? minVal : newVal);
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example 5
Source File: Unpivots.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static void unpivotBytes8(final long srcFixedAddr, final int blockWidth,
    final long target, final int byteOffset, final int start, final int count) {
  final long startAddr = srcFixedAddr + (start * blockWidth);
  long maxAddr = startAddr + (count * blockWidth);
  long targetAddr = target;

  for(long srcAddr = startAddr; srcAddr < maxAddr; srcAddr += blockWidth, targetAddr+=8){
    final long value = PlatformDependent.getLong(srcAddr + byteOffset);
    PlatformDependent.putLong(targetAddr, value);
  }
}
 
Example 6
Source File: UnSafeTuple.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public IntervalDatum getInterval(int fieldId) {
  long pos = getFieldAddr(fieldId);
  int months = PlatformDependent.getInt(pos);
  pos += SizeOf.SIZE_OF_INT;
  long millisecs = PlatformDependent.getLong(pos);
  return new IntervalDatum(months, millisecs);
}
 
Example 7
Source File: HashComputation.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Used for hash computation by EightByteInnerLeftProbeOff in Vectorized Hash Join
 * @param hashValueAddress starting address of the buffer that stores the hashvalues.
 * @param srcDataAddr starting address of the source data (keys).
 * @param count number of records
 */
public static final void computeHash(long hashValueAddress, long srcDataAddr, final int count) {
  final long maxDataAddr = srcDataAddr + (count * EIGHT_BYTES);
  for (long keyAddr = srcDataAddr; keyAddr < maxDataAddr; keyAddr += EIGHT_BYTES, hashValueAddress += EIGHT_BYTES) {
    final long key = PlatformDependent.getLong(keyAddr);
    final long keyHash = computeHash(key);
    PlatformDependent.putLong(hashValueAddress, keyHash);
  }
}
 
Example 8
Source File: ByteFunctionHelpers.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static final int memEqual(final long laddr, int lStart, int lEnd, final long raddr, int rStart,
    final int rEnd) {

  int n = lEnd - lStart;
  if (n == rEnd - rStart) {
    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 0;
      }
      lPos += 8;
      rPos += 8;
      n -= 8;
    }
    while (n-- != 0) {
      byte leftByte = PlatformDependent.getByte(lPos);
      byte rightByte = PlatformDependent.getByte(rPos);
      if (leftByte != rightByte) {
        return 0;
      }
      lPos++;
      rPos++;
    }
    return 1;
  } else {
    return 0;
  }
}
 
Example 9
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 long newVal = PlatformDependent.getLong(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 10
Source File: LBlockHashTableEight.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private final void rehash(int newCapacity) {
  final long free = this.freeValue;
  // grab old references.

  final long[] oldFixedAddrs = this.tableFixedAddresses;

  final int oldNullKeyOrdinal = nullKeyOrdinal;
  if (oldNullKeyOrdinal != NO_MATCH) {
    removeNull();
  }

  try(RollbackCloseable closer = new RollbackCloseable()){ // Close old control blocks when done rehashing.
    for(FixedBlockVector cb : this.fixedBlocks){
      closer.add(cb);
    }

    internalInit(newCapacity);
    final int capacityMask = this.capacityMask;
    final long[] newFixedAddrs = this.tableFixedAddresses;

    for(int batch = 0; batch < oldFixedAddrs.length; batch++){
      long addr = oldFixedAddrs[batch];
      final long max = addr + (MAX_VALUES_PER_BATCH * BLOCK_WIDTH);
      for(long oldFixedAddr = addr; oldFixedAddr < max; oldFixedAddr += BLOCK_WIDTH){
        long key = PlatformDependent.getLong(oldFixedAddr);

        if(key != free){
          int newIndex = hash(key) & capacityMask; // get previously computed hash and slice it.
          long newFixedAddr = newFixedAddrs[newIndex >>> BITS_IN_CHUNK] + ((newIndex & CHUNK_OFFSET_MASK) * BLOCK_WIDTH);

          if (PlatformDependent.getLong(newFixedAddr) != free) {
            while (true) {
              newIndex = (newIndex - 1) & capacityMask;
              newFixedAddr = newFixedAddrs[newIndex >>> BITS_IN_CHUNK] + ((newIndex & CHUNK_OFFSET_MASK) * BLOCK_WIDTH);
              if (PlatformDependent.getLong(newFixedAddr) == free) {
                break;
              }
            }
          }

          final int ordinalValue = PlatformDependent.getInt(oldFixedAddr + KEY_WIDTH);
          PlatformDependent.putLong(newFixedAddr, key);
          PlatformDependent.putInt(newFixedAddr + KEY_WIDTH, ordinalValue);

        }
      }
    }

  } catch (Exception e) {
    throw Throwables.propagate(e);
  }

  if (oldNullKeyOrdinal != NO_MATCH) {
    insertNull(oldNullKeyOrdinal);
  }
}
 
Example 11
Source File: DecimalMixedEndianComparator.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
default long getLongValueLow(ArrowBuf buf, int index) {
  long startingAddress = buf.memoryAddress() + index;
  return PlatformDependent.getLong(startingAddress);
}
 
Example 12
Source File: LBlockHashTableNoSpill.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private final void rehash(int newCapacity) {
  // grab old references.
  final ControlBlock[] oldControlBlocks = this.controlBlocks;
  final long[] oldControlAddrs = this.tableControlAddresses;

  try(RollbackCloseable closer = new RollbackCloseable()){ // Close old control blocks when done rehashing.
    for(ControlBlock cb : oldControlBlocks){
      closer.add(cb);
    }


    internalInit(newCapacity);

    final int capacityMask = this.capacityMask;
    final long[] controlAddrs = this.tableControlAddresses;

    // loop through backwards.

    for(int batch =0; batch < oldControlAddrs.length; batch++){
      long addr = oldControlAddrs[batch];
      final long max = addr + MAX_VALUES_PER_BATCH * CONTROL_WIDTH;
      for(long oldControlAddr = addr; oldControlAddr < max; oldControlAddr += CONTROL_WIDTH){
        long oldControl = PlatformDependent.getLong(oldControlAddr);

        if(oldControl != LFREE){
          int index = ((int) (oldControl >>> 32)) & capacityMask; // get previously computed hash and slice it.
          int newChunkIndex = index >>> BITS_IN_CHUNK;
          long controlAddr = controlAddrs[newChunkIndex] + ((index & CHUNK_OFFSET_MASK) * CONTROL_WIDTH);

          if (PlatformDependent.getInt(controlAddr) != FREE) {
            while (true) {
              index = (index - 1) & capacityMask;
              newChunkIndex = index >>> BITS_IN_CHUNK;
              controlAddr = controlAddrs[newChunkIndex] + ((index & CHUNK_OFFSET_MASK) * CONTROL_WIDTH);
              if (PlatformDependent.getInt(controlAddr) == FREE) {
                break;
              }
            }
          }
          PlatformDependent.putLong(controlAddr, oldControl);
        }
      }
    }


  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
 
Example 13
Source File: PooledUnsafeDirectByteBuf.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected long _getLong(int index) {
    long v = PlatformDependent.getLong(addr(index));
    return NATIVE_ORDER? v : Long.reverseBytes(v);
}
 
Example 14
Source File: LBlockHashTable.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private final void rehash(int newCapacity) {
  // grab old references.
  final ControlBlock[] oldControlBlocks = this.controlBlocks;
  final long[] oldControlAddrs = this.tableControlAddresses;

  try {
    /* this is the only step that allocates memory during rehash, if the method fails the state is unchanged */
    internalInit(newCapacity);

    final long[] controlAddrs = this.tableControlAddresses;

    // loop through backwards.

    final int capacity = this.capacity;
    for(int batch =0; batch < oldControlAddrs.length; batch++){
      long addr = oldControlAddrs[batch];
      final long max = addr + MAX_VALUES_PER_BATCH * CONTROL_WIDTH;
      for(long oldControlAddr = addr; oldControlAddr < max; oldControlAddr += CONTROL_WIDTH){
        long oldControl = PlatformDependent.getLong(oldControlAddr);

        if(oldControl != LFREE){
          int index = ((int) (oldControl >>> 32)) & (capacity - 1); // get previously computed hash and slice it.
          int newChunkIndex = index >>> BITS_IN_CHUNK;
          int offetInChunk = index & CHUNK_OFFSET_MASK;
          long controlAddr = controlAddrs[newChunkIndex] + (offetInChunk * CONTROL_WIDTH);
          if (PlatformDependent.getInt(controlAddr) != FREE) {
            while (true) {
              index = (index - 1) & (capacity - 1);
              newChunkIndex = index >>> BITS_IN_CHUNK;
              offetInChunk = index & CHUNK_OFFSET_MASK;
              controlAddr = controlAddrs[newChunkIndex] + (offetInChunk * CONTROL_WIDTH);
              if (PlatformDependent.getInt(controlAddr) == FREE) {
                break;
              }
            }
          }
          PlatformDependent.putLong(controlAddr, oldControl);
        }
      }
    }

    // Release existing control blocks only after rehashing is successful.
    AutoCloseables.close(asList(oldControlBlocks));
  } catch (Exception e) {
    logger.debug("ERROR: failed to rehash, exception: ", e);
    /* VectorizedHashAggOperator inserts data into hashtable  and will handle (if OOM) this exception */
    throw Throwables.propagate(e);
  }
}
 
Example 15
Source File: UnsafeHeapSwappedByteBuf.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
protected long _getLong(AbstractByteBuf wrapped, int index) {
    return PlatformDependent.getLong(wrapped.array(), idx(wrapped, index));
}
 
Example 16
Source File: ReadOnlyUnsafeDirectByteBuf.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected long _getLong(int index) {
    long v = PlatformDependent.getLong(addr(index));
    return NATIVE_ORDER? v : Long.reverseBytes(v);
}
 
Example 17
Source File: UnsafeDirectLittleEndian.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override
public long getLong(int index) {
  //wrapped.checkIndex(index, 8);
  return PlatformDependent.getLong(addr(index));
}
 
Example 18
Source File: MinAccumulators.java    From dremio-oss with Apache License 2.0 4 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 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);
    // first 4 bytes are the number of days (in little endian, that's the bottom 32 bits)
    // second 4 bytes are the number of milliseconds (in little endian, that's the top 32 bits)
    final int newDays = (int) newVal;
    final int newMillis = (int)(newVal >>> 32);
    // To compare the pairs of day/milli, we swap them, with days getting the most significant bits
    // The incoming value is updated to either be MAX (if incoming is null), or keep as is (if the value is not null)
    final long newSwappedVal = ((((long)newDays) << 32) | newMillis) * bitVal + Long.MAX_VALUE * (bitVal ^ 1);
    final long minVal = PlatformDependent.getLong(minAddr);
    final int minDays = (int) minVal;
    final int minMillis = (int)(minVal >>> 32);
    final long minSwappedVal = (((long)minDays) << 32) | minMillis;
    /* store the accumulated values(new min or existing) at the target location of accumulation vector */
    PlatformDependent.putLong(minAddr, (minSwappedVal < newSwappedVal) ? minVal : newVal);
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example 19
Source File: LBlockHashTable.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method for inserting/searching the hash table.
 * For a given key, it first searches (linear probing) the hash table
 * If the key is not found and the caller indicates that the new key
 * has to be added, this function inserts the given key
 *
 * @param keyFixedAddr pointer to record in fixed key buffer
 * @param keyVarAddr pointer to record in variable key buffer
 * @param keyVarLen length of variable key
 * @param keyHash 32 bit hash
 * @param dataWidth width of data in fixed key buffer
 *
 * @return for find operation (ordinal if the key exists, -1 otherwise)
 *         for add operation (ordinal if the key exists or new ordinal after insertion or -2 if the caller should retry)
 */
private int probeOrInsert(final long keyFixedAddr, final long keyVarAddr, final int keyVarLen,
                          final int keyHash, final int dataWidth, final boolean insertNew) {
  final boolean fixedOnly =  this.fixedOnly;
  final int blockWidth = pivot.getBlockWidth();
  final long[] tableControlAddresses = this.tableControlAddresses;
  final long[] tableFixedAddresses = this.tableFixedAddresses;
  final long[] initVariableAddresses = this.initVariableAddresses;

  // start with a hash index.
  int controlIndex = keyHash & (capacity - 1);

  int controlChunkIndex = controlIndex >>> BITS_IN_CHUNK;
  int offsetInChunk = controlIndex & CHUNK_OFFSET_MASK;
  long tableControlAddr = tableControlAddresses[controlChunkIndex] + (offsetInChunk * CONTROL_WIDTH);
  long control = PlatformDependent.getLong(tableControlAddr);

  keyAbsent: if (control != LFREE) {
    int dataChunkIndex;
    long tableDataAddr;

    int ordinal = (int) control;
    if (keyHash == (int) (control >>> 32)){
      dataChunkIndex = ordinal >>> BITS_IN_CHUNK;
      offsetInChunk = ordinal & CHUNK_OFFSET_MASK;
      tableDataAddr = tableFixedAddresses[dataChunkIndex] + (offsetInChunk * blockWidth);
      if(fixedKeyEquals(keyFixedAddr, tableDataAddr, dataWidth) && (fixedOnly || variableKeyEquals(keyVarAddr, initVariableAddresses[dataChunkIndex] + PlatformDependent.getInt(tableDataAddr + dataWidth), keyVarLen))){
        return ordinal;
      }
    }

    while (true) {
      controlIndex = (controlIndex - 1) & (capacity - 1);
      controlChunkIndex = controlIndex >>> BITS_IN_CHUNK;
      offsetInChunk = controlIndex & CHUNK_OFFSET_MASK;
      tableControlAddr = tableControlAddresses[controlChunkIndex] + (offsetInChunk * CONTROL_WIDTH);
      control = PlatformDependent.getLong(tableControlAddr);

      if (control == LFREE) {
        break keyAbsent;
      } else if(keyHash == (int) (control >>> 32)){
        ordinal = (int) control;
        dataChunkIndex = ordinal >>> BITS_IN_CHUNK;
        offsetInChunk = ordinal & CHUNK_OFFSET_MASK;
        tableDataAddr = tableFixedAddresses[dataChunkIndex] + (offsetInChunk * blockWidth);
        if(fixedKeyEquals(keyFixedAddr, tableDataAddr, dataWidth) && (fixedOnly || variableKeyEquals(keyVarAddr, initVariableAddresses[dataChunkIndex] + PlatformDependent.getInt(tableDataAddr + dataWidth), keyVarLen))){
          // key is present
          return ordinal;
        }
      }

    }
  }

  // key not found
  if(!insertNew) {
    // caller doesn't want to add key so return
    return -1;
  } else {
    // caller wants to add key so insert
    return insert(blockWidth, tableControlAddr, keyHash, dataWidth, keyFixedAddr, keyVarAddr, keyVarLen);
  }
}
 
Example 20
Source File: DrillBuf.java    From Bats with Apache License 2.0 3 votes vote down vote up
/**
 * Read a long at position src+srcIndex and copy it to the dest+destIndex
 *
 * @param src source byte array
 * @param srcIndex source index
 * @param dest destination byte array
 * @param destIndex destination index
 */
public static void putLong(byte[] src, int srcIndex, byte[] dest, int destIndex) {
  check(srcIndex, LONG_NUM_BYTES, src.length);
  check(destIndex,LONG_NUM_BYTES, dest.length);

  long value = PlatformDependent.getLong(src, srcIndex);
  PlatformDependent.putLong(dest, destIndex, value);
}