gpt4 book ai didi

com.yahoo.memory.WritableMemory.getCapacity()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-23 21:05:05 25 4
gpt4 key购买 nike

本文整理了Java中com.yahoo.memory.WritableMemory.getCapacity()方法的一些代码示例,展示了WritableMemory.getCapacity()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WritableMemory.getCapacity()方法的具体详情如下:
包路径:com.yahoo.memory.WritableMemory
类名称:WritableMemory
方法名:getCapacity

WritableMemory.getCapacity介绍

暂无

代码示例

代码示例来源:origin: DataSketches/sketches-core

@Override
int getCombinedBufferItemCapacity() {
 return ((int)mem_.getCapacity() - COMBINED_BUFFER) / 8;
}

代码示例来源:origin: DataSketches/sketches-core

@Override
int getCombinedBufferItemCapacity() {
 return ((int)mem_.getCapacity() - COMBINED_BUFFER) / 8;
}

代码示例来源:origin: DataSketches/sketches-core

@Override
void putMaxValue(final double maxValue) {
 assert (mem_.getCapacity() >= COMBINED_BUFFER);
 mem_.putDouble(MAX_DOUBLE, maxValue);
}

代码示例来源:origin: DataSketches/sketches-core

@Override
void putN(final long n) {
 assert (mem_.getCapacity() >= COMBINED_BUFFER);
 mem_.putLong(N_LONG, n);
}

代码示例来源:origin: DataSketches/sketches-core

@Override
void putMinValue(final double minValue) {
 assert (mem_.getCapacity() >= COMBINED_BUFFER);
 mem_.putDouble(MIN_DOUBLE, minValue);
}

代码示例来源:origin: DataSketches/sketches-core

@Override
public long getN() {
 return (mem_.getCapacity() < COMBINED_BUFFER) ? 0 : mem_.getLong(N_LONG);
}

代码示例来源:origin: DataSketches/sketches-core

@Override
void serializeInto(final WritableMemory mem) {
 mem_.copyTo(0, mem, 0, mem.getCapacity());
}

代码示例来源:origin: DataSketches/sketches-core

@Override
public long getN() {
 return (mem_.getCapacity() < COMBINED_BUFFER) ? 0 : mem_.getLong(N_LONG);
}

代码示例来源:origin: DataSketches/sketches-core

/**
 * Puts the current sketch into the given Memory if there is sufficient space.
 * Otherwise, throws an error.
 *
 * @param dstMem the given memory.
 * @param serDe an instance of ArrayOfItemsSerDe
 */
public void putMemory(final WritableMemory dstMem, final ArrayOfItemsSerDe<T> serDe) {
 final byte[] byteArr = toByteArray(serDe);
 final long memCap = dstMem.getCapacity();
 if (memCap < byteArr.length) {
  throw new SketchesArgumentException(
    "Destination Memory not large enough: " + memCap + " < " + byteArr.length);
 }
 dstMem.putByteArray(0, byteArr, 0, byteArr.length);
}

代码示例来源:origin: DataSketches/sketches-core

@Override
public void reset() {
 if (mem_.getCapacity() >= COMBINED_BUFFER) {
  mem_.putByte(FLAGS_BYTE, (byte) EMPTY_FLAG_MASK); //not compact, not ordered
  mem_.putLong(N_LONG, 0L);
  mem_.putDouble(MIN_DOUBLE, Double.NaN);
  mem_.putDouble(MAX_DOUBLE, Double.NaN);
 }
}

代码示例来源:origin: DataSketches/sketches-core

static void putEmptyMerged(final WritableMemory wmem,
  final int lgK,
  final short seedHash) {
 final Format format = Format.EMPTY_MERGED;
 final byte preInts = getDefinedPreInts(format);
 final byte fiCol = (byte) 0;
 final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
 checkCapacity(wmem.getCapacity(), 8);
 putFirst8(wmem, preInts, (byte) lgK, fiCol, flags, seedHash);
}

代码示例来源:origin: DataSketches/sketches-core

