本文整理汇总了Java中com.yahoo.memory.WritableMemory类的典型用法代码示例。如果您正苦于以下问题:Java WritableMemory类的具体用法?Java WritableMemory怎么用?Java WritableMemory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WritableMemory类属于com.yahoo.memory包,在下文中一共展示了WritableMemory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invalidSerVer
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Test
public void invalidSerVer() {
final int nRows = 3;
final int nCols = 3;
final Matrix m = generateIncreasingEye(nRows, nCols);
final byte[] sketchBytes = m.toByteArray();
final WritableMemory mem = WritableMemory.wrap(sketchBytes);
MatrixPreambleUtil.insertSerVer(mem.getArray(), mem.getCumulativeOffset(0L), 0);
try {
MatrixImplOjAlgo.heapifyInstance(mem);
fail();
} catch (final IllegalArgumentException e) {
// expected
}
}
示例2: invalidFamily
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Test
public void invalidFamily() {
final int nRows = 3;
final int nCols = 3;
final Matrix m = generateIncreasingEye(nRows, nCols);
final byte[] sketchBytes = m.toByteArray();
final WritableMemory mem = WritableMemory.wrap(sketchBytes);
MatrixPreambleUtil.insertFamilyID(mem.getArray(), mem.getCumulativeOffset(0L), 0);
try {
MatrixImplOjAlgo.heapifyInstance(mem);
fail();
} catch (final IllegalArgumentException e) {
// expected
}
}
示例3: invalidSerVer
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Test
public void invalidSerVer() {
final int nRows = 50;
final int nCols = 75;
final MatrixBuilder mb = new MatrixBuilder();
final Matrix m = mb.build(nRows, nCols);
final byte[] sketchBytes = m.toByteArray();
final WritableMemory mem = WritableMemory.wrap(sketchBytes);
MatrixPreambleUtil.insertSerVer(mem.getArray(), mem.getCumulativeOffset(0L), 0);
try {
MatrixPreambleUtil.preambleToString(mem);
fail();
} catch (final IllegalArgumentException e) {
// expected
}
}
示例4: invalidFamily
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Test
public void invalidFamily() {
final int nRows = 3;
final int nCols = 3;
final MatrixBuilder mb = new MatrixBuilder();
final Matrix m = mb.build(nRows, nCols);
final byte[] sketchBytes = m.toByteArray();
final WritableMemory mem = WritableMemory.wrap(sketchBytes);
MatrixPreambleUtil.insertFamilyID(mem.getArray(), mem.getCumulativeOffset(0L), 0);
try {
MatrixPreambleUtil.preambleToString(mem);
fail();
} catch (final IllegalArgumentException e) {
// expected
}
}
示例5: deserializeFromMemory
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Override
public Tuple[] deserializeFromMemory(final Memory mem, final int numItems) {
final byte[] bytes = (byte[]) ((WritableMemory) mem).getArray();
final int offset = (int) ((WritableMemory) mem).getRegionOffset(0L);
final int length = (int) mem.getCapacity();
final Tuple[] result = new Tuple[numItems];
try (final ByteArrayInputStream bais = new ByteArrayInputStream(bytes, offset, length);
final DataInputStream dis = new DataInputStream(bais)) {
for (int i = 0; i < numItems; ++i) {
// BinInterSedes is more efficient, but only suitable for intermediate data within a job.
// We know we're getting Tuples back in this case so cast is safe
result[i] = (Tuple) DataReaderWriter.readDatum(dis);
}
} catch (final IOException e) {
throw new RuntimeException("Error deserializing tuple: " + e.getMessage());
}
return result;
}
示例6: toByteArray
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
/**
* Returns a serialized representation of the sketch.
* @return A serialized representation of the sketch.
*/
public byte[] toByteArray() {
final boolean empty = isEmpty();
final int familyId = MatrixFamily.FREQUENTDIRECTIONS.getID();
final Matrix wrapB = Matrix.wrap(B_);
final int preLongs = empty
? MatrixFamily.FREQUENTDIRECTIONS.getMinPreLongs()
: MatrixFamily.FREQUENTDIRECTIONS.getMaxPreLongs();
final int mtxBytes = empty ? 0 : wrapB.getCompactSizeBytes(nextZeroRow_, d_);
final int outBytes = (preLongs * Long.BYTES) + mtxBytes;
final byte[] outArr = new byte[outBytes];
final WritableMemory memOut = WritableMemory.wrap(outArr);
final Object memObj = memOut.getArray();
final long memAddr = memOut.getCumulativeOffset(0L);
insertPreLongs(memObj, memAddr, preLongs);
insertSerVer(memObj, memAddr, SER_VER);
insertFamilyID(memObj, memAddr, familyId);
insertFlags(memObj, memAddr, (empty ? EMPTY_FLAG_MASK : 0));
insertK(memObj, memAddr, k_);
insertNumRows(memObj, memAddr, nextZeroRow_);
insertNumColumns(memObj, memAddr, d_);
if (empty) {
return outArr;
}
insertN(memObj, memAddr, n_);
insertSVAdjustment(memObj, memAddr, svAdjustment_);
memOut.putByteArray(preLongs * Long.BYTES,
wrapB.toCompactByteArray(nextZeroRow_, d_), 0, mtxBytes);
return outArr;
}
示例7: deserialise
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Override
public BoundedTimestampSet deserialise(final byte[] allBytes, final int offset, final int length) throws SerialisationException {
if (allBytes.length == 0 || length == 0) {
return null;
}
final ByteArrayInputStream bais = new ByteArrayInputStream(allBytes, offset, length);
final DataInputStream dis = new DataInputStream(bais);
final int bucketInt = (int) CompactRawSerialisationUtils.read(dis);
final CommonTimeUtil.TimeBucket bucket = CommonTimeUtil.TimeBucket.values()[bucketInt];
final int maxSize = (int) CompactRawSerialisationUtils.read(dis);
final BoundedTimestampSet boundedTimestampSet = new BoundedTimestampSet(bucket, maxSize);
try {
final byte state = dis.readByte();
if (NOT_FULL == state) {
final RBMBackedTimestampSet rbmBackedTimestampSet = new RBMBackedTimestampSet(bucket);
final RoaringBitmap rbm = new RoaringBitmap();
final byte[] serialisedRBM = new byte[bais.available()];
if (-1 == dis.read(serialisedRBM)) {
throw new SerialisationException("Unexpected end of stream when reading serialised RoaringBitmap");
}
final byte[] convertedBytes = RoaringBitmapUtils.upConvertSerialisedForm(serialisedRBM, 0, serialisedRBM.length);
final ByteArrayInputStream baisConvertedBytes = new ByteArrayInputStream(convertedBytes);
final DataInputStream disConvertedBytes = new DataInputStream(baisConvertedBytes);
rbm.deserialize(disConvertedBytes);
rbmBackedTimestampSet.setRbm(rbm);
boundedTimestampSet.setRbmBackedTimestampSet(rbmBackedTimestampSet);
} else if (SAMPLE == state) {
final byte[] serialisedRLU = new byte[dis.available()];
if (-1 == dis.read(serialisedRLU)) {
throw new SerialisationException("Unexpected end of stream when reading serialised ReservoirLongsUnion");
}
final ReservoirLongsUnion reservoirLongsUnion = ReservoirLongsUnion.heapify(WritableMemory.wrap(serialisedRLU));
boundedTimestampSet.setReservoirLongsUnion(reservoirLongsUnion);
} else {
throw new SerialisationException("Unexpected byte indicating the state: expected " + NOT_FULL + " or "
+ SAMPLE + ", got " + state);
}
} catch (final IOException e) {
throw new SerialisationException("IOException deserialising BoundedTimestampSet from byte array", e);
}
return boundedTimestampSet;
}
示例8: deserialise
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Override
public ItemsSketch<String> deserialise(final byte[] bytes) throws SerialisationException {
return ItemsSketch.getInstance(WritableMemory.wrap(bytes), SERIALISER);
}
示例9: deserialise
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Override
public LongsSketch deserialise(final byte[] bytes) throws SerialisationException {
return LongsSketch.getInstance(WritableMemory.wrap(bytes));
}
示例10: deserialise
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Override
public ItemsSketch<String> deserialise(final byte[] bytes) throws SerialisationException {
return ItemsSketch.getInstance(WritableMemory.wrap(bytes), Comparator.naturalOrder(), SERIALISER);
}
示例11: deserialise
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Override
public DoublesUnion deserialise(final byte[] bytes) throws SerialisationException {
final DoublesUnion union = DoublesUnion.builder().build();
union.update(WritableMemory.wrap(bytes));
return union;
}
示例12: deserialise
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Override
public ItemsUnion<String> deserialise(final byte[] bytes) throws SerialisationException {
return ItemsUnion.getInstance(WritableMemory.wrap(bytes), Comparator.naturalOrder(), SERIALISER);
}
示例13: deserialise
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Override
public Union deserialise(final byte[] bytes) throws SerialisationException {
final Union union = Sketches.setOperationBuilder().buildUnion();
union.update(WritableMemory.wrap(bytes));
return union;
}
示例14: deserialise
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Override
public ReservoirItemsUnion<Number> deserialise(final byte[] bytes) throws SerialisationException {
return ReservoirItemsUnion.heapify(WritableMemory.wrap(bytes), SERIALISER);
}
示例15: deserialise
import com.yahoo.memory.WritableMemory; //导入依赖的package包/类
@Override
public ReservoirLongsUnion deserialise(final byte[] bytes) throws SerialisationException {
return ReservoirLongsUnion.heapify(WritableMemory.wrap(bytes));
}