gpt4 book ai didi

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

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

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

WritableMemory.putByteArray介绍

[英]Puts the byte array at the given offset
[中]

代码示例

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

@Override
public byte[] serializeToByteArray(final String[] items) {
 int length = 0;
 final byte[][] itemsBytes = new byte[items.length][];
 for (int i = 0; i < items.length; i++) {
  itemsBytes[i] = items[i].getBytes(StandardCharsets.UTF_8);
  length += itemsBytes[i].length + Integer.BYTES;
 }
 final byte[] bytes = new byte[length];
 final WritableMemory mem = WritableMemory.wrap(bytes);
 long offsetBytes = 0;
 for (int i = 0; i < items.length; i++) {
  mem.putInt(offsetBytes, itemsBytes[i].length);
  offsetBytes += Integer.BYTES;
  mem.putByteArray(offsetBytes, itemsBytes[i], 0, itemsBytes[i].length);
  offsetBytes += itemsBytes[i].length;
 }
 return bytes;
}

代码示例来源: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

private static final void insertHll(final AbstractHllArray impl, final WritableMemory wmem,
  final boolean compact) {
 insertCommonHll(impl, wmem, compact);
 final byte[] hllByteArr = ((HllArray)impl).hllByteArr;
 wmem.putByteArray(HLL_BYTE_ARR_START, hllByteArr, 0, hllByteArr.length);
 if (impl.getAuxHashMap() != null) {
  insertAux(impl, wmem, compact);
 } else {
  wmem.putInt(AUX_COUNT_INT, 0);
 }
}

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

static void byteArrToFile(byte[] byteArr, String fileName) throws Exception {
 String userDir = System.getProperty("user.dir");
 String fullPathName = userDir + "/src/test/resources/" + fileName;
 File file = new File(fullPathName);
 if (file.exists()) { Files.delete(file.toPath()); }
 assertTrue(file.createNewFile());
 assertTrue(file.setWritable(true, false));
 assertTrue(file.isFile());
 try (WritableMapHandle wmh
   = WritableMemory.map(file, 0, byteArr.length, ByteOrder.nativeOrder())) {
  WritableMemory wmem = wmh.get();
  wmem.putByteArray(0, byteArr, 0, byteArr.length);
  wmh.force();
 } catch (IOException e) {
  e.printStackTrace();
 }
}

代码示例来源: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 compact if true, compacts and sorts the base buffer, which optimizes merge
 *                performance at the cost of slightly increased serialization time.
 */
public void putMemory(final WritableMemory dstMem, final boolean compact) {
 if (isDirect() && (isCompact() == compact)) {
  final Memory srcMem = getMemory();
  srcMem.copyTo(0, dstMem, 0, getStorageBytes());
 } else {
  final byte[] byteArr = toByteArray(compact);
  final int arrLen = byteArr.length;
  final long memCap = dstMem.getCapacity();
  if (memCap < arrLen) {
   throw new SketchesArgumentException(
       "Destination Memory not large enough: " + memCap + " < " + arrLen);
  }
  dstMem.putByteArray(0, byteArr, 0, arrLen);
 }
}

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

final byte[] markBytes;
 markBytes = MARK_SERDE.serializeToByteArray(marks_.subList(0, h_).toArray(new Boolean[0]));
 mem.putByteArray(offset, markBytes, 0, markBytes.length);
 offset += markBytes.length;
mem.putByteArray(offset, itemBytes, 0, itemBytes.length);

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

@Test
public void checkNonEmptyDegenerateSketch() {
 // make an empty serialized sketch, then copy the items into a
 // PreambleUtil.VO_WARMUP_PRELONGS-sized byte array
 // so there'll be no items, then clear the empty flag so it will try to load
 // the rest.
 final VarOptItemsSketch<String> vis = VarOptItemsSketch.newInstance(12, ResizeFactor.X2);
 final byte[] sketchBytes = vis.toByteArray(new ArrayOfStringsSerDe());
 final byte[] dstByteArr = new byte[PreambleUtil.VO_WARMUP_PRELONGS << 3];
 final WritableMemory mem = WritableMemory.wrap(dstByteArr);
 mem.putByteArray(0, sketchBytes, 0, sketchBytes.length);
 // ensure non-empty but with H and R region sizes set to 0
 PreambleUtil.insertFlags(mem, 0); // set not-empty
 PreambleUtil.insertHRegionItemCount(mem, 0);
 PreambleUtil.insertRRegionItemCount(mem, 0);
 final VarOptItemsSketch<String> rebuilt
     = VarOptItemsSketch.heapify(mem, new ArrayOfStringsSerDe());
 assertNotNull(rebuilt);
 assertEquals(rebuilt.getNumSamples(), 0);
}

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

static <T> byte[] toByteArray(final ItemsSketch<T> sketch, final boolean ordered,
  final ArrayOfItemsSerDe<T> serDe) {
 final boolean empty = sketch.isEmpty();
 final int flags = (empty ? EMPTY_FLAG_MASK : 0)
   | (ordered ? ORDERED_FLAG_MASK : 0)
   | COMPACT_FLAG_MASK; //always compact
 if (empty) {
  final byte[] outByteArr = new byte[Long.BYTES];
  final WritableMemory memOut = WritableMemory.wrap(outByteArr);
  final int preLongs = 1;
  insertPre0(memOut, preLongs, flags, sketch.getK());
  return outByteArr;
 }
 //not empty
 final T[] dataArr = combinedBufferToItemsArray(sketch, ordered); //includes min and max
 final int preLongs = 2;
 final byte[] itemsByteArr = serDe.serializeToByteArray(dataArr);
 final int numOutBytes = (preLongs << 3) + itemsByteArr.length;
 final byte[] outByteArr = new byte[numOutBytes];
 final WritableMemory memOut = WritableMemory.wrap(outByteArr);
 //insert preamble
 insertPre0(memOut, preLongs, flags, sketch.getK());
 insertN(memOut, sketch.getN());
 //insert data
 memOut.putByteArray(preLongs << 3, itemsByteArr, 0, itemsByteArr.length);
 return outByteArr;
}

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