static void putEmptyHip(final WritableMemory wmem,
  final int lgK,
  final short seedHash) {
 final Format format = Format.EMPTY_HIP;
 final byte preInts = getDefinedPreInts(format);
 final byte fiCol = (byte) 0;
 final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
 checkCapacity(wmem.getCapacity(), 8);
 putFirst8(wmem, preInts, (byte) lgK, fiCol, flags, seedHash);
}

代码示例来源:origin: DataSketches/sketches-core

private WritableMemory growCombinedMemBuffer(final int itemSpaceNeeded) {
  final long memBytes = mem_.getCapacity();
  final int needBytes = (itemSpaceNeeded << 3) + COMBINED_BUFFER; //+ preamble + min & max
  assert needBytes > memBytes;

  memReqSvr = (memReqSvr == null) ? mem_.getMemoryRequestServer() : memReqSvr;

  final WritableMemory newMem = memReqSvr.request(needBytes);

  mem_.copyTo(0, newMem, 0, memBytes);

  memReqSvr.requestClose(mem_, newMem);

  return newMem;
 }
}

代码示例来源:origin: DataSketches/sketches-core

@Override
public UpdateDoublesSketch getResult(final WritableMemory dstMem) {
 final long memCapBytes = dstMem.getCapacity();
 if (gadget_ == null) {
  if (memCapBytes < DoublesSketch.getUpdatableStorageBytes(0, 0)) {
   throw new SketchesArgumentException("Insufficient capacity for result: " + memCapBytes);
  }
  return DirectUpdateDoublesSketch.newInstance(maxK_, dstMem);
 }
 gadget_.putMemory(dstMem, false);
 return DirectUpdateDoublesSketch.wrapInstance(dstMem);
}

代码示例来源:origin: DataSketches/sketches-core

/**
 * Constructs a new sketch with the type of HLL sketch to configure and the given
 * WritableMemory as the destination for the sketch. This WritableMemory is usually configured
 * for off-heap memory. What remains on the java heap is a thin wrapper object that reads and
 * writes to the given WritableMemory.
 *
 * <p>The given <i>dstMem</i> is checked for the required capacity as determined by
 * {@link #getMaxUpdatableSerializationBytes(int, TgtHllType)}.
 * @param lgConfigK The Log2 of K for the target HLL sketch. This value must be
 * between 4 and 21 inclusively.
 * @param tgtHllType the desired Hll type.
 * @param dstMem the destination memory for the sketch.
 */
public HllSketch(final int lgConfigK, final TgtHllType tgtHllType, final WritableMemory dstMem) {
 final long minBytes = getMaxUpdatableSerializationBytes(lgConfigK, tgtHllType);
 final long capBytes = dstMem.getCapacity();
 HllUtil.checkMemSize(minBytes, capBytes);
 dstMem.clear(0, minBytes);
 hllSketchImpl = DirectCouponList.newInstance(lgConfigK, tgtHllType, dstMem);
}

代码示例来源:origin: DataSketches/sketches-core

static void putPinnedSlidingMergedNoSv(final WritableMemory wmem,
  final int lgK,
  final int fiCol,
  final int numCoupons, //unsigned
  final int wLengthInts,
  final short seedHash,
  final int[] wStream) {
 final Format format = Format.PINNED_SLIDING_MERGED_NOSV;
 final byte preInts = getDefinedPreInts(format);
 final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
 checkCapacity(wmem.getCapacity(), 4L * (preInts + wLengthInts));
 putFirst8(wmem, preInts, (byte) lgK, (byte) fiCol, flags, seedHash);
 wmem.putInt(getHiFieldOffset(format, HiField.NUM_COUPONS), numCoupons);
 wmem.putInt(getHiFieldOffset(format, HiField.W_LENGTH_INTS), wLengthInts);
 wmem.putIntArray(getWStreamOffset(wmem), wStream, 0, wLengthInts);
}

代码示例来源:origin: DataSketches/sketches-core

