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

x33g5p2x  于2022-02-03 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(104)

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

WritableMemory.putByte介绍

[英]Puts the byte value at the given offset
[中]将字节值置于给定偏移量

代码示例

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

static void insertPreLongs(final WritableMemory wmem, final int preLongs) {
 final int curByte = wmem.getByte(PREAMBLE_LONGS_BYTE);
 final int mask = 0x3F;
 final byte newByte = (byte) ((preLongs & mask) | (~mask & curByte));
 wmem.putByte(PREAMBLE_LONGS_BYTE, newByte);
}

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

static void insertEmptyFlag(final WritableMemory wmem, final boolean empty) {
 int flags = wmem.getByte(FLAGS_BYTE);
 if (empty) { flags |= EMPTY_FLAG_MASK; }
 else { flags &= ~EMPTY_FLAG_MASK; }
 wmem.putByte(FLAGS_BYTE, (byte) flags);
}

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

@Override
final void putSlot(final int slotNo, final int newValue) {
 final long offset = HLL_BYTE_ARR_START + (slotNo >>> 1);
 final int oldValue = mem.getByte(offset);
 final byte value = ((slotNo & 1) == 0) //even?
   ? (byte) ((oldValue & hiNibbleMask) | (newValue & loNibbleMask)) //set low nibble
   : (byte) ((oldValue & loNibbleMask) | ((newValue << 4) & hiNibbleMask)); //set high nibble
 wmem.putByte(offset, value);
}

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

static void insertLgResizeFactor(final WritableMemory wmem, final int rf) {
 final int curByte = wmem.getByte(PREAMBLE_LONGS_BYTE) & 0xFF;
 final int shift = LG_RESIZE_FACTOR_BIT; // shift in bits
 final int mask = 3;
 final byte newByte = (byte) (((rf & mask) << shift) | (~(mask << shift) & curByte));
 wmem.putByte(PREAMBLE_LONGS_BYTE, newByte);
}

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

static void setEmpty(final WritableMemory wmem) {
 int flags = wmem.getByte(FLAGS_BYTE) & 0XFF;
 flags |= EMPTY_FLAG_MASK;
 wmem.putByte(FLAGS_BYTE, (byte) flags);
}

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

private static void putFirst8(final WritableMemory wmem, final byte preInts, final byte lgK,
  final byte fiCol, final byte flags, final short seedHash) {
 wmem.clear(0L, 4L * preInts);
 wmem.putByte(getLoFieldOffset(LoField.PRE_INTS), preInts);
 wmem.putByte(getLoFieldOffset(LoField.SER_VERSION), SER_VER);
 wmem.putByte(getLoFieldOffset(LoField.FAMILY), (byte) Family.CPC.getID());
 wmem.putByte(getLoFieldOffset(LoField.LG_K), lgK);
 wmem.putByte(getLoFieldOffset(LoField.FI_COL), fiCol);
 wmem.putByte(getLoFieldOffset(LoField.FLAGS), flags);
 wmem.putShort(getLoFieldOffset(LoField.SEED_HASH), seedHash);
}

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