mem.putByteArray(preBytes, gadgetBytes, 0, gadgetBytes.length);

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

mem.putByteArray(preBytes, gadgetBytes, 0, gadgetBytes.length);

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

mem.putByteArray(preBytes, bytes, 0, bytes.length);

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

mem.putByteArray(preBytes, gadgetBytes, 0, gadgetBytes.length);

代码示例来源:origin: com.yahoo.datasketches/sketches-core

@Override
public byte[] serializeToByteArray(final String[] items) {
 int length = 0;
 final byte[][] itemsBytes = new byte[items.length][];
 for (int i = 0; i < items.length; i++) {
  itemsBytes[i] = items[i].getBytes(StandardCharsets.UTF_8);
  length += itemsBytes[i].length + Integer.BYTES;
 }
 final byte[] bytes = new byte[length];
 final WritableMemory mem = WritableMemory.wrap(bytes);
 long offsetBytes = 0;
 for (int i = 0; i < items.length; i++) {
  mem.putInt(offsetBytes, itemsBytes[i].length);
  offsetBytes += Integer.BYTES;
  mem.putByteArray(offsetBytes, itemsBytes[i], 0, itemsBytes[i].length);
  offsetBytes += itemsBytes[i].length;
 }
 return bytes;
}

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

final int preBytes = preLongs << 3;
mem.putLongArray(preBytes, hashMap.getActiveValues(), 0, activeItems);
mem.putByteArray(preBytes + (this.getNumActiveItems() << 3), bytes, 0, bytes.length);

代码示例来源:origin: com.yahoo.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: com.yahoo.datasketches/sketches-core

private static final void insertHll(final AbstractHllArray impl, final WritableMemory wmem,
  final boolean compact) {
 insertCommonHll(impl, wmem, compact);
 final byte[] hllByteArr = ((HllArray)impl).hllByteArr;
 wmem.putByteArray(HLL_BYTE_ARR_START, hllByteArr, 0, hllByteArr.length);
 if (impl.getAuxHashMap() != null) {
  insertAux(impl, wmem, compact);
 } else {
  wmem.putInt(AUX_COUNT_INT, 0);
 }
}

代码示例来源:origin: com.yahoo.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 compact if true, compacts and sorts the base buffer, which optimizes merge
 *                performance at the cost of slightly increased serialization time.
 */
public void putMemory(final WritableMemory dstMem, final boolean compact) {
 if (isDirect() && (isCompact() == compact)) {
  final Memory srcMem = getMemory();
  srcMem.copyTo(0, dstMem, 0, getStorageBytes());
 } else {
  final byte[] byteArr = toByteArray(compact);
  final int arrLen = byteArr.length;
  final long memCap = dstMem.getCapacity();
  if (memCap < arrLen) {
   throw new SketchesArgumentException(
       "Destination Memory not large enough: " + memCap + " < " + arrLen);
  }
  dstMem.putByteArray(0, byteArr, 0, arrLen);
 }
}

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

gadgetWmem.clear(0, bytes);
final byte[] dstByteArr = dstImpl.toUpdatableByteArray();
gadgetWmem.putByteArray(0, dstByteArr, 0, dstByteArr.length);
dstImpl = HllSketch.writableWrap(gadgetWmem).hllSketchImpl;

代码示例来源:origin: com.yahoo.datasketches/sketches-core

static <T> byte[] toByteArray(final ItemsSketch<T> sketch, final boolean ordered,
  final ArrayOfItemsSerDe<T> serDe) {
 final boolean empty = sketch.isEmpty();
 final int flags = (empty ? EMPTY_FLAG_MASK : 0)
   | (ordered ? ORDERED_FLAG_MASK : 0)
   | COMPACT_FLAG_MASK; //always compact
 if (empty) {
  final byte[] outByteArr = new byte[Long.BYTES];
  final WritableMemory memOut = WritableMemory.wrap(outByteArr);
  final int preLongs = 1;
  insertPre0(memOut, preLongs, flags, sketch.getK());
  return outByteArr;
 }
 //not empty
 final T[] dataArr = combinedBufferToItemsArray(sketch, ordered); //includes min and max
 final int preLongs = 2;
 final byte[] itemsByteArr = serDe.serializeToByteArray(dataArr);
 final int numOutBytes = (preLongs << 3) + itemsByteArr.length;
 final byte[] outByteArr = new byte[numOutBytes];
 final WritableMemory memOut = WritableMemory.wrap(outByteArr);
 //insert preamble
 insertPre0(memOut, preLongs, flags, sketch.getK());
 insertN(memOut, sketch.getN());
 //insert data
 memOut.putByteArray(preLongs << 3, itemsByteArr, 0, itemsByteArr.length);
 return outByteArr;
}

代码示例来源:origin: com.yahoo.datasketches/sketches-core

mem.putByteArray(preBytes, gadgetBytes, 0, gadgetBytes.length);

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