static void putSparseHybridMerged(final WritableMemory wmem,
  final int lgK,
  final int numCoupons, //unsigned
  final int svLengthInts,
  final short seedHash,
  final int[] svStream) {
 final Format format = Format.SPARSE_HYBRID_MERGED;
 final byte preInts = getDefinedPreInts(format);
 final byte fiCol = (byte) 0;
 final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
 checkCapacity(wmem.getCapacity(), 4L * (preInts + svLengthInts));
 putFirst8(wmem, preInts, (byte) lgK, fiCol, flags, seedHash);
 wmem.putInt(getHiFieldOffset(format, HiField.NUM_COUPONS), numCoupons);
 wmem.putInt(getHiFieldOffset(format, HiField.SV_LENGTH_INTS), svLengthInts);
 wmem.putIntArray(getSvStreamOffset(wmem), svStream, 0, svLengthInts);
}

代码示例来源:origin: DataSketches/sketches-core

/**
 * @return a byte array representation of this object
 */
public byte[] toByteArray() {
 final int sizeBytes = PREAMBLE_SIZE_BYTES + sketch_.getSerializedSizeBytes();
 final byte[] byteArray = new byte[sizeBytes];
 final WritableMemory mem = WritableMemory.wrap(byteArray);
 mem.putByte(PREAMBLE_LONGS_BYTE, (byte) 1); // unused, always 1
 mem.putByte(SERIAL_VERSION_BYTE, serialVersionUID);
 mem.putByte(FAMILY_ID_BYTE, (byte) Family.TUPLE.getID());
 mem.putByte(SKETCH_TYPE_BYTE, (byte) SerializerDeserializer.SketchType.ArrayOfDoublesUnion.ordinal());
 mem.putLong(THETA_LONG, theta_);
 sketch_.serializeInto(mem.writableRegion(PREAMBLE_SIZE_BYTES, mem.getCapacity() - PREAMBLE_SIZE_BYTES));
 return byteArray;
}

代码示例来源:origin: DataSketches/sketches-core

@Test
public void checkGrowBaseBuf() {
 final int k = 128;
 final int u = 32; // don't need the BB to fill here
 final int initBytes = (4 + (u / 2)) << 3; // not enough to hold everything
 try (WritableDirectHandle memHandler = WritableMemory.allocateDirect(initBytes)) {
  //final MemoryManager memMgr = new MemoryManager();
  //final WritableMemory mem1 = memMgr.request(initBytes);
  final WritableMemory mem1 = memHandler.get();
  println("Initial mem size: " + mem1.getCapacity());
  final UpdateDoublesSketch usk1 = DoublesSketch.builder().setK(k).build(mem1);
  for (int i = 1; i <= u; i++) {
   usk1.update(i);
  }
  final int currentSpace = usk1.getCombinedBufferItemCapacity();
  println("curCombBufItemCap: " + currentSpace);
  assertEquals(currentSpace, 2 * k);
 }
}

代码示例来源:origin: DataSketches/sketches-core

static void putSparseHybridHip(final WritableMemory wmem,
  final int lgK,
  final int numCoupons, //unsigned
  final int svLengthInts,
  final double kxp,
  final double hipAccum,
  final short seedHash,
  final int[] svStream) {
 final Format format = Format.SPARSE_HYBRID_HIP;
 final byte preInts = getDefinedPreInts(format);
 final byte fiCol = (byte) 0;
 final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
 checkCapacity(wmem.getCapacity(), 4L * (preInts + svLengthInts));
 putFirst8(wmem, preInts, (byte) lgK, fiCol, flags, seedHash);
 wmem.putInt(getHiFieldOffset(format, HiField.NUM_COUPONS), numCoupons);
 wmem.putInt(getHiFieldOffset(format, HiField.SV_LENGTH_INTS), svLengthInts);
 wmem.putDouble(getHiFieldOffset(format, HiField.KXP), kxp);
 wmem.putDouble(getHiFieldOffset(format, HiField.HIP_ACCUM), hipAccum);
 wmem.putIntArray(getSvStreamOffset(wmem), svStream, 0, svLengthInts);
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com