static void insertTgtHllType(final WritableMemory wmem, final TgtHllType tgtHllType) {
 final int typeId = tgtHllType.ordinal();
 int mode = wmem.getByte(MODE_BYTE) & ~TGT_HLL_TYPE_MASK; //strip bits 2, 3
 mode |= (typeId << 2) & TGT_HLL_TYPE_MASK;
 wmem.putByte(MODE_BYTE, (byte) mode);
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadFamily() {
 final WritableMemory mem = getBasicSerializedRLS();
 mem.putByte(FAMILY_BYTE, (byte) 0); // corrupt the family ID
 ReservoirLongsSketch.heapify(mem);
 fail();
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadSerVer() {
 final WritableMemory mem = getBasicSerializedRLS();
 mem.putByte(SER_VER_BYTE, (byte) 0); // corrupt the serialization version
 ReservoirLongsSketch.heapify(mem);
 fail();
}

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

@Test
public void checkStreamErrors() {
 WritableMemory wmem = WritableMemory.allocate(4 * 10);
 putEmptyMerged(wmem, (byte) 12, defaultSeedHash);
 try { getSvStreamOffset(wmem); fail(); } catch (SketchesArgumentException e) { }
 wmem.putByte(5, (byte) (7 << 2));
 try { getSvStreamOffset(wmem); fail(); } catch (SketchesStateException e) { }
 wmem.putByte(5, (byte) 0);
 try { getWStreamOffset(wmem); fail(); } catch (SketchesArgumentException e) { }
 wmem.putByte(5, (byte) (7 << 2));
 try { getWStreamOffset(wmem); fail(); } catch (SketchesStateException e) { }
}

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

private static void tryBadMem(WritableMemory mem, int byteOffset, int byteValue) {
 ArrayOfLongsSerDe serDe = new ArrayOfLongsSerDe();
 try {
  mem.putByte(byteOffset, (byte) byteValue); //Corrupt
  ItemsSketch.getInstance(mem, serDe);
  fail();
 } catch (SketchesArgumentException e) {
  //expected
 }
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadPreLongs() {
 final WritableMemory mem = getBasicSerializedLongsRIS();
 mem.putByte(PREAMBLE_LONGS_BYTE, (byte) 0); // corrupt the preLongs count
 ReservoirItemsSketch.heapify(mem, new ArrayOfLongsSerDe());
 fail();
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadSerVer() {
 final WritableMemory mem = getBasicSerializedLongsRIS();
 mem.putByte(SER_VER_BYTE, (byte) 0); // corrupt the serialization version
 ReservoirItemsSketch.heapify(mem, new ArrayOfLongsSerDe());
 fail();
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadLgNomLongs() {
 int k = 16;
 lgK = 4;
 WritableMemory mem = WritableMemory.wrap(new byte[(k*16) +24]);
 buildConcSketch(mem);
 mem.putByte(LG_NOM_LONGS_BYTE, (byte) 3); //Corrupt LgNomLongs byte
 DirectQuickSelectSketch.writableWrap(mem, DEFAULT_UPDATE_SEED);
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadFamily() {
 final ReservoirLongsUnion rlu = ReservoirLongsUnion.newInstance(1024);
 final WritableMemory mem = WritableMemory.wrap(rlu.toByteArray());
 mem.putByte(FAMILY_BYTE, (byte) 0); // corrupt the family ID
 ReservoirLongsUnion.heapify(mem);
 fail();
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkHeapifyCorruptLgNomLongs() {
 lgK = 4;
 UpdateSketch usk = buildConcSketch();
 WritableMemory srcMem = WritableMemory.wrap(usk.toByteArray());
 srcMem.putByte(LG_NOM_LONGS_BYTE, (byte)2); //corrupt
 Sketch.heapify(srcMem, DEFAULT_UPDATE_SEED);
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkWrapIllegalFamilyID_direct() {
 lgK = 9;
 int k = 1 << lgK;
 int maxBytes = (k << 4) + (Family.QUICKSELECT.getMinPreLongs() << 3);
 WritableMemory mem = WritableMemory.wrap(new byte[maxBytes]);
 buildConcSketch(mem);
 mem.putByte(FAMILY_BYTE, (byte) 0); //corrupt the Sketch ID byte
 //try to wrap the corrupted mem
 DirectQuickSelectSketch.writableWrap(mem, DEFAULT_UPDATE_SEED);
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadSerVer() {
 final ReservoirItemsUnion<String> riu = ReservoirItemsUnion.newInstance(1024);
 final WritableMemory mem = WritableMemory.wrap(riu.toByteArray(new ArrayOfStringsSerDe()));
 mem.putByte(SER_VER_BYTE, (byte) 0); // corrupt the serialization version
 ReservoirItemsUnion.heapify(mem, new ArrayOfStringsSerDe());
 fail();
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkHeapifyCorruptLgNomLongs() {
 UpdateSketch usk = UpdateSketch.builder().setNominalEntries(16).build();
 WritableMemory srcMem = WritableMemory.wrap(usk.toByteArray());
 srcMem.putByte(LG_NOM_LONGS_BYTE, (byte)2); //corrupt
 Sketch.heapify(srcMem, DEFAULT_UPDATE_SEED);
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkWrapIllegalFamilyID_wrap() {
 int k = 512;
 int maxBytes = (k << 4) + (Family.QUICKSELECT.getMinPreLongs() << 3);
 WritableMemory mem = WritableMemory.wrap(new byte[maxBytes]);
 UpdateSketch.builder().setNominalEntries(k).build(mem);
 mem.putByte(FAMILY_BYTE, (byte) 0); //corrupt the Sketch ID byte
 //try to wrap the corrupted mem
 Sketch.wrap(mem); //catch in Sketch.constructDirectSketch
}

相关